+
+ if (explain_xslt_fname.length())
+ {
+ const char *path = 0;
+
+ if (xsldir.length())
+ path = xsldir.c_str();
+ else
+ path = file_path.c_str();
+
+ char fullpath[1024];
+ char *cp = yaz_filepath_resolve(explain_xslt_fname.c_str(),
+ path, 0, fullpath);
+ if (!cp)
+ {
+ throw mp::filter::FilterException
+ ("Cannot read XSLT " + explain_xslt_fname);
+ }
+
+ xmlDoc *xsp_doc = xmlParseFile(cp);
+ if (!xsp_doc)
+ {
+ throw mp::filter::FilterException
+ ("Cannot parse XSLT " + explain_xslt_fname);
+ }
+
+ explain_xsp = xsltParseStylesheetDoc(xsp_doc);
+ if (!explain_xsp)
+ {
+ xmlFreeDoc(xsp_doc);
+ throw mp::filter::FilterException
+ ("Cannot parse XSLT " + explain_xslt_fname);
+
+ }
+ }
+
+ if (record_xslt_fname.length())
+ {
+ const char *path = 0;
+
+ if (xsldir.length())
+ path = xsldir.c_str();
+ else
+ path = file_path.c_str();
+
+ char fullpath[1024];
+ char *cp = yaz_filepath_resolve(record_xslt_fname.c_str(),
+ path, 0, fullpath);
+ if (!cp)
+ {
+ throw mp::filter::FilterException
+ ("Cannot read XSLT " + record_xslt_fname);
+ }
+
+ xmlDoc *xsp_doc = xmlParseFile(cp);
+ if (!xsp_doc)
+ {
+ throw mp::filter::FilterException
+ ("Cannot parse XSLT " + record_xslt_fname);
+ }
+
+ record_xsp = xsltParseStylesheetDoc(xsp_doc);
+ if (!record_xsp)
+ {
+ xmlFreeDoc(xsp_doc);
+ throw mp::filter::FilterException
+ ("Cannot parse XSLT " + record_xslt_fname);
+
+ }
+ }
+}
+
+bool yf::Zoom::Frontend::create_content_session(mp::Package &package,
+ BackendPtr b,
+ int *error, char **addinfo,
+ ODR odr,
+ std::string authentication,
+ std::string proxy,
+ std::string realm)
+{
+ if (b->sptr->contentConnector.length())
+ {
+ std::string proxyhostname;
+ std::string tmp_file;
+ bool legacy_format = false;
+
+ if (m_p->content_proxy_server.length())
+ {
+ proxyhostname = m_p->content_proxy_server;
+ legacy_format = true;
+ }
+
+ if (m_p->content_tmp_file.length())
+ tmp_file = m_p->content_tmp_file;
+
+ if (m_p->content_config_file.length())
+ {
+ FILE *inf = fopen(m_p->content_config_file.c_str(), "r");
+ if (inf)
+ {
+ char buf[1024];
+ while (fgets(buf, sizeof(buf)-1, inf))
+ {
+ char *cp;
+ cp = strchr(buf, '#');
+ if (cp)
+ *cp = '\0';
+ cp = strchr(buf, '\n');
+ if (cp)
+ *cp = '\0';
+ cp = strchr(buf, ':');
+ if (cp)
+ {
+ char *cp1 = cp;
+ while (cp1 != buf && cp1[-1] == ' ')
+ cp1--;
+ *cp1 = '\0';
+ cp++;
+ while (*cp == ' ')
+ cp++;
+ if (!strcmp(buf, "proxyhostname"))
+ proxyhostname = cp;
+ if (!strcmp(buf, "sessiondir") && *cp)
+ {
+ if (cp[strlen(cp)-1] == '/')
+ cp[strlen(cp)-1] = '\0';
+ tmp_file = std::string(cp) + std::string("/cf.XXXXXX.p");
+ }
+ }
+ }
+ fclose(inf);
+ }
+ else
+ {
+ package.log("zoom", YLOG_WARN|YLOG_ERRNO,
+ "unable to open content config %s",
+ m_p->content_config_file.c_str());
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *addinfo = (char *) odr_malloc(odr, 60 + tmp_file.length());
+ sprintf(*addinfo, "unable to open content config %s",
+ m_p->content_config_file.c_str());
+ return false;
+ }
+ }
+
+ if (proxyhostname.length() == 0)
+ {
+ package.log("zoom", YLOG_WARN, "no proxyhostname");
+ return true;
+ }
+ if (tmp_file.length() == 0)
+ {
+ package.log("zoom", YLOG_WARN, "no tmp_file");
+ return true;
+ }
+
+ char *fname = xstrdup(tmp_file.c_str());
+ char *xx = strstr(fname, "XXXXXX");
+ if (!xx)
+ {
+ package.log("zoom", YLOG_WARN, "bad tmp_file %s", tmp_file.c_str());
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *addinfo = (char *) odr_malloc(odr, 60 + tmp_file.length());
+ sprintf(*addinfo, "bad format of content tmp_file: %s",
+ tmp_file.c_str());
+ xfree(fname);
+ return false;
+ }
+ char tmp_char = xx[6];
+ sprintf(xx, "%06d", ((unsigned) rand()) % 1000000);
+ if (legacy_format)
+ b->cproxy_host = std::string(xx) + "." + proxyhostname;
+ else
+ b->cproxy_host = proxyhostname + "/" + xx;
+ 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);
+ return false;
+ }
+ mp::wrbuf w;
+ 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 (realm.length())
+ wrbuf_printf(w, "realm: %s\n", realm.c_str());
+
+ fwrite(w.buf(), 1, w.len(), file);
+ fclose(file);
+ package.log("zoom", YLOG_LOG, "content file: %s", fname);
+ xfree(fname);
+ }
+ return true;