From: Adam Dickmeiss Date: Wed, 4 Apr 2001 14:02:49 +0000 (+0000) Subject: URSULA / Z-ruth service. X-Git-Tag: YAZPP.0.3~47 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=ba7a7aa994136b9bb5b775ad84192f96259bd9c0;p=yazpp-moved-to-github.git URSULA / Z-ruth service. --- diff --git a/configure.in b/configure.in index cbb90bf..27a05c7 100644 --- a/configure.in +++ b/configure.in @@ -23,6 +23,7 @@ AC_OUTPUT([ Makefile src/Makefile include/Makefile + include/yaz/Makefile include/yaz++/Makefile yaz++-config src/yaz++-config diff --git a/include/Makefile.am b/include/Makefile.am index 023dc50..340c400 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = yaz++ +SUBDIRS = yaz yaz++ diff --git a/include/yaz++/yaz-z-server.h b/include/yaz++/yaz-z-server.h index 6d48de4..3f399c1 100644 --- a/include/yaz++/yaz-z-server.h +++ b/include/yaz++/yaz-z-server.h @@ -2,13 +2,27 @@ * Copyright (c) 2000-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-server.h,v 1.5 2001-04-03 14:37:19 adam Exp $ + * $Id: yaz-z-server.h,v 1.6 2001-04-04 14:02:49 adam Exp $ */ #include +#include class Yaz_Z_Server; +class YAZ_EXPORT Yaz_Z_ServerUtility { + public: + void create_databaseRecord (ODR odr, Z_NamePlusRecord *rec, + const char *dbname, int format, + const void *buf, int len); + void create_surrogateDiagnostics(ODR odr, Z_NamePlusRecord *rec, + const char *dbname, int error, + char *const addinfo); + + Z_Records *create_nonSurrogateDiagnostics (ODR odr, int error, + const char *addinfo); +}; + class YAZ_EXPORT IYaz_Server_Facility { public: virtual int init(Yaz_Z_Server *server, @@ -18,32 +32,36 @@ class YAZ_EXPORT IYaz_Server_Facility { }; +class YAZ_EXPORT Yaz_Facility_Ursula : public IYaz_Server_Facility { + public: + virtual void ursula_service (Z_ExtendedServicesRequest *req, + Z_UrsPDU *u, + Z_ExtendedServicesResponse *res) = 0; + + int init(Yaz_Z_Server *server, + Z_InitRequest *initRequest, + Z_InitResponse *initResponse); + int recv(Yaz_Z_Server *server, Z_APDU *apdu); +}; + + class YAZ_EXPORT Yaz_Facility_ILL : public IYaz_Server_Facility { public: virtual int ill_init (Z_InitRequest *initRequest, Z_InitResponse *initResponse) = 0; virtual void ill_service (Z_ExtendedServicesRequest *req, - Z_ItemOrder *io, Z_ExtendedServicesResponse *res) = 0; + Z_ItemOrder *io, + Z_ExtendedServicesResponse *res) = 0; int init(Yaz_Z_Server *server, Z_InitRequest *initRequest, Z_InitResponse *initResponse); int recv(Yaz_Z_Server *server, Z_APDU *apdu); - - - void create_databaseRecord (Z_NamePlusRecord *rec, - const char *dbname, int format, - const void *buf, int len); - void create_surrogateDiagnostics(Z_NamePlusRecord *rec, - const char *dbname, int error, - char *const addinfo); - virtual ODR odr_encode(); - private: - ODR m_odr; }; -class YAZ_EXPORT Yaz_Facility_Retrieval : public IYaz_Server_Facility { +class YAZ_EXPORT Yaz_Facility_Retrieval : public IYaz_Server_Facility, + public Yaz_Z_ServerUtility { public: virtual int sr_init (Z_InitRequest *initRequest, @@ -63,30 +81,26 @@ class YAZ_EXPORT Yaz_Facility_Retrieval : public IYaz_Server_Facility { Z_InitResponse *initResponse); int recv(Yaz_Z_Server *server, Z_APDU *apdu); - void create_databaseRecord (Z_NamePlusRecord *rec, - const char *dbname, int format, - const void *buf, int len); - void create_surrogateDiagnostics(Z_NamePlusRecord *rec, - const char *dbname, int error, - char *const addinfo); - - Z_Records *create_nonSurrogateDiagnostics (int error, - const char *addinfo); - virtual ODR odr_encode(); + ODR odr_encode(); + ODR odr_decode(); private: - Z_Records *pack_records (const char *resultSetName, + Z_Records *pack_records (Yaz_Z_Server *s, + const char *resultSetName, int start, int num, Z_RecordComposition *comp, int *next, int *pres, int *oid); - void fetch_via_piggyback (Z_SearchRequest *searchRequest, + void fetch_via_piggyback (Yaz_Z_Server *s, + Z_SearchRequest *searchRequest, Z_SearchResponse *searchResponse); - void fetch_via_present (Z_PresentRequest *req, Z_PresentResponse *res); + void fetch_via_present (Yaz_Z_Server *s, + Z_PresentRequest *req, Z_PresentResponse *res); int m_preferredMessageSize; int m_maximumRecordSize; - ODR m_odr; + ODR m_odr_encode; + ODR m_odr_decode; }; class YAZ_EXPORT Yaz_Z_Server_Facility_Info { @@ -96,6 +110,8 @@ class YAZ_EXPORT Yaz_Z_Server_Facility_Info { Yaz_Z_Server_Facility_Info *m_next; }; + + class YAZ_EXPORT Yaz_Z_Server : public Yaz_Z_Assoc { public: Yaz_Z_Server(IYaz_PDU_Observable *the_PDU_Observable); @@ -103,6 +119,8 @@ public: virtual void recv_Z_PDU(Z_APDU *apdu); void facility_add(IYaz_Server_Facility *facility, const char *name); void facility_reset (); + + private: Yaz_Z_Server_Facility_Info *m_facilities; }; diff --git a/src/Makefile.am b/src/Makefile.am index 2061c40..43f5cf4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.3 2001-03-27 14:47:45 adam Exp $ +## $Id: Makefile.am,v 1.4 2001-04-04 14:02:49 adam Exp $ INCLUDES=$(YAZINC) -I$(srcdir)/../include @@ -7,7 +7,7 @@ lib_LTLIBRARIES = libyaz++.la libyaz___la_SOURCES=yaz-socket-manager.cpp yaz-pdu-assoc.cpp \ yaz-z-assoc.cpp yaz-proxy.cpp yaz-z-query.cpp yaz-ir-assoc.cpp \ yaz-z-server.cpp yaz-pdu-assoc-thread.cpp yaz-z-server-sr.cpp \ - yaz-z-server-ill.cpp + yaz-z-server-ill.cpp zes-ursula.c yaz-z-server-ursula.cpp libyaz___la_LDFLAGS=-version-info 0:0:0 @@ -21,3 +21,6 @@ yaz_my_server_SOURCES=yaz-my-server.cpp yaz-marc-sample.cpp yaz_proxy_SOURCES=yaz-proxy-main.cpp LDADD=libyaz++.la $(YAZLALIB) + +zes-ursula.c $(top_srcdir)/include/yaz/zes-ursula.h: ursula.tcl ursula.asn + cd $(srcdir); ../../yaz/util/yaz-comp -d $(srcdir)/../../yaz/z39.50/z.tcl -d ursula.tcl -i yaz -I ../include ursula.asn diff --git a/src/ursula.asn b/src/ursula.asn new file mode 100644 index 0000000..38f8b1c --- /dev/null +++ b/src/ursula.asn @@ -0,0 +1,80 @@ +ESFormat-Ursula +{Z39-50-extendedService DBC(105) UrsulaItemOrder (1)} DEFINITIONS ::= + -- oid is 1.2.840.10003.9.1000.105.3 +BEGIN +IMPORTS InternationalString FROM Z39-50-APDU-1995; + +-- Ursula Reserveringer / bestillinger +PDU ::= CHOICE { + request [1] Request, + update [2] Update, + reservation [3] Reservation, + renewal [4] Renewal +} + +-- Foresporgsel +Request ::= SEQUENCE { + libraryNo [1] IMPLICIT LibraryNo OPTIONAL, + borrowerTickerNo [2] IMPLICIT InternationalString OPTIONAL, + disposalType [3] IMPLICIT DisposalType OPTIONAL, + lastUseDate [4] IMPLICIT OCTET STRING OPTIONAL, + items [5] IMPLICIT SEQUENCE OF RequestItem, + counter [6] IMPLICIT ServiceCounter OPTIONAL, + priority [7] IMPLICIT Priority OPTIONAL, + disposalNote [8] IMPLICIT DisposalNote OPTIONAL, + overrule [9] IMPLICIT BOOLEAN OPTIONAL +} + +-- Opdatering/sletning +Update ::= SEQUENCE { + libraryNo [1] IMPLICIT LibraryNo OPTIONAL, + disposalId [2] IMPLICIT OCTET STRING OPTIONAL, + priority [3] IMPLICIT Priority OPTIONAL, + counter [4] IMPLICIT ServiceCounter OPTIONAL, + lastUseDate [5] IMPLICIT OCTET STRING OPTIONAL, + disposalNote [6] IMPLICIT DisposalNote OPTIONAL +} + +-- Eksemplarreserveringer +Reservation ::= CHOICE { + request [1] IMPLICIT RequestItem, + update [2] IMPLICIT SEQUENCE OF UpdateItem, + del [3] IMPLICIT DeleteItem +} + +-- Fornyelse +Renewal ::= SEQUENCE { + libraryNo [1] IMPLICIT LibraryNo OPTIONAL, + borrowerTicketNo [2] IMPLICIT BorrowerTicketNo OPTIONAL, + copies [3] IMPLICIT SEQUENCE OF InternationalString OPTIONAL, + newReturnDate [4] IMPLICIT InternationalString OPTIONAL, + overrule [5] IMPLICIT BOOLEAN OPTIONAL +} + + +RequestItem ::= SEQUENCE { + id [1] IMPLICIT OCTET STRING, + titlePartNo [2] IMPLICIT InternationalString +} + +UpdateItem ::= SEQUENCE { + copyNo [1] IMPLICIT InternationalString, + adviceTxt [2] IMPLICIT InternationalString +} + +DeleteItem ::= SEQUENCE { + copyNo [1] IMPLICIT InternationalString +} + +DisposalType ::= OCTET STRING + +BorrowerTicketNo ::= InternationalString + +Priority ::= INTEGER + +ServiceCounter ::= INTEGER + +LibraryNo ::= InternationalString + +DisposalNote ::= InternationalString + diff --git a/src/ursula.tcl b/src/ursula.tcl new file mode 100644 index 0000000..ff65e29 --- /dev/null +++ b/src/ursula.tcl @@ -0,0 +1,6 @@ +# $Id: ursula.tcl,v 1.1 2001-04-04 14:02:49 adam Exp $ + +set prefix(ESFormat-Ursula) {z_Urs Z_Urs Z_Urs} + +set m ESFormat-Ursula +set filename($m) zes-ursula diff --git a/src/yaz-my-client.cpp b/src/yaz-my-client.cpp index 94ed951..5ac5307 100644 --- a/src/yaz-my-client.cpp +++ b/src/yaz-my-client.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-my-client.cpp,v $ - * Revision 1.1 2001-03-27 14:47:45 adam + * Revision 1.2 2001-04-04 14:02:49 adam + * URSULA / Z-ruth service. + * + * Revision 1.1 2001/03/27 14:47:45 adam * New server facility scheme. * * Revision 1.17 2001/03/26 14:43:49 adam @@ -68,9 +71,11 @@ #include #include #include +#include #include #include #include +#include extern "C" { #if HAVE_READLINE_READLINE_H @@ -124,6 +129,7 @@ public: int cmd_init(char *args); int cmd_format(char *args); int cmd_proxy(char *args); + int cmd_ursula(char *args); }; @@ -348,7 +354,7 @@ void MyClient::recv_record(Z_DatabaseRecord *record, int offset, */ if (r->direct_reference) { - printf("Record type: "); + printf("Record type: "); if (ent) printf("%s\n", ent->desc); } @@ -383,9 +389,37 @@ void MyClient::recv_record(Z_DatabaseRecord *record, int offset, } if (r->which == Z_External_octet && record->u.octet_aligned->len) { - recv_textRecord((int) ent->value, - (const char *) record->u.octet_aligned->buf, - (size_t) record->u.octet_aligned->len); + switch (ent->value) + { + case VAL_ISO2709: + case VAL_UNIMARC: + case VAL_INTERMARC: + case VAL_USMARC: + case VAL_UKMARC: + case VAL_NORMARC: + case VAL_LIBRISMARC: + case VAL_DANMARC: + case VAL_FINMARC: + case VAL_MAB: + case VAL_CANMARC: + case VAL_SBN: + case VAL_PICAMARC: + case VAL_AUSMARC: + case VAL_IBERMARC: + case VAL_CATMARC: + case VAL_MALMARC: + case VAL_JPMARC: + case VAL_SWEMARC: + case VAL_SIGLEMARC: + case VAL_ISDSMARC: + case VAL_RUSMARC: + marc_display((char*) record->u.octet_aligned->buf,stdout); + break; + default: + recv_textRecord((int) ent->value, + (const char *) record->u.octet_aligned->buf, + (size_t) record->u.octet_aligned->len); + } } else if (ent && ent->value == VAL_SUTRS && r->which == Z_External_sutrs) recv_textRecord((int) VAL_SUTRS, (const char *) r->u.sutrs->buf, @@ -564,6 +598,56 @@ int MyClient::cmd_proxy(char *args) return 1; } +int MyClient::cmd_ursula(char *args) +{ + Z_APDU *apdu = create_Z_PDU(Z_APDU_extendedServicesRequest); + Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; + + req->packageType = odr_getoidbystr(odr_encode(), "1.2.840.10003"); + + Z_External *ext = (Z_External *) odr_malloc(odr_encode(), sizeof(*ext)); + req->taskSpecificParameters = ext; + ext->direct_reference = req->packageType; + ext->descriptor = 0; + ext->indirect_reference = 0; + + ext->which = Z_External_octet; + ext->u.single_ASN1_type = (Odr_oct *) + odr_malloc (odr_encode(), sizeof(Odr_oct)); + + Z_UrsPDU *pdu = (Z_UrsPDU *) odr_malloc (odr_encode(), sizeof(*pdu)); + pdu->which = Z_UrsPDU_request; + pdu->u.request = (Z_UrsRequest *) + odr_malloc (odr_encode(), sizeof(*pdu->u.request)); + pdu->u.request->libraryNo = odr_strdup(odr_encode(), "000200"); + pdu->u.request->borrowerTickerNo = 0; + pdu->u.request->disposalType = 0; + pdu->u.request->lastUseDate = 0; + pdu->u.request->num_items = 0; + pdu->u.request->items = (Z_UrsRequestItem **) odr_nullval(); + pdu->u.request->counter = 0; + pdu->u.request->priority = 0; + pdu->u.request->disposalNote = 0; + pdu->u.request->overrule = 0; + + if (!z_UrsPDU (odr_encode(), &pdu, 0, "")) + { + yaz_log (LOG_LOG, "ursula encoding failed"); + return 1; + } + char *buf = + odr_getbuf (odr_encode(), &ext->u.single_ASN1_type->len, 0); + + ext->u.single_ASN1_type->buf = (unsigned char*) + odr_malloc (odr_encode(), ext->u.single_ASN1_type->len); + memcpy (ext->u.single_ASN1_type->buf, buf, ext->u.single_ASN1_type->len); + ext->u.single_ASN1_type->size = ext->u.single_ASN1_type->len; + + if (send_Z_PDU(apdu) >= 0) + wait(); + return 1; +} + int MyClient::processCommand(const char *commandLine) { char cmdStr[1024], cmdArgs[1024]; @@ -584,6 +668,7 @@ int MyClient::processCommand(const char *commandLine) {"init", &MyClient::cmd_init, ""}, {"format", &MyClient::cmd_format, ""}, {"proxy", &MyClient::cmd_proxy, ":[':']"}, + {"ursula", &MyClient::cmd_ursula, ""}, {0,0,0} }; diff --git a/src/yaz-my-server.cpp b/src/yaz-my-server.cpp index d9176b9..a9aeb0a 100644 --- a/src/yaz-my-server.cpp +++ b/src/yaz-my-server.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-my-server.cpp,v $ - * Revision 1.2 2001-03-29 15:14:26 adam + * Revision 1.3 2001-04-04 14:02:49 adam + * URSULA / Z-ruth service. + * + * Revision 1.2 2001/03/29 15:14:26 adam * Minor updates. * * Revision 1.1 2001/03/27 14:47:45 adam @@ -70,6 +73,9 @@ class MyILL : public Yaz_Facility_ILL { public: int ill_init (Z_InitRequest *initRequest, Z_InitResponse *initResponse); + void ill_service (Z_ExtendedServicesRequest *req, + Z_ItemOrder *io, + Z_ExtendedServicesResponse *res); }; class MyRetrieval : public Yaz_Facility_Retrieval, Yaz_USMARC { @@ -88,6 +94,13 @@ public: Z_Records *records); }; +class MyUrsula : public Yaz_Facility_Ursula { +public: + void ursula_service (Z_ExtendedServicesRequest *req, + Z_UrsPDU *u, + Z_ExtendedServicesResponse *res); +}; + class MyServer : public Yaz_Z_Server { public: ~MyServer(); @@ -99,8 +112,9 @@ public: void connectNotify(); private: - MyRetrieval *m_retrieval; - MyILL *m_ill; + MyRetrieval m_retrieval; + MyILL m_ill; + MyUrsula m_ursula; int m_no; }; @@ -111,6 +125,41 @@ int MyILL::ill_init (Z_InitRequest *initRequest, return 1; } +void MyILL::ill_service (Z_ExtendedServicesRequest *req, + Z_ItemOrder *io, + Z_ExtendedServicesResponse *res) +{ + yaz_log (LOG_LOG, "MyServer::ill_service"); +} + + +void MyUrsula::ursula_service (Z_ExtendedServicesRequest *req, + Z_UrsPDU *u, + Z_ExtendedServicesResponse *res) +{ + yaz_log (LOG_LOG, "MyServer::ursula_service"); + switch (u->which) + { + case Z_UrsPDU_request: + yaz_log(LOG_LOG, "request"); + if (u->u.request->libraryNo) + yaz_log (LOG_LOG, "libraryNo: %s", u->u.request->libraryNo); + break; + case Z_UrsPDU_update: + yaz_log(LOG_LOG, "request"); + break; + case Z_UrsPDU_reservation: + yaz_log(LOG_LOG, "request"); + break; + case Z_UrsPDU_renewal: + yaz_log(LOG_LOG, "request"); + break; + default: + yaz_log(LOG_LOG, "unknown"); + break; + } +} + int MyRetrieval::sr_init (Z_InitRequest *initRequest, Z_InitResponse *initResponse) { @@ -154,14 +203,12 @@ void MyRetrieval::sr_record (const char *resultSetName, { yaz_log (LOG_LOG, "MyServer::recv_Z_record"); const char *rec = get_record(position); - create_databaseRecord (namePlusRecord, 0, VAL_USMARC, rec, + create_databaseRecord (odr_encode(), namePlusRecord, 0, VAL_USMARC, rec, strlen(rec)); } MyServer::~MyServer() { - delete m_ill; - delete m_retrieval; } IYaz_PDU_Observer *MyServer::sessionNotify( @@ -171,10 +218,9 @@ IYaz_PDU_Observer *MyServer::sessionNotify( m_no++; new_server = new MyServer(the_PDU_Observable); new_server->timeout(900); - new_server->m_retrieval = new MyRetrieval; - new_server->m_ill = new MyILL; - new_server->facility_add(new_server->m_retrieval, "my sr"); - new_server->facility_add(new_server->m_ill, "my ill"); + new_server->facility_add(&new_server->m_retrieval, "my sr"); + new_server->facility_add(&new_server->m_ill, "my ill"); + new_server->facility_add(&new_server->m_ursula, "my ill"); new_server->set_APDU_log(get_APDU_log()); @@ -185,8 +231,6 @@ MyServer::MyServer(IYaz_PDU_Observable *the_PDU_Observable) : Yaz_Z_Server (the_PDU_Observable) { m_no = 0; - m_ill = 0; - m_retrieval = 0; } void MyServer::timeoutNotify() diff --git a/src/yaz-z-server-ill.cpp b/src/yaz-z-server-ill.cpp index 063c2a8..fbe05d9 100644 --- a/src/yaz-z-server-ill.cpp +++ b/src/yaz-z-server-ill.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-z-server-ill.cpp,v $ - * Revision 1.3 2001-04-03 14:37:19 adam + * Revision 1.4 2001-04-04 14:02:49 adam + * URSULA / Z-ruth service. + * + * Revision 1.3 2001/04/03 14:37:19 adam * More work ILL-service. * * Revision 1.2 2001/03/29 15:14:26 adam @@ -17,55 +20,6 @@ #include #include -/* - * database record. - */ -void Yaz_Facility_ILL::create_databaseRecord ( - Z_NamePlusRecord *rec, const char *dbname, int format, - const void *buf, int len) -{ - rec->databaseName = dbname ? odr_strdup (m_odr, dbname) : 0; - rec->which = Z_NamePlusRecord_databaseRecord; - rec->u.databaseRecord = z_ext_record (m_odr, format, - (const char *) buf, len); -} - -/* - * surrogate diagnostic. - */ -void Yaz_Facility_ILL::create_surrogateDiagnostics( - Z_NamePlusRecord *rec, const char *dbname, int error, char *const addinfo) -{ - int oid[OID_SIZE]; - int *err = (int *)odr_malloc (m_odr, sizeof(*err)); - oident bib1; - Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (m_odr, sizeof(*drec)); - Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) - odr_malloc (m_odr, sizeof(*dr)); - - bib1.proto = PROTO_Z3950; - bib1.oclass = CLASS_DIAGSET; - bib1.value = VAL_BIB1; - - yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo); - *err = error; - rec->databaseName = dbname ? odr_strdup (m_odr, dbname) : 0; - rec->which = Z_NamePlusRecord_surrogateDiagnostic; - rec->u.surrogateDiagnostic = drec; - drec->which = Z_DiagRec_defaultFormat; - drec->u.defaultFormat = dr; - dr->diagnosticSetId = odr_oiddup (m_odr, - oid_ent_to_oid(&bib1, oid)); - dr->condition = err; - dr->which = Z_DefaultDiagFormat_v2Addinfo; - dr->u.v2Addinfo = odr_strdup (m_odr, addinfo ? addinfo : ""); -} - -ODR Yaz_Facility_ILL::odr_encode() -{ - return m_odr; -} - int Yaz_Facility_ILL::init(Yaz_Z_Server *s, Z_InitRequest *initRequest, Z_InitResponse *initResponse) { @@ -81,7 +35,6 @@ int Yaz_Facility_ILL::recv(Yaz_Z_Server *s, Z_APDU *apdu_request) { Z_APDU *apdu_response; - m_odr = s->odr_encode(); if (apdu_request->which != Z_APDU_extendedServicesRequest) return 0; Z_ExtendedServicesRequest *req = apdu_request->u.extendedServicesRequest; diff --git a/src/yaz-z-server-sr.cpp b/src/yaz-z-server-sr.cpp index 010fb13..4c0b58d 100644 --- a/src/yaz-z-server-sr.cpp +++ b/src/yaz-z-server-sr.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-z-server-sr.cpp,v $ - * Revision 1.1 2001-03-27 15:02:14 adam + * Revision 1.2 2001-04-04 14:02:49 adam + * URSULA / Z-ruth service. + * + * Revision 1.1 2001/03/27 15:02:14 adam * New server facility scheme. * */ @@ -11,92 +14,20 @@ #include #include -/* - * database record. - */ -void Yaz_Facility_Retrieval::create_databaseRecord ( - Z_NamePlusRecord *rec, const char *dbname, int format, - const void *buf, int len) -{ - rec->databaseName = dbname ? odr_strdup (m_odr, dbname) : 0; - rec->which = Z_NamePlusRecord_databaseRecord; - rec->u.databaseRecord = z_ext_record (m_odr, format, - (const char *) buf, len); -} - -/* - * surrogate diagnostic. - */ -void Yaz_Facility_Retrieval::create_surrogateDiagnostics( - Z_NamePlusRecord *rec, const char *dbname, int error, char *const addinfo) -{ - int oid[OID_SIZE]; - int *err = (int *)odr_malloc (m_odr, sizeof(*err)); - oident bib1; - Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (m_odr, sizeof(*drec)); - Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) - odr_malloc (m_odr, sizeof(*dr)); - - bib1.proto = PROTO_Z3950; - bib1.oclass = CLASS_DIAGSET; - bib1.value = VAL_BIB1; - - yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo); - *err = error; - rec->databaseName = dbname ? odr_strdup (m_odr, dbname) : 0; - rec->which = Z_NamePlusRecord_surrogateDiagnostic; - rec->u.surrogateDiagnostic = drec; - drec->which = Z_DiagRec_defaultFormat; - drec->u.defaultFormat = dr; - dr->diagnosticSetId = odr_oiddup (m_odr, - oid_ent_to_oid(&bib1, oid)); - dr->condition = err; - dr->which = Z_DefaultDiagFormat_v2Addinfo; - dr->u.v2Addinfo = odr_strdup (m_odr, addinfo ? addinfo : ""); -} - -Z_Records *Yaz_Facility_Retrieval::create_nonSurrogateDiagnostics ( - int error, const char *addinfo) -{ - int oid[OID_SIZE]; - Z_Records *rec = (Z_Records *) - odr_malloc (m_odr, sizeof(*rec)); - oident bib1; - int *err = (int *) - odr_malloc (m_odr, sizeof(*err)); - Z_DiagRec *drec = (Z_DiagRec *) - odr_malloc (m_odr, sizeof(*drec)); - Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) - odr_malloc (m_odr, sizeof(*dr)); - - bib1.proto = PROTO_Z3950; - bib1.oclass = CLASS_DIAGSET; - bib1.value = VAL_BIB1; - - *err = error; - rec->which = Z_Records_NSD; - rec->u.nonSurrogateDiagnostic = dr; - dr->diagnosticSetId = - odr_oiddup (m_odr, oid_ent_to_oid(&bib1, oid)); - dr->condition = err; - dr->which = Z_DefaultDiagFormat_v2Addinfo; - dr->u.v2Addinfo = odr_strdup (m_odr, addinfo ? addinfo : ""); - return rec; -} - -Z_Records *Yaz_Facility_Retrieval::pack_records (const char *resultSetName, - int start, int xnum, - Z_RecordComposition *comp, - int *next, int *pres, - int *format) +Z_Records *Yaz_Facility_Retrieval::pack_records (Yaz_Z_Server *s, + const char *resultSetName, + int start, int xnum, + Z_RecordComposition *comp, + int *next, int *pres, + int *format) { int recno, total_length = 0, toget = xnum, dumped_records = 0; Z_Records *records = - (Z_Records *) odr_malloc (m_odr, sizeof(*records)); + (Z_Records *) odr_malloc (odr_encode(), sizeof(*records)); Z_NamePlusRecordList *reclist = - (Z_NamePlusRecordList *) odr_malloc (m_odr, sizeof(*reclist)); + (Z_NamePlusRecordList *) odr_malloc (odr_encode(), sizeof(*reclist)); Z_NamePlusRecord **list = - (Z_NamePlusRecord **) odr_malloc (m_odr, sizeof(*list) * toget); + (Z_NamePlusRecord **) odr_malloc (odr_encode(), sizeof(*list) * toget); records->which = Z_Records_DBOSD; records->u.databaseOrSurDiagnostics = reclist; @@ -111,7 +42,7 @@ Z_Records *Yaz_Facility_Retrieval::pack_records (const char *resultSetName, for (recno = start; reclist->num_records < toget; recno++) { Z_NamePlusRecord *this_rec = - (Z_NamePlusRecord *) odr_malloc (m_odr, sizeof(*this_rec)); + (Z_NamePlusRecord *) odr_malloc (odr_encode(), sizeof(*this_rec)); this_rec->databaseName = 0; this_rec->which = Z_NamePlusRecord_databaseRecord; this_rec->u.databaseRecord = 0; @@ -129,15 +60,15 @@ Z_Records *Yaz_Facility_Retrieval::pack_records (const char *resultSetName, if (this_rec->which == Z_NamePlusRecord_databaseRecord && this_rec->u.databaseRecord == 0) { // handler did not return a record.. - create_surrogateDiagnostics(this_rec, 0, 14, 0); + create_surrogateDiagnostics(odr_encode(), this_rec, 0, 14, 0); } /* * we get the number of bytes allocated on the stream before any * allocation done by the backend - this should give us a reasonable * idea of the total size of the data so far. */ - total_length = odr_total(m_odr) - dumped_records; - this_length = odr_total(m_odr) - total_length; + total_length = odr_total(odr_encode()) - dumped_records; + this_length = odr_total(odr_encode()) - total_length; yaz_log(LOG_LOG, " fetched record, len=%d, total=%d", this_length, total_length); if (this_length + total_length > m_preferredMessageSize) @@ -153,7 +84,7 @@ Z_Records *Yaz_Facility_Retrieval::pack_records (const char *resultSetName, { /* too big entirely */ yaz_log(LOG_LOG, "Record > maxrcdsz"); reclist->records[reclist->num_records] = this_rec; - create_surrogateDiagnostics(this_rec, + create_surrogateDiagnostics(odr_encode(), this_rec, this_rec->databaseName, 17, 0); reclist->num_records++; *next = recno + 1; @@ -167,7 +98,7 @@ Z_Records *Yaz_Facility_Retrieval::pack_records (const char *resultSetName, { yaz_log(LOG_DEBUG, " Dropped it"); reclist->records[reclist->num_records] = this_rec; - create_surrogateDiagnostics(this_rec, + create_surrogateDiagnostics(odr_encode(), this_rec, this_rec->databaseName, 16, 0); reclist->num_records++; @@ -185,10 +116,11 @@ Z_Records *Yaz_Facility_Retrieval::pack_records (const char *resultSetName, return records; } -void Yaz_Facility_Retrieval::fetch_via_piggyback (Z_SearchRequest *req, +void Yaz_Facility_Retrieval::fetch_via_piggyback (Yaz_Z_Server *s, + Z_SearchRequest *req, Z_SearchResponse *res) { - bool_t *sr = (bool_t *)odr_malloc (m_odr, sizeof(*sr)); + bool_t *sr = (bool_t *)odr_malloc (odr_encode(), sizeof(*sr)); *sr = 1; int toget = 0; @@ -196,7 +128,7 @@ void Yaz_Facility_Retrieval::fetch_via_piggyback (Z_SearchRequest *req, Z_RecordComposition comp, *compp = 0; int hits = *res->resultCount; - int *nulint = (int *)odr_malloc (m_odr, sizeof(*nulint)); + int *nulint = (int *)odr_malloc (odr_encode(), sizeof(*nulint)); *nulint = 0; comp.which = Z_RecordComp_simple; @@ -218,10 +150,10 @@ void Yaz_Facility_Retrieval::fetch_via_piggyback (Z_SearchRequest *req, if (toget && !res->records) { - res->presentStatus = (int *) odr_malloc (m_odr, sizeof(int)); + res->presentStatus = (int *) odr_malloc (odr_encode(), sizeof(int)); *res->presentStatus = Z_PRES_SUCCESS; res->records = - pack_records(req->resultSetName, 1, toget, compp, + pack_records(s, req->resultSetName, 1, toget, compp, res->nextResultSetPosition, res->presentStatus, req->preferredRecordSyntax); @@ -244,25 +176,22 @@ void Yaz_Facility_Retrieval::fetch_via_piggyback (Z_SearchRequest *req, } } -void Yaz_Facility_Retrieval::fetch_via_present (Z_PresentRequest *req, - Z_PresentResponse *res) +void Yaz_Facility_Retrieval::fetch_via_present (Yaz_Z_Server *s, + Z_PresentRequest *req, + Z_PresentResponse *res) { - res->records = pack_records (req->resultSetId,*req->resultSetStartPoint, - *req->numberOfRecordsRequested, - req->recordComposition, - res->nextResultSetPosition, - res->presentStatus, - req->preferredRecordSyntax); + res->records = + pack_records (s, req->resultSetId,*req->resultSetStartPoint, + *req->numberOfRecordsRequested, + req->recordComposition, + res->nextResultSetPosition, + res->presentStatus, + req->preferredRecordSyntax); if (res->records->which == Z_Records_DBOSD) *res->numberOfRecordsReturned = res->records->u.databaseOrSurDiagnostics->num_records; } -ODR Yaz_Facility_Retrieval::odr_encode() -{ - return m_odr; -} - int Yaz_Facility_Retrieval::init(Yaz_Z_Server *s, Z_InitRequest *initRequest, Z_InitResponse *initResponse) { @@ -278,10 +207,21 @@ int Yaz_Facility_Retrieval::init(Yaz_Z_Server *s, Z_InitRequest *initRequest, return sr_init (initRequest, initResponse); } +ODR Yaz_Facility_Retrieval::odr_encode() +{ + return m_odr_encode; +} + +ODR Yaz_Facility_Retrieval::odr_decode() +{ + return m_odr_decode; +} + int Yaz_Facility_Retrieval::recv(Yaz_Z_Server *s, Z_APDU *apdu_request) { Z_APDU *apdu_response; - m_odr = s->odr_encode(); + m_odr_encode = s->odr_encode(); + m_odr_decode = s->odr_decode(); switch (apdu_request->which) { case Z_APDU_searchRequest: @@ -291,7 +231,7 @@ int Yaz_Facility_Retrieval::recv(Yaz_Z_Server *s, Z_APDU *apdu_request) apdu_response->u.searchResponse); if (!apdu_response->u.searchResponse->records) { - fetch_via_piggyback(apdu_request->u.searchRequest, + fetch_via_piggyback(s, apdu_request->u.searchRequest, apdu_response->u.searchResponse); } s->send_Z_PDU(apdu_response); @@ -302,7 +242,7 @@ int Yaz_Facility_Retrieval::recv(Yaz_Z_Server *s, Z_APDU *apdu_request) sr_present (apdu_request->u.presentRequest, apdu_response->u.presentResponse); if (!apdu_response->u.presentResponse->records) - fetch_via_present(apdu_request->u.presentRequest, + fetch_via_present(s, apdu_request->u.presentRequest, apdu_response->u.presentResponse); s->send_Z_PDU(apdu_response); return 1; diff --git a/src/yaz-z-server-ursula.cpp b/src/yaz-z-server-ursula.cpp new file mode 100644 index 0000000..07abb13 --- /dev/null +++ b/src/yaz-z-server-ursula.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2001, Index Data. + * See the file LICENSE for details. + * + * $Log: yaz-z-server-ursula.cpp,v $ + * Revision 1.1 2001-04-04 14:02:49 adam + * URSULA / Z-ruth service. + * + */ + +#include +#include + +int Yaz_Facility_Ursula::init(Yaz_Z_Server *s, Z_InitRequest *initRequest, + Z_InitResponse *initResponse) +{ + Z_Options *req = initRequest->options; + Z_Options *res = initResponse->options; + + if (ODR_MASK_GET(req, Z_Options_extendedServices)) + ODR_MASK_SET(res, Z_Options_extendedServices); + return 1; +} + +int Yaz_Facility_Ursula::recv(Yaz_Z_Server *s, Z_APDU *apdu_request) +{ + Z_APDU *apdu_response; + + if (apdu_request->which != Z_APDU_extendedServicesRequest) + return 0; + Z_ExtendedServicesRequest *req = apdu_request->u.extendedServicesRequest; + + Z_External *r = req->taskSpecificParameters; + + if (!r) + return 0; + + if (r->which != ODR_EXTERNAL_octet) + { + logf (LOG_LOG, "ursula::recv not octet alighed"); + return 0; + } + odr_setbuf (s->odr_decode(), (char*) r->u.octet_aligned->buf, + r->u.octet_aligned->len, 0); + Z_UrsPDU *pdu = 0; + if (!z_UrsPDU (s->odr_decode(), &pdu, 0, "")) + { + logf (LOG_LOG, "ursula::decode failed"); + return 0; + } + yaz_log (LOG_LOG, "got ursula packet"); + apdu_response = s->create_Z_PDU(Z_APDU_extendedServicesResponse); + ursula_service(req, pdu, apdu_response->u.extendedServicesResponse); + s->send_Z_PDU(apdu_response); + return 1; +} diff --git a/src/yaz-z-server.cpp b/src/yaz-z-server.cpp index a2812f9..378981a 100644 --- a/src/yaz-z-server.cpp +++ b/src/yaz-z-server.cpp @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: yaz-z-server.cpp,v $ - * Revision 1.9 2001-03-29 15:14:26 adam + * Revision 1.10 2001-04-04 14:02:49 adam + * URSULA / Z-ruth service. + * + * Revision 1.9 2001/03/29 15:14:26 adam * Minor updates. * * Revision 1.8 2001/03/27 14:47:45 adam @@ -120,8 +123,82 @@ void Yaz_Z_Server::recv_Z_PDU (Z_APDU *apdu_request) } if (!taken) { - yaz_log (LOG_LOG, "got request = %d", apdu_request->which); + yaz_log (LOG_LOG, "unhandled request = %d", apdu_request->which); delete this; } } } + +/* + * database record. + */ +void Yaz_Z_ServerUtility::create_databaseRecord ( + ODR odr, Z_NamePlusRecord *rec, const char *dbname, int format, + const void *buf, int len) +{ + rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0; + rec->which = Z_NamePlusRecord_databaseRecord; + rec->u.databaseRecord = z_ext_record (odr, format, + (const char *) buf, len); +} + +/* + * surrogate diagnostic. + */ +void Yaz_Z_ServerUtility::create_surrogateDiagnostics( + ODR odr, Z_NamePlusRecord *rec, const char *dbname, + int error, char *const addinfo) +{ + int oid[OID_SIZE]; + int *err = (int *)odr_malloc (odr, sizeof(*err)); + oident bib1; + Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (odr, sizeof(*drec)); + Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) + odr_malloc (odr, sizeof(*dr)); + + bib1.proto = PROTO_Z3950; + bib1.oclass = CLASS_DIAGSET; + bib1.value = VAL_BIB1; + + yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo); + *err = error; + rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0; + rec->which = Z_NamePlusRecord_surrogateDiagnostic; + rec->u.surrogateDiagnostic = drec; + drec->which = Z_DiagRec_defaultFormat; + drec->u.defaultFormat = dr; + dr->diagnosticSetId = odr_oiddup (odr, + oid_ent_to_oid(&bib1, oid)); + dr->condition = err; + dr->which = Z_DefaultDiagFormat_v2Addinfo; + dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : ""); +} + +Z_Records *Yaz_Z_ServerUtility::create_nonSurrogateDiagnostics ( + ODR odr, int error, const char *addinfo) +{ + int oid[OID_SIZE]; + Z_Records *rec = (Z_Records *) + odr_malloc (odr, sizeof(*rec)); + oident bib1; + int *err = (int *) + odr_malloc (odr, sizeof(*err)); + Z_DiagRec *drec = (Z_DiagRec *) + odr_malloc (odr, sizeof(*drec)); + Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) + odr_malloc (odr, sizeof(*dr)); + + bib1.proto = PROTO_Z3950; + bib1.oclass = CLASS_DIAGSET; + bib1.value = VAL_BIB1; + + *err = error; + rec->which = Z_Records_NSD; + rec->u.nonSurrogateDiagnostic = dr; + dr->diagnosticSetId = + odr_oiddup (odr, oid_ent_to_oid(&bib1, oid)); + dr->condition = err; + dr->which = Z_DefaultDiagFormat_v2Addinfo; + dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : ""); + return rec; +}