+
+std::string mp_util::zQueryToString(Z_Query *query)
+{
+ std::string query_str = "";
+
+ if (query && query->which == Z_Query_type_1)
+ {
+ Z_RPNQuery *rpn = query->u.type_1;
+
+ if (rpn)
+ {
+ mp::wrbuf w;
+
+ // put query in w
+ yaz_rpnquery_to_wrbuf(w, rpn);
+
+ // from w to std::string
+ query_str = std::string(w.buf(), w.len());
+ }
+ }
+
+#if 0
+ if (query && query->which == Z_Query_type_1){
+
+ // allocate wrbuf (strings in YAZ!)
+ WRBUF w = wrbuf_alloc();
+
+ // put query in w
+ yaz_query_to_wrbuf(w, query);
+
+ // from w to std::string
+ query_str = std::string(wrbuf_buf(w), wrbuf_len(w));
+
+ // destroy wrbuf
+ wrbuf_free(w, 1);
+ }
+#endif
+ return query_str;
+}
+
+void mp_util::get_default_diag(Z_DefaultDiagFormat *r,
+ int &error_code, std::string &addinfo)
+{
+ error_code = *r->condition;
+ switch (r->which)
+ {
+ case Z_DefaultDiagFormat_v2Addinfo:
+ addinfo = std::string(r->u.v2Addinfo);
+ break;
+ case Z_DefaultDiagFormat_v3Addinfo:
+ addinfo = r->u.v3Addinfo;
+ break;
+ }
+}
+
+void mp_util::get_init_diagnostics(
+ Z_InitResponse *initrs, int &error_code, std::string &addinfo)
+{
+
+ Z_DefaultDiagFormat *df = yaz_decode_init_diag(0, initrs);
+
+ if (df)
+ get_default_diag(df, error_code, addinfo);
+}
+
+int mp_util::get_or_remove_vhost_otherinfo(
+ Z_OtherInformation **otherInformation,
+ bool remove_flag,
+ std::list<std::string> &vhosts)
+{
+ int cat;
+ for (cat = 1; ; cat++)
+ {
+ // check virtual host
+ const char *vhost =
+ yaz_oi_get_string_oid(otherInformation,
+ yaz_oid_userinfo_proxy,
+ cat /* categoryValue */,
+ remove_flag /* delete flag */);
+ if (!vhost)
+ break;
+ vhosts.push_back(std::string(vhost));
+ }
+ --cat;
+ return cat;
+}
+
+void mp_util::get_vhost_otherinfo(
+ Z_OtherInformation *otherInformation,
+ std::list<std::string> &vhosts)
+{
+ get_or_remove_vhost_otherinfo(&otherInformation, false, vhosts);
+}
+
+int mp_util::remove_vhost_otherinfo(
+ Z_OtherInformation **otherInformation,
+ std::list<std::string> &vhosts)
+{
+ return get_or_remove_vhost_otherinfo(otherInformation, true, vhosts);
+}
+
+void mp_util::set_vhost_otherinfo(
+ Z_OtherInformation **otherInformation, ODR odr,
+ const std::list<std::string> &vhosts)
+{
+ int cat;
+ std::list<std::string>::const_iterator it = vhosts.begin();
+
+ for (cat = 1; it != vhosts.end() ; cat++, it++)
+ {
+ yaz_oi_set_string_oid(otherInformation, odr,
+ yaz_oid_userinfo_proxy, cat, it->c_str());
+ }
+}
+
+void mp_util::set_vhost_otherinfo(
+ Z_OtherInformation **otherInformation, ODR odr,
+ const std::string vhost, const int cat)
+{
+ yaz_oi_set_string_oid(otherInformation, odr,
+ yaz_oid_userinfo_proxy, cat, vhost.c_str());
+}
+
+void mp_util::split_zurl(std::string zurl, std::string &host,
+ std::list<std::string> &db)
+{
+ const char *zurl_cstr = zurl.c_str();
+ const char *args = 0;
+ cs_get_host_args(zurl_cstr, &args);
+
+ if (args && *args)
+ {
+ host = std::string(zurl_cstr, args - zurl_cstr);
+
+ const char *cp1 = args;
+ while (1)
+ {
+ const char *cp2 = strchr(cp1, '+');
+ if (cp2)
+ db.push_back(std::string(cp1, cp2 - cp1));
+ else
+ {
+ db.push_back(std::string(cp1));
+ break;
+ }
+ cp1 = cp2+1;
+ }
+ }
+ else
+ host = zurl;
+}
+
+bool mp_util::set_databases_from_zurl(
+ ODR odr, std::string zurl,
+ int *db_num, char ***db_strings)
+{
+ std::string host;
+ std::list<std::string> dblist;
+
+ split_zurl(zurl, host, dblist);
+
+ if (dblist.size() == 0)
+ return false;
+ *db_num = dblist.size();
+ *db_strings = (char **) odr_malloc(odr, sizeof(char*) * (*db_num));
+
+ std::list<std::string>::const_iterator it = dblist.begin();
+ for (int i = 0; it != dblist.end(); it++, i++)
+ (*db_strings)[i] = odr_strdup(odr, it->c_str());
+ return true;
+}
+
+mp::odr::odr(int type)