Rename func termlist->get_termlist_score
[pazpar2-moved-to-github.git] / src / http_command.c
index b3e4dc7..90b6cd6 100644 (file)
@@ -41,10 +41,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "settings.h"
 #include "client.h"
 
+#ifdef HAVE_MALLINFO
 #include <malloc.h>
 
 void print_meminfo(WRBUF wrbuf) {
-#ifdef __GNUC__
+
     struct mallinfo minfo;
     minfo = mallinfo();
     wrbuf_printf(wrbuf, "  <memory>\n"
@@ -60,8 +61,10 @@ void print_meminfo(WRBUF wrbuf) {
                         "  </memory>\n", 
                  minfo.arena, minfo.uordblks, minfo.fordblks,minfo.ordblks, minfo.keepcost, minfo.hblks, minfo.hblkhd, minfo.arena + minfo.hblkhd, minfo.uordblks + minfo.hblkhd);
 
-#endif
 }
+#else
+#define print_meminfo(x)
+#endif
 
 
 // Update this when the protocol changes
@@ -362,7 +365,12 @@ static int process_settings(struct session *se, struct http_request *rq,
 
 static void cmd_exit(struct http_channel *c)
 {
+    char buf[1024];
+    struct http_response *rs = c->response;
     yaz_log(YLOG_WARN, "exit");
+    sprintf(buf, HTTP_COMMAND_RESPONSE_PREFIX "<exit><status>OK</status></exit>");
+    rs->payload = nmem_strdup(c->nmem, buf);
+    http_send_response(c);
     http_close_server(c->server);
 }
 
@@ -574,7 +582,7 @@ static void cmd_termlist(struct http_channel *c)
         }
         else
         {
-            p = termlist(s->psession, tname, &len);
+            p = get_termlist_score(s->psession, tname, &len);
             if (p && len)
                 wrbuf_printf(debug_log, " %s: %d", tname, len);
             if (p) {
@@ -721,11 +729,10 @@ static void cmd_bytarget(struct http_channel *c)
         if (settings && *settings == '1')
         {
             wrbuf_puts(c->wrbuf, "<settings>\n");
-            wrbuf_puts(c->wrbuf, wrbuf_cstr(ht[i].settings_xml));
+            wrbuf_puts(c->wrbuf, ht[i].settings_xml);
             wrbuf_puts(c->wrbuf, "</settings>\n");
         }
         wrbuf_puts(c->wrbuf, "</target>");
-        wrbuf_destroy(ht[i].settings_xml);
     }
 
     wrbuf_puts(c->wrbuf, "</bytarget>");
@@ -1089,31 +1096,6 @@ static void cmd_ping(struct http_channel *c)
     release_session(c, s);
 }
 
-static int utf_8_valid(const char *str)
-{
-    yaz_iconv_t cd = yaz_iconv_open("utf-8", "utf-8");
-    if (cd)
-    {
-        /* check that query is UTF-8 encoded */
-        char *inbuf = (char *) str; /* we know iconv does not alter this */
-        size_t inbytesleft = strlen(inbuf);
-
-        size_t outbytesleft = strlen(inbuf) + 10;
-        char *out = xmalloc(outbytesleft);
-        char *outbuf = out;
-        size_t r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-
-        /* if OK, try flushing the rest  */
-        if (r != (size_t) (-1))
-            r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
-        yaz_iconv_close(cd);
-        xfree(out);
-        if (r == (size_t) (-1))
-            return 0;
-    }
-    return 1;
-}
-
 static void cmd_search(struct http_channel *c)
 {
     struct http_request *rq = c->request;
@@ -1134,7 +1116,7 @@ static void cmd_search(struct http_channel *c)
         release_session(c,s);
         return;
     }
-    if (!utf_8_valid(query))
+    if (!yaz_utf8_check(query))
     {
         error(rs, PAZPAR2_MALFORMED_PARAMETER_ENCODING, "query");
         release_session(c,s);