prevent sending empty XML elements in term lists.
[pazpar2-moved-to-github.git] / src / client.c
index 10db126..fe1d950 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.2 2007-04-24 07:04:36 adam Exp $
+/* $Id: client.c,v 1.6 2007-06-02 04:32:28 quinn Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -373,9 +373,10 @@ void client_search_response(struct client *cl, Z_APDU *a)
             Z_Records *recs = r->records;
             if (recs->which == Z_Records_NSD)
             {
-                yaz_log(YLOG_WARN, 
-                        "Search response: Non-surrogate diagnostic %s",
-                        cl->database->database->url);
+                yaz_log(YLOG_WARN,  
+                    "Search response: Non-surrogate diagnostic %s (%d)", 
+                    cl->database->database->url, 
+                    *recs->u.nonSurrogateDiagnostic->condition); 
                 cl->diagnostic = *recs->u.nonSurrogateDiagnostic->condition;
                 cl->state = Client_Error;
             }
@@ -441,13 +442,16 @@ static void init_authentication(struct client *cl, Z_InitRequest *req)
     struct session_database *sdb = client_get_database(cl);
     char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
 
-    if (auth)
+    if (*auth)
     {
+        struct connection *co = client_get_connection(cl);
+        struct session *se = client_get_session(cl);
         Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
                 sizeof(*idAuth));
         idAuth->which = Z_IdAuthentication_open;
         idAuth->u.open = auth;
         req->idAuthentication = idAuth;
+        connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
     }
 }
 
@@ -622,18 +626,17 @@ int client_parse_query(struct client *cl, const char *query)
     }
     wrbuf_rewind(se->wrbuf);
     ccl_pquery(se->wrbuf, cn);
-    wrbuf_putc(se->wrbuf, '\0');
-    if (cl->pquery)
-        xfree(cl->pquery);
-    cl->pquery = xstrdup(wrbuf_buf(se->wrbuf));
+    xfree(cl->pquery);
+    cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
 
     if (!se->relevance)
     {
         // Initialize relevance structure with query terms
         char *p[512];
         extract_terms(se->nmem, cn, p);
-        se->relevance = relevance_create(se->nmem, (const char **) p,
-                se->expected_maxrecs);
+        se->relevance = relevance_create(client_get_database(cl)->pct,
+                                         se->nmem, (const char **) p,
+                                         se->expected_maxrecs);
     }
 
     ccl_rpn_delete(cn);