Changed the way yaz-client encodes charset negotiation information
[yaz-moved-to-github.git] / src / seshigh.c
index 4b8b89e..999d1ba 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2007, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.118 2007-05-06 20:12:20 adam Exp $
+ * $Id: seshigh.c,v 1.121 2007-05-30 21:56:59 adam Exp $
  */
 /**
  * \file seshigh.c
@@ -584,7 +584,7 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr)
 #if YAZ_HAVE_XML2
     yaz_record_conv_t rc = 0;
     const char *match_schema = 0;
-    int *match_syntax = 0;
+    Odr_oid *match_syntax = 0;
 
     if (assoc->server)
     {
@@ -1264,6 +1264,7 @@ static void srw_bend_scan(association *assoc, request *req,
         bsrr->print = assoc->print;
         bsrr->step_size = odr_intdup(assoc->decode, 0);
         bsrr->entries = 0;
+        bsrr->setname = 0;
 
         if (bsrr->num_entries > 0) 
         {
@@ -2289,36 +2290,32 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
         strcat(options, " sort");
     }
     
-    if (!assoc->init->charneg_response && !assoc->init->charneg_request)
+    if (ODR_MASK_GET(req->options, Z_Options_negotiationModel))
     {
-        if (assoc->init->query_charset)
+        Z_OtherInformationUnit *p0;
+
+        if (!assoc->init->charneg_response)
         {
-            assoc->init->charneg_response = yaz_set_response_charneg(
-                assoc->encode, assoc->init->query_charset, 0, 
-                assoc->init->records_in_same_charset);
+            if (assoc->init->query_charset)
+            {
+                assoc->init->charneg_response = yaz_set_response_charneg(
+                    assoc->encode, assoc->init->query_charset, 0, 
+                    assoc->init->records_in_same_charset);
+            }
+            else
+            {
+                yaz_log(YLOG_WARN, "default query_charset not defined by backend");
+            }
         }
-        else
+        if (assoc->init->charneg_response
+            && (p0=yaz_oi_update(&resp->otherInfo, assoc->encode, NULL, 0, 0)))
         {
-            yaz_log(YLOG_WARN, "default query_charset not defined by backend");
-        }
-    }
-    if (assoc->init->charneg_response 
-        && ODR_MASK_GET(req->options, Z_Options_negotiationModel))
-    {
-        Z_OtherInformation **p;
-        Z_OtherInformationUnit *p0;
-        
-        yaz_oi_APDU(apdu, &p);
-        
-        if ((p0=yaz_oi_update(p, assoc->encode, NULL, 0, 0))) {
-            ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
-            
             p0->which = Z_OtherInfo_externallyDefinedInfo;
             p0->information.externallyDefinedInfo =
                 assoc->init->charneg_response;
+            ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
+            strcat(options, " negotiation");
         }
-        ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
-        strcat(options, " negotiation");
     }
     if (ODR_MASK_GET(req->options, Z_Options_triggerResourceCtrl))
         ODR_MASK_SET(resp->options, Z_Options_triggerResourceCtrl);
@@ -2358,7 +2355,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
                 assoc->init->implementation_name,
                 odr_prepend(assoc->encode, "GFS", resp->implementationName));
 
-    version = odr_strdup(assoc->encode, "$Revision: 1.118 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.121 $");
     if (strlen(version) > 10)   /* check for unexpanded CVS strings */
         version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
@@ -2472,7 +2469,7 @@ static Z_Records *pack_records(association *a, char *setname, int start,
                                int *num, Z_RecordComposition *comp,
                                int *next, int *pres,
                                Z_ReferenceId *referenceId,
-                               int *oid, int *errcode)
+                               Odr_oid *oid, int *errcode)
 {
     int recno, total_length = 0, toget = *num, dumped_records = 0;
     Z_Records *records =
@@ -3014,6 +3011,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
     bsrr->stream = assoc->encode;
     bsrr->print = assoc->print;
     bsrr->step_size = res->stepSize;
+    bsrr->setname = yaz_oi_get_string_oid(&req->otherInfo, 
+                                          yaz_oid_userinfo_scan_set, 1, 0);
     bsrr->entries = 0;
     /* For YAZ 2.0 and earlier it was the backend handler that
        initialized entries (member display_term did not exist)
@@ -3127,35 +3126,32 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
         int i;
         WRBUF wr = wrbuf_alloc();
         wrbuf_printf(wr, "Scan ");
-        for (i = 0 ; i < req->num_databaseNames; i++){
+        for (i = 0 ; i < req->num_databaseNames; i++)
+        {
             if (i)
                 wrbuf_printf(wr, "+");
             wrbuf_printf(wr, req->databaseNames[i]);
         }
+
         wrbuf_printf(wr, " ");
         
-        if (bsrr->errcode){
+        if (bsrr->errcode)
             wr_diag(wr, bsrr->errcode, bsrr->errstring);
-            wrbuf_printf(wr, " ");
-        }
         else
-            wrbuf_printf(wr, "OK "); 
-        /* else if (*res->scanStatus == Z_Scan_success) */
-        /*    wrbuf_printf(wr, "OK "); */
-        /* else */
-        /* wrbuf_printf(wr, "Partial "); */
-
-        if (*res->numberOfEntriesReturned)
-            wrbuf_printf(wr, "%d - ", *res->numberOfEntriesReturned);
-        else
-            wrbuf_printf(wr, "0 - ");
+            wrbuf_printf(wr, "OK"); 
 
-        wrbuf_printf(wr, "%d+%d+%d ",
+        wrbuf_printf(wr, " %d - %d+%d+%d",
+                     res->numberOfEntriesReturned ?
+                     *res->numberOfEntriesReturned : 0,
                      (req->preferredPositionInResponse ?
                       *req->preferredPositionInResponse : 1),
                      *req->numberOfTermsRequested,
                      (res->stepSize ? *res->stepSize : 1));
+        
+        if (bsrr->setname)
+            wrbuf_printf(wr, "+%s", bsrr->setname);
 
+        wrbuf_printf(wr, " ");
         yaz_scan_to_wrbuf(wr, req->termListAndStartPoint, 
                           bsrr->attributeset);
         yaz_log(log_request, "%s", wrbuf_cstr(wr) );