X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=zlayer%2Fzaccess-yaz.c;h=31ef2424b663cc73dcf7ed2c77c7ca0baf03b543;hb=015df1a4126226d11e1b0cee52b7d569ca2f567e;hp=62d3ef223e4af536b9faf6e1994b8ea640a3a34e;hpb=a1b0ce967a250e6bb5df41d763766f53028aa7bb;p=egate.git diff --git a/zlayer/zaccess-yaz.c b/zlayer/zaccess-yaz.c index 62d3ef2..31ef242 100644 --- a/zlayer/zaccess-yaz.c +++ b/zlayer/zaccess-yaz.c @@ -4,17 +4,25 @@ * Z39.50 API for the Email gateway - YAZ version * * $Log: zaccess-yaz.c,v $ - * Revision 1.2 1995/04/19 09:24:02 quinn + * Revision 1.5 1995/04/20 15:25:32 quinn + * Asynch. API + * + * Revision 1.4 1995/04/19 16:02:28 adam + * Record type hack. + * + * Revision 1.3 1995/04/19 12:55:15 quinn + * Added auth. + * + * Revision 1.2 1995/04/19 09:24:02 quinn * Fixed bug in zass_open - variable initialized after use * * Revision 1.1 1995/04/17 11:26:53 quinn * Added YAZ version of zaccess * - * */ /* - * Interface to the Z39.50 toolkit. + * Interface to the YAZ Z39.50 toolkit. */ #include @@ -39,14 +47,14 @@ struct zass /* Z-assoc */ ODR encode; ODR decode; int fd; /* low-level socket (for select only) */ + int nonblocking; int maxrecordsize; int preferredmessagesize; - char *outbuf; /* intermediary buffer */ char *inbuf; int inbuflen; }; -static Z_APDU *get_apdu(struct zass *z) +static Z_APDU *get_apdu(struct zass *z, int *complete) { int res; Z_APDU *ap; @@ -54,16 +62,28 @@ static Z_APDU *get_apdu(struct zass *z) if ((res = cs_get(z->ass, &z->inbuf, &z->inbuflen)) <= 0) { gw_log(GW_LOG_WARN, ZASS_TYPE, "cs_get failed"); + if (complete) + *complete = 1; return 0; } + else if (res == 1) + { + if (complete) + *complete = 0; + return 0; + } odr_reset(z->decode); odr_setbuf(z->decode, z->inbuf, res); if (!z_APDU(z->decode, &ap, 0)) { gw_log(GW_LOG_WARN, ZASS_TYPE, "decode: %s", odr_errlist[odr_geterror(z->decode)]); + if (complete) + *complete = 0; return 0; } + if (complete) + *complete = 1; return ap; } @@ -83,16 +103,17 @@ static int send_apdu(struct zass *z, Z_APDU *a) gw_log(GW_LOG_FATAL, ZASS_TYPE, "cs_put"); return -1; } - odr_reset(z->encode); + odr_reset(z->encode); /* release odr_allocated structures */ return 0; } -static int send_initreq(struct zass *p) +static int send_initreq(struct zass *p, char *auth) { Z_APDU a; Z_InitRequest init; Odr_bitmask options, protocolVersion; char name[512]; + Z_IdAuthentication idauth; a.which = Z_APDU_initRequest; a.u.initRequest = &init; @@ -108,6 +129,15 @@ static int send_initreq(struct zass *p) ODR_MASK_SET(&protocolVersion, Z_ProtocolVersion_2); init.preferredMessageSize = &p->preferredmessagesize; init.maximumRecordSize = &p->maxrecordsize; + + if (auth) + { + init.idAuthentication = &idauth; + idauth.which = Z_IdAuthentication_open; + idauth.u.open = auth; + } + else + init.idAuthentication = 0; init.idAuthentication = 0; init.implementationId = ZASS_ID; sprintf(name, "%s (YAZ protocol layer)", ZASS_NAME); @@ -119,12 +149,17 @@ static int send_initreq(struct zass *p) return 0; } -static int receive_initres(struct zass *p) +int zass_fileno(ZASS a) +{ + return a->fd; +} + +int zass_openresult(ZASS p, int *complete) { Z_APDU *ap; Z_InitResponse *res; - if (!(ap = get_apdu(p))) + if (!(ap = get_apdu(p, complete))) return -1; if (ap->which != Z_APDU_initResponse) { @@ -152,7 +187,7 @@ static int receive_initres(struct zass *p) return 0; } -ZASS zass_open(char *host, int port) +ZASS zass_open(char *host, int port, int *complete, char *auth) { struct zass *p; char addstr[512]; @@ -163,6 +198,13 @@ ZASS zass_open(char *host, int port) gw_log(GW_LOG_FATAL|GW_LOG_ERRNO, ZASS_TYPE, "malloc"); return 0; } + if (complete) + { + *complete = 1; + p->nonblocking = 1; + } + else + p->nonblocking = 0; if (!(p->encode = odr_createmem(ODR_ENCODE)) || !(p->decode = odr_createmem(ODR_DECODE))) { @@ -171,17 +213,13 @@ ZASS zass_open(char *host, int port) } p->maxrecordsize = ZASS_MAXRECORDSIZE; p->preferredmessagesize = ZASS_PREFERREDMESSAGESIZE; - if (!(p->outbuf = malloc(p->maxrecordsize + 1024))) - { - gw_log(GW_LOG_FATAL|GW_LOG_ERRNO, ZASS_TYPE, "malloc"); - return 0; - } - odr_setbuf(p->encode, p->outbuf, p->maxrecordsize + 1024); if (!(p->ass = cs_create(tcpip_type, 1, CS_Z3950))) { gw_log(GW_LOG_FATAL|GW_LOG_ERRNO, ZASS_TYPE, "cs_create"); return 0; } + p->inbuf = 0; + p->inbuflen = 0; sprintf(addstr, "%s:%d", host, port); if (!(address = tcpip_strtoaddr(addstr))) { @@ -195,18 +233,25 @@ ZASS zass_open(char *host, int port) gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to connect to %s", addstr); return 0; } - gw_log(ZASS_DEBUG, ZASS_TYPE, "connected ok"); - p->inbuf = 0; - p->inbuflen = 0; - if (send_initreq(p) < 0 || receive_initres(p) < 0) + gw_log(ZASS_DEBUG, ZASS_TYPE, "connected ok... initializing"); + if (send_initreq(p, auth) < 0) { - gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to initialize"); + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to send init"); return 0; } - gw_log(ZASS_DEBUG, ZASS_TYPE, "Sent init request"); - return p; + if (p->nonblocking) + { + *complete = 0; + return p; + } + if (zass_openresult(p, complete) < 0) + return 0; + return p; /* all done */ } +/* + * Convert the egate (ccl2rpn) version of RPN to YAZ RPN. + */ static Z_RPNStructure *rpn2rpn(ODR o, struct ccl_rpn_node *q) { Z_RPNStructure *r = odr_malloc(o, sizeof(*r)); @@ -269,13 +314,13 @@ static Z_RPNStructure *rpn2rpn(ODR o, struct ccl_rpn_node *q) } } -static const struct zass_searchent *search_result(ZASS a) +const struct zass_searchent *zass_searchresult(ZASS a, int *complete) { static struct zass_searchent r; Z_APDU *apdu; Z_SearchResponse *res; - if (!(apdu = get_apdu(a))) + if (!(apdu = get_apdu(a, complete))) return 0; if (apdu->which != Z_APDU_searchResponse) { @@ -317,7 +362,7 @@ static const struct zass_searchent *search_result(ZASS a) } const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, - char *resname, char *databases) + char *resname, char *databases, int *complete) { Z_Query q; Z_RPNQuery rpnq; @@ -370,12 +415,20 @@ const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, bib1.class = CLASS_ATTSET; bib1.value = VAL_BIB1; rpnq.attributeSetId = oid_getoidbyent(&bib1); + + if (complete) + *complete = 1; if (!(rpnq.RPNStructure = rpn2rpn(a->encode, query))) return 0; if (send_apdu(a, &apdu) < 0) return 0; - - return search_result(a); + if (complete) + { + *complete = 0; + return 0; + } + else + return zass_searchresult(a, complete); } /* @@ -463,7 +516,9 @@ static int send_present(ZASS a, char *name, int start, int num, { Z_APDU apdu; Z_PresentRequest req; +#if 0 oident recsyn; +#endif apdu.which = Z_APDU_presentRequest; apdu.u.presentRequest = &req; @@ -472,22 +527,29 @@ static int send_present(ZASS a, char *name, int start, int num, req.resultSetStartPoint = &start; req.numberOfRecordsRequested = # req.elementSetNames = 0; +#if 0 recsyn.proto = PROTO_Z3950; recsyn.class = CLASS_RECSYN; recsyn.value = form; req.preferredRecordSyntax = oid_getoidbyent(&recsyn); +#else + req.preferredRecordSyntax = 0; +#endif return send_apdu(a, &apdu); } /* * Note that 1== first record. + * TODO: make this baby operate in nonblocking mode, too. */ const struct zass_presentent *zass_present(ZASS a, char *resname, int start, - int num) + int num, int *complete) { static struct zass_presentent r; zass_record **rec = &r.records; + if (complete) + *complete = 1; r.num = 0; if (r.records) { @@ -503,8 +565,12 @@ const struct zass_presentent *zass_present(ZASS a, char *resname, int start, "Fetching %d records from # %d", num - r.num, start); if (send_present(a, resname, start, num - r.num, VAL_USMARC) < 0) return 0; - if (!(apdu = get_apdu(a))) + if (!(apdu = get_apdu(a, complete))) + { + if (complete) + *complete = 1; return 0; + } if (apdu->which != Z_APDU_presentResponse) { gw_log(GW_LOG_FATAL, ZASS_TYPE, "Expected presentresponse, got #%d", @@ -538,3 +604,9 @@ const struct zass_presentent *zass_present(ZASS a, char *resname, int start, while (num - r.num && start); return &r; } + +const struct zass_presentent *zass_presentresult(ZASS a, int *complete) +{ + *complete = 1; + return 0; +}