Remove unused client code
[pazpar2-moved-to-github.git] / src / client.c
index 5f05633..27a32f3 100644 (file)
@@ -115,6 +115,7 @@ struct client {
     char *addinfo; // diagnostic info for most resent error
     Odr_int hits;
     int record_offset;
+    int show_stat_no;
     int filtered; // When using local:, this will count the number of filtered records.
     int maxrecs;
     int startrecs;
@@ -220,11 +221,6 @@ struct session *client_get_session(struct client *cl)
     return cl->session;
 }
 
-const char *client_get_pquery(struct client *cl)
-{
-    return cl->pquery;
-}
-
 static void client_send_raw_present(struct client *cl);
 static int nativesyntax_to_type(const char *s, char *type, ZOOM_record rec);
 
@@ -358,7 +354,7 @@ void client_show_raw_remove(struct client *cl, void *data)
     }
 }
 
-void client_show_raw_dequeue(struct client *cl)
+static void client_show_raw_dequeue(struct client *cl)
 {
     struct show_raw *rr = cl->show_raw;
 
@@ -454,7 +450,7 @@ static int nativesyntax_to_type(const char *s, char *type,
  * TODO Consider thread safety!!!
  *
  */
-void client_report_facets(struct client *cl, ZOOM_resultset rs)
+static void client_report_facets(struct client *cl, ZOOM_resultset rs)
 {
     struct session_database *sdb = client_get_database(cl);
     ZOOM_facet_field *facets = ZOOM_resultset_facets(rs);
@@ -645,7 +641,7 @@ static void client_record_ingest(struct client *cl)
     }
 }
 
-void client_record_response(struct client *cl)
+void client_record_response(struct client *cl, int *got_records)
 {
     struct connection *co = cl->connection;
     ZOOM_connection link = connection_get_link(co);
@@ -678,6 +674,7 @@ void client_record_response(struct client *cl)
         else
         {
             client_record_ingest(cl);
+            *got_records = 1;
         }
     }
 }
@@ -762,21 +759,57 @@ static const char *get_strategy_plus_sort(struct client *l, const char *field)
     return strategy_plus_sort;
 }
 
+void client_update_show_stat(struct client *cl, int cmd)
+{
+    if (cmd == 0)
+        cl->show_stat_no = 0;
+    else if (cmd == 1)
+        cl->show_stat_no++;
+}
+
 int client_fetch_more(struct client *cl)
 {
-    int extra = cl->hits - cl->record_offset;
-    if (extra > 0)
+    struct session_database *sdb = client_get_database(cl);
+    const char *str;
+    int extend_recs = 0;
+    int number;
+
+    str = session_setting_oneval(sdb, PZ_EXTENDRECS);
+    if (!str || !*str)
+        return 0;
+
+    extend_recs = atoi(str);
+
+    yaz_log(YLOG_LOG, "cl=%s show_stat_no=%d got=%d",
+            client_get_id(cl), cl->show_stat_no, cl->record_offset);
+    if (cl->show_stat_no < cl->record_offset)
+        return 0;
+    yaz_log(YLOG_LOG, "cl=%s Trying to fetch more", client_get_id(cl));
+
+    if (extend_recs > cl->hits)
+        extend_recs = cl->hits;
+
+    number = extend_recs - cl->record_offset;
+    if (number > 0)
     {
         ZOOM_resultset set = cl->resultset;
-        int max_extra = 10;
+        struct connection *co = client_get_connection(cl);
 
-        if (extra > max_extra)
-            extra = max_extra;
+        str = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
+        ZOOM_resultset_option_set(set, "preferredRecordSyntax", str);
+        str = session_setting_oneval(sdb, PZ_ELEMENTS);
+        if (str && *str)
+            ZOOM_resultset_option_set(set, "elementSetName", str);
 
-        ZOOM_resultset_records(set, 0, cl->record_offset, extra);
+        ZOOM_resultset_records(set, 0, cl->record_offset, number);
         client_set_state(cl, Client_Working);
+        connection_continue(co);
         return 1;
     }
+    else
+    {
+        yaz_log(YLOG_LOG, "cl=%s. OK no more in total set", client_get_id(cl));
+    }
     return 0;
 }
 
@@ -1281,8 +1314,8 @@ static int apply_limit(struct session_database *sdb,
                                 sdb->database->id, cvalue);
                         ret = -1; /* bad limitmap */
                     }
-                    break;
                 }
+                break;
             }
         }
         if (!s)
@@ -1671,11 +1704,6 @@ static void client_suggestions_destroy(struct client *cl)
     nmem_destroy(nmem);
 }
 
-int client_test_sort_order(struct client *cl, struct reclist_sortparms *sp)
-{
-    //TODO implement correctly.
-    return 1;
-}
 /*
  * Local variables:
  * c-basic-offset: 4