No unsigned char's in public API (except for iconv)
[yaz-moved-to-github.git] / src / zoom-z3950.c
index cf1b12f..fe86050 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -126,9 +126,7 @@ static Z_External *encode_ill_request(ZOOM_package p)
         r->which = Z_External_single;
 
         r->u.single_ASN1_type =
-            odr_create_Odr_oct(out,
-                               (unsigned char *)illRequest_buf,
-                               illRequest_size);
+            odr_create_Odr_oct(out, illRequest_buf, illRequest_size);
     }
     return r;
 }
@@ -272,8 +270,7 @@ static Z_APDU *create_xmlupdate_package(ZOOM_package p)
     ext->indirect_reference = 0;
 
     ext->which = Z_External_octet;
-    ext->u.single_ASN1_type =
-        odr_create_Odr_oct(p->odr_out, (const unsigned char *) doc, len);
+    ext->u.single_ASN1_type = odr_create_Odr_oct(p->odr_out, doc, len);
     return apdu;
 }
 
@@ -417,8 +414,7 @@ static Z_APDU *create_update_package(ZOOM_package p)
         if (recordIdOpaque)
         {
             notToKeep->elements[0]->u.opaque =
-                odr_create_Odr_oct(p->odr_out,
-                                   (const unsigned char *) recordIdOpaque,
+                odr_create_Odr_oct(p->odr_out, recordIdOpaque,
                                    recordIdOpaque_len);
         }
         else if (recordIdNumber)
@@ -642,6 +638,7 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
     ZOOM_resultset r;
     int lslb, ssub, mspn;
     const char *syntax;
+    const char *schema;
     Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_searchRequest);
     Z_SearchRequest *search_req = apdu->u.searchRequest;
     const char *elementSetName;
@@ -722,6 +719,8 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
     /* get syntax (no need to provide unless piggyback is in effect) */
     syntax = c->tasks->u.search.syntax;
 
+    schema = c->tasks->u.search.schema;
+
     lslb = ZOOM_options_get_int(r->options, "largeSetLowerBound", -1);
     ssub = ZOOM_options_get_int(r->options, "smallSetUpperBound", -1);
     mspn = ZOOM_options_get_int(r->options, "mediumSetPresentNumber", -1);
@@ -733,7 +732,7 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
         *search_req->mediumSetPresentNumber = mspn;
     }
     else if (c->tasks->u.search.start == 0 && c->tasks->u.search.count > 0
-             && r->piggyback && !r->r_sort_spec && !r->schema)
+             && r->piggyback && !r->r_sort_spec && !schema)
     {
         /* Regular piggyback - do it unless we're going to do sort */
         *search_req->largeSetLowerBound = 2000000000;
@@ -959,7 +958,6 @@ ZOOM_API(void)
     }
 }
 
-
 static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
                                  int present_phase);
 
@@ -1085,35 +1083,6 @@ static int handle_Z3950_es_response(ZOOM_connection c,
     return 1;
 }
 
-static void interpret_init_diag(ZOOM_connection c,
-                                Z_DiagnosticFormat *diag)
-{
-    if (diag->num > 0)
-    {
-        Z_DiagnosticFormat_s *ds = diag->elements[0];
-        if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec)
-            response_default_diag(c, ds->u.defaultDiagRec);
-    }
-}
-
-
-static void interpret_otherinformation_field(ZOOM_connection c,
-                                             Z_OtherInformation *ui)
-{
-    int i;
-    for (i = 0; i < ui->num_elements; i++)
-    {
-        Z_OtherInformationUnit *unit = ui->list[i];
-        if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
-            unit->information.externallyDefinedInfo &&
-            unit->information.externallyDefinedInfo->which ==
-            Z_External_diag1)
-        {
-            interpret_init_diag(c, unit->information.externallyDefinedInfo->u.diag1);
-        }
-    }
-}
-
 static char *get_term_cstr(ODR odr, Z_Term *term) {
 
     switch (term->which) {
@@ -1147,7 +1116,8 @@ static ZOOM_facet_field get_zoom_facet_field(ODR odr, Z_FacetField *facet) {
 }
 
 /* Can be share with SOLR/SRU/SRW requests */
-void handle_facet_list(ZOOM_resultset r, Z_FacetList *fl) {
+void ZOOM_handle_facet_list(ZOOM_resultset r, Z_FacetList *fl)
+{
     int j;
     r->num_facets   = fl->num;
     yaz_log(YLOG_DEBUG, "Facets found: %d", fl->num);
@@ -1173,7 +1143,7 @@ static void handle_facet_result(ZOOM_connection c, ZOOM_resultset r,
             Z_External *ext = o->list[i]->information.externallyDefinedInfo;
             if (ext->which == Z_External_userFacets)
             {
-                handle_facet_list(r, ext->u.facetList);
+                ZOOM_handle_facet_list(r, ext->u.facetList);
             }
         }
     }
@@ -1356,7 +1326,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
 {
     ZOOM_resultset resultset;
     int *start, *count;
-    const char *syntax = 0, *elementSetName = 0;
+    const char *syntax = 0, *elementSetName = 0, *schema = 0;
 
     if (!c->tasks)
         return ;
@@ -1368,6 +1338,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
         count = &c->tasks->u.search.count;
         syntax = c->tasks->u.search.syntax;
         elementSetName = c->tasks->u.search.elementSetName;
+        schema =  c->tasks->u.search.schema;
         break;
     case ZOOM_TASK_RETRIEVE:
         resultset = c->tasks->u.retrieve.resultset;
@@ -1375,6 +1346,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
         count = &c->tasks->u.retrieve.count;
         syntax = c->tasks->u.retrieve.syntax;
         elementSetName = c->tasks->u.retrieve.elementSetName;
+        schema =  c->tasks->u.retrieve.schema;
         break;
     default:
         return;
@@ -1403,8 +1375,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
             for (i = 0; i<p->num_records; i++)
             {
                 ZOOM_record_cache_add(resultset, p->records[i], i + *start,
-                                      syntax, elementSetName,
-                                      elementSetName, 0);
+                                      syntax, elementSetName, schema, 0);
             }
             *count -= i;
             if (*count < 0)
@@ -1426,7 +1397,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
                         YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
                         "ZOOM C generated. Present phase and no records");
                 ZOOM_record_cache_add(resultset, myrec, *start,
-                                      syntax, elementSetName, 0, 0);
+                                      syntax, elementSetName, schema, 0);
             }
         }
         else if (present_phase)
@@ -1438,7 +1409,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
                     YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
                     "ZOOM C generated: Present response and no records");
             ZOOM_record_cache_add(resultset, myrec, *start,
-                                  syntax, elementSetName, 0, 0);
+                                  syntax, elementSetName, schema, 0);
         }
     }
 }
@@ -1488,7 +1459,8 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
     int i = 0;
     const char *syntax = 0;
     const char *elementSetName = 0;
-    ZOOM_resultset  resultset;
+    const char *schema = 0;
+    ZOOM_resultset resultset;
     int *start, *count;
 
     if (!c->tasks)
@@ -1505,6 +1477,7 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
         count = &c->tasks->u.search.count;
         syntax = c->tasks->u.search.syntax;
         elementSetName = c->tasks->u.search.elementSetName;
+        schema =  c->tasks->u.search.schema;
         break;
     case ZOOM_TASK_RETRIEVE:
         resultset = c->tasks->u.retrieve.resultset;
@@ -1512,6 +1485,7 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
         count = &c->tasks->u.retrieve.count;
         syntax = c->tasks->u.retrieve.syntax;
         elementSetName = c->tasks->u.retrieve.elementSetName;
+        schema = c->tasks->u.retrieve.schema;
         break;
     default:
         return zoom_complete;
@@ -1533,7 +1507,7 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
     {
         ZOOM_record rec =
             ZOOM_record_cache_lookup(resultset, i + *start,
-                                     syntax, elementSetName);
+                                     syntax, elementSetName, schema);
         if (!rec)
             break;
         else
@@ -1572,7 +1546,7 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
         req->preferredRecordSyntax =
             zoom_yaz_str_to_z3950oid(c, CLASS_RECSYN, syntax);
 
-    if (resultset->schema && *resultset->schema)
+    if (schema && *schema)
     {
         Z_RecordComposition *compo = (Z_RecordComposition *)
             odr_malloc(c->odr_out, sizeof(*compo));
@@ -1590,14 +1564,14 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
 
         compo->u.complex->generic->which = Z_Schema_oid;
         compo->u.complex->generic->schema.oid = (Odr_oid *)
-            zoom_yaz_str_to_z3950oid (c, CLASS_SCHEMA, resultset->schema);
+            zoom_yaz_str_to_z3950oid(c, CLASS_SCHEMA, schema);
 
         if (!compo->u.complex->generic->schema.oid)
         {
             /* OID wasn't a schema! Try record syntax instead. */
 
             compo->u.complex->generic->schema.oid = (Odr_oid *)
-                zoom_yaz_str_to_z3950oid (c, CLASS_RECSYN, resultset->schema);
+                zoom_yaz_str_to_z3950oid(c, CLASS_RECSYN, schema);
         }
         if (elementSetName && *elementSetName)
         {
@@ -1680,12 +1654,11 @@ void ZOOM_handle_Z3950_apdu(ZOOM_connection c, Z_APDU *apdu)
 
         if (!*initrs->result)
         {
-            Z_External *uif = initrs->userInformationField;
-
-            ZOOM_set_error(c, ZOOM_ERROR_INIT, 0); /* default error */
-
-            if (uif && uif->which == Z_External_userInfo1)
-                interpret_otherinformation_field(c, uif->u.userInfo1);
+            Z_DefaultDiagFormat *df = yaz_decode_init_diag(0, initrs);
+            if (df)
+                response_default_diag(c, df);
+            else
+                ZOOM_set_error(c, ZOOM_ERROR_INIT, 0); /* default error */
         }
         else
         {