Revert Giannis patch. Doing the fix in client.c
[pazpar2-moved-to-github.git] / src / client.c
index 7c563b2..ada9698 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2010 Index Data
+   Copyright (C) 2006-2011 Index Data
 
 Pazpar2 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
@@ -103,6 +103,8 @@ struct client {
     ZOOM_resultset resultset;
     YAZ_MUTEX mutex;
     int ref_count;
+    /* copy of database->url */
+    char *url;
 };
 
 struct show_raw {
@@ -485,13 +487,15 @@ void client_search_response(struct client *cl)
     }
     else
     {
-        yaz_log(YLOG_DEBUG, "client_search_response: hits %d", cl->hits);
+        yaz_log(YLOG_DEBUG, "client_search_response: hits "
+                ODR_INT_PRINTF, cl->hits);
         client_report_facets(cl, resultset);
         cl->record_offset = cl->startrecs;
         cl->hits = ZOOM_resultset_size(resultset);
         if (se) {
             se->total_hits += cl->hits;
-            yaz_log(YLOG_DEBUG, "client_search_response: total hits %d", se->total_hits);
+            yaz_log(YLOG_DEBUG, "client_search_response: total hits "
+                    ODR_INT_PRINTF, se->total_hits);
         }
     }
 }
@@ -590,6 +594,10 @@ static int client_set_facets_request(struct client *cl, ZOOM_connection link)
     struct session_database *sdb = client_get_database(cl);
     const char *opt_facet_term_sort  = session_setting_oneval(sdb, PZ_TERMLIST_TERM_SORT);
     const char *opt_facet_term_count = session_setting_oneval(sdb, PZ_TERMLIST_TERM_COUNT);
+
+    /* Future record filtering on target */
+    /* const char *opt_facet_record_filter = session_setting_oneval(sdb, PZ_RECORDFILTER); */
+
     /* Disable when no count is set */
     /* TODO Verify: Do we need to reset the  ZOOM facets if a ZOOM Connection is being reused??? */
     if (opt_facet_term_count && *opt_facet_term_count)
@@ -729,27 +737,28 @@ void client_start_search(struct client *cl)
 
 struct client *client_create(void)
 {
-    struct client *r = xmalloc(sizeof(*r));
-    r->maxrecs = 100;
-    r->startrecs = 0;
-    r->pquery = 0;
-    r->cqlquery = 0;
-    r->database = 0;
-    r->connection = 0;
-    r->session = 0;
-    r->hits = 0;
-    r->record_offset = 0;
-    r->diagnostic = 0;
-    r->state = Client_Disconnected;
-    r->show_raw = 0;
-    r->resultset = 0;
-    r->mutex = 0;
-    pazpar2_mutex_create(&r->mutex, "client");
-    r->preferred = 0;
-    r->ref_count = 1;
+    struct client *cl = xmalloc(sizeof(*cl));
+    cl->maxrecs = 100;
+    cl->startrecs = 0;
+    cl->pquery = 0;
+    cl->cqlquery = 0;
+    cl->database = 0;
+    cl->connection = 0;
+    cl->session = 0;
+    cl->hits = 0;
+    cl->record_offset = 0;
+    cl->diagnostic = 0;
+    cl->state = Client_Disconnected;
+    cl->show_raw = 0;
+    cl->resultset = 0;
+    cl->mutex = 0;
+    pazpar2_mutex_create(&cl->mutex, "client");
+    cl->preferred = 0;
+    cl->ref_count = 1;
+    cl->url = 0;
     client_use(1);
     
-    return r;
+    return cl;
 }
 
 void client_lock(struct client *c)
@@ -781,6 +790,7 @@ int client_destroy(struct client *c)
             c->pquery = 0;
             xfree(c->cqlquery);
             c->cqlquery = 0;
+            xfree(c->url);
             assert(!c->connection);
 
             if (c->resultset)
@@ -929,7 +939,7 @@ int client_parse_query(struct client *cl, const char *query)
     if (!cn)
     {
         client_set_state(cl, Client_Error);
-        yaz_log(YLOG_WARN, "Failed to parse CCL query %s for %s",
+        session_log(se, YLOG_WARN, "Failed to parse CCL query '%s' for %s",
                 query,
                 client_get_database(cl)->database->url);
         return -1;
@@ -1042,6 +1052,10 @@ int client_get_diagnostic(struct client *cl)
 void client_set_database(struct client *cl, struct session_database *db)
 {
     cl->database = db;
+    /* Copy the URL for safe logging even after session is gone */
+    if (db) {
+        cl->url = xstrdup(db->database->url);
+    }
 }
 
 struct host *client_get_host(struct client *cl)
@@ -1051,9 +1065,10 @@ struct host *client_get_host(struct client *cl)
 
 const char *client_get_url(struct client *cl)
 {
-    if (cl->database)
-        return client_get_database(cl)->database->url;
+    if (cl->url)
+        return cl->url;
     else
+        /* This must not happen anymore, as the url is present until destruction of client  */
         return "NOURL";
 }
 
@@ -1062,6 +1077,11 @@ void client_set_maxrecs(struct client *cl, int v)
     cl->maxrecs = v;
 }
 
+int client_get_maxrecs(struct client *cl)
+{
+    return cl->maxrecs;
+}
+
 void client_set_startrecs(struct client *cl, int v)
 {
     cl->startrecs = v;