+ b->set_option("rpnCharset", sptr->query_encoding);
+
+ b->set_option("timeout", "40");
+
+ if (m_p->apdu_log)
+ b->set_option("apdulog", "1");
+
+ if (sptr->piggyback)
+ b->set_option("count", "10");
+ b->set_option("piggyback", sptr->piggyback ? "1" : "0");
+
+ std::string authentication = sptr->authentication;
+ std::string proxy = sptr->cfProxy;
+
+ const char *param_user = 0;
+ const char *param_password = 0;
+ const char *param_proxy = 0;
+ if (db_args.length())
+ {
+ 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 if (!strcmp(name, "proxy"))
+ param_proxy = value;
+ else if (!strcmp(name, "cproxysession"))
+ ;
+ 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)
+ {
+ authentication = std::string(param_user);
+ if (param_password)
+ authentication += "/" + std::string(param_password);
+ }
+ if (param_proxy)
+ proxy = param_proxy;
+ }
+
+ if (sptr->cfAuth.length())
+ {
+ // A CF target
+ b->set_option("user", sptr->cfAuth);
+ if (!param_user && !param_password && authentication.length())
+ {
+ if (db_args.length())
+ db_args += "&";
+ // 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);
+ }
+ if (!param_proxy && proxy.length())
+ {
+ if (db_args.length())
+ db_args += "&";
+ db_args += "proxy=" + mp::util::uri_encode(proxy);
+ }
+ if (sptr->cfSubDb.length())
+ {
+ if (db_args.length())
+ db_args += "&";
+ db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb);
+ }
+ }
+ else
+ {
+ db_args.clear(); // no arguments to be passed (non-CF)
+
+ size_t found = authentication.find('/');
+
+ if (sptr->sru.length() && found != std::string::npos)
+ {
+ b->set_option("user", authentication.substr(0, found));
+ b->set_option("password", authentication.substr(found+1));
+ }
+ else
+ b->set_option("user", authentication);
+
+ if (proxy.length())
+ b->set_option("proxy", proxy);
+ }
+ if (b->sptr->contentConnector.length())
+ {
+ char *fname = (char *) xmalloc(m_p->content_tmp_file.length() + 8);
+ strcpy(fname, m_p->content_tmp_file.c_str());
+ char *xx = strstr(fname, "XXXXXX");
+ if (!xx)
+ {
+ xx = fname + strlen(fname);
+ strcat(fname, "XXXXXX");
+ }
+ char tmp_char = xx[6];
+ sprintf(xx, "%06d", ((unsigned) rand()) % 1000000);
+ xx[6] = tmp_char;
+
+ int fd = creat(fname, 0666);
+ if (fd == -1)
+ {
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "create %s", fname);
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *addinfo = (char *) odr_malloc(odr, 40 + strlen(fname));
+ sprintf(*addinfo, "Could not create %s", fname);
+ xfree(fname);
+ BackendPtr backend_null;
+ return backend_null;
+ }
+ b->content_session_id.assign(xx, 6);
+ WRBUF w = wrbuf_alloc();
+ wrbuf_puts(w, "#content_proxy\n");
+ wrbuf_printf(w, "connector: %s\n", b->sptr->contentConnector.c_str());
+ if (authentication.length())
+ wrbuf_printf(w, "authentication: %s\n", authentication.c_str());
+ if (proxy.length())
+ wrbuf_printf(w, "proxy: %s\n", proxy.c_str());
+ if (sptr->cfAuth.length())
+ wrbuf_printf(w, "cfauth: %s\n", sptr->cfAuth.c_str());
+ if (sptr->cfProxy.length())
+ wrbuf_printf(w, "cfproxy: %s\n", sptr->cfProxy.c_str());
+
+ write(fd, wrbuf_buf(w), wrbuf_len(w));
+ close(fd);
+ yaz_log(YLOG_LOG, "file %s created\n", fname);
+ xfree(fname);
+ }