+
+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){
+
+ // allocate wrbuf (strings in YAZ!)
+ WRBUF w = wrbuf_alloc();
+
+ // put query in w
+ yaz_rpnquery_to_wrbuf(w, rpn);
+
+ // from w to std::string
+ query_str = std::string(wrbuf_buf(w), wrbuf_len(w));
+
+ // destroy wrbuf
+ wrbuf_free(w, 1);
+ }
+ }
+
+#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_External *uif = initrs->userInformationField;
+
+ if (uif && uif->which == Z_External_userInfo1)
+ {
+ Z_OtherInformation *ui = uif->u.userInfo1;
+ int i;
+ for (i = 0; i < ui->num_elements; i++)
+ {
+ Z_OtherInformationUnit *unit = ui->list[i];
+ if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
+ unit->information.externallyDefinedInfo &&
+ unit->information.externallyDefinedInfo->which ==
+ Z_External_diag1)
+ {
+ Z_DiagnosticFormat *diag =
+ unit->information.externallyDefinedInfo->u.diag1;
+
+ if (diag->num > 0)
+ {
+ Z_DiagnosticFormat_s *ds = diag->elements[0];
+ if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec)
+ mp::util::get_default_diag(ds->u.defaultDiagRec,
+ error_code, addinfo);
+ }
+ }
+ }
+ }
+}
+
+int mp_util::get_or_remove_vhost_otherinfo(
+ Z_OtherInformation **otherInformation,
+ bool remove_flag,
+ std::list<std::string> &vhosts)