Read HTTP listener and proxy address from config file (-h and -p still override).
authorSebastian Hammer <quinn@indexdata.com>
Thu, 11 Jan 2007 17:14:06 +0000 (17:14 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Thu, 11 Jan 2007 17:14:06 +0000 (17:14 +0000)
Moved pazpar2.cfg to pazpar2.cfg.dist to facilitate local setups
Only -s is still required.

etc/pazpar2.cfg [deleted file]
etc/pazpar2.cfg.dist [new file with mode: 0644]
src/config.h
src/http_command.c
src/pazpar2.c
src/pazpar2.h

diff --git a/etc/pazpar2.cfg b/etc/pazpar2.cfg
deleted file mode 100644 (file)
index 3ea7efa..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
-
-<server>
-  <listen port="9004"/>
-  <proxy host="localhost" port="80"/>
-
-  <service>
-    <metadata name="title" brief="yes" sortkey="skiparticle" merge="longest" rank="6"/>
-    <metadata name="date" brief="yes" sortkey="numeric" type="year" merge="range"/>
-    <metadata name="author" brief="yes" termlist="yes" merge="longest" rank="2"/>
-    <metadata name="subject" merge="unique" termlist="yes" rank="3"/>
-  </service>
-</server>
-
-<!-- Need to figure out where to get ZeeRex records for targets from -->
-
-<queryprofile/>  <!-- Like a CCL profile++ . Can optionally refer to XSLT to 
-       convert ZeeRex into queryprofile. Multiple profiles can exist.  -->
-
-<retrievalprofile>
-  <requestsyntax>marc21</requestsyntax>
-  <nativesyntax name="iso2709" format="marc21" encoding="marc-8" mapto="marcxml"/>
-  <map type="xslt" stylesheet="marc21.xsl"/>
-</retrievalprofile>
-
-</pazpar2>
diff --git a/etc/pazpar2.cfg.dist b/etc/pazpar2.cfg.dist
new file mode 100644 (file)
index 0000000..04aa241
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
+
+<server>
+  <listen port="9004"/>
+  <proxy host="us1.indexdata.com"/>
+
+  <service>
+    <metadata name="title" brief="yes" sortkey="skiparticle" merge="longest" rank="6"/>
+    <metadata name="date" brief="yes" sortkey="numeric" type="year" merge="range"/>
+    <metadata name="author" brief="yes" termlist="yes" merge="longest" rank="2"/>
+    <metadata name="subject" merge="unique" termlist="yes" rank="3"/>
+  </service>
+</server>
+
+<!-- Need to figure out where to get ZeeRex records for targets from -->
+
+<queryprofile/>  <!-- Like a CCL profile++ . Can optionally refer to XSLT to 
+       convert ZeeRex into queryprofile. Multiple profiles can exist.  -->
+
+<retrievalprofile>
+  <requestsyntax>marc21</requestsyntax>
+  <nativesyntax name="iso2709" format="marc21" encoding="marc-8" mapto="marcxml"/>
+  <map type="xslt" stylesheet="marc21.xsl"/>
+</retrievalprofile>
+
+</pazpar2>
index 56caece..3077451 100644 (file)
@@ -12,6 +12,7 @@ struct conf_metadata
     int brief;   // Is this element to be returned in the brief format?
     int termlist;// Is this field to be treated as a termlist for browsing?
     int rank;    // Rank factor. 0 means don't use this field for ranking, 1 is default
+                 // values >1  give additional significance to a field
     enum
     {
         Metadata_type_generic,          // Generic text field
@@ -23,7 +24,8 @@ struct conf_metadata
         Metadata_sortkey_no,            // This is not to be used as a sortkey
         Metadata_sortkey_numeric,       // Standard numerical sorting
         Metadata_sortkey_range,         // Range sorting (pick lowest or highest)
-        Metadata_sortkey_skiparticle    // Skip leading article when sorting
+        Metadata_sortkey_skiparticle,   // Skip leading article when sorting
+        Metadata_sortkey_string
     } sortkey;
     enum
     {
index 1fef304..e29a1bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: http_command.c,v 1.17 2007-01-11 10:03:01 sondberg Exp $
+ * $Id: http_command.c,v 1.18 2007-01-11 17:14:06 quinn Exp $
  */
 
 #include <stdio.h>
@@ -17,6 +17,7 @@
 
 #include <yaz/yaz-util.h>
 
+#include "config.h"
 #include "util.h"
 #include "eventl.h"
 #include "pazpar2.h"
@@ -498,6 +499,15 @@ static void cmd_stat(struct http_channel *c)
     http_send_response(c);
 }
 
+static void cmd_info(struct http_channel *c)
+{
+    struct http_request *rq = c->request;
+    struct http_response *rs = c->response;
+    struct http_session *s = locate_session(rq, rs);
+
+    if (!s)
+        return;
+}
 
 struct {
     char *name;
@@ -512,6 +522,7 @@ struct {
     { "exit", cmd_exit },
     { "ping", cmd_ping },
     { "record", cmd_record },
+    { "info", cmd_info },
     {0,0}
 };
 
index 1fe17a8..e7b2b4a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.26 2007-01-10 11:56:10 adam Exp $ */
+/* $Id: pazpar2.c,v 1.27 2007-01-11 17:14:06 quinn Exp $ */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -72,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,
@@ -1397,11 +1399,53 @@ 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) == SIG_ERR)
         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
@@ -1416,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);
@@ -1449,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");
index b075232..50b0a1b 100644 (file)
@@ -169,6 +169,8 @@ struct hitsbytarget {
 };
 
 struct parameters {
+    char proxy_override[128];
+    char listener_override[128];
     struct conf_server *server;
     int dump_records;
     int timeout;               /* operations timeout, in seconds */