X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zlayer%2Fzaccess.c;h=eef418735a4addc591fe7522476b6c754cffe977;hb=7b58e36bc4c5a57dec46408bbfb3707638dd967a;hp=0420161026213c3f5b3ff3558147aac71e426d71;hpb=f6164c93ea8b575c43586bd08b34122b37f5f7af;p=egate.git diff --git a/zlayer/zaccess.c b/zlayer/zaccess.c index 0420161..eef4187 100644 --- a/zlayer/zaccess.c +++ b/zlayer/zaccess.c @@ -1,10 +1,59 @@ /* + * 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 * * $Log: zaccess.c,v $ - * Revision 1.15 1995/04/17 11:26:55 quinn + * Revision 1.17 1995/05/16 09:41:47 adam + * LICENSE. Uses new versions of odr_{set,get}buf. + * + * 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 +98,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 +181,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 +247,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 +271,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,