Added [host:]port syntax to -h to bind HTTP listener to specific local IP
[pazpar2-moved-to-github.git] / pazpar2.c
index 55dabb2..4105ba2 100644 (file)
--- a/pazpar2.c
+++ b/pazpar2.c
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.13 2006-12-14 14:58:03 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.17 2006-12-19 04:49:34 quinn Exp $ */;
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -33,8 +33,9 @@ static void client_fatal(struct client *cl);
 static void connection_destroy(struct connection *co);
 static int client_prep_connection(struct client *cl);
 static void ingest_records(struct client *cl, Z_Records *r);
+void session_alert_watch(struct session *s, int what);
 
-IOCHAN channel_list = 0;  // Master list of connections we're listening to.
+IOCHAN channel_list = 0;  // Master list of connections we're handling events to
 
 static struct connection *connection_freelist = 0;
 static struct client *client_freelist = 0;
@@ -638,6 +639,7 @@ static struct record *ingest_record(struct client *cl, char *buf, int len)
 static void ingest_records(struct client *cl, Z_Records *r)
 {
     struct record *rec;
+    struct session *s = cl->session;
     Z_NamePlusRecordList *rlist;
     int i;
 
@@ -669,6 +671,8 @@ static void ingest_records(struct client *cl, Z_Records *r)
         if (!rec)
             continue;
     }
+    if (s->watchlist[SESSION_WATCH_RECORDS].fun && rlist->num_records)
+        session_alert_watch(s, SESSION_WATCH_RECORDS);
 }
 
 static void do_presentResponse(IOCHAN i, Z_APDU *a)
@@ -709,6 +713,12 @@ static void handler(IOCHAN i, int event)
 
     if (cl)
         se = cl->session;
+    else
+    {
+        yaz_log(YLOG_WARN, "Destroying orphan connection (fix me?)");
+        connection_destroy(co);
+        return;
+    }
 
     if (co->state == Conn_Connecting && event & EVENT_OUTPUT)
     {
@@ -972,7 +982,7 @@ void load_simpletargets(const char *fn)
             continue;
         url = line + 7;
         url[strlen(url) - 1] = '\0';
-        yaz_log(LOG_DEBUG, "Target: %s", url);
+        yaz_log(YLOG_DEBUG, "Target: %s", url);
         if ((db = strchr(url, '/')))
             *(db++) = '\0';
         else
@@ -1121,6 +1131,15 @@ void session_set_watch(struct session *s, int what, session_watchfun fun, void *
     s->watchlist[what].data = data;
 }
 
+void session_alert_watch(struct session *s, int what)
+{
+    if (!s->watchlist[what].fun)
+        return;
+    (*s->watchlist[what].fun)(s->watchlist[what].data);
+    s->watchlist[what].fun = 0;
+    s->watchlist[what].data = 0;
+}
+
 // This should be extended with parameters to control selection criteria
 // Associates a set of clients with a session;
 int select_targets(struct session *se)
@@ -1317,7 +1336,7 @@ int main(int argc, char **argv)
     if (signal(SIGPIPE, SIG_IGN) < 0)
         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
 
-    yaz_log_init(YLOG_DEFAULT_LEVEL|YLOG_DEBUG, "pazpar2", 0);
+    yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
 
     while ((ret = options("c:h:p:C:s:", argv, argc, &arg)) != -2)
     {
@@ -1327,7 +1346,7 @@ int main(int argc, char **argv)
                 setport++;
                break;
             case 'h':
-                http_init(atoi(arg));
+                http_init(arg);
                 setport++;
                 break;
             case 'C':
@@ -1341,7 +1360,7 @@ int main(int argc, char **argv)
                 break;
            default:
                fprintf(stderr, "Usage: pazpar2\n"
-                        "    -h httpport             (REST)\n"
+                        "    -h [host:]port          (REST protocol listener)\n"
                         "    -c cmdport              (telnet-style)\n"
                         "    -C cclconfig\n"
                         "    -s simpletargetfile\n"