X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-z3950.c;h=69d6dbe525ad96346b9c1ed4ad5ae378c8ea2c2a;hp=cf1b12f9cc3edc74866a454c9c8453d334b479dd;hb=80559dbf0a5d6993eef844e6f6198d28ff5a44fa;hpb=5242cb5a8634bfa38b9333ff7f903e718ac6e292 diff --git a/src/zoom-z3950.c b/src/zoom-z3950.c index cf1b12f..69d6dbe 100644 --- a/src/zoom-z3950.c +++ b/src/zoom-z3950.c @@ -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; @@ -673,8 +670,7 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c) if (facets) { Z_FacetList *facet_list = yaz_pqf_parse_facet_list(c->odr_out, facets); if (facet_list) { - Z_OtherInformation **oi; - yaz_oi_APDU(apdu, &oi); + Z_OtherInformation **oi = &search_req->additionalSearchInfo; yaz_oi_set_facetlist(oi, c->odr_out, facet_list); } else @@ -722,6 +718,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 +731,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 +957,6 @@ ZOOM_API(void) } } - static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr, int present_phase); @@ -1085,35 +1082,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 +1115,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 +1142,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 +1325,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 +1337,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 +1345,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 +1374,7 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr, for (i = 0; inum_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 +1396,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 +1408,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 +1458,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 +1476,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 +1484,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 +1506,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 +1545,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 +1563,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 +1653,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 {