X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zlayer%2Fzaccess-yaz.c;h=4bd4d23a6173cbea5ffe21b66ce5f62c7fe0bca2;hb=25db261b6bbbfcc7bc26f679f195b51d31b9d7d7;hp=2fa87831e820ee8226813c98fa6aed40a5fb3254;hpb=e27961b186fe4a43d8b57af769389c980bd035dc;p=egate.git diff --git a/zlayer/zaccess-yaz.c b/zlayer/zaccess-yaz.c index 2fa8783..4bd4d23 100644 --- a/zlayer/zaccess-yaz.c +++ b/zlayer/zaccess-yaz.c @@ -1,10 +1,62 @@ /* + * Copyright (c) 1995, the EUROPAGATE consortium (see below). + * + * The EUROPAGATE consortium members are: + * + * University College Dublin + * Danmarks Teknologiske Videnscenter + * An Chomhairle Leabharlanna + * Consejo Superior de Investigaciones Cientificas + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of EUROPAGATE or the project partners may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * 3. Users of this software (implementors and gateway operators) agree to + * inform the EUROPAGATE consortium of their use of the software. This + * information will be used to evaluate the EUROPAGATE project and the + * software, and to plan further developments. The consortium may use + * the information in later publications. + * + * 4. Users of this software agree to make their best efforts, when + * documenting their use of the software, to acknowledge the EUROPAGATE + * consortium, and the role played by the software in their work. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE + * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF + * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND + * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* * Europagate, 1995 * * Z39.50 API for the Email gateway - YAZ version * * $Log: zaccess-yaz.c,v $ - * Revision 1.8 1995/04/28 14:18:38 quinn + * Revision 1.11 1995/07/03 08:20:50 adam + * Old directory. To be deleted. + * + * Revision 1.10 1995/05/16 09:41:46 adam + * LICENSE. Uses new versions of odr_{set,get}buf. + * + * Revision 1.9 1995/05/03 10:15:43 quinn + * Fixed bug in the get_record loop - crashed when diagrec was received. + * + * Revision 1.8 1995/04/28 14:18:38 quinn * *** empty log message *** * * Revision 1.7 1995/04/21 16:29:32 quinn @@ -82,7 +134,7 @@ static Z_APDU *get_apdu(struct zass *z, int *complete) return 0; } odr_reset(z->decode); - odr_setbuf(z->decode, z->inbuf, res); + odr_setbuf(z->decode, z->inbuf, res, 0); if (!z_APDU(z->decode, &ap, 0)) { gw_log(GW_LOG_WARN, ZASS_TYPE, "decode: %s", @@ -106,7 +158,7 @@ static int send_apdu(struct zass *z, Z_APDU *a) gw_log(GW_LOG_FATAL, ZASS_TYPE, "encoding initreq"); return -1; } - buf = odr_getbuf(z->encode, &len); + buf = odr_getbuf(z->encode, &len, NULL); if (cs_put(z->ass, buf, len) < 0) { gw_log(GW_LOG_FATAL, ZASS_TYPE, "cs_put"); @@ -118,41 +170,28 @@ static int send_apdu(struct zass *z, Z_APDU *a) static int send_initreq(struct zass *p, char *auth) { - Z_APDU a; - Z_InitRequest init; - Odr_bitmask options, protocolVersion; + Z_APDU *apdu; + Z_InitRequest *req; char name[512]; Z_IdAuthentication idauth; - a.which = Z_APDU_initRequest; - a.u.initRequest = &init; - init.referenceId = 0; - init.options = &options; - ODR_MASK_ZERO(&options); - ODR_MASK_SET(&options, Z_Options_search); - ODR_MASK_SET(&options, Z_Options_present); - ODR_MASK_SET(&options, Z_Options_delSet); - init.protocolVersion = &protocolVersion; - ODR_MASK_ZERO(&protocolVersion); - ODR_MASK_SET(&protocolVersion, Z_ProtocolVersion_1); - ODR_MASK_SET(&protocolVersion, Z_ProtocolVersion_2); - init.preferredMessageSize = &p->preferredmessagesize; - init.maximumRecordSize = &p->maxrecordsize; + apdu = zget_APDU (p->encode, Z_APDU_initRequest); + req = apdu->u.initRequest; + req->preferredMessageSize = &p->preferredmessagesize; + req->maximumRecordSize = &p->maxrecordsize; if (auth) { - init.idAuthentication = &idauth; + req->idAuthentication = &idauth; idauth.which = Z_IdAuthentication_open; idauth.u.open = auth; } else - init.idAuthentication = 0; - init.implementationId = ZASS_ID; + req->idAuthentication = 0; sprintf(name, "%s (YAZ protocol layer)", ZASS_NAME); - init.implementationName = name; - init.implementationVersion = ZASS_VERSION; - init.userInformationField = 0; - if (send_apdu(p, &a) < 0) + req->implementationName = name; + req->implementationVersion = ZASS_VERSION; + if (send_apdu(p, apdu) < 0) return -1; return 0; } @@ -294,8 +333,15 @@ static Z_RPNStructure *rpn2rpn(ODR o, struct ccl_rpn_node *q) odr_malloc(o, sizeof(*a)); a->attributeType = odr_malloc(o, sizeof(int)); *a->attributeType = i->type; - a->attributeValue = odr_malloc(o, sizeof(*a)); +#ifdef Z_95 + a->attributeSet = 0; + a->which = Z_AttributeValue_numeric; + a->value.numeric = odr_malloc(o, sizeof(*a->value.numeric)); + *a->value.numeric = i->value; +#else + a->attributeValue = odr_malloc(o, sizeof(*a->attributeValue)); *a->attributeValue = i->value; +#endif } return r; case CCL_RPN_SET: @@ -351,6 +397,24 @@ const struct zass_searchent *zass_searchresult(ZASS a, int *complete) oident *id; Z_DiagRec *dr = res->records->u.nonSurrogateDiagnostic; +#ifdef Z_95 + if (dr->which != Z_DiagRec_defaultFormat || + !(id = oid_getentbyoid + (dr->u.defaultFormat->diagnosticSetId)) || + id->class != CLASS_DIAGSET || + id->value != VAL_BIB1) + gw_log(GW_LOG_WARN, ZASS_TYPE, + "Missing or unknown diagset - ignoring error!"); + else + { + r.errcode = *dr->u.defaultFormat->condition; + if (dr->u.defaultFormat->addinfo) + { + strncpy(r.errstring, dr->u.defaultFormat->addinfo, 512); + r.errstring[511] = '\0'; + } + } +#else if (!(id = oid_getentbyoid(dr->diagnosticSetId)) || id->class != CLASS_DIAGSET || id->value != VAL_BIB1) gw_log(GW_LOG_WARN, ZASS_TYPE, @@ -364,6 +428,7 @@ const struct zass_searchent *zass_searchresult(ZASS a, int *complete) r.errstring[511] = '\0'; } } +#endif } } return &r; @@ -374,8 +439,8 @@ const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, { Z_Query q; Z_RPNQuery rpnq; - Z_APDU apdu; - Z_SearchRequest req; + Z_APDU *apdu; + Z_SearchRequest *req; oident bib1; int smallSetUpperBound = 0; int largeSetLowerBound = 1; @@ -383,17 +448,17 @@ const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, int replaceIndicator = 1; char *datab[100]; - apdu.which = Z_APDU_searchRequest; - apdu.u.searchRequest = &req; - req.referenceId = 0; - req.smallSetUpperBound = &smallSetUpperBound; - req.largeSetLowerBound = &largeSetLowerBound; - req.mediumSetPresentNumber = &mediumSetPresentNumber; - req.replaceIndicator = &replaceIndicator; - req.resultSetName = resname; - req.num_databaseNames = 0; - req.databaseNames = datab; - while (*databases && req.num_databaseNames < 100) + apdu = zget_APDU (a->encode, Z_APDU_searchRequest); + req = apdu->u.searchRequest; + + req->smallSetUpperBound = &smallSetUpperBound; + req->largeSetLowerBound = &largeSetLowerBound; + req->mediumSetPresentNumber = &mediumSetPresentNumber; + req->replaceIndicator = &replaceIndicator; + req->resultSetName = resname; + req->num_databaseNames = 0; + req->databaseNames = datab; + while (*databases && req->num_databaseNames < 100) { char *p = databases; int more; @@ -407,16 +472,13 @@ const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, *p = '\0'; if (p - databases) { - req.databaseNames[req.num_databaseNames] = odr_malloc(a->encode, + req->databaseNames[req->num_databaseNames] = odr_malloc(a->encode, (p - databases) + 1); - strcpy(req.databaseNames[req.num_databaseNames++], databases); + strcpy(req->databaseNames[req->num_databaseNames++], databases); } databases = p + more; } - req.smallSetElementSetNames = 0; - req.mediumSetElementSetNames = 0; - req.preferredRecordSyntax = 0; - req.query = &q; + req->query = &q; q.which = Z_Query_type_1; q.u.type_1 = &rpnq; bib1.proto = PROTO_Z3950; @@ -428,7 +490,7 @@ const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, *complete = 1; if (!(rpnq.RPNStructure = rpn2rpn(a->encode, query))) return 0; - if (send_apdu(a, &apdu) < 0) + if (send_apdu(a, apdu) < 0) return 0; if (complete) { @@ -447,6 +509,20 @@ void get_diagrec(zass_record ***p, Z_DiagRec *r) { **p = malloc(sizeof(***p)); (**p)->next = 0; +#ifdef Z_95 + (**p)->errstring[0] = '\0'; + if (r->which == Z_DiagRec_defaultFormat) + { + (**p)->errcode = *r->u.defaultFormat->condition; + if (r->u.defaultFormat->addinfo) + { + strncpy((**p)->errstring, r->u.defaultFormat->addinfo, 200); + (**p)->errstring[200] = 0; + } + } + else + (**p)->errcode = 0; +#else (**p)->errcode = *r->condition; if (r->addinfo) { @@ -455,6 +531,7 @@ void get_diagrec(zass_record ***p, Z_DiagRec *r) } else (**p)->errstring[0] = '\0'; +#endif (**p)->which = ZASS_REC_DIAG; *p = &(**p)->next; } @@ -510,8 +587,8 @@ void get_responserecords(zass_record ***p, Z_NamePlusRecordList *recs) gw_log(ZASS_DEBUG, ZASS_TYPE, "Got a record of %d bytes", r->u.octet_aligned->len); } + (*p) = &(**p)->next; } - (*p) = &(**p)->next; } } @@ -522,28 +599,27 @@ static void zass_records_free(zass_record *p) static int send_present(ZASS a, char *name, int start, int num, enum oid_value form) { - Z_APDU apdu; - Z_PresentRequest req; + Z_APDU *apdu; + Z_PresentRequest *req; #if 0 oident recsyn; #endif - apdu.which = Z_APDU_presentRequest; - apdu.u.presentRequest = &req; - req.referenceId = 0; - req.resultSetId = name; - req.resultSetStartPoint = &start; - req.numberOfRecordsRequested = # - req.elementSetNames = 0; + apdu = zget_APDU (a->encode, Z_APDU_presentRequest); + req = apdu->u.presentRequest; + + req->resultSetId = name; + req->resultSetStartPoint = &start; + req->numberOfRecordsRequested = # #if 0 recsyn.proto = PROTO_Z3950; recsyn.class = CLASS_RECSYN; recsyn.value = form; - req.preferredRecordSyntax = oid_getoidbyent(&recsyn); + req->preferredRecordSyntax = oid_getoidbyent(&recsyn); #else - req.preferredRecordSyntax = 0; + req->preferredRecordSyntax = 0; #endif - return send_apdu(a, &apdu); + return send_apdu(a, apdu); } /*