+ 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", "1"); /* some SRU servers INSIST on getting
+ maximumRecords > 0 */
+ b->set_option("piggyback", sptr->piggyback ? "1" : "0");
+
+ if (authentication.length() == 0)
+ authentication = sptr->authentication;
+
+ if (proxy.length() == 0)
+ proxy = sptr->cfProxy;
+
+ 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(); // Only x-args to be passed (non-CF)
+ if (x_args)
+ db_args = x_args;
+
+ 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;
+
+ FILE *file = fopen(fname, "w");
+ if (!file)
+ {
+ package.log("zoom", 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, "auth: %s\n", authentication.c_str());
+ if (proxy.length())
+ wrbuf_printf(w, "proxy: %s\n", proxy.c_str());
+ if (sptr->cfProxy.length())
+ wrbuf_printf(w, "cfproxy: %s\n", sptr->cfProxy.c_str());
+
+ fwrite(wrbuf_buf(w), 1, wrbuf_len(w), file);
+ fclose(file);
+ package.log("zoom", YLOG_LOG, "file %s created\n", fname);
+ xfree(fname);
+ }