Implemented session timeout; ping command
[pazpar2-moved-to-github.git] / pazpar2.c
index a1d939a..f953a7d 100644 (file)
--- a/pazpar2.c
+++ b/pazpar2.c
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.9 2006-12-04 02:27:02 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.12 2006-12-12 02:36:24 quinn Exp $ */;
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -17,8 +17,6 @@
 #include <yaz/readconf.h>
 #include <yaz/pquery.h>
 #include <yaz/yaz-util.h>
-#include <yaz/ccl.h>
-#include <yaz/yaz-ccl.h>
 
 #include "pazpar2.h"
 #include "eventl.h"
@@ -57,25 +55,14 @@ static char *client_states[] = {
     "Client_Stopped"
 };
 
-static struct parameters {
-    int timeout;               /* operations timeout, in seconds */
-    char implementationId[128];
-    char implementationName[128];
-    char implementationVersion[128];
-    int target_timeout; // seconds
-    int toget;
-    int chunk;
-    CCL_bibset ccl_filter;
-    yaz_marc_t yaz_marc;
-    ODR odr_out;
-    ODR odr_in;
-} global_parameters = 
+struct parameters global_parameters = 
 {
     30,
     "81",
     "Index Data PazPar2 (MasterKey)",
     PAZPAR2_VERSION,
     600, // 10 minutes
+    60,
     100,
     MAX_CHUNK,
     0,
@@ -359,11 +346,11 @@ char *extract_title(struct session *s, const char *rec)
         }
     }
     wrbuf_putc(s->wrbuf, '\0');
-    obuf = nmem_strdup(s->nmem, wrbuf_buf(s->wrbuf));
+    obuf = (unsigned char*) nmem_strdup(s->nmem, wrbuf_buf(s->wrbuf));
     for (p = obuf; *p; p++)
         if (*p == '&' || *p == '<' || *p > 122 || *p < ' ')
             *p = ' ';
-    return obuf;
+    return (char*) obuf;
 }
 
 // Extract 245 $a $b 100 $a
@@ -1121,7 +1108,7 @@ void client_destroy(struct client *c)
             cc->next = c->next;
     }
     if (c->connection)
-        connection_destroy(c->connection);
+        connection_release(c->connection);
     c->next = client_freelist;
     client_freelist = c;
 }
@@ -1182,6 +1169,15 @@ char *search(struct session *se, char *query)
     return 0;
 }
 
+void destroy_session(struct session *s)
+{
+    yaz_log(YLOG_LOG, "Destroying session");
+    while (s->clients)
+        client_destroy(s->clients);
+    nmem_destroy(s->nmem);
+    wrbuf_free(s->wrbuf, 1);
+}
+
 struct session *new_session() 
 {
     struct session *session = xmalloc(sizeof(*session));
@@ -1203,11 +1199,6 @@ struct session *new_session()
     return session;
 }
 
-void session_destroy(struct session *s)
-{
-    // FIXME do some shit here!!!!
-}
-
 struct hitsbytarget *hitsbytarget(struct session *se, int *count)
 {
     static struct hitsbytarget res[1000]; // FIXME MM
@@ -1307,6 +1298,7 @@ int main(int argc, char **argv)
 {
     int ret;
     char *arg;
+    int setport = 0;
 
     if (signal(SIGPIPE, SIG_IGN) < 0)
         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
@@ -1316,16 +1308,16 @@ int main(int argc, char **argv)
     while ((ret = options("c:h:p:C:s:", argv, argc, &arg)) != -2)
     {
        switch (ret) {
-           case 0:
-               break;
            case 'c':
                command_init(atoi(arg));
+                setport++;
                break;
-            case 'C':
-                global_parameters.ccl_filter = load_cclfile(arg);
-                break;
             case 'h':
                 http_init(atoi(arg));
+                setport++;
+                break;
+            case 'C':
+                global_parameters.ccl_filter = load_cclfile(arg);
                 break;
             case 'p':
                 http_set_proxyaddr(arg);
@@ -1334,11 +1326,22 @@ int main(int argc, char **argv)
                 load_simpletargets(arg);
                 break;
            default:
-               fprintf(stderr, "Usage: pazpar2 -d comport");
+               fprintf(stderr, "Usage: pazpar2\n"
+                        "    -h httpport             (REST)\n"
+                        "    -c cmdport              (telnet-style)\n"
+                        "    -C cclconfig\n"
+                        "    -s simpletargetfile\n"
+                        "    -p hostname[:portno]    (HTTP proxy)\n");
                exit(1);
        }
     }
 
+    if (!setport)
+    {
+        fprintf(stderr, "Set command port with -h or -c\n");
+        exit(1);
+    }
+
     global_parameters.ccl_filter = load_cclfile("default.bib");
     global_parameters.yaz_marc = yaz_marc_create();
     yaz_marc_subfield_str(global_parameters.yaz_marc, "\t");