X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=zlayer%2Fzaccess.c;h=3cbc5ca590a99a886680f17cc762d8a47b56bb04;hb=c3d25c24fb405af98c6879fa7f5f619ccc895151;hp=d0eead41285c1faee63adcd488b5932f8e0c797b;hpb=799bd870edcfb1ea7318299ca1360da404b47cf8;p=egate.git diff --git a/zlayer/zaccess.c b/zlayer/zaccess.c index d0eead4..3cbc5ca 100644 --- a/zlayer/zaccess.c +++ b/zlayer/zaccess.c @@ -1,8 +1,37 @@ /* * Europagate, 1995 * + * Z39.50 API for the Email gateway + * * $Log: zaccess.c,v $ - * Revision 1.4 1995/02/16 15:33:45 quinn + * 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 + * First kick at present handling + * + * Revision 1.4 1995/02/16 15:33:45 quinn * Fixed bug in KWAQS generator * * Revision 1.3 1995/02/16 15:20:45 quinn @@ -252,10 +281,192 @@ const struct zass_searchent *zass_search(ZASS a, struct ccl_rpn_node *query, } /* + * Triple indirection - that's kinda heavy. We'll fix it later. + * There are worse things around, though. Like ZDist. + */ +void get_diagrec(zass_record ***p, DATA_DIR *rec) +{ + DATA_DIR *ad; + + **p = malloc(sizeof(***p)); + (**p)->next = 0; + (**p)->errcode = zutil_GetTaggedInt(rec, ASN1_INTEGER); + if ((ad = zutil_GetTaggedObject(rec, ASN1_VISIBLESTRING))) + { + char *s; + + if ((s = OctetString_GetASCIIString(ad))) + { + strcpy((**p)->errstring, s); + FREE(s); + } + } + (**p)->which = ZASS_REC_DIAG; + *p = &(**p)->next; +} + +void get_responserecords(zass_record ***p, DATA_DIR *rec) +{ + int num, recsyntaxlen, i; + DATA_DIR *record, *retrec, *align; + PEXTERNAL ext; + POBJECTIDENTIFIER oid; + char recsyntax[256]; + + num = ResponseRecords_GetCount(rec); + for (i = 1; i <= num; i++) + { + record = ResponseRecords_GetRecord(rec, i); + if (!record) + { + gw_log(GW_LOG_WARN, ZASS_TYPE, "Failed to get record."); + return; + } + retrec = NamePlusRecord_GetRetrievalRecord(record); + if (!retrec) + { + /* check if it's a diagrec */ + if (record->ptr.child->fldid == 2) + get_diagrec(p, record->ptr.child); + else + { + gw_log(GW_LOG_WARN, ZASS_TYPE, "Illegal record."); + return; + } + } + ext = RetrievalRecord_GetExternal(retrec); + if (!ext) + { + gw_log(GW_LOG_WARN, ZASS_TYPE, "No external in record"); + return; + } + oid = External_GetDirectReference(ext); + if (!oid) + { + gw_log(GW_LOG_WARN, ZASS_TYPE, "Unknown record type."); + return; + } + recsyntaxlen = DirectReference_GetLength(oid); + memcpy(recsyntax, DirectReference_GetData(oid), recsyntaxlen); + recsyntax[recsyntaxlen] = '\0'; + **p = malloc(sizeof(***p)); + (**p)->next = 0; + if (!strcmp(recsyntax, USMARC_OID)) + (**p)->which = ZASS_REC_USMARC; + else + { + gw_log(GW_LOG_WARN, ZASS_TYPE, "ZLAYER only knows USMARC at this point."); + 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, "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(GW_LOG_FATAL, ZASS_TYPE, "malloc"); + return; + } + memcpy((**p)->record, align->ptr.data, align->count); + (**p)->record[align->count] = '\0'; + gw_log(ZASS_DEBUG, ZASS_TYPE, "Got a record of %d bytes", + align->count); + + (*p) = &(**p)->next; + } +} + +static void zass_records_free(zass_record *p) +{ +} + +/* * Note that 1== first record. */ const struct zass_presentent *zass_present(ZASS a, char *resname, int start, int num) { - return 0; + static struct zass_presentent r = {0, 0, 0, 0}; + zass_record **rec = &r.records; + DATA_DIR *pdu; + int len; + + r.num = 0; + if (r.records) + { + zass_records_free(r.records); + r.records = 0; + } + do + { + gw_log(ZASS_DEBUG, ZASS_TYPE, "Fetching %d records from # %d", num - r.num, + start); + pdu = PresentRequest_CreateInitAllASCII(0, resname, start, num - r.num, "F", + USMARC_OID); + if (!pdu) + { + gw_log(GW_LOG_FATAL, "ZASS_TYPE", "failed to create presentrequest"); + return 0; + } + zutil_GetBEREncodedBuffer(pdu, (unsigned char*)a->buf, &len, + a->maxrecordsize); + if (len <= 0) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to encode presentrequest"); + return 0; + } + PresentRequest_Destroy(pdu); + if (netbox_SendBuffer(a->ass, a->buf, len) != len) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to send presentrequest"); + return 0; + } + gw_log(ZASS_DEBUG, ZASS_TYPE, "Sent presentrequest."); + if ((len = zutil_GetBERFromNet(a->ass, (unsigned char*)a->buf, + a->maxrecordsize)) <= 0) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to receive presentresponse"); + return 0; + } + pdu = zutil_CreateFromData((unsigned char*)a->buf, len); + if (zutil_GetTag(pdu) != PRESENTRESPONSE_TAG) + { + gw_log(GW_LOG_FATAL, ZASS_TYPE, "Expected presentresponse from target"); + return 0; + } + 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."); + return 0; + } + r.nextpos = PresentResponse_GetNextResultSetPosition(pdu); + start = r.nextpos; + switch(PresentResponse_GetRecordType(pdu)) + { + case RESPONSERECORDS_TAG: + get_responserecords(&rec, PresentResponse_GetResponseRecords(pdu)); + break; + case NONSURROGATEDIAGNOSTIC_TAG: + get_diagrec(&rec, PresentResponse_GetNonSurrogateDiagnostic(pdu)); + break; + default: + gw_log(GW_LOG_WARN, ZASS_TYPE, "Bad tag in response rec."); + } + PresentResponse_Destroy(pdu); + } + while (num - r.num); + *rec = 0; + + return &r; }