Merge branch 'master' into sru_2_0
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 20 Sep 2013 07:20:23 +0000 (09:20 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 20 Sep 2013 07:20:23 +0000 (09:20 +0200)
Conflicts:
IDMETA
debian/changelog
debian/rules

1  2 
client/client.c
debian/changelog
src/seshigh.c

diff --combined client/client.c
@@@ -83,7 -83,6 +83,7 @@@ static file_history_t file_history = 0
  
  static char sru_method[10] = "soap";
  static char sru_version[10] = "1.2";
 +static char sru_recordPacking[10] = "";
  static char *codeset = 0;               /* character set for output */
  static int hex_dump = 0;
  static char *dump_file_prefix = 0;
@@@ -318,9 -317,14 +318,9 @@@ static void print_refid(Z_ReferenceId *
  
  static Z_ReferenceId *set_refid(ODR out)
  {
 -    Z_ReferenceId *id;
      if (!refid)
          return 0;
 -    id = (Z_ReferenceId *) odr_malloc(out, sizeof(*id));
 -    id->size = id->len = strlen(refid);
 -    id->buf = (unsigned char *) odr_malloc(out, id->len);
 -    memcpy(id->buf, refid, id->len);
 -    return id;
 +    return odr_create_Odr_oct(out, refid, strlen(refid));
  }
  
  /* INIT SERVICE ------------------------------- */
@@@ -923,7 -927,10 +923,10 @@@ static void display_record(Z_External *
              || !oid_oidcmp(oid, yaz_oid_recsyn_html))
          {
              print_xml_record(octet_buf, octet_len);
+         }
+         else if (!oid_oidcmp(oid, yaz_oid_recsyn_mab))
+         {
+             print_record(octet_buf, octet_len);
          }
          else
          {
@@@ -1413,12 -1420,12 +1416,12 @@@ static int send_SRW_scanRequest(const c
      switch (queryType)
      {
      case QueryType_CQL:
 -        sr->u.scan_request->query_type = Z_SRW_query_type_cql;
 -        sr->u.scan_request->scanClause.cql = encode_SRW_term(out, arg);
 +        sr->u.scan_request->queryType = "cql";
 +        sr->u.scan_request->scanClause = encode_SRW_term(out, arg);
          break;
      case QueryType_Prefix:
 -        sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
 -        sr->u.scan_request->scanClause.pqf = encode_SRW_term(out, arg);
 +        sr->u.scan_request->queryType = "pqf";
 +        sr->u.scan_request->scanClause = encode_SRW_term(out, arg);
          break;
      default:
          printf("Only CQL and PQF supported in SRW\n");
@@@ -1452,25 -1459,23 +1455,25 @@@ static int send_SRW_searchRequest(cons
      switch (queryType)
      {
      case QueryType_CQL:
 -        srw_sr->u.request->query_type = Z_SRW_query_type_cql;
 -        srw_sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg);
 +        srw_sr->u.request->queryType = "cql";
 +        srw_sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg);
  
 -        sr->u.request->query_type = Z_SRW_query_type_cql;
 -        sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg);
 +        sr->u.request->queryType = "cql";
 +        sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg);
          break;
      case QueryType_Prefix:
 -        srw_sr->u.request->query_type = Z_SRW_query_type_pqf;
 -        srw_sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg);
 +        srw_sr->u.request->queryType = "pqf";
 +        srw_sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg);
  
 -        sr->u.request->query_type = Z_SRW_query_type_pqf;
 -        sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg);
 +        sr->u.request->queryType = "pqf";
 +        sr->u.request->query = encode_SRW_term(srw_sr_odr_out, arg);
          break;
      default:
          printf("Only CQL and PQF supported in SRW\n");
          return 0;
      }
 +    if (*sru_recordPacking)
 +        sr->u.request->recordPacking = sru_recordPacking;
      sru_maximumRecords = 0;
      sr->u.request->maximumRecords = odr_intdup(out, 0);
      sr->u.request->facetList = facet_list;
@@@ -1555,12 -1560,12 +1558,12 @@@ static int send_Z3950_searchRequest(con
      req->referenceId = set_refid(out);
      if (!strcmp(arg, "@big")) /* strictly for troublemaking */
      {
 -        static unsigned char big[2100];
 +        static char big[2100];
          static Odr_oct bigo;
  
          /* send a very big referenceid to test transport stack etc. */
          memset(big, 'A', 2100);
 -        bigo.len = bigo.size = 2100;
 +        bigo.len = 2100;
          bigo.buf = big;
          req->referenceId = &bigo;
      }
      case QueryType_CCL:
          query.which = Z_Query_type_2;
          query.u.type_2 = &ccl_query;
 -        ccl_query.buf = (unsigned char*) arg;
 +        ccl_query.buf = (char *) arg;
          ccl_query.len = strlen(arg);
          break;
      case QueryType_CCL2RPN:
@@@ -1862,7 -1867,7 +1865,7 @@@ static void print_referenceId(int iLeve
          int i;
  
          print_level(iLevel);
 -        printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
 +        printf("Ref Id (%d): ", referenceId->len);
          for (i = 0; i < referenceId->len; i++)
              printf("%c", referenceId->buf[i]);
          printf("\n");
@@@ -2124,8 -2129,16 +2127,8 @@@ static Z_External *create_external_item
          r->indirect_reference = 0;
          r->descriptor = 0;
          r->which = Z_External_single;
 -
 -        r->u.single_ASN1_type = (Odr_oct *)
 -            odr_malloc(out, sizeof(*r->u.single_ASN1_type));
 -        r->u.single_ASN1_type->buf = (unsigned char *)
 -        odr_malloc(out, item_request_size);
 -        r->u.single_ASN1_type->len = item_request_size;
 -        r->u.single_ASN1_type->size = item_request_size;
 -        memcpy(r->u.single_ASN1_type->buf, item_request_buf,
 -                item_request_size);
 -
 +        r->u.single_ASN1_type =
 +            odr_create_Odr_oct(out, item_request_buf, item_request_size);
          do_hex_dump(item_request_buf,item_request_size);
      }
      return r;
@@@ -2169,8 -2182,18 +2172,8 @@@ static Z_External *create_external_ILL_
          r->indirect_reference = 0;
          r->descriptor = 0;
          r->which = Z_External_single;
 -
 -        r->u.single_ASN1_type = (Odr_oct *)
 -            odr_malloc(out, sizeof(*r->u.single_ASN1_type));
 -        r->u.single_ASN1_type->buf = (unsigned char *)
 -        odr_malloc(out, ill_request_size);
 -        r->u.single_ASN1_type->len = ill_request_size;
 -        r->u.single_ASN1_type->size = ill_request_size;
 -        memcpy(r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
 -/*         printf("len = %d\n", ill_request_size); */
 -/*              do_hex_dump(ill_request_buf,ill_request_size); */
 -/*              printf("--- end of extenal\n"); */
 -
 +        r->u.single_ASN1_type = odr_create_Odr_oct(out, ill_request_buf,
 +                                                   ill_request_size);
      }
      return r;
  }
@@@ -2459,8 -2482,16 +2462,8 @@@ static int send_Z3950_update(int versio
          notToKeep->elements[0] = (Z_IU0SuppliedRecords_elem *)
              odr_malloc(out, sizeof(**notToKeep->elements));
          notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
 -        if (recid)
 -        {
 -            notToKeep->elements[0]->u.opaque = (Odr_oct *)
 -                odr_malloc(out, sizeof(Odr_oct));
 -            notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
 -            notToKeep->elements[0]->u.opaque->size = strlen(recid);
 -            notToKeep->elements[0]->u.opaque->len = strlen(recid);
 -        }
 -        else
 -            notToKeep->elements[0]->u.opaque = 0;
 +        notToKeep->elements[0]->u.opaque = recid ?
 +            odr_create_Odr_oct(out, recid, strlen(recid)) : 0;
          notToKeep->elements[0]->supplementalId = 0;
          notToKeep->elements[0]->correlationInfo = 0;
          notToKeep->elements[0]->record = record_this;
          notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
              odr_malloc(out, sizeof(**notToKeep->elements));
          notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
 -        if (recid)
 -        {
 -            notToKeep->elements[0]->u.opaque = (Odr_oct *)
 -                odr_malloc(out, sizeof(Odr_oct));
 -            notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
 -            notToKeep->elements[0]->u.opaque->size = strlen(recid);
 -            notToKeep->elements[0]->u.opaque->len = strlen(recid);
 -        }
 -        else
 -            notToKeep->elements[0]->u.opaque = 0;
 +        notToKeep->elements[0]->u.opaque = recid ?
 +            odr_create_Odr_oct(out, recid, strlen(recid)) : 0;
          notToKeep->elements[0]->supplementalId = 0;
          notToKeep->elements[0]->correlationInfo = 0;
          notToKeep->elements[0]->record = record_this;
@@@ -2543,7 -2582,7 +2546,7 @@@ static int cmd_xmles(const char *arg
                            &ext->u.single_ASN1_type->len) == 0)
              return 0;
  
 -        ext->u.single_ASN1_type->buf = (unsigned char *) asn_buf;
 +        ext->u.single_ASN1_type->buf = asn_buf;
  
          oid = yaz_string_to_oid_odr(yaz_oid_std(),
                                      CLASS_EXTSERV, oid_str, out);
@@@ -2786,8 -2825,7 +2789,8 @@@ static int cmd_sru(const char *arg
      }
      else
      {
 -        int r = sscanf(arg, "%9s %9s", sru_method, sru_version);
 +        int r = sscanf(arg, "%9s %9s %9s", sru_method, sru_version,
 +            sru_recordPacking);
          if (r >= 1)
          {
              if (!yaz_matchstr(sru_method, "post"))
@@@ -3130,8 -3168,6 +3133,8 @@@ static int send_SRW_presentRequest(cons
          return 0;
      if (!parse_show_args(arg, setstring, &setno, &nos))
          return 0;
 +    if (*sru_recordPacking)
 +        sr->u.request->recordPacking = sru_recordPacking;
      sr->u.request->startRecord = odr_intdup(out, setno);
      sru_maximumRecords = nos;
      sr->u.request->maximumRecords = odr_intdup(out, nos);
@@@ -3348,8 -3384,10 +3351,8 @@@ static int send_Z3950_scanrequest(cons
              req->termListAndStartPoint->term->u.general)
          {
              req->termListAndStartPoint->term->u.general->buf =
 -                (unsigned char *) odr_strdup(out, term);
 -            req->termListAndStartPoint->term->u.general->len =
 -                req->termListAndStartPoint->term->u.general->size =
 -                strlen(term);
 +                odr_strdup(out, term);
 +            req->termListAndStartPoint->term->u.general->len = strlen(term);
          }
      }
      req->referenceId = set_refid(out);
@@@ -4417,7 -4455,7 +4420,7 @@@ static void http_response(Z_HTTP_Respon
              Z_SOAP *soap_package = 0;
              ODR o = odr_createmem(ODR_DECODE);
              Z_SOAP_Handler soap_handlers[] = {
 -                {YAZ_XMLNS_SRU_v2_response, 0, (Z_SOAP_fun) yaz_srw_codec},
 +                {YAZ_XMLNS_SRU_v2_mask, 0, (Z_SOAP_fun) yaz_srw_codec},
                  {YAZ_XMLNS_UPDATE_v0_9, 0, (Z_SOAP_fun) yaz_ucp_codec},
                  {YAZ_XMLNS_SRU_v1_response, 0, (Z_SOAP_fun) yaz_srw_codec},
                  {0, 0, 0}
diff --combined debian/changelog
@@@ -1,9 -1,9 +1,15 @@@
 +yaz (5.0.0-1indexdata) unstable; urgency=low
 +
 +  * Version 5.
 +
 + -- Adam Dickmeiss <adam@indexdata.dk>  Wed, 11 Sep 2013 09:26:11 +0200
 +
+ yaz (4.2.67-1indexdata) unstable; urgency=low
+   * Upstram.
+  -- Adam Dickmeiss <adam@indexdata.dk>  Thu, 19 Sep 2013 13:19:07 +0200
  yaz (4.2.66-1indexdata) unstable; urgency=low
  
    * Upstream.
diff --combined src/seshigh.c
@@@ -56,7 -56,6 +56,7 @@@
  #include <libxml/tree.h>
  #endif
  
 +#include <yaz/facet.h>
  #include <yaz/xmalloc.h>
  #include <yaz/comstack.h>
  #include "eventl.h"
@@@ -934,11 -933,11 +934,11 @@@ static void srw_bend_search(associatio
          rr.present_number = srw_req->maximumRecords ?
              *srw_req->maximumRecords : 0;
  
 -        if (srw_req->query_type == Z_SRW_query_type_cql)
 +        if (!srw_req->queryType || !strcmp(srw_req->queryType, "cql"))
          {
              if (assoc->server && assoc->server->cql_transform)
              {
 -                int srw_errcode = cql2pqf(assoc->encode, srw_req->query.cql,
 +                int srw_errcode = cql2pqf(assoc->encode, srw_req->query,
                                            assoc->server->cql_transform,
                                            rr.query,
                                            &rr.srw_sortKeys);
                  ext->indirect_reference = 0;
                  ext->descriptor = 0;
                  ext->which = Z_External_CQL;
 -                ext->u.cql = srw_req->query.cql;
 +                ext->u.cql = srw_req->query;
  
                  rr.query->which = Z_Query_type_104;
                  rr.query->u.type_104 =  ext;
              }
          }
 -        else if (srw_req->query_type == Z_SRW_query_type_pqf)
 +        else if (!strcmp(srw_req->queryType, "pqf"))
          {
              Z_RPNQuery *RPNquery;
              YAZ_PQF_Parser pqf_parser;
  
              pqf_parser = yaz_pqf_create();
  
 -            RPNquery = yaz_pqf_parse(pqf_parser, assoc->decode,
 -                                     srw_req->query.pqf);
 +            RPNquery = yaz_pqf_parse(pqf_parser, assoc->decode, srw_req->query);
              if (!RPNquery)
              {
                  const char *pqf_msg;
              rr.errstring = 0;
              rr.search_info = 0;
              rr.search_input = 0;
 +
 +            if (srw_req->facetList)
 +                yaz_oi_set_facetlist(&rr.search_input, assoc->encode,
 +                                     srw_req->facetList);
 +
              yaz_log_zquery_level(log_requestdetail,rr.query);
  
              (assoc->init->bend_search)(assoc->backend, &rr);
                          odr_intdup(assoc->encode, *rr.srw_setnameIdleTime );
                }
  
 +                srw_res->facetList = yaz_oi_get_facetlist(&rr.search_info);
                  if (start > rr.hits || start < 1)
                  {
                      /* if hits<=0 and start=1 we don't return a diagnostic */
                      res->extraResponseData_buf = rr.extra_response_data;
                      res->extraResponseData_len = strlen(rr.extra_response_data);
                  }
 -                if (rr.estimated_hit_count || rr.partial_resultset)
 +                if (strcmp(res->srw_version, "2.") > 0)
 +                {
 +                    if (rr.estimated_hit_count)
 +                        srw_res->resultCountPrecision =
 +                            odr_strdup(assoc->encode, "estimate");
 +                    else if (rr.partial_resultset)
 +                        srw_res->resultCountPrecision =
 +                            odr_strdup(assoc->encode, "minimum");
 +                    else
 +                        srw_res->resultCountPrecision =
 +                            odr_strdup(assoc->encode, "exact");
 +                }
 +                else if (rr.estimated_hit_count || rr.partial_resultset)
                  {
                      yaz_add_srw_diagnostic(
                          assoc->encode,
      }
      if (log_request)
      {
 -        const char *querystr = "?";
 -        const char *querytype = "?";
          WRBUF wr = wrbuf_alloc();
  
 -        switch (srw_req->query_type)
 -        {
 -        case Z_SRW_query_type_cql:
 -            querytype = "CQL";
 -            querystr = srw_req->query.cql;
 -            break;
 -        case Z_SRW_query_type_pqf:
 -            querytype = "PQF";
 -            querystr = srw_req->query.pqf;
 -            break;
 -        }
          wrbuf_printf(wr, "SRWSearch %s ", srw_req->database);
          if (srw_res->num_diagnostics)
              wrbuf_printf(wr, "ERROR %s", srw_res->diagnostics[0].uri);
                        srw_res->resultSetId : "-"),
                       (srw_req->startRecord ? *srw_req->startRecord : 1),
                       srw_res->num_records);
 -        yaz_log(log_request, "%s %s: %s", wrbuf_cstr(wr), querytype, querystr);
 +        yaz_log(log_request, "%s %s: %s", wrbuf_cstr(wr), srw_req->queryType,
 +                srw_req->query);
          wrbuf_destroy(wr);
      }
  }
@@@ -1355,20 -1349,20 +1355,20 @@@ static void srw_bend_scan(association *
          }
          save_entries = bsrr->entries;  /* save it so we can compare later */
  
 -        if (srw_req->query_type == Z_SRW_query_type_pqf &&
 +        if (srw_req->queryType && !strcmp(srw_req->queryType, "pqf") &&
              assoc->init->bend_scan)
          {
              YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
  
              bsrr->term = yaz_pqf_scan(pqf_parser, assoc->decode,
                                        &bsrr->attributeset,
 -                                      srw_req->scanClause.pqf);
 +                                      srw_req->scanClause);
              yaz_pqf_destroy(pqf_parser);
              bsrr->scanClause = 0;
              ((int (*)(void *, bend_scan_rr *))
               (*assoc->init->bend_scan))(assoc->backend, bsrr);
          }
 -        else if (srw_req->query_type == Z_SRW_query_type_cql
 +        else if ((!srw_req->queryType || !strcmp(srw_req->queryType, "cql"))
                   && assoc->init->bend_scan && assoc->server
                   && assoc->server->cql_transform)
          {
              bsrr->term = (Z_AttributesPlusTerm *)
                  odr_malloc(assoc->decode, sizeof(*bsrr->term));
              srw_error = cql2pqf_scan(assoc->encode,
 -                                     srw_req->scanClause.cql,
 +                                     srw_req->scanClause,
                                       assoc->server->cql_transform,
                                       bsrr->term);
              if (srw_error)
                   (*assoc->init->bend_scan))(assoc->backend, bsrr);
              }
          }
 -        else if (srw_req->query_type == Z_SRW_query_type_cql
 +        else if ((!srw_req->queryType || !strcmp(srw_req->queryType, "cql"))
                   && assoc->init->bend_srw_scan)
          {
              bsrr->term = 0;
              bsrr->attributeset = 0;
 -            bsrr->scanClause = srw_req->scanClause.cql;
 +            bsrr->scanClause = srw_req->scanClause;
              ((int (*)(void *, bend_scan_rr *))
               (*assoc->init->bend_srw_scan))(assoc->backend, bsrr);
          }
      if (log_request)
      {
          WRBUF wr = wrbuf_alloc();
 -        const char *querytype = 0;
 -        const char *querystr = 0;
 -
 -        switch(srw_req->query_type)
 -        {
 -        case Z_SRW_query_type_pqf:
 -            querytype = "PQF";
 -            querystr = srw_req->scanClause.pqf;
 -            break;
 -        case Z_SRW_query_type_cql:
 -            querytype = "CQL";
 -            querystr = srw_req->scanClause.cql;
 -            break;
 -        default:
 -            querytype = "UNKNOWN";
 -            querystr = "";
 -        }
 -
          wrbuf_printf(wr, "SRWScan %s ", srw_req->database);
  
          if (srw_res->num_diagnostics)
                       (srw_req->maximumTerms ?
                        *srw_req->maximumTerms : 1));
          /* there is no step size in SRU/W ??? */
 -        wrbuf_printf(wr, "%s: %s ", querytype, querystr);
 +        wrbuf_printf(wr, "%s: %s ", srw_req->queryType, srw_req->scanClause);
          yaz_log(log_request, "%s ", wrbuf_cstr(wr) );
          wrbuf_destroy(wr);
      }
@@@ -2681,7 -2693,9 +2681,9 @@@ static Z_APDU *process_searchRequest(as
          bsrr->errcode = 0;
          bsrr->errstring = NULL;
          bsrr->search_info = NULL;
-         bsrr->search_input = req->otherInfo;
+         bsrr->search_input = req->additionalSearchInfo;
+         if (!bsrr->search_input)
+             bsrr->search_input = req->otherInfo;
          bsrr->present_number = *req->mediumSetPresentNumber;
  
          if (assoc->server && assoc->server->cql_transform
@@@ -3098,6 -3112,7 +3100,6 @@@ static Z_APDU *process_scanRequest(asso
          {
              Z_Entry *e;
              Z_TermInfo *t;
 -            Odr_oct *o;
  
              tab[i] = e = (Z_Entry *)odr_malloc(assoc->encode, sizeof(*e));
              if (bsrr->entries[i].occurrences >= 0)
                  t->term = (Z_Term *)
                      odr_malloc(assoc->encode, sizeof(*t->term));
                  t->term->which = Z_Term_general;
 -                t->term->u.general = o =
 -                    (Odr_oct *)odr_malloc(assoc->encode, sizeof(Odr_oct));
 -                o->buf = (unsigned char *)
 -                    odr_malloc(assoc->encode, o->len = o->size =
 -                               strlen(bsrr->entries[i].term));
 -                memcpy(o->buf, bsrr->entries[i].term, o->len);
 +                t->term->u.general =
 +                    odr_create_Odr_oct(assoc->encode,
 +                                       bsrr->entries[i].term,
 +                                       strlen(bsrr->entries[i].term));
                  yaz_log(YLOG_DEBUG, "  term #%d: '%s' (" ODR_INT_PRINTF ")", i,
                           bsrr->entries[i].term, bsrr->entries[i].occurrences);
              }