/*
+ * 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.10 1995/02/20 18:19:30 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
+ * Changed header.
+ *
+ * Revision 1.12 1995/02/20 20:35:37 quinn
+ * Pull present status from presresp.
+ *
+ * Revision 1.11 1995/02/20 18:58:05 quinn
+ * Added hack for record in ANY
+ *
+ * Revision 1.10 1995/02/20 18:19:30 quinn
* More relaxed about record types.
*
* Revision 1.9 1995/02/17 15:17:51 quinn
*/
/*
- * 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 <stdlib.h>
}
}
-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;
PINITRESPONSE ires;
int len;
+ char name[512];
if (!(p = malloc(sizeof(*p))))
{
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, ZASS_NAME, ZASS_VERSION, 0);
+ p->preferredmessagesize, ZASS_ID, name, ZASS_VERSION, 0);
if (!ireq)
{
gw_log(GW_LOG_FATAL, "ZASS_TYPE", "failed to create initrequest");
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,
align = External_GetEncodingAligned(ext);
if (!align)
{
- gw_log(GW_LOG_WARN, ZASS_TYPE, "AAAARRRGH!! Enough of these log-messages!!!");
- return;
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Record wasn't octet-aligned");
+ align = External_GetEncodingSingle(ext);
+ if (!align)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Record wasn't ANY");
+ return;
+ }
+ align = align->ptr.child;
}
if (!((**p)->record = malloc(align->count + 1)))
{
}
gw_log(ZASS_DEBUG, ZASS_TYPE, "Got presentresponse");
r.num += PresentResponse_GetNumberOfRecordsReturned(pdu);
+ r.presentstatus = PresentResponse_GetPresentStatus(pdu);
if (r.num == 0)
{
gw_log(GW_LOG_WARN, ZASS_TYPE, "Got 0 records from target.");
}
PresentResponse_Destroy(pdu);
}
- while (num - r.num);
+ while (num - r.num && start);
*rec = 0;
return &r;