+ if (sptr->cfAuth.length())
+ {
+ // A CF target
+ b->set_option("user", sptr->cfAuth.c_str());
+ if (authentication.length() && db_args.length() == 0)
+ {
+ // no database (auth) args specified already.. and the
+ // Torus authentication has it.. Generate the args that CF
+ // understands..
+ size_t found = authentication.find('/');
+ if (found != std::string::npos)
+ {
+ db_args += "user=" + mp::util::uri_encode(authentication.substr(0, found))
+ + "&password=" + mp::util::uri_encode(authentication.substr(found+1));
+ }
+ else
+ db_args += "user=" + mp::util::uri_encode(authentication);
+ }
+ }
+ else
+ {
+ // A non-CF target
+ if (db_args.length())
+ {
+ // user has specified backend authentication
+ const char *param_user = 0;
+ const char *param_password = 0;
+ char **names;
+ char **values;
+ int i;
+ int no_parms = yaz_uri_to_array(db_args.c_str(),
+ odr, &names, &values);
+ for (i = 0; i < no_parms; i++)
+ {
+ const char *name = names[i];
+ const char *value = values[i];
+ if (!strcmp(name, "user"))
+ param_user = value;
+ else if (!strcmp(name, "password"))
+ param_password = value;
+ else
+ {
+ BackendPtr notfound;
+ char *msg = (char*) odr_malloc(odr, strlen(name) + 30);
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ sprintf(msg, "Bad database argument: %s", name);
+ *addinfo = msg;
+ return notfound;
+ }
+ }
+ if (param_user && param_password)
+ {
+ char *auth = (char*) odr_malloc(
+ odr, strlen(param_user) + strlen(param_password) + 2);
+ strcpy(auth, param_user);
+ strcat(auth, "/");
+ strcat(auth, param_password);
+ b->set_option("user", auth);
+ }
+ db_args.clear(); // no arguments to be passed (non-CF)
+ }
+ else
+ {
+ // use authentication from Torus, if given
+ if (authentication.length())
+ b->set_option("user", authentication.c_str());
+ }
+ }
+ if (sptr->cfProxy.length())
+ {
+ if (db_args.length())
+ db_args += "&";
+ db_args += "proxy=" + mp::util::uri_encode(sptr->cfProxy);
+ }
+ if (sptr->cfSubDb.length())
+ {
+ if (db_args.length())
+ db_args += "&";
+ db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb);
+ }
+