Added auth.
[egate.git] / zlayer / zaccess.c
index 346d4ed..0420161 100644 (file)
@@ -1,8 +1,34 @@
 /*
  * Europagate, 1995
  *
+ * Z39.50 API for the Email gateway
+ *
  * $Log: zaccess.c,v $
- * Revision 1.6  1995/02/17 14:41:22  quinn
+ * 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
+ * Bug fix
+ *
+ * Revision 1.8  1995/02/17  14:48:41  quinn
+ * 'nother bug in present
+ *
+ * Revision 1.7  1995/02/17  14:42:21  quinn
+ * Trivial bug in fetch-loop.
+ *
+ * Revision 1.6  1995/02/17  14:41:22  quinn
  * Debugging.
  *
  * Revision 1.5  1995/02/17  13:58:01  quinn
@@ -101,6 +127,7 @@ ZASS zass_open(char *host, int port)
     PINITREQUEST ireq;
     PINITRESPONSE ires;
     int len;
+    char name[512];
 
     if (!(p = malloc(sizeof(*p))))
     {
@@ -131,8 +158,9 @@ ZASS zass_open(char *host, int 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");
@@ -333,13 +361,19 @@ void get_responserecords(zass_record ***p, DATA_DIR *rec)
        else
        {
            gw_log(GW_LOG_WARN, ZASS_TYPE, "ZLAYER only knows USMARC at this point.");
-           return;
+           gw_log(GW_LOG_WARN, ZASS_TYPE, "Type was '%d'", (**p)->which);
        }
        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)))
        {
@@ -378,9 +412,9 @@ const struct zass_presentent *zass_present(ZASS a, char *resname, int start,
     }
     do
     {
-       gw_log(ZASS_DEBUG, ZASS_TYPE, "Fetching %d records from # %d", num,
+       gw_log(ZASS_DEBUG, ZASS_TYPE, "Fetching %d records from # %d", num - r.num,
            start);
-       pdu = PresentRequest_CreateInitAllASCII(0, resname, start, num, "F",
+       pdu = PresentRequest_CreateInitAllASCII(0, resname, start, num - r.num, "F",
            USMARC_OID);
        if (!pdu)
        {
@@ -414,15 +448,15 @@ const struct zass_presentent *zass_present(ZASS a, char *resname, int start,
            return 0;
        }
        gw_log(ZASS_DEBUG, ZASS_TYPE, "Got presentresponse");
-       r.num = PresentResponse_GetNumberOfRecordsReturned(pdu);
+       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.");
            return 0;
        }
        r.nextpos = PresentResponse_GetNextResultSetPosition(pdu);
-       start += r.nextpos;
-       num -= r.num;
+       start = r.nextpos;
        switch(PresentResponse_GetRecordType(pdu))
        {
            case RESPONSERECORDS_TAG:
@@ -434,10 +468,10 @@ const struct zass_presentent *zass_present(ZASS a, char *resname, int start,
            default:
                gw_log(GW_LOG_WARN, ZASS_TYPE, "Bad tag in response rec.");
        }
-       *rec = 0;
+       PresentResponse_Destroy(pdu);
     }
-    while (num);
-    PresentResponse_Destroy(pdu);
+    while (num - r.num && start);
+    *rec = 0;
        
     return &r;
 }