Get rid of record_assign_client
[pazpar2-moved-to-github.git] / src / logic.c
index 261febc..1ceffce 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: logic.c,v 1.31 2007-05-23 14:44:18 marc Exp $
+/* $Id: logic.c,v 1.38 2007-06-07 12:27:03 adam Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -79,10 +79,10 @@ struct parameters global_parameters =
 {
     "",
     "",
-    "",
-    "",
-    0,
+    "", 
     0,
+    0, /* dump_records */
+    0, /* debug_mode */
     30,
     "81",
     "Index Data PazPar2",
@@ -153,48 +153,73 @@ xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
 {
     struct database_retrievalmap *m;
     struct database *db = sdb->database;
-    xmlNode *res;
-    xmlDoc *rdoc;
+    xmlDoc *rdoc = 0;
+    const Odr_oid *oid = rec->direct_reference;
 
-    // First normalize to XML
-    if (sdb->yaz_marc)
+    /* convert response record to XML somehow */
+    if (rec->which == Z_External_octet && oid
+        && !oid_oidcmp(oid, yaz_oid_recsyn_xml))
     {
-        char *buf;
-        int len;
-        if (rec->which != Z_External_octet)
+        /* xml already */
+        rdoc = xmlParseMemory((char*) rec->u.octet_aligned->buf,
+                              rec->u.octet_aligned->len);
+        if (!rdoc)
         {
-            yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s",
+            yaz_log(YLOG_FATAL, "Non-wellformed XML received from %s",
                     db->url);
             return 0;
         }
-        buf = (char*) rec->u.octet_aligned->buf;
-        len = rec->u.octet_aligned->len;
-        if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0)
+    }
+    else if (oid && yaz_oid_is_iso2709(oid))
+    {
+        /* ISO2709 gets converted to MARCXML */
+        if (!sdb->yaz_marc)
         {
-            yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url);
+            yaz_log(YLOG_FATAL, "Unable to handle ISO2709 record");
             return 0;
         }
-
-        yaz_marc_write_using_libxml2(sdb->yaz_marc, 1);
-        if (yaz_marc_write_xml(sdb->yaz_marc, &res,
-                    "http://www.loc.gov/MARC21/slim", 0, 0) < 0)
+        else
         {
-            yaz_log(YLOG_WARN, "Failed to encode as XML %s",
-                    db->url);
-            return 0;
+            xmlNode *res;
+            char *buf;
+            int len;
+            
+            if (rec->which != Z_External_octet)
+            {
+                yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s",
+                        db->url);
+                return 0;
+            }
+            buf = (char*) rec->u.octet_aligned->buf;
+            len = rec->u.octet_aligned->len;
+            if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0)
+            {
+                yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url);
+                return 0;
+            }
+            
+            yaz_marc_write_using_libxml2(sdb->yaz_marc, 1);
+            if (yaz_marc_write_xml(sdb->yaz_marc, &res,
+                                   "http://www.loc.gov/MARC21/slim", 0, 0) < 0)
+            {
+                yaz_log(YLOG_WARN, "Failed to encode as XML %s",
+                        db->url);
+                return 0;
+            }
+            rdoc = xmlNewDoc((xmlChar *) "1.0");
+            xmlDocSetRootElement(rdoc, res);
         }
-        rdoc = xmlNewDoc((xmlChar *) "1.0");
-        xmlDocSetRootElement(rdoc, res);
-
     }
     else
     {
+        char oid_name_buf[OID_STR_MAX];
+        const char *oid_name = yaz_oid_to_string_buf(oid, 0, oid_name_buf);
         yaz_log(YLOG_FATAL, 
-                "Unknown native_syntax in normalize_record from %s",
-                db->url);
+                "Unable to handle record of type %s from %s", 
+                oid_name, db->url);
         return 0;
     }
-
+    
     if (global_parameters.dump_records){
         fprintf(stderr, 
                 "Input Record (normalized) from %s\n----------------\n",
@@ -476,9 +501,7 @@ char *search(struct session *se, char *query, char *filter)
     }
 
     for (cl = se->clients; cl; cl = client_next_in_session(cl))
-    {
         client_prep_connection(cl);
-    }
 
     return 0;
 }
@@ -493,13 +516,12 @@ static void session_init_databases_fun(void *context, struct database *db)
 
     new->database = db;
     new->yaz_marc = 0;
-
+    
 #ifdef HAVE_ICU
     if (global_parameters.server && global_parameters.server->icu_chn)
-            new->pct
-                = pp2_charset_create(global_parameters.server->icu_chn);
-        else
-            new->pct = pp2_charset_create(0);
+        new->pct = pp2_charset_create(global_parameters.server->icu_chn);
+    else
+        new->pct = pp2_charset_create(0);
 #else // HAVE_ICU
     new->pct = pp2_charset_create(0);
 #endif // HAVE_ICU
@@ -833,38 +855,6 @@ void start_proxy(void)
     http_set_proxyaddr(hp, ser->myurl ? ser->myurl : "");
 }
 
-void start_zproxy(void)
-{
-    struct conf_server *ser = global_parameters.server;
-
-    if (*global_parameters.zproxy_override){
-        yaz_log(YLOG_LOG, "Z39.50 proxy  %s", 
-                global_parameters.zproxy_override);
-        return;
-    }
-
-    else if (ser->zproxy_host || ser->zproxy_port)
-    {
-        char hp[128] = "";
-
-        strcpy(hp, ser->zproxy_host ? ser->zproxy_host : "");
-        if (ser->zproxy_port)
-        {
-            if (*hp)
-                strcat(hp, ":");
-            else
-                strcat(hp, "@:");
-
-            sprintf(hp + strlen(hp), "%d", ser->zproxy_port);
-        }
-        strcpy(global_parameters.zproxy_override, hp);
-        yaz_log(YLOG_LOG, "Z39.50 proxy  %s", 
-                global_parameters.zproxy_override);
-
-    }
-    else
-        return;
-}
 
 // Master list of connections we're handling events to
 static IOCHAN channel_list = 0; 
@@ -904,8 +894,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec,
     }
 
     record = record_create(se->nmem, 
-                           service->num_metadata, service->num_sortkeys);
-    record_assign_client(record, cl);
+                           service->num_metadata, service->num_sortkeys, cl);
 
     mergekey_norm = (xmlChar *) nmem_strdup(se->nmem, (char*) mergekey);
     xmlFree(mergekey);