Make more room for YAZ version string
[pazpar2-moved-to-github.git] / src / pazpar2.c
index b5a0ee7..e7b2b4a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.22 2007-01-09 22:06:49 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.27 2007-01-11 17:14:06 quinn Exp $ */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -29,6 +29,8 @@
 #include <yaz/timing.h>
 #endif
 
+#include <netinet/in.h>
+
 #include "pazpar2.h"
 #include "eventl.h"
 #include "http.h"
@@ -70,6 +72,8 @@ static char *client_states[] = {
 // Note: Some things in this structure will eventually move to configuration
 struct parameters global_parameters = 
 {
+    "",
+    "",
     0,
     0,
     30,
@@ -480,7 +484,7 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
     res->next = 0;
     res->metadata = nmem_malloc(se->nmem,
             sizeof(struct record_metadata*) * service->num_metadata);
-    bzero(res->metadata, sizeof(struct record_metadata*) * service->num_metadata);
+    memset(res->metadata, 0, sizeof(struct record_metadata*) * service->num_metadata);
 
     mergekey_norm = nmem_strdup(se->nmem, (char*) mergekey);
     xmlFree(mergekey);
@@ -859,7 +863,8 @@ static struct connection *connection_create(struct client *cl)
 
     if (!(addr = cs_straddr(link, cl->database->host->ipport)))
     {
-        yaz_log(YLOG_WARN|YLOG_ERRNO, "Lookup of IP address failed?");
+        yaz_log(YLOG_WARN|YLOG_ERRNO, "Lookup of IP address %s failed?", 
+           cl->database->host->ipport);
         return 0;
     }
 
@@ -1015,7 +1020,7 @@ void load_simpletargets(const char *fn)
             }
             assert(addrinfo->ai_family == PF_INET);
             memcpy(addrbuf, &((struct sockaddr_in*)addrinfo->ai_addr)->sin_addr.s_addr, 4);
-            sprintf(ipport, "%hhd.%hhd.%hhd.%hhd:%s",
+            sprintf(ipport, "%u.%u.%u.%u:%s",
                     addrbuf[0], addrbuf[1], addrbuf[2], addrbuf[3], port);
             host->ipport = xstrdup(ipport);
             freeaddrinfo(addrinfo);
@@ -1359,7 +1364,7 @@ void statistics(struct session *se, struct statistics *stat)
     struct client *cl;
     int count = 0;
 
-    bzero(stat, sizeof(*stat));
+    memset(stat, 0, sizeof(*stat));
     for (cl = se->clients; cl; cl = cl->next)
     {
         if (!cl->connection)
@@ -1394,13 +1399,55 @@ static CCL_bibset load_cclfile(const char *fn)
     return res;
 }
 
+static void start_http_listener(void)
+{
+    char hp[128] = "";
+    struct conf_server *ser = global_parameters.server;
+
+    if (*global_parameters.listener_override)
+        strcpy(hp, global_parameters.listener_override);
+    else
+    {
+        strcpy(hp, ser->host ? ser->host : "");
+        if (ser->port)
+        {
+            if (*hp)
+                strcat(hp, ":");
+            sprintf(hp + strlen(hp), "%d", ser->port);
+        }
+    }
+    http_init(hp);
+}
+
+static void start_proxy(void)
+{
+    char hp[128] = "";
+    struct conf_server *ser = global_parameters.server;
+
+    if (*global_parameters.proxy_override)
+        strcpy(hp, global_parameters.proxy_override);
+    else if (ser->proxy_host || ser->proxy_port)
+    {
+        strcpy(hp, ser->proxy_host ? ser->proxy_host : "");
+        if (ser->proxy_port)
+        {
+            if (*hp)
+                strcat(hp, ":");
+            sprintf(hp + strlen(hp), "%d", ser->proxy_port);
+        }
+    }
+    else
+        return;
+
+    http_set_proxyaddr(hp);
+}
+
 int main(int argc, char **argv)
 {
     int ret;
     char *arg;
-    int setport = 0;
 
-    if (signal(SIGPIPE, SIG_IGN) < 0)
+    if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
 
     yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
@@ -1413,14 +1460,13 @@ int main(int argc, char **argv)
                     exit(1);
                 break;
             case 'h':
-                http_init(arg);
-                setport++;
+                strcpy(global_parameters.listener_override, arg);
                 break;
             case 'C':
                 global_parameters.ccl_filter = load_cclfile(arg);
                 break;
             case 'p':
-                http_set_proxyaddr(arg);
+                strcpy(global_parameters.proxy_override, arg);
                 break;
             case 's':
                 load_simpletargets(arg);
@@ -1446,12 +1492,8 @@ int main(int argc, char **argv)
     }
     global_parameters.server = config->servers;
 
-    if (!setport)
-    {
-        fprintf(stderr, "Set command port with -h\n");
-        exit(1);
-    }
-
+    start_http_listener();
+    start_proxy();
     global_parameters.ccl_filter = load_cclfile("../etc/default.bib");
     global_parameters.yaz_marc = yaz_marc_create();
     yaz_marc_subfield_str(global_parameters.yaz_marc, "\t");