X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zlayer%2Fzaccess.c;h=6d7bc9f239a11f83f3200100586cc8ef77ee7161;hb=015df1a4126226d11e1b0cee52b7d569ca2f567e;hp=0420161026213c3f5b3ff3558147aac71e426d71;hpb=7dcd55800b587a1e12dd8b6cb9209dfe38be32e3;p=egate.git diff --git a/zlayer/zaccess.c b/zlayer/zaccess.c index 0420161..6d7bc9f 100644 --- a/zlayer/zaccess.c +++ b/zlayer/zaccess.c @@ -4,7 +4,10 @@ * Z39.50 API for the Email gateway * * $Log: zaccess.c,v $ - * Revision 1.15 1995/04/17 11:26:55 quinn + * Revision 1.16 1995/04/20 15:25:34 quinn + * Asynch. API + * + * Revision 1.15 1995/04/17 11:26:55 quinn * Added YAZ version of zaccess * * Revision 1.14 1995/02/23 08:32:26 adam @@ -49,7 +52,18 @@ */ /* - * Interface to the Z39.50 toolkit. + * Interface to the Z39.50 toolkit. Primary function is to hide Zdist, or + * whatever lower-layer we decide to use later. The decision to add a + * layer atop the toolkit was twofold: It vastly simplifies the + * implementation of the protocol persistence, and it hides Zdist. The + * latter is useful after Zdist has gone and changed their fine API after + * we went through all the trouble of documenting it in our Design. Don't + * want that to happen again. + * + * For the time being at least, we'll have these routines hang (or err) if + * they get a WOULDBLOCK on a write. That seems safe since, under normal + * circumstances, the network buffers should always be able to absorb + * the small request packages. */ #include @@ -121,7 +135,38 @@ int rpn2kwaqs(struct ccl_rpn_node *q, char **p) } } -ZASS zass_open(char *host, int port) +int zass_openresult(ZASS p, int *complete) +{ + int len; + PINITRESPONSE ires; + + if ((len = zutil_GetBERFromNet(p->ass, (unsigned char*)p->buf, + p->maxrecordsize)) <= 0) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to receive initresponse"); + return 0; + } + ires = (PINITRESPONSE) zutil_CreateFromData((unsigned char*)p->buf, len); + if (InitResponse_GetTag(ires) != INITRESPONSE_TAG) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Expected initresponse from target"); + return 0; + } + gw_log(ZASS_DEBUG, ZASS_TYPE, "Got initresponse"); + if (!InitResponse_GetResult(ires)) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Access to target denied."); + return 0; + } + gw_log(ZASS_DEBUG, ZASS_TYPE, "Connected OK"); + p->preferredmessagesize = InitResponse_GetPreferredMessageSize(ires); + p->maxrecordsize = InitResponse_GetExceptionalRecordSize(ires); + InitResponse_Destroy(ires); + *complete = 1; + return 0; +} + +ZASS zass_open(char *host, int port, int *complete) { struct zass *p; PINITREQUEST ireq; @@ -156,8 +201,8 @@ ZASS zass_open(char *host, int port) gw_log(GW_LOG_WARN, ZASS_TYPE, "netbox_Open failed"); return 0; } - gw_log(ZASS_DEBUG, ZASS_TYPE, "Opened connection to %s:%d", p->ass->HostName, - p->ass->Port); + gw_log(ZASS_DEBUG, ZASS_TYPE, "Opened connection to %s:%d", + p->ass->HostName, p->ass->Port); sprintf(name, "%s (ZDIST protocol layer)", ZASS_NAME); ireq = InitRequest_CreateInitAllASCII(0, "yy", "yy", p->maxrecordsize, p->preferredmessagesize, ZASS_ID, name, ZASS_VERSION, 0); @@ -180,29 +225,12 @@ ZASS zass_open(char *host, int port) return 0; } gw_log(ZASS_DEBUG, ZASS_TYPE, "Sent initrequest."); - if ((len = zutil_GetBERFromNet(p->ass, (unsigned char*)p->buf, - p->maxrecordsize)) <= 0) - { - gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to receive initresponse"); - return 0; - } - ires = (PINITRESPONSE) zutil_CreateFromData((unsigned char*)p->buf, len); - if (InitResponse_GetTag(ires) != INITRESPONSE_TAG) - { - gw_log(GW_LOG_FATAL, ZASS_TYPE, "Expected initresponse from target"); - return 0; - } - gw_log(ZASS_DEBUG, ZASS_TYPE, "Got initresponse"); - if (!InitResponse_GetResult(ires)) - { - gw_log(GW_LOG_FATAL, ZASS_TYPE, "Access to target denied."); + + if (zass_openresult(p, complete) < 0 && (!complete || *complete)) return 0; - } - gw_log(ZASS_DEBUG, ZASS_TYPE, "Connected OK"); - p->preferredmessagesize = InitResponse_GetPreferredMessageSize(ires); - p->maxrecordsize = InitResponse_GetExceptionalRecordSize(ires); - InitResponse_Destroy(ires); - return p; + else + return p; + } const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query,