Happy new year
[pazpar2-moved-to-github.git] / src / client.c
index bb5ee3a..d861bd8 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
@@ -147,7 +147,9 @@ void client_set_state(struct client *cl, enum client_state st)
        that session is not mutex locked if client is already active */
     if (was_active && !client_is_active(cl) && cl->session)
     {
+
         int no_active = session_active_clients(cl->session);
+        yaz_log(YLOG_DEBUG, "%s: releasing watches on zero active: %d", client_get_url(cl), no_active);
         if (no_active == 0) {
             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
             session_alert_watch(cl->session, SESSION_WATCH_SHOW_PREF);
@@ -445,16 +447,24 @@ static void ingest_raw_record(struct client *cl, ZOOM_record rec)
     client_show_raw_dequeue(cl);
 }
 
-static void client_check_preferred_watch(struct client *cl)
+void client_check_preferred_watch(struct client *cl)
 {
     struct session *se = cl->session;
+    yaz_log(YLOG_DEBUG, "client_check_preferred_watch: %s ", client_get_url(cl));
     if (se)
     {
         client_unlock(cl);
-        if (session_preferred_clients_ready(se))
+        if (session_is_preferred_clients_ready(se)) {
             session_alert_watch(se, SESSION_WATCH_SHOW_PREF);
+        }
+        else
+            yaz_log(YLOG_DEBUG, "client_check_preferred_watch: Still locked on preferred targets.");
+
         client_lock(cl);
     }
+    else
+        yaz_log(YLOG_WARN, "client_check_preferred_watch: %s. No session!", client_get_url(cl));
+
 }
 
 void client_search_response(struct client *cl)
@@ -475,13 +485,16 @@ void client_search_response(struct client *cl)
     }
     else
     {
+        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)
+        if (se) {
             se->total_hits += cl->hits;
-        if (cl->preferred)
-            client_check_preferred_watch(cl);
+            yaz_log(YLOG_DEBUG, "client_search_response: total hits "
+                    ODR_INT_PRINTF, se->total_hits);
+        }
     }
 }
 
@@ -655,7 +668,8 @@ void client_start_search(struct client *cl)
 
     if (opt_preferred) {
         cl->preferred = atoi(opt_preferred);
-        yaz_log(YLOG_LOG, "Target %s has preferred: %d", sdb->database->url, cl->preferred);
+        if (cl->preferred)
+            yaz_log(YLOG_LOG, "Target %s has preferred status: %d", sdb->database->url, cl->preferred);
     }
     client_set_state(cl, Client_Working);
 
@@ -717,27 +731,27 @@ 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;
     client_use(1);
     
-    return r;
+    return cl;
 }
 
 void client_lock(struct client *c)
@@ -917,7 +931,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;
@@ -1050,6 +1064,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;