-/* $Id: util.cpp,v 1.18 2006-06-19 23:54:02 adam Exp $
+/* $Id: util.cpp,v 1.21 2006-10-02 13:44:48 marc Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
*/
#include "config.hpp"
+#include "util.hpp"
#include <yaz/odr.h>
#include <yaz/pquery.h>
#include <yaz/otherinfo.h>
#include <yaz/querytowrbuf.h> // for yaz_query_to_wrbuf()
-#include "util.hpp"
-//#include <iostream>
+#include <iostream>
namespace mp = metaproxy_1;
// Doxygen doesn't like mp::util, so we use this instead
namespace mp_util = metaproxy_1::util;
+
+std::string mp_util::http_header_value(const Z_HTTP_Header* header,
+ const std::string name)
+{
+ while (header && header->name
+ && std::string(header->name) != name)
+ header = header->next;
+
+ if (header && header->name && std::string(header->name) == name
+ && header->value)
+ return std::string(header->value);
+
+ return std::string();
+}
+
+std::string mp_util::http_headers_debug(const Z_HTTP_Request &http_req)
+{
+ std::string message("<html>\n<body>\n<h1>"
+ "Metaproxy SRUtoZ3950 filter"
+ "</h1>\n");
+
+ message += "<h3>HTTP Info</h3><br/>\n";
+ message += "<p>\n";
+ message += "<b>Method: </b> " + std::string(http_req.method) + "<br/>\n";
+ message += "<b>Version:</b> " + std::string(http_req.version) + "<br/>\n";
+ message += "<b>Path: </b> " + std::string(http_req.path) + "<br/>\n";
+
+ message += "<b>Content-Type:</b>"
+ + mp_util::http_header_value(http_req.headers, "Content-Type")
+ + "<br/>\n";
+ message += "<b>Content-Length:</b>"
+ + mp_util::http_header_value(http_req.headers, "Content-Length")
+ + "<br/>\n";
+ message += "</p>\n";
+
+ message += "<h3>Headers</h3><br/>\n";
+ message += "<p>\n";
+ Z_HTTP_Header* header = http_req.headers;
+ while (header){
+ message += "<b>Header: </b> <i>"
+ + std::string(header->name) + ":</i> "
+ + std::string(header->value) + "<br/>\n";
+ header = header->next;
+ }
+ message += "</p>\n";
+ message += "</body>\n</html>\n";
+ return message;
+}
+
+
int mp_util::memcmp2(const void *buf1, int len1,
const void *buf2, int len2)
{
}
}
-int mp_util::get_vhost_otherinfo(
+int mp_util::get_or_remove_vhost_otherinfo(
Z_OtherInformation **otherInformation,
bool remove_flag,
std::list<std::string> &vhosts)
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)