Fix Metaproxy stops logging after check config failed MP-590
[metaproxy-moved-to-github.git] / src / util.cpp
index 4a3d478..f23c00c 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2013 Index Data
+   Copyright (C) Index Data
 
 Metaproxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -500,15 +500,9 @@ void mp_util::transfer_referenceId(ODR odr, const Z_APDU *src, Z_APDU *dst)
     if (src)
     {
         Z_ReferenceId **id_from = mp::util::get_referenceId(src);
-        if (id_from && *id_from && id_to)
-        {
-            *id_to = (Z_ReferenceId*) odr_malloc (odr, sizeof(**id_to));
-            (*id_to)->size = (*id_to)->len = (*id_from)->len;
-            (*id_to)->buf = (unsigned char*) odr_malloc(odr, (*id_to)->len);
-            memcpy((*id_to)->buf, (*id_from)->buf, (*id_to)->len);
-        }
-        else if (id_to)
-            *id_to = 0;
+        if (id_from && *id_from)
+            *id_to = odr_create_Odr_oct(odr, (*id_from)->buf,
+                                        (*id_from)->len);
     }
 }
 
@@ -593,8 +587,9 @@ Z_APDU *mp::odr::create_scanResponse(const Z_APDU *in_apdu,
     return apdu;
 }
 
-Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session,
-                                     Z_HTTP_Request *hreq, int code)
+Z_GDU *mp::odr::create_HTTP_Response_details(mp::Session &session,
+                                             Z_HTTP_Request *hreq, int code,
+                                             const char *details)
 {
     const char *response_version = "1.0";
     bool keepalive = false;
@@ -617,15 +612,23 @@ Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session,
         response_version = "1.1";
     }
 
-    Z_GDU *gdu = z_get_HTTP_Response(m_odr, code);
+    Z_GDU *gdu = z_get_HTTP_Response_server(
+        m_odr, code, details, "Metaproxy/" VERSION,
+        "http://www.indexdata.com/metaproxy");
     Z_HTTP_Response *hres = gdu->u.HTTP_Response;
     hres->version = odr_strdup(m_odr, response_version);
     if (keepalive)
         z_HTTP_header_add(m_odr, &hres->headers, "Connection", "Keep-Alive");
-
     return gdu;
 }
 
+Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session,
+                                     Z_HTTP_Request *hreq, int code)
+{
+    return create_HTTP_Response_details(session, hreq, code, 0);
+
+}
+
 Z_ReferenceId **mp_util::get_referenceId(const Z_APDU *apdu)
 {
     switch (apdu->which)
@@ -724,6 +727,15 @@ const char *mp::wrbuf::buf()
     return wrbuf_buf(m_wrbuf);
 }
 
+const char *mp::wrbuf::c_str()
+{
+    return wrbuf_cstr(m_wrbuf);
+}
+
+const char *mp::wrbuf::c_str_null()
+{
+    return wrbuf_cstr_null(m_wrbuf);
+}
 
 /*
  * Local variables: