From 7411ed6df7fc0b535f83503f73d70e80f390e295 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 25 Jun 2005 15:53:19 +0000 Subject: [PATCH] Expanded tabs in all source files. Added vim/emacs local variables trailer. --- include/yaz++/cql2rpn.h | 12 +- include/yaz++/gdu.h | 46 ++-- include/yaz++/ir-assoc.h | 10 +- include/yaz++/pdu-assoc.h | 34 +-- include/yaz++/pdu-observer.h | 12 +- include/yaz++/query.h | 10 +- include/yaz++/record-cache.h | 16 +- include/yaz++/socket-manager.h | 34 +-- include/yaz++/socket-observer.h | 20 +- include/yaz++/z-assoc.h | 32 ++- include/yaz++/z-databases.h | 10 +- include/yaz++/z-query.h | 10 +- include/yaz++/z-server.h | 80 ++++--- src/gdu.cpp | 26 ++- src/yaz-cql2rpn.cpp | 78 ++++--- src/yaz-ir-assoc.cpp | 130 +++++------ src/yaz-marc-sample.cpp | 14 +- src/yaz-my-client.cpp | 460 ++++++++++++++++++++------------------- src/yaz-my-server.cpp | 146 +++++++------ src/yaz-pdu-assoc-thread.cpp | 18 +- src/yaz-pdu-assoc.cpp | 406 +++++++++++++++++----------------- src/yaz-socket-manager.cpp | 238 ++++++++++---------- src/yaz-z-assoc.cpp | 230 ++++++++++---------- src/yaz-z-cache.cpp | 140 ++++++------ src/yaz-z-databases.cpp | 10 +- src/yaz-z-query.cpp | 168 +++++++------- src/yaz-z-server-ill.cpp | 16 +- src/yaz-z-server-sr.cpp | 284 ++++++++++++------------ src/yaz-z-server-update.cpp | 42 ++-- src/yaz-z-server.cpp | 106 ++++----- zlint/main.cpp | 14 +- zlint/test-init-01.cpp | 42 ++-- zlint/test-init-02.cpp | 30 ++- zlint/test-init-03.cpp | 32 ++- zlint/test-init-04.cpp | 38 ++-- zlint/test-init-05.cpp | 116 +++++----- zlint/test-init-06.cpp | 72 +++--- zlint/test-init-07.cpp | 114 +++++----- zlint/test-init-08.cpp | 50 +++-- zlint/test-scan-01.cpp | 126 ++++++----- zlint/test-search-01.cpp | 312 +++++++++++++------------- zlint/zlint.cpp | 110 +++++----- zlint/zlint.h | 10 +- zoom/canonical.cpp | 8 + zoom/zclient.cpp | 60 ++--- zoom/zconn.cpp | 56 +++-- zoom/zexcept.cpp | 104 +++++---- zoom/zquery.cpp | 20 +- zoom/zrec.cpp | 114 +++++----- zoom/zrs.cpp | 38 ++-- 50 files changed, 2352 insertions(+), 1952 deletions(-) diff --git a/include/yaz++/cql2rpn.h b/include/yaz++/cql2rpn.h index 19c2305..6d0454d 100644 --- a/include/yaz++/cql2rpn.h +++ b/include/yaz++/cql2rpn.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: cql2rpn.h,v 1.2 2005-06-02 06:40:20 adam Exp $ + * $Id: cql2rpn.h,v 1.3 2005-06-25 15:53:19 adam Exp $ */ #include @@ -15,9 +15,17 @@ class YAZ_EXPORT Yaz_cql2rpn { ~Yaz_cql2rpn(); void set_pqf_file(const char *fname); int query_transform(const char *cql, Z_RPNQuery **rpnquery, ODR o, - char **addinfop); + char **addinfop); private: cql_transform_t m_transform; }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/gdu.h b/include/yaz++/gdu.h index ede395e..7512bf0 100644 --- a/include/yaz++/gdu.h +++ b/include/yaz++/gdu.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: gdu.h,v 1.1 2005-06-21 17:37:15 adam Exp $ + * $Id: gdu.h,v 1.2 2005-06-25 15:53:19 adam Exp $ */ #ifndef YAZPP_GDU_INCLUDED @@ -15,35 +15,43 @@ namespace yazpp_1 { class YAZ_EXPORT GDU { public: - GDU(Z_GDU *gdu); - GDU(Z_APDU *apdu); - ~GDU(); - Z_GDU *get(); - void extract_odr_to(ODR dst); + GDU(Z_GDU *gdu); + GDU(Z_APDU *apdu); + ~GDU(); + Z_GDU *get(); + void extract_odr_to(ODR dst); private: - void base(Z_GDU *gdu, ODR o); - Z_GDU *m_gdu; - ODR m_decode; + void base(Z_GDU *gdu, ODR o); + Z_GDU *m_gdu; + ODR m_decode; }; class GDUQueue_List { - friend class GDUQueue; + friend class GDUQueue; private: - GDU *m_item; - GDUQueue_List *m_next; + GDU *m_item; + GDUQueue_List *m_next; }; class GDUQueue { public: - GDUQueue(); - ~GDUQueue(); - void clear(); - void enqueue(GDU *gdu); - GDU *dequeue(); - int size(); + GDUQueue(); + ~GDUQueue(); + void clear(); + void enqueue(GDU *gdu); + GDU *dequeue(); + int size(); private: - GDUQueue_List *m_list; + GDUQueue_List *m_list; }; }; #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/ir-assoc.h b/include/yaz++/ir-assoc.h index eac8d05..6e5e12f 100644 --- a/include/yaz++/ir-assoc.h +++ b/include/yaz++/ir-assoc.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: ir-assoc.h,v 1.5 2005-06-08 13:28:05 adam Exp $ + * $Id: ir-assoc.h,v 1.6 2005-06-25 15:53:19 adam Exp $ */ #include @@ -80,3 +80,11 @@ class YAZ_EXPORT IR_Assoc: public Z_Assoc { int m_log; }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/pdu-assoc.h b/include/yaz++/pdu-assoc.h index 33875cc..081e120 100644 --- a/include/yaz++/pdu-assoc.h +++ b/include/yaz++/pdu-assoc.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: pdu-assoc.h,v 1.7 2005-06-08 13:28:05 adam Exp $ + * $Id: pdu-assoc.h,v 1.8 2005-06-25 15:53:19 adam Exp $ */ #ifndef YAZ_PDU_ASSOC_INCLUDED @@ -23,20 +23,20 @@ class YAZ_EXPORT PDU_Assoc : public IPDU_Observable, yazpp_1::ISocketObserver { friend class PDU_AssocThread; private: enum { - Connecting, - Listen, - Ready, - Closed, - Writing, - Accepting + Connecting, + Listen, + Ready, + Closed, + Writing, + Accepting } m_state; class PDU_Queue { public: - PDU_Queue(const char *buf, int len); - PDU_Queue::~PDU_Queue(); - char *m_buf; - int m_len; - PDU_Queue *m_next; + PDU_Queue(const char *buf, int len); + PDU_Queue::~PDU_Queue(); + char *m_buf; + int m_len; + PDU_Queue *m_next; }; PDU_Assoc *m_parent; PDU_Assoc *m_children; @@ -59,7 +59,7 @@ class YAZ_EXPORT PDU_Assoc : public IPDU_Observable, yazpp_1::ISocketObserver { PDU_Assoc(yazpp_1::ISocketObservable *socketObservable); /// Create Object using existing comstack PDU_Assoc(yazpp_1::ISocketObservable *socketObservable, - COMSTACK cs); + COMSTACK cs); /// Close socket and destroy object. /// virtual ~PDU_Assoc(); /// Clone the object @@ -94,3 +94,11 @@ class YAZ_EXPORT PDU_AssocThread : public PDU_Assoc { #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/pdu-observer.h b/include/yaz++/pdu-observer.h index bdb6b87..3a0627a 100644 --- a/include/yaz++/pdu-observer.h +++ b/include/yaz++/pdu-observer.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: pdu-observer.h,v 1.6 2005-06-08 13:28:05 adam Exp $ + * $Id: pdu-observer.h,v 1.7 2005-06-25 15:53:19 adam Exp $ */ #ifndef YAZ_PDU_OBSERVER_H @@ -54,8 +54,16 @@ class YAZ_EXPORT IPDU_Observer { virtual void timeoutNotify() = 0; /// Make clone of observer using IPDU_Observable interface virtual IPDU_Observer *sessionNotify( - IPDU_Observable *the_PDU_Observable, int fd) = 0; + IPDU_Observable *the_PDU_Observable, int fd) = 0; }; }; #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/query.h b/include/yaz++/query.h index 722b74d..af4f7e0 100644 --- a/include/yaz++/query.h +++ b/include/yaz++/query.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2000, Index Data. * See the file LICENSE for details. * - * $Id: query.h,v 1.2 2005-06-02 06:40:21 adam Exp $ + * $Id: query.h,v 1.3 2005-06-25 15:53:19 adam Exp $ */ namespace yazpp_1 { @@ -15,3 +15,11 @@ class YAZ_EXPORT Yaz_Query { virtual void print (char *str, int len) = 0; }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/record-cache.h b/include/yaz++/record-cache.h index 36543c7..95fbba4 100644 --- a/include/yaz++/record-cache.h +++ b/include/yaz++/record-cache.h @@ -2,7 +2,7 @@ * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: record-cache.h,v 1.3 2005-06-08 13:28:05 adam Exp $ + * $Id: record-cache.h,v 1.4 2005-06-25 15:53:19 adam Exp $ */ @@ -19,7 +19,7 @@ class YAZ_EXPORT RecordCache { void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits); int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num, - Odr_oid *syntax, Z_RecordComposition *comp); + Odr_oid *syntax, Z_RecordComposition *comp); void clear(); void copy_searchRequest(Z_SearchRequest *sr); @@ -31,8 +31,16 @@ class YAZ_EXPORT RecordCache { Z_SearchRequest *m_searchRequest; Z_PresentRequest *m_presentRequest; int match (RecordCache_Entry *entry, - Odr_oid *syntax, int offset, - Z_RecordComposition *comp); + Odr_oid *syntax, int offset, + Z_RecordComposition *comp); int m_max_size; }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/socket-manager.h b/include/yaz++/socket-manager.h index cd3cff3..fa471f1 100644 --- a/include/yaz++/socket-manager.h +++ b/include/yaz++/socket-manager.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: socket-manager.h,v 1.5 2005-06-08 13:28:05 adam Exp $ + * $Id: socket-manager.h,v 1.6 2005-06-25 15:53:19 adam Exp $ */ #ifndef YAZ_SOCKET_MANAGER_INCLUDED @@ -20,26 +20,26 @@ namespace yazpp_1 { class YAZ_EXPORT SocketManager : public ISocketObservable { private: struct SocketEntry { - ISocketObserver *observer; - int fd; - unsigned mask; - int timeout; + ISocketObserver *observer; + int fd; + unsigned mask; + int timeout; int timeout_this; - time_t last_activity; - SocketEntry *next; + time_t last_activity; + SocketEntry *next; }; SocketEntry *m_observers; // all registered observers struct SocketEvent { - ISocketObserver *observer; - int event; - SocketEvent *next; // front in queue - SocketEvent *prev; // back in queue + ISocketObserver *observer; + int event; + SocketEvent *next; // front in queue + SocketEvent *prev; // back in queue }; SocketEvent *m_queue_front; SocketEvent *m_queue_back; SocketEntry **SocketManager::lookupObserver - (ISocketObserver *observer); + (ISocketObserver *observer); SocketEvent *SocketManager::getEvent(); void putEvent(SocketEvent *event); void removeEvent(ISocketObserver *observer); @@ -55,7 +55,7 @@ class YAZ_EXPORT SocketManager : public ISocketObservable { virtual void maskObserver(ISocketObserver *observer, int mask); /// Set timeout virtual void timeoutObserver(ISocketObserver *observer, - int timeout); + int timeout); /// Process one event. return > 0 if event could be processed; int processEvent(); SocketManager(); @@ -65,3 +65,11 @@ class YAZ_EXPORT SocketManager : public ISocketObservable { }; #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/socket-observer.h b/include/yaz++/socket-observer.h index 42e7be0..34c5e31 100644 --- a/include/yaz++/socket-observer.h +++ b/include/yaz++/socket-observer.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: socket-observer.h,v 1.5 2005-06-08 13:28:05 adam Exp $ + * $Id: socket-observer.h,v 1.6 2005-06-25 15:53:19 adam Exp $ */ #ifndef YAZ_SOCKET_OBSERVER_H @@ -13,10 +13,10 @@ namespace yazpp_1 { enum SocketObserve { - SOCKET_OBSERVE_READ=1, - SOCKET_OBSERVE_WRITE=2, - SOCKET_OBSERVE_EXCEPT=4, - SOCKET_OBSERVE_TIMEOUT=8 + SOCKET_OBSERVE_READ=1, + SOCKET_OBSERVE_WRITE=2, + SOCKET_OBSERVE_EXCEPT=4, + SOCKET_OBSERVE_TIMEOUT=8 }; /** @@ -53,7 +53,7 @@ class YAZ_EXPORT ISocketObservable { virtual void maskObserver(ISocketObserver *observer, int mask) = 0; /// Specify timeout virtual void timeoutObserver(ISocketObserver *observer, - int timeout)=0; + int timeout)=0; }; /** Socket Observer. @@ -69,3 +69,11 @@ class YAZ_EXPORT ISocketObserver { }; #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/z-assoc.h b/include/yaz++/z-assoc.h index d9229a0..1a6e673 100644 --- a/include/yaz++/z-assoc.h +++ b/include/yaz++/z-assoc.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: z-assoc.h,v 1.9 2005-06-21 17:37:15 adam Exp $ + * $Id: z-assoc.h,v 1.10 2005-06-25 15:53:19 adam Exp $ */ #ifndef YAZ_Z_ASSOC_INCLUDED @@ -62,20 +62,20 @@ class YAZ_EXPORT Z_Assoc : public IPDU_Observer { /// OtherInformation void get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip); Z_OtherInformationUnit *update_otherInformation ( - Z_OtherInformation **otherInformationP, int createFlag, - int *oid, int categoryValue, int deleteFlag); + Z_OtherInformation **otherInformationP, int createFlag, + int *oid, int categoryValue, int deleteFlag); void set_otherInformationString ( - Z_OtherInformation **otherInformationP, - int *oid, int categoryValue, - const char *str); + Z_OtherInformation **otherInformationP, + int *oid, int categoryValue, + const char *str); void set_otherInformationString ( - Z_OtherInformation **otherInformation, - int oidval, int categoryValue, - const char *str); + Z_OtherInformation **otherInformation, + int oidval, int categoryValue, + const char *str); void set_otherInformationString ( - Z_APDU *apdu, - int oidval, int categoryValue, - const char *str); + Z_APDU *apdu, + int oidval, int categoryValue, + const char *str); Z_ReferenceId *getRefID(char* str); Z_ReferenceId **get_referenceIdP(Z_APDU *apdu); @@ -101,3 +101,11 @@ class YAZ_EXPORT Z_Assoc : public IPDU_Observer { }; #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/z-databases.h b/include/yaz++/z-databases.h index 9f2ce49..c33179b 100644 --- a/include/yaz++/z-databases.h +++ b/include/yaz++/z-databases.h @@ -2,7 +2,7 @@ * Copyright (c) 2001, Index Data. * See the file LICENSE for details. * - * $Id: z-databases.h,v 1.2 2005-06-02 06:40:21 adam Exp $ + * $Id: z-databases.h,v 1.3 2005-06-25 15:53:19 adam Exp $ */ #include @@ -26,3 +26,11 @@ public: NMEM nmem; }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/z-query.h b/include/yaz++/z-query.h index 31fcaa9..6977b82 100644 --- a/include/yaz++/z-query.h +++ b/include/yaz++/z-query.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2000, Index Data. * See the file LICENSE for details. * - * $Id: z-query.h,v 1.4 2005-06-02 06:40:21 adam Exp $ + * $Id: z-query.h,v 1.5 2005-06-25 15:53:19 adam Exp $ */ #include @@ -40,3 +40,11 @@ class YAZ_EXPORT Yaz_Z_Query : public Yaz_Query { void pr_term(WRBUF wbuf, char *buf, int len); }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz++/z-server.h b/include/yaz++/z-server.h index bbb1db5..f4e4ea4 100644 --- a/include/yaz++/z-server.h +++ b/include/yaz++/z-server.h @@ -2,7 +2,7 @@ * Copyright (c) 2000-2005, Index Data. * See the file LICENSE for details. * - * $Id: z-server.h,v 1.7 2005-06-08 13:28:05 adam Exp $ + * $Id: z-server.h,v 1.8 2005-06-25 15:53:19 adam Exp $ */ #include @@ -14,14 +14,14 @@ class Z_Server; class YAZ_EXPORT Z_ServerUtility { public: void create_databaseRecord (ODR odr, Z_NamePlusRecord *rec, - const char *dbname, int format, - const void *buf, int len); + 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); + const char *dbname, int error, + char *const addinfo); Z_Records *create_nonSurrogateDiagnostics (ODR odr, int error, - const char *addinfo); + const char *addinfo); void Z_ServerUtility::create_diagnostics ( ODR odr, int error, const char *addinfo, @@ -31,36 +31,36 @@ class YAZ_EXPORT Z_ServerUtility { class YAZ_EXPORT IServer_Facility { public: virtual int init(Z_Server *server, - Z_InitRequest *initRequest, - Z_InitResponse *initResponse) = 0; + Z_InitRequest *initRequest, + Z_InitResponse *initResponse) = 0; virtual int recv(Z_Server *server, Z_APDU *apdu) = 0; }; class YAZ_EXPORT Yaz_Facility_ILL : public IServer_Facility { public: virtual void ill_service (Z_ExtendedServicesRequest *req, - Z_ItemOrder *io, - Z_ExtendedServicesResponse *res) = 0; + Z_ItemOrder *io, + Z_ExtendedServicesResponse *res) = 0; int init(Z_Server *server, - Z_InitRequest *initRequest, - Z_InitResponse *initResponse); + Z_InitRequest *initRequest, + Z_InitResponse *initResponse); int recv(Z_Server *server, Z_APDU *apdu); }; class YAZ_EXPORT Yaz_Facility_Update : public IServer_Facility { public: virtual void update_service (Z_ExtendedServicesRequest *req, - Z_IUUpdate *io, - Z_ExtendedServicesResponse *res) = 0; + Z_IUUpdate *io, + Z_ExtendedServicesResponse *res) = 0; virtual void update_service0 (Z_ExtendedServicesRequest *req, - Z_IU0Update *io, - Z_ExtendedServicesResponse *res) = 0; + Z_IU0Update *io, + Z_ExtendedServicesResponse *res) = 0; int init(Z_Server *server, - Z_InitRequest *initRequest, - Z_InitResponse *initResponse); + Z_InitRequest *initRequest, + Z_InitResponse *initResponse); int recv(Z_Server *server, Z_APDU *apdu); }; @@ -70,37 +70,37 @@ class YAZ_EXPORT Yaz_Facility_Retrieval : public IServer_Facility, public: virtual int sr_init (Z_InitRequest *initRequest, - Z_InitResponse *initResponse) = 0; + Z_InitResponse *initResponse) = 0; virtual void sr_search (Z_SearchRequest *searchRequest, - Z_SearchResponse *searchResponse) = 0; + Z_SearchResponse *searchResponse) = 0; virtual void sr_present (Z_PresentRequest *presentRequest, - Z_PresentResponse *presentResponse) = 0; + Z_PresentResponse *presentResponse) = 0; virtual void sr_record (const char *resultSetName, - int position, - int *format, - Z_RecordComposition *comp, - Z_NamePlusRecord *namePlusRecord, - Z_Records *diagnostics) = 0; + int position, + int *format, + Z_RecordComposition *comp, + Z_NamePlusRecord *namePlusRecord, + Z_Records *diagnostics) = 0; int init(Z_Server *server, - Z_InitRequest *initRequest, - Z_InitResponse *initResponse); + Z_InitRequest *initRequest, + Z_InitResponse *initResponse); int recv(Z_Server *server, Z_APDU *apdu); ODR odr_encode(); ODR odr_decode(); private: Z_Records *pack_records (Z_Server *s, - const char *resultSetName, - int start, int num, - Z_RecordComposition *comp, - int *next, int *pres, - int *oid); + const char *resultSetName, + int start, int num, + Z_RecordComposition *comp, + int *next, int *pres, + int *oid); void fetch_via_piggyback (Z_Server *s, - Z_SearchRequest *searchRequest, - Z_SearchResponse *searchResponse); + Z_SearchRequest *searchRequest, + Z_SearchResponse *searchResponse); void fetch_via_present (Z_Server *s, - Z_PresentRequest *req, Z_PresentResponse *res); + Z_PresentRequest *req, Z_PresentResponse *res); int m_preferredMessageSize; int m_maximumRecordSize; @@ -136,3 +136,11 @@ class YAZ_EXPORT Yaz_USMARC { const char *get_record(size_t position); }; }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/gdu.cpp b/src/gdu.cpp index 676a334..084c8c5 100644 --- a/src/gdu.cpp +++ b/src/gdu.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: gdu.cpp,v 1.1 2005-06-21 17:37:15 adam Exp $ + * $Id: gdu.cpp,v 1.2 2005-06-25 15:53:19 adam Exp $ */ #include @@ -29,11 +29,11 @@ void GDU::base(Z_GDU *gdu, ODR encode) m_gdu = 0; if (z_GDU(encode, &gdu, 0, "encode")) { - int len; - char *buf = odr_getbuf(encode, &len, 0); - - odr_setbuf(m_decode, buf, len, 0); - z_GDU(m_decode, &m_gdu, 0, 0); + int len; + char *buf = odr_getbuf(encode, &len, 0); + + odr_setbuf(m_decode, buf, len, 0); + z_GDU(m_decode, &m_gdu, 0, 0); } odr_destroy(encode); } @@ -52,7 +52,7 @@ void GDU::extract_odr_to(ODR dst) { NMEM nmem = odr_extract_mem(m_decode); if (!dst->mem) - dst->mem = nmem_create(); + dst->mem = nmem_create(); nmem_transfer(dst->mem, nmem); nmem_destroy(nmem); } @@ -86,7 +86,7 @@ GDU *GDUQueue::dequeue() if (!*l) return 0; while ((*l)->m_next) - l = &(*l)->m_next; + l = &(*l)->m_next; GDU *m = (*l)->m_item; delete *l; *l = 0; @@ -97,10 +97,18 @@ void GDUQueue::clear() { GDU *g; while ((g = dequeue())) - delete g; + delete g; } GDUQueue::~GDUQueue() { clear(); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-cql2rpn.cpp b/src/yaz-cql2rpn.cpp index cf59791..3906dff 100644 --- a/src/yaz-cql2rpn.cpp +++ b/src/yaz-cql2rpn.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-cql2rpn.cpp,v 1.7 2005-06-02 06:40:21 adam Exp $ + * $Id: yaz-cql2rpn.cpp,v 1.8 2005-06-25 15:53:19 adam Exp $ */ #include @@ -19,62 +19,70 @@ Yaz_cql2rpn::Yaz_cql2rpn() Yaz_cql2rpn::~Yaz_cql2rpn() { if (m_transform) - cql_transform_close(m_transform); + cql_transform_close(m_transform); } void Yaz_cql2rpn::set_pqf_file(const char *fname) { if (!m_transform) - m_transform = cql_transform_open_fname(fname); + m_transform = cql_transform_open_fname(fname); } int Yaz_cql2rpn::query_transform(const char *cql_query, - Z_RPNQuery **rpnquery, ODR o, - char **addinfop) + Z_RPNQuery **rpnquery, ODR o, + char **addinfop) { const char *addinfo = 0; if (!m_transform) - return -3; + return -3; CQL_parser cp = cql_parser_create(); int r = cql_parser_string(cp, cql_query); if (r) { - yaz_log(YLOG_LOG, "CQL Parse Error"); - r = 10; + yaz_log(YLOG_LOG, "CQL Parse Error"); + r = 10; } else { - char rpn_buf[1024]; - r = cql_transform_buf(m_transform, cql_parser_result(cp), - rpn_buf, sizeof(rpn_buf)-1); - if (!r) - { - YAZ_PQF_Parser pp = yaz_pqf_create(); + char rpn_buf[1024]; + r = cql_transform_buf(m_transform, cql_parser_result(cp), + rpn_buf, sizeof(rpn_buf)-1); + if (!r) + { + YAZ_PQF_Parser pp = yaz_pqf_create(); - *rpnquery = yaz_pqf_parse(pp, o, rpn_buf); - if (!*rpnquery) - { - size_t off; - const char *pqf_msg; - int code = yaz_pqf_error(pp, &pqf_msg, &off); - yaz_log(YLOG_WARN, "PQF Parser Error %s (code %d)", - pqf_msg, code); - r = -1; - } - yaz_pqf_destroy(pp); - } - else - { - r = cql_transform_error(m_transform, &addinfo); - yaz_log(YLOG_LOG, "CQL Transform Error %d %s", r, - addinfo ? addinfo : ""); - } - } + *rpnquery = yaz_pqf_parse(pp, o, rpn_buf); + if (!*rpnquery) + { + size_t off; + const char *pqf_msg; + int code = yaz_pqf_error(pp, &pqf_msg, &off); + yaz_log(YLOG_WARN, "PQF Parser Error %s (code %d)", + pqf_msg, code); + r = -1; + } + yaz_pqf_destroy(pp); + } + else + { + r = cql_transform_error(m_transform, &addinfo); + yaz_log(YLOG_LOG, "CQL Transform Error %d %s", r, + addinfo ? addinfo : ""); + } + } cql_parser_destroy(cp); if (addinfo) - *addinfop = odr_strdup(o, addinfo); + *addinfop = odr_strdup(o, addinfo); else - *addinfop = 0; + *addinfop = 0; return r; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-ir-assoc.cpp b/src/yaz-ir-assoc.cpp index 02b061a..4a004cb 100644 --- a/src/yaz-ir-assoc.cpp +++ b/src/yaz-ir-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-ir-assoc.cpp,v 1.25 2005-06-08 13:28:05 adam Exp $ + * $Id: yaz-ir-assoc.cpp,v 1.26 2005-06-25 15:53:19 adam Exp $ */ #include @@ -31,7 +31,7 @@ IR_Assoc::IR_Assoc(IPDU_Observable *the_PDU_Observable) IR_Assoc::~IR_Assoc() { if (m_elementSetNames) - delete [] m_elementSetNames->u.generic; + delete [] m_elementSetNames->u.generic; delete [] m_elementSetNames; delete [] m_host; delete [] m_proxy; @@ -50,15 +50,15 @@ void IR_Assoc::set_databaseNames (int num, const char **list) int i; yaz_log (m_log, "IR_Assoc::set_databaseNames num=%d", num); for (i = 0; iu.generic; + delete [] m_elementSetNames->u.generic; delete m_elementSetNames; m_elementSetNames = 0; if (elementSetName && *elementSetName) { - m_elementSetNames = new Z_ElementSetNames; - m_elementSetNames->which = Z_ElementSetNames_generic; - m_elementSetNames->u.generic = new char[strlen(elementSetName)+1]; - strcpy (m_elementSetNames->u.generic, elementSetName); + m_elementSetNames = new Z_ElementSetNames; + m_elementSetNames->which = Z_ElementSetNames_generic; + m_elementSetNames->u.generic = new char[strlen(elementSetName)+1]; + strcpy (m_elementSetNames->u.generic, elementSetName); } } @@ -143,10 +143,10 @@ void IR_Assoc::get_elementSetName (Z_ElementSetNames **elementSetNames) void IR_Assoc::get_elementSetName (const char **elementSetName) { if (!m_elementSetNames || - m_elementSetNames->which != Z_ElementSetNames_generic) + m_elementSetNames->which != Z_ElementSetNames_generic) { - *elementSetName = 0; - return; + *elementSetName = 0; + return; } *elementSetName = m_elementSetNames->u.generic; } @@ -155,7 +155,7 @@ void IR_Assoc::get_elementSetName (const char **elementSetName) void IR_Assoc::recv_GDU(Z_GDU *apdu, int len) { if (apdu->which == Z_GDU_Z3950) - recv_Z_PDU(apdu->u.z3950, len); + recv_Z_PDU(apdu->u.z3950, len); } void IR_Assoc::recv_Z_PDU(Z_APDU *apdu, int len) @@ -165,28 +165,28 @@ void IR_Assoc::recv_Z_PDU(Z_APDU *apdu, int len) switch (apdu->which) { case Z_APDU_initResponse: - yaz_log (m_log, "recv InitResponse"); - recv_initResponse(apdu->u.initResponse); - break; + yaz_log (m_log, "recv InitResponse"); + recv_initResponse(apdu->u.initResponse); + break; case Z_APDU_initRequest: yaz_log (m_log, "recv InitRequest"); - recv_initRequest(apdu->u.initRequest); + recv_initRequest(apdu->u.initRequest); break; case Z_APDU_searchRequest: yaz_log (m_log, "recv searchRequest"); - recv_searchRequest(apdu->u.searchRequest); + recv_searchRequest(apdu->u.searchRequest); break; case Z_APDU_searchResponse: - yaz_log (m_log, "recv searchResponse"); - recv_searchResponse(apdu->u.searchResponse); - break; + yaz_log (m_log, "recv searchResponse"); + recv_searchResponse(apdu->u.searchResponse); + break; case Z_APDU_presentRequest: yaz_log (m_log, "recv presentRequest"); - recv_presentRequest(apdu->u.presentRequest); + recv_presentRequest(apdu->u.presentRequest); break; case Z_APDU_presentResponse: yaz_log (m_log, "recv presentResponse"); - recv_presentResponse(apdu->u.presentResponse); + recv_presentResponse(apdu->u.presentResponse); break; case Z_APDU_extendedServicesResponse: yaz_log (m_log, "recv extendedServiceResponse"); @@ -205,25 +205,25 @@ int IR_Assoc::send_searchRequest(Yaz_Z_Query *query, req->query = query->get_Z_Query(); if (!req->query) - return -1; + return -1; get_databaseNames (&req->num_databaseNames, &req->databaseNames); int oid_syntax[OID_SIZE]; oident prefsyn; get_preferredRecordSyntax(&recordSyntax); if (recordSyntax != VAL_NONE) { - prefsyn.proto = PROTO_Z3950; - prefsyn.oclass = CLASS_RECSYN; - prefsyn.value = (enum oid_value) recordSyntax; - oid_ent_to_oid(&prefsyn, oid_syntax); - req->preferredRecordSyntax = oid_syntax; + prefsyn.proto = PROTO_Z3950; + prefsyn.oclass = CLASS_RECSYN; + prefsyn.value = (enum oid_value) recordSyntax; + oid_ent_to_oid(&prefsyn, oid_syntax); + req->preferredRecordSyntax = oid_syntax; } yaz_log (m_log, "send_searchRequest"); assert (req->otherInfo == 0); if (m_cookie) { - set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); - assert (req->otherInfo); + set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); + assert (req->otherInfo); } if ( pRefId ) @@ -256,24 +256,24 @@ int IR_Assoc::send_presentRequest(int start, get_preferredRecordSyntax (&recordSyntax); if (recordSyntax != VAL_NONE) { - prefsyn.proto = PROTO_Z3950; - prefsyn.oclass = CLASS_RECSYN; - prefsyn.value = (enum oid_value) recordSyntax; - oid_ent_to_oid(&prefsyn, oid_syntax); - req->preferredRecordSyntax = oid_syntax; + prefsyn.proto = PROTO_Z3950; + prefsyn.oclass = CLASS_RECSYN; + prefsyn.value = (enum oid_value) recordSyntax; + oid_ent_to_oid(&prefsyn, oid_syntax); + req->preferredRecordSyntax = oid_syntax; } Z_RecordComposition compo; Z_ElementSetNames *elementSetNames; get_elementSetName (&elementSetNames); if (elementSetNames) { - req->recordComposition = &compo; + req->recordComposition = &compo; compo.which = Z_RecordComp_simple; compo.u.simple = elementSetNames; } if (m_cookie) - set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); + set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); if ( pRefId ) { @@ -294,8 +294,8 @@ void IR_Assoc::set_proxy(const char *str) m_proxy = 0; if (str) { - m_proxy = new char[strlen(str)+1]; - strcpy (m_proxy, str); + m_proxy = new char[strlen(str)+1]; + strcpy (m_proxy, str); } } @@ -305,8 +305,8 @@ void IR_Assoc::set_cookie(const char *str) m_cookie = 0; if (str) { - m_cookie = new char[strlen(str)+1]; - strcpy(m_cookie, str); + m_cookie = new char[strlen(str)+1]; + strcpy(m_cookie, str); } } @@ -322,7 +322,7 @@ void IR_Assoc::client(const char *addr) strcpy(m_host, addr); const char *dbpart = strchr(m_host, '/'); if (dbpart) - set_databaseNames (dbpart+1, "+ "); + set_databaseNames (dbpart+1, "+ "); Z_Assoc::client(m_proxy ? m_proxy : m_host); } @@ -404,9 +404,9 @@ int IR_Assoc::send_initRequest(char* pRefId) } if (m_proxy && m_host) - set_otherInformationString(&req->otherInfo, VAL_PROXY, 1, m_host); + set_otherInformationString(&req->otherInfo, VAL_PROXY, 1, m_host); if (m_cookie) - set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); + set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); return send_Z_PDU(apdu, 0); } @@ -443,3 +443,11 @@ int IR_Assoc::send_deleteResultSetRequest(char* pResultSetId, char* pRefId) } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-marc-sample.cpp b/src/yaz-marc-sample.cpp index 5708a5d..906fdd2 100644 --- a/src/yaz-marc-sample.cpp +++ b/src/yaz-marc-sample.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2000-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-marc-sample.cpp,v 1.8 2005-06-02 06:40:21 adam Exp $ + * $Id: yaz-marc-sample.cpp,v 1.9 2005-06-25 15:53:19 adam Exp $ */ #include @@ -1483,7 +1483,15 @@ static const char *marc_records[] = { const char *Yaz_USMARC::get_record(size_t position) { if (position >= 1 && position <= ( - sizeof(marc_records) / sizeof(*marc_records))) - return marc_records[position-1]; + sizeof(marc_records) / sizeof(*marc_records))) + return marc_records[position-1]; return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-my-client.cpp b/src/yaz-my-client.cpp index 203f16e..c310895 100644 --- a/src/yaz-my-client.cpp +++ b/src/yaz-my-client.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-my-client.cpp,v 1.20 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-my-client.cpp,v 1.21 2005-06-25 15:53:19 adam Exp $ */ #include @@ -34,9 +34,9 @@ private: SocketManager *m_socketManager; public: MyClient(IPDU_Observable *the_PDU_Observable, - SocketManager *the_SocketManager); + SocketManager *the_SocketManager); IPDU_Observer *sessionNotify( - IPDU_Observable *the_PDU_Observable, int fd); + IPDU_Observable *the_PDU_Observable, int fd); int args(SocketManager *socketManager, int argc, char **argv); int interactive(SocketManager *socketManager); int wait(); @@ -47,7 +47,7 @@ public: void recv_diagrecs(Z_DiagRec **pp, int num); void recv_namePlusRecord (Z_NamePlusRecord *zpr, int offset); void recv_record(Z_DatabaseRecord *record, int offset, - const char *databaseName); + const char *databaseName); void recv_textRecord(int type, const char *buf, size_t len); void recv_genericRecord(Z_GenericRecord *r); void display_genericRecord(Z_GenericRecord *r, int level); @@ -90,13 +90,13 @@ void MyClient::failNotify() } IPDU_Observer *MyClient::sessionNotify(IPDU_Observable *the_PDU_Observable, - int fd) + int fd) { return new MyClient(the_PDU_Observable, m_socketManager); } MyClient::MyClient(IPDU_Observable *the_PDU_Observable, - SocketManager *the_socketManager) : + SocketManager *the_socketManager) : IR_Assoc (the_PDU_Observable) { m_setOffset = 1; @@ -122,9 +122,9 @@ char *MyClient::get_cookie(Z_OtherInformation **otherInfo) ent.value = (oid_value) VAL_COOKIE; if (oid_ent_to_oid (&ent, oid) && - (oi = update_otherInformation(otherInfo, 0, oid, 1, 1)) && - oi->which == Z_OtherInfo_characterInfo) - return oi->information.characterInfo; + (oi = update_otherInformation(otherInfo, 0, oid, 1, 1)) && + oi->which == Z_OtherInfo_characterInfo) + return oi->information.characterInfo; return 0; } @@ -133,17 +133,17 @@ void MyClient::recv_initResponse(Z_InitResponse *initResponse) printf ("Got InitResponse. Status "); if (*initResponse->result) { - printf ("Ok\n"); - - const char *p = get_cookie (&initResponse->otherInfo); - if (p) - { - printf ("cookie = %s\n", p); - set_cookie(p); - } + printf ("Ok\n"); + + const char *p = get_cookie (&initResponse->otherInfo); + if (p) + { + printf ("cookie = %s\n", p); + set_cookie(p); + } } else - printf ("Fail\n"); + printf ("Fail\n"); } void MyClient::recv_diagrecs(Z_DiagRec **pp, int num) @@ -155,33 +155,33 @@ void MyClient::recv_diagrecs(Z_DiagRec **pp, int num) printf("Diagnostic message(s) from database:\n"); for (i = 0; iwhich != Z_DiagRec_defaultFormat) - { - printf("Diagnostic record not in default format.\n"); - return; - } - else - r = p->u.defaultFormat; - if (!(ent = oid_getentbyoid(r->diagnosticSetId)) || - ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1) - printf("Missing or unknown diagset\n"); - printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition)); + Z_DiagRec *p = pp[i]; + if (p->which != Z_DiagRec_defaultFormat) + { + printf("Diagnostic record not in default format.\n"); + return; + } + else + r = p->u.defaultFormat; + if (!(ent = oid_getentbyoid(r->diagnosticSetId)) || + ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1) + printf("Missing or unknown diagset\n"); + printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition)); #ifdef ASN_COMPILED - switch (r->which) - { - case Z_DefaultDiagFormat_v2Addinfo: - printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo); - break; - case Z_DefaultDiagFormat_v3Addinfo: - printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo); - break; - } + switch (r->which) + { + case Z_DefaultDiagFormat_v2Addinfo: + printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo); + break; + case Z_DefaultDiagFormat_v3Addinfo: + printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo); + break; + } #else - if (r->addinfo && *r->addinfo) - printf(" -- '%s'\n", r->addinfo); - else - printf("\n"); + if (r->addinfo && *r->addinfo) + printf(" -- '%s'\n", r->addinfo); + else + printf("\n"); #endif } } @@ -198,12 +198,12 @@ void MyClient::display_variant(Z_Variant *v, int level) for (i = 0; i < v->num_triples; i++) { - printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass, - *v->triples[i]->type); - if (v->triples[i]->which == Z_Triple_internationalString) - printf(",value=%s\n", v->triples[i]->value.internationalString); - else - printf("\n"); + printf("%*sclass=%d,type=%d", level * 4, "", *v->triples[i]->zclass, + *v->triples[i]->type); + if (v->triples[i]->which == Z_Triple_internationalString) + printf(",value=%s\n", v->triples[i]->value.internationalString); + else + printf("\n"); } } @@ -236,43 +236,43 @@ void MyClient::display_genericRecord(Z_GenericRecord *r, int level) else if (t->content->which == Z_ElementData_string) printf("%s\n", t->content->u.string); else if (t->content->which == Z_ElementData_numeric) - printf("%d\n", *t->content->u.numeric); - else if (t->content->which == Z_ElementData_oid) - { - int *ip = t->content->u.oid; - oident *oent; - - if ((oent = oid_getentbyoid(t->content->u.oid))) - printf("OID: %s\n", oent->desc); - else - { - printf("{"); - while (ip && *ip >= 0) - printf(" %d", *(ip++)); - printf(" }\n"); - } - } - else if (t->content->which == Z_ElementData_noDataRequested) - printf("[No data requested]\n"); - else if (t->content->which == Z_ElementData_elementEmpty) - printf("[Element empty]\n"); - else if (t->content->which == Z_ElementData_elementNotThere) - printf("[Element not there]\n"); - else + printf("%d\n", *t->content->u.numeric); + else if (t->content->which == Z_ElementData_oid) + { + int *ip = t->content->u.oid; + oident *oent; + + if ((oent = oid_getentbyoid(t->content->u.oid))) + printf("OID: %s\n", oent->desc); + else + { + printf("{"); + while (ip && *ip >= 0) + printf(" %d", *(ip++)); + printf(" }\n"); + } + } + else if (t->content->which == Z_ElementData_noDataRequested) + printf("[No data requested]\n"); + else if (t->content->which == Z_ElementData_elementEmpty) + printf("[Element empty]\n"); + else if (t->content->which == Z_ElementData_elementNotThere) + printf("[Element not there]\n"); + else printf("??????\n"); - if (t->appliedVariant) - display_variant(t->appliedVariant, level+1); - if (t->metaData && t->metaData->supportedVariants) - { - int c; - - printf("%*s---- variant list\n", (level+1)*4, ""); - for (c = 0; c < t->metaData->num_supportedVariants; c++) - { - printf("%*svariant #%d\n", (level+1)*4, "", c); - display_variant(t->metaData->supportedVariants[c], level + 2); - } - } + if (t->appliedVariant) + display_variant(t->appliedVariant, level+1); + if (t->metaData && t->metaData->supportedVariants) + { + int c; + + printf("%*s---- variant list\n", (level+1)*4, ""); + for (c = 0; c < t->metaData->num_supportedVariants; c++) + { + printf("%*svariant #%d\n", (level+1)*4, "", c); + display_variant(t->metaData->supportedVariants[c], level + 2); + } + } } } @@ -282,7 +282,7 @@ void MyClient::recv_genericRecord(Z_GenericRecord *r) } void MyClient::recv_record(Z_DatabaseRecord *record, int offset, - const char *databaseName) + const char *databaseName) { Z_External *r = (Z_External*) record; oident *ent = oid_getentbyoid(r->direct_reference); @@ -292,76 +292,76 @@ 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); } /* Check if this is a known, ASN.1 type tucked away in an octet string */ Z_ext_typeent *etype = z_ext_getentbyref(ent->value); if (ent && (r->which == Z_External_octet || r->which == Z_External_single) - && (etype = z_ext_getentbyref(ent->value))) + && (etype = z_ext_getentbyref(ent->value))) { - void *rr; - /* - * Call the given decoder to process the record. - */ - odr_setbuf(odr_decode(), (char*)record->u.octet_aligned->buf, - record->u.octet_aligned->len, 0); - if (!(*etype->fun)(odr_decode(), (char **)&rr, 0, 0)) - { - odr_perror(odr_decode(), "Decoding constructed record."); - fprintf(stderr, "[Near %d]\n", odr_offset(odr_decode())); - fprintf(stderr, "Packet dump:\n---------\n"); - odr_dumpBER(stderr, (char*)record->u.octet_aligned->buf, - record->u.octet_aligned->len); - fprintf(stderr, "---------\n"); - } - if (etype->what == Z_External_sutrs) - { - Z_SUTRS *sutrs = (Z_SUTRS *) rr; - recv_textRecord ((int) VAL_SUTRS, (const char *) sutrs->buf, - (size_t) sutrs->len); - } - return; + void *rr; + /* + * Call the given decoder to process the record. + */ + odr_setbuf(odr_decode(), (char*)record->u.octet_aligned->buf, + record->u.octet_aligned->len, 0); + if (!(*etype->fun)(odr_decode(), (char **)&rr, 0, 0)) + { + odr_perror(odr_decode(), "Decoding constructed record."); + fprintf(stderr, "[Near %d]\n", odr_offset(odr_decode())); + fprintf(stderr, "Packet dump:\n---------\n"); + odr_dumpBER(stderr, (char*)record->u.octet_aligned->buf, + record->u.octet_aligned->len); + fprintf(stderr, "---------\n"); + } + if (etype->what == Z_External_sutrs) + { + Z_SUTRS *sutrs = (Z_SUTRS *) rr; + recv_textRecord ((int) VAL_SUTRS, (const char *) sutrs->buf, + (size_t) sutrs->len); + } + return; } if (r->which == Z_External_octet && 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,0); - break; - default: - 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,0); + 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, - (size_t) r->u.sutrs->len); + recv_textRecord((int) VAL_SUTRS, (const char *) r->u.sutrs->buf, + (size_t) r->u.sutrs->len); else if (ent && ent->value == VAL_GRS1 && r->which == Z_External_grs1) recv_genericRecord(r->u.grs1); else @@ -378,7 +378,7 @@ void MyClient::recv_record(Z_DatabaseRecord *record, int offset, void MyClient::recv_namePlusRecord (Z_NamePlusRecord *zpr, int offset) { if (zpr->databaseName) - printf("[%s]", zpr->databaseName); + printf("[%s]", zpr->databaseName); if (zpr->which == Z_NamePlusRecord_surrogateDiagnostic) recv_diagrecs(&zpr->u.surrogateDiagnostic, 1); else @@ -391,29 +391,29 @@ void MyClient::recv_records (Z_Records *records) Z_DiagRec dr, *dr_p = &dr; #endif if (!records) - return; + return; int i; switch (records->which) { case Z_Records_DBOSD: for (i = 0; i < records->u.databaseOrSurDiagnostics->num_records; i++) recv_namePlusRecord(records->u.databaseOrSurDiagnostics-> - records[i], i + m_setOffset); - m_setOffset += records->u.databaseOrSurDiagnostics->num_records; - break; + records[i], i + m_setOffset); + m_setOffset += records->u.databaseOrSurDiagnostics->num_records; + break; case Z_Records_NSD: #ifdef ASN_COMPILED - dr.which = Z_DiagRec_defaultFormat; - dr.u.defaultFormat = records->u.nonSurrogateDiagnostic; - recv_diagrecs (&dr_p, 1); + dr.which = Z_DiagRec_defaultFormat; + dr.u.defaultFormat = records->u.nonSurrogateDiagnostic; + recv_diagrecs (&dr_p, 1); #else - recv_diagrecs (&records->u.nonSurrogateDiagnostic, 1); + recv_diagrecs (&records->u.nonSurrogateDiagnostic, 1); #endif - break; + break; case Z_Records_multipleNSD: - recv_diagrecs (records->u.multipleNonSurDiagnostics->diagRecs, - records->u.multipleNonSurDiagnostics->num_diagRecs); - break; + recv_diagrecs (records->u.multipleNonSurDiagnostics->diagRecs, + records->u.multipleNonSurDiagnostics->num_diagRecs); + break; } } @@ -422,12 +422,12 @@ void MyClient::recv_searchResponse(Z_SearchResponse *searchResponse) printf ("Got SearchResponse. Status "); if (!*searchResponse->searchStatus) { - printf ("Fail\n"); + printf ("Fail\n"); } else { - printf ("Ok\n"); - printf ("Hits: %d\n", *searchResponse->resultCount); + printf ("Ok\n"); + printf ("Hits: %d\n", *searchResponse->resultCount); } recv_records (searchResponse->records); } @@ -443,8 +443,8 @@ int MyClient::wait() set_lastReceived(0); while (m_socketManager->processEvent() > 0) { - if (get_lastReceived()) - return 1; + if (get_lastReceived()) + return 1; } return 0; } @@ -475,9 +475,9 @@ int MyClient::cmd_open(char *host) int MyClient::cmd_init(char *args) { if (send_initRequest() >= 0) - wait(); + wait(); else - close(); + close(); return 1; } @@ -498,13 +498,13 @@ int MyClient::cmd_find(char *args) if (query.set_rpn(args) <= 0) { - printf ("Bad RPN query\n"); - return 1; + printf ("Bad RPN query\n"); + return 1; } if (send_searchRequest(&query) >= 0) - wait(); + wait(); else - printf ("Not connected\n"); + printf ("Not connected\n"); return 1; } @@ -515,9 +515,9 @@ int MyClient::cmd_show(char *args) sscanf (args, "%d %d", &start, &number); m_setOffset = start; if (send_presentRequest(start, number) >= 0) - wait(); + wait(); else - printf ("Not connected\n"); + printf ("Not connected\n"); return 1; } @@ -549,35 +549,35 @@ int MyClient::processCommand(const char *commandLine) int (MyClient::*fun)(char *arg); const char *ad; } cmd[] = { - {"open", &MyClient::cmd_open, "[':'][/]"}, - {"connect", &MyClient::cmd_connect, "[':'][/]"}, - {"quit", &MyClient::cmd_quit, ""}, - {"close", &MyClient::cmd_close, ""}, - {"find", &MyClient::cmd_find, ""}, - {"show", &MyClient::cmd_show, "[ []]"}, - {"cookie", &MyClient::cmd_cookie, ""}, - {"init", &MyClient::cmd_init, ""}, - {"format", &MyClient::cmd_format, ""}, - {"proxy", &MyClient::cmd_proxy, ":[':']"}, - {0,0,0} + {"open", &MyClient::cmd_open, "[':'][/]"}, + {"connect", &MyClient::cmd_connect, "[':'][/]"}, + {"quit", &MyClient::cmd_quit, ""}, + {"close", &MyClient::cmd_close, ""}, + {"find", &MyClient::cmd_find, ""}, + {"show", &MyClient::cmd_show, "[ []]"}, + {"cookie", &MyClient::cmd_cookie, ""}, + {"init", &MyClient::cmd_init, ""}, + {"format", &MyClient::cmd_format, ""}, + {"proxy", &MyClient::cmd_proxy, ":[':']"}, + {0,0,0} }; if (sscanf(commandLine, "%s %[^;]", cmdStr, cmdArgs) < 1) - return 1; + return 1; int i; for (i = 0; cmd[i].cmd; i++) - if (!strncmp(cmd[i].cmd, cmdStr, strlen(cmdStr))) - break; + if (!strncmp(cmd[i].cmd, cmdStr, strlen(cmdStr))) + break; int res = 1; if (cmd[i].cmd) // Invoke command handler - res = (this->*cmd[i].fun)(cmdArgs); + res = (this->*cmd[i].fun)(cmdArgs); else // Dump help screen { - printf("Unknown command: %s.\n", cmdStr); - printf("Currently recognized commands:\n"); - for (i = 0; cmd[i].cmd; i++) - printf(" %s %s\n", cmd[i].cmd, cmd[i].ad); + printf("Unknown command: %s.\n", cmdStr); + printf("Currently recognized commands:\n"); + for (i = 0; cmd[i].cmd; i++) + printf(" %s %s\n", cmd[i].cmd, cmd[i].ad); } return res; } @@ -589,10 +589,10 @@ const char *MyClient::getCommand() char *line_in; line_in=readline(C_PROMPT); if (!line_in) - return 0; + return 0; #if HAVE_READLINE_HISTORY_H if (*line_in) - add_history(line_in); + add_history(line_in); #endif strncpy(m_thisCommand,line_in, 1023); m_thisCommand[1023] = '\0'; @@ -602,20 +602,20 @@ const char *MyClient::getCommand() printf (C_PROMPT); fflush(stdout); if (!fgets(m_thisCommand, 1023, stdin)) - return 0; + return 0; #endif // Remove trailing whitespace char *cp = m_thisCommand + strlen(m_thisCommand); while (cp != m_thisCommand && strchr("\t \n", cp[-1])) - cp--; + cp--; *cp = '\0'; cp = m_thisCommand; // Remove leading spaces... while (*cp && strchr ("\t \n", *cp)) - cp++; + cp++; // Save command if non-empty if (*cp != '\0') - strcpy (m_lastCommand, cp); + strcpy (m_lastCommand, cp); return m_lastCommand; } @@ -623,11 +623,11 @@ int MyClient::interactive(SocketManager *socketManager) { const char *cmd; if (!m_interactive_flag) - return 0; + return 0; while ((cmd = getCommand())) { - if (!processCommand(cmd)) - break; + if (!processCommand(cmd)) + break; } return 0; } @@ -646,42 +646,42 @@ int MyClient::args(SocketManager *socketManager, int argc, char **argv) { case 0: if (host) - { - usage(prog); - return 1; - } - host = arg; + { + usage(prog); + return 1; + } + host = arg; break; case 'p': - if (proxy) - { - usage(prog); - return 1; - } - set_proxy(arg); - break; - case 'c': - set_cookie(arg); - break; - case 'v': - yaz_log_init_level (yaz_log_mask_str(arg)); - break; - case 'q': - m_interactive_flag = 0; - break; + if (proxy) + { + usage(prog); + return 1; + } + set_proxy(arg); + break; + case 'c': + set_cookie(arg); + break; + case 'v': + yaz_log_init_level (yaz_log_mask_str(arg)); + break; + case 'q': + m_interactive_flag = 0; + break; default: - usage(prog); - return 1; + usage(prog); + return 1; } } if (host) { - client (host); + client (host); timeout (10); - wait (); + wait (); timeout (-1); - send_initRequest(); - wait (); + send_initRequest(); + wait (); } return 0; } @@ -694,8 +694,16 @@ int main(int argc, char **argv) MyClient z(some, &mySocketManager); if (z.args(&mySocketManager, argc, argv)) - exit (1); + exit (1); if (z.interactive(&mySocketManager)) - exit (1); + exit (1); return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-my-server.cpp b/src/yaz-my-server.cpp index 421aa4d..86ff26e 100644 --- a/src/yaz-my-server.cpp +++ b/src/yaz-my-server.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-my-server.cpp,v 1.18 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-my-server.cpp,v 1.19 2005-06-25 15:53:19 adam Exp $ */ #include @@ -18,35 +18,35 @@ using namespace yazpp_1; class MyILL : public Yaz_Facility_ILL { public: void ill_service (Z_ExtendedServicesRequest *req, - Z_ItemOrder *io, - Z_ExtendedServicesResponse *res); + Z_ItemOrder *io, + Z_ExtendedServicesResponse *res); }; class MyUpdate : public Yaz_Facility_Update { public: void update_service (Z_ExtendedServicesRequest *req, - Z_IUUpdate *io, - Z_ExtendedServicesResponse *res); + Z_IUUpdate *io, + Z_ExtendedServicesResponse *res); void update_service0 (Z_ExtendedServicesRequest *req, - Z_IU0Update *io, - Z_ExtendedServicesResponse *res); + Z_IU0Update *io, + Z_ExtendedServicesResponse *res); }; class MyRetrieval : public Yaz_Facility_Retrieval, Yaz_USMARC { public: int sr_init (Z_InitRequest *initRequest, - Z_InitResponse *initResponse); + Z_InitResponse *initResponse); void sr_search (Z_SearchRequest *searchRequest, - Z_SearchResponse *searchResponse); + Z_SearchResponse *searchResponse); void sr_present (Z_PresentRequest *presentRequest, - Z_PresentResponse *presentResponse); + Z_PresentResponse *presentResponse); void sr_record (const char *resultSetName, - int position, - int *format, - Z_RecordComposition *comp, - Z_NamePlusRecord *namePlusRecord, - Z_Records *records); + int position, + int *format, + Z_RecordComposition *comp, + Z_NamePlusRecord *namePlusRecord, + Z_Records *records); }; class MyServer : public Z_Server { @@ -54,7 +54,7 @@ public: ~MyServer(); MyServer(IPDU_Observable *the_PDU_Observable); IPDU_Observer* sessionNotify(IPDU_Observable *the_PDU_Observable, - int fd); + int fd); void failNotify(); void timeoutNotify(); void connectNotify(); @@ -67,75 +67,75 @@ private: }; void MyILL::ill_service (Z_ExtendedServicesRequest *req, - Z_ItemOrder *io, - Z_ExtendedServicesResponse *res) + Z_ItemOrder *io, + Z_ExtendedServicesResponse *res) { yaz_log (YLOG_LOG, "MyServer::ill_service"); } void MyUpdate::update_service (Z_ExtendedServicesRequest *req, - Z_IUUpdate *io, - Z_ExtendedServicesResponse *res) + Z_IUUpdate *io, + Z_ExtendedServicesResponse *res) { yaz_log (YLOG_LOG, "MyServer::update_service (v1.1)"); } void MyUpdate::update_service0 (Z_ExtendedServicesRequest *req, - Z_IU0Update *io, - Z_ExtendedServicesResponse *res) + Z_IU0Update *io, + Z_ExtendedServicesResponse *res) { yaz_log (YLOG_LOG, "MyServer::update_service (v1.0)"); } int MyRetrieval::sr_init (Z_InitRequest *initRequest, - Z_InitResponse *initResponse) + Z_InitResponse *initResponse) { yaz_log (YLOG_LOG, "MyServer::sr_init"); return 1; } void MyRetrieval::sr_search (Z_SearchRequest *searchRequest, - Z_SearchResponse *searchResponse) + Z_SearchResponse *searchResponse) { yaz_log (YLOG_LOG, "MyServer::recv_Z_search"); if (searchRequest->query->which == Z_Query_type_1) { - Z_RPNStructure *s = searchRequest->query->u.type_1->RPNStructure; - if (s->which == Z_RPNStructure_simple && - s->u.simple->which == Z_Operand_APT && - s->u.simple->u.attributesPlusTerm->term->which == Z_Term_general) - { - Odr_oct *term = s->u.simple->u.attributesPlusTerm->term->u.general; - char *str = (char *) odr_malloc (odr_encode(), term->len+1); - if (term->len) - memcpy (str, term->buf, term->len); - str[term->len] = '\0'; - *searchResponse->resultCount = atoi(str); - } + Z_RPNStructure *s = searchRequest->query->u.type_1->RPNStructure; + if (s->which == Z_RPNStructure_simple && + s->u.simple->which == Z_Operand_APT && + s->u.simple->u.attributesPlusTerm->term->which == Z_Term_general) + { + Odr_oct *term = s->u.simple->u.attributesPlusTerm->term->u.general; + char *str = (char *) odr_malloc (odr_encode(), term->len+1); + if (term->len) + memcpy (str, term->buf, term->len); + str[term->len] = '\0'; + *searchResponse->resultCount = atoi(str); + } } } void MyRetrieval::sr_present (Z_PresentRequest *presentRequest, - Z_PresentResponse *presentResponse) + Z_PresentResponse *presentResponse) { yaz_log (YLOG_LOG, "MyServer::recv_Z_present"); } void MyRetrieval::sr_record (const char *resultSetName, - int position, - int *format, - Z_RecordComposition *comp, - Z_NamePlusRecord *namePlusRecord, - Z_Records *records) + int position, + int *format, + Z_RecordComposition *comp, + Z_NamePlusRecord *namePlusRecord, + Z_Records *records) { yaz_log (YLOG_LOG, "MyServer::recv_Z_record"); const char *rec = get_record(position); if (rec) - create_databaseRecord (odr_encode(), namePlusRecord, 0, - VAL_USMARC, rec, strlen(rec)); + create_databaseRecord (odr_encode(), namePlusRecord, 0, + VAL_USMARC, rec, strlen(rec)); else - create_surrogateDiagnostics(odr_encode(), namePlusRecord, 0, - YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE, 0); + create_surrogateDiagnostics(odr_encode(), namePlusRecord, 0, + YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE, 0); } MyServer::~MyServer() @@ -202,30 +202,30 @@ int main(int argc, char **argv) while ((ret = options("a:v:T", argv, argc, &arg)) != -2) { - switch (ret) - { - case 0: - addr = xstrdup(arg); - break; - case 'a': - apdu_log = xstrdup(arg); - break; - case 'v': - yaz_log_init_level (yaz_log_mask_str(arg)); - break; - case 'T': - thread_flag = 1; - break; - default: - usage(prog); - return 1; - } + switch (ret) + { + case 0: + addr = xstrdup(arg); + break; + case 'a': + apdu_log = xstrdup(arg); + break; + case 'v': + yaz_log_init_level (yaz_log_mask_str(arg)); + break; + case 'T': + thread_flag = 1; + break; + default: + usage(prog); + return 1; + } } #if YAZ_POSIX_THREADS if (thread_flag) - my_PDU_Assoc = new PDU_AssocThread(&mySocketManager); + my_PDU_Assoc = new PDU_AssocThread(&mySocketManager); else - my_PDU_Assoc = new PDU_Assoc(&mySocketManager); + my_PDU_Assoc = new PDU_Assoc(&mySocketManager); #else my_PDU_Assoc = new PDU_Assoc(&mySocketManager); #endif @@ -234,12 +234,20 @@ int main(int argc, char **argv) z->server(addr); if (apdu_log) { - yaz_log (YLOG_LOG, "set_APDU_log %s", apdu_log); - z->set_APDU_log(apdu_log); + yaz_log (YLOG_LOG, "set_APDU_log %s", apdu_log); + z->set_APDU_log(apdu_log); } while (mySocketManager.processEvent() > 0) - ; + ; delete z; return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-pdu-assoc-thread.cpp b/src/yaz-pdu-assoc-thread.cpp index 207a68b..294aa60 100644 --- a/src/yaz-pdu-assoc-thread.cpp +++ b/src/yaz-pdu-assoc-thread.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-pdu-assoc-thread.cpp,v 1.11 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-pdu-assoc-thread.cpp,v 1.12 2005-06-25 15:53:19 adam Exp $ */ #ifdef WIN32 @@ -53,7 +53,7 @@ events(void *p) yaz_log (YLOG_LOG, "thread started"); while (s->processEvent() > 0) - ; + ; yaz_log (YLOG_LOG, "thread finished"); #ifdef WIN32 #else @@ -72,7 +72,7 @@ void PDU_AssocThread::childNotify(COMSTACK cs) /// Clone PDU Observer new_observable->m_PDU_Observer = - m_PDU_Observer->sessionNotify(new_observable, cs_fileno(cs)); + m_PDU_Observer->sessionNotify(new_observable, cs_fileno(cs)); #ifdef WIN32 long t_id; t_id = _beginthread (events, 0, socket_observable); @@ -86,9 +86,17 @@ void PDU_AssocThread::childNotify(COMSTACK cs) int id = pthread_create (&tid, 0, events, socket_observable); if (id) - yaz_log (YLOG_ERRNO|YLOG_FATAL, "pthread_create returned id=%d", id); + yaz_log (YLOG_ERRNO|YLOG_FATAL, "pthread_create returned id=%d", id); else - pthread_detach (tid); + pthread_detach (tid); #endif } #endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-pdu-assoc.cpp b/src/yaz-pdu-assoc.cpp index b8e3416..5a41980 100644 --- a/src/yaz-pdu-assoc.cpp +++ b/src/yaz-pdu-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-pdu-assoc.cpp,v 1.42 2005-06-21 21:30:24 adam Exp $ + * $Id: yaz-pdu-assoc.cpp,v 1.43 2005-06-25 15:53:19 adam Exp $ */ #include @@ -38,31 +38,31 @@ PDU_Assoc::PDU_Assoc(ISocketObservable *socketObservable) } PDU_Assoc::PDU_Assoc(ISocketObservable *socketObservable, - COMSTACK cs) + COMSTACK cs) { init(socketObservable); m_cs = cs; unsigned mask = 0; if (cs->io_pending & CS_WANT_WRITE) - mask |= SOCKET_OBSERVE_WRITE; + mask |= SOCKET_OBSERVE_WRITE; if (cs->io_pending & CS_WANT_READ) - mask |= SOCKET_OBSERVE_READ; + mask |= SOCKET_OBSERVE_READ; m_socketObservable->addObserver(cs_fileno(cs), this); if (!mask) { - yaz_log (m_log, "new PDU_Assoc. Ready"); - m_state = Ready; - flush_PDU(); + yaz_log (m_log, "new PDU_Assoc. Ready"); + m_state = Ready; + flush_PDU(); } else { - yaz_log (m_log, "new PDU_Assoc. Accepting"); - // assume comstack is accepting... - m_state = Accepting; - m_socketObservable->addObserver(cs_fileno(cs), this); - yaz_log(m_log, "maskObserver 1"); - m_socketObservable->maskObserver(this, - mask |SOCKET_OBSERVE_EXCEPT); + yaz_log (m_log, "new PDU_Assoc. Accepting"); + // assume comstack is accepting... + m_state = Accepting; + m_socketObservable->addObserver(cs_fileno(cs), this); + yaz_log(m_log, "maskObserver 1"); + m_socketObservable->maskObserver(this, + mask |SOCKET_OBSERVE_EXCEPT); } } @@ -76,7 +76,7 @@ IPDU_Observable *PDU_Assoc::clone() void PDU_Assoc::socketNotify(int event) { yaz_log (m_log, "PDU_Assoc::socketNotify p=%p state=%d event = %d", - this, m_state, event); + this, m_state, event); if (event & SOCKET_OBSERVE_EXCEPT) { close(); @@ -91,156 +91,156 @@ void PDU_Assoc::socketNotify(int event) switch (m_state) { case Accepting: - if (!cs_accept (m_cs)) - { - yaz_log (m_log, "PDU_Assoc::cs_accept failed"); - m_cs = 0; - close(); - m_PDU_Observer->failNotify(); - } - else - { - unsigned mask = 0; - if (m_cs->io_pending & CS_WANT_WRITE) - mask |= SOCKET_OBSERVE_WRITE; - if (m_cs->io_pending & CS_WANT_READ) - mask |= SOCKET_OBSERVE_READ; - if (!mask) - { // accept is complete. turn to ready state and write if needed - m_state = Ready; - flush_PDU(); - } - else - { // accept still incomplete. - yaz_log(m_log, "maskObserver 2"); - m_socketObservable->maskObserver(this, - mask|SOCKET_OBSERVE_EXCEPT); - } - } - break; + if (!cs_accept (m_cs)) + { + yaz_log (m_log, "PDU_Assoc::cs_accept failed"); + m_cs = 0; + close(); + m_PDU_Observer->failNotify(); + } + else + { + unsigned mask = 0; + if (m_cs->io_pending & CS_WANT_WRITE) + mask |= SOCKET_OBSERVE_WRITE; + if (m_cs->io_pending & CS_WANT_READ) + mask |= SOCKET_OBSERVE_READ; + if (!mask) + { // accept is complete. turn to ready state and write if needed + m_state = Ready; + flush_PDU(); + } + else + { // accept still incomplete. + yaz_log(m_log, "maskObserver 2"); + m_socketObservable->maskObserver(this, + mask|SOCKET_OBSERVE_EXCEPT); + } + } + break; case Connecting: - if (event & SOCKET_OBSERVE_READ && - event & SOCKET_OBSERVE_WRITE) - { - // For Unix: if both read and write is set, then connect failed. - close(); - m_PDU_Observer->failNotify(); - } - else - { - yaz_log (m_log, "cs_rcvconnect"); - int res = cs_rcvconnect (m_cs); - if (res == 1) - { - unsigned mask = SOCKET_OBSERVE_EXCEPT; - if (m_cs->io_pending & CS_WANT_WRITE) - mask |= SOCKET_OBSERVE_WRITE; - if (m_cs->io_pending & CS_WANT_READ) - mask |= SOCKET_OBSERVE_READ; - yaz_log(m_log, "maskObserver 3"); - m_socketObservable->maskObserver(this, mask); - } - else - { - m_state = Ready; - if (m_PDU_Observer) - m_PDU_Observer->connectNotify(); - flush_PDU(); - } - } - break; + if (event & SOCKET_OBSERVE_READ && + event & SOCKET_OBSERVE_WRITE) + { + // For Unix: if both read and write is set, then connect failed. + close(); + m_PDU_Observer->failNotify(); + } + else + { + yaz_log (m_log, "cs_rcvconnect"); + int res = cs_rcvconnect (m_cs); + if (res == 1) + { + unsigned mask = SOCKET_OBSERVE_EXCEPT; + if (m_cs->io_pending & CS_WANT_WRITE) + mask |= SOCKET_OBSERVE_WRITE; + if (m_cs->io_pending & CS_WANT_READ) + mask |= SOCKET_OBSERVE_READ; + yaz_log(m_log, "maskObserver 3"); + m_socketObservable->maskObserver(this, mask); + } + else + { + m_state = Ready; + if (m_PDU_Observer) + m_PDU_Observer->connectNotify(); + flush_PDU(); + } + } + break; case Listen: - if (event & SOCKET_OBSERVE_READ) - { - int res; - COMSTACK new_line; - - if ((res = cs_listen(m_cs, 0, 0)) == 1) - return; - if (res < 0) - { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "cs_listen failed"); - return; - } - if (!(new_line = cs_accept(m_cs))) - return; - /* 1. create socket-manager + if (event & SOCKET_OBSERVE_READ) + { + int res; + COMSTACK new_line; + + if ((res = cs_listen(m_cs, 0, 0)) == 1) + return; + if (res < 0) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "cs_listen failed"); + return; + } + if (!(new_line = cs_accept(m_cs))) + return; + /* 1. create socket-manager 2. create pdu-assoc 3. create top-level object setup observer for child fileid in pdu-assoc 4. start thread - */ - yaz_log (m_log, "new session: parent fd=%d child fd=%d", - cs_fileno(m_cs), cs_fileno(new_line)); - childNotify (new_line); - } - break; + */ + yaz_log (m_log, "new session: parent fd=%d child fd=%d", + cs_fileno(m_cs), cs_fileno(new_line)); + childNotify (new_line); + } + break; case Writing: if (event & (SOCKET_OBSERVE_READ|SOCKET_OBSERVE_WRITE)) flush_PDU(); break; case Ready: - if (event & (SOCKET_OBSERVE_READ|SOCKET_OBSERVE_WRITE)) - { - do - { - int res = cs_get (m_cs, &m_input_buf, &m_input_len); - if (res == 1) + if (event & (SOCKET_OBSERVE_READ|SOCKET_OBSERVE_WRITE)) + { + do + { + int res = cs_get (m_cs, &m_input_buf, &m_input_len); + if (res == 1) { unsigned mask = SOCKET_OBSERVE_EXCEPT; if (m_cs->io_pending & CS_WANT_WRITE) mask |= SOCKET_OBSERVE_WRITE; if (m_cs->io_pending & CS_WANT_READ) mask |= SOCKET_OBSERVE_READ; - yaz_log(m_log, "maskObserver 4"); - m_socketObservable->maskObserver(this, mask); - return; + yaz_log(m_log, "maskObserver 4"); + m_socketObservable->maskObserver(this, mask); + return; + } + else if (res <= 0) + { + yaz_log (m_log, "PDU_Assoc::Connection closed by peer"); + close(); + if (m_PDU_Observer) + m_PDU_Observer->failNotify(); // problem here.. + return; } - else if (res <= 0) - { - yaz_log (m_log, "PDU_Assoc::Connection closed by peer"); - close(); - if (m_PDU_Observer) - m_PDU_Observer->failNotify(); // problem here.. - return; - } - // lock it, so we know if recv_PDU deletes it. - int destroyed = 0; - m_destroyed = &destroyed; + // lock it, so we know if recv_PDU deletes it. + int destroyed = 0; + m_destroyed = &destroyed; - if (!m_PDU_Observer) - return; + if (!m_PDU_Observer) + return; #if 0 - PDU_Queue **pq = &m_queue_in; - while (*pq) - pq = &(*pq)->m_next; - - *pq = new PDU_Queue(m_input_buf, res); + PDU_Queue **pq = &m_queue_in; + while (*pq) + pq = &(*pq)->m_next; + + *pq = new PDU_Queue(m_input_buf, res); #else - m_PDU_Observer->recv_PDU(m_input_buf, res); + m_PDU_Observer->recv_PDU(m_input_buf, res); #endif - if (destroyed) // it really was destroyed, return now. - return; + if (destroyed) // it really was destroyed, return now. + return; m_destroyed = 0; - } while (m_cs && cs_more (m_cs)); - if (m_cs && m_state == Ready) + } while (m_cs && cs_more (m_cs)); + if (m_cs && m_state == Ready) { - yaz_log(m_log, "maskObserver 5"); - m_socketObservable->maskObserver(this, - SOCKET_OBSERVE_EXCEPT| - SOCKET_OBSERVE_READ); - } - } - break; + yaz_log(m_log, "maskObserver 5"); + m_socketObservable->maskObserver(this, + SOCKET_OBSERVE_EXCEPT| + SOCKET_OBSERVE_READ); + } + } + break; case Closed: - yaz_log (m_log, "CLOSING state=%d event was %d", m_state, event); - close(); - m_PDU_Observer->failNotify(); - break; + yaz_log (m_log, "CLOSING state=%d event was %d", m_state, event); + close(); + m_PDU_Observer->failNotify(); + break; default: - yaz_log (m_log, "Unknown state=%d event was %d", m_state, event); - close(); - m_PDU_Observer->failNotify(); + yaz_log (m_log, "Unknown state=%d event was %d", m_state, event); + close(); + m_PDU_Observer->failNotify(); } } @@ -248,21 +248,21 @@ void PDU_Assoc::close() { PDU_Assoc *ch; for (ch = m_children; ch; ch = ch->m_next) - ch->close(); + ch->close(); m_socketObservable->deleteObserver(this); m_state = Closed; if (m_cs) { - yaz_log (m_log, "PDU_Assoc::close fd=%d", cs_fileno(m_cs)); - cs_close (m_cs); + yaz_log (m_log, "PDU_Assoc::close fd=%d", cs_fileno(m_cs)); + cs_close (m_cs); } m_cs = 0; while (m_queue_out) { - PDU_Queue *q_this = m_queue_out; - m_queue_out = m_queue_out->m_next; - delete q_this; + PDU_Queue *q_this = m_queue_out; + m_queue_out = m_queue_out->m_next; + delete q_this; } xfree (m_input_buf); m_input_buf = 0; @@ -274,28 +274,28 @@ void PDU_Assoc::destroy() close(); if (m_destroyed) - *m_destroyed = 1; + *m_destroyed = 1; PDU_Assoc **c; // delete from parent's child list (if any) if (m_parent) { - c = &m_parent->m_children; - while (*c != this) - { - assert (*c); - c = &(*c)->m_next; - } - *c = (*c)->m_next; + c = &m_parent->m_children; + while (*c != this) + { + assert (*c); + c = &(*c)->m_next; + } + *c = (*c)->m_next; } // delete all children ... c = &m_children; while (*c) { - PDU_Assoc *here = *c; - *c = (*c)->m_next; - here->m_parent = 0; - delete here; + PDU_Assoc *here = *c; + *c = (*c)->m_next; + here->m_parent = 0; + delete here; } yaz_log (m_log, "PDU_Assoc::destroy this=%p", this); } @@ -320,17 +320,17 @@ int PDU_Assoc::flush_PDU() if (m_state != Ready && m_state != Writing) { yaz_log (m_log, "YAZ_PDU_Assoc::flush_PDU, not ready"); - return 1; + return 1; } PDU_Queue *q = m_queue_out; if (!q) { - m_state = Ready; - yaz_log (m_log, "YAZ_PDU_Assoc::flush_PDU queue empty"); - yaz_log(m_log, "maskObserver 6"); - m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ| - SOCKET_OBSERVE_WRITE| - SOCKET_OBSERVE_EXCEPT); + m_state = Ready; + yaz_log (m_log, "YAZ_PDU_Assoc::flush_PDU queue empty"); + yaz_log(m_log, "maskObserver 6"); + m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ| + SOCKET_OBSERVE_WRITE| + SOCKET_OBSERVE_EXCEPT); return 0; } r = cs_put (m_cs, q->m_buf, q->m_len); @@ -338,7 +338,7 @@ int PDU_Assoc::flush_PDU() { yaz_log (m_log, "PDU_Assoc::flush_PDU cs_put failed"); close(); - m_PDU_Observer->failNotify(); + m_PDU_Observer->failNotify(); return r; } if (r == 1) @@ -350,11 +350,11 @@ int PDU_Assoc::flush_PDU() if (m_cs->io_pending & CS_WANT_READ) mask |= SOCKET_OBSERVE_READ; - mask |= SOCKET_OBSERVE_WRITE; - yaz_log(m_log, "maskObserver 7"); - m_socketObservable->maskObserver(this, mask); + mask |= SOCKET_OBSERVE_WRITE; + yaz_log(m_log, "maskObserver 7"); + m_socketObservable->maskObserver(this, mask); yaz_log (m_log, "PDU_Assoc::flush_PDU cs_put %d bytes fd=%d (inc)", - q->m_len, cs_fileno(m_cs)); + q->m_len, cs_fileno(m_cs)); return r; } yaz_log (m_log, "PDU_Assoc::flush_PDU cs_put %d bytes", q->m_len); @@ -365,9 +365,9 @@ int PDU_Assoc::flush_PDU() if (!m_queue_out) { m_state = Ready; - yaz_log(m_log, "maskObserver 8"); - m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ| - SOCKET_OBSERVE_EXCEPT); + yaz_log(m_log, "maskObserver 8"); + m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ| + SOCKET_OBSERVE_EXCEPT); } return r; } @@ -380,7 +380,7 @@ int PDU_Assoc::send_PDU(const char *buf, int len) if (!m_cs) { - yaz_log (m_log, "PDU_Assoc::send_PDU failed, m_cs == 0"); + yaz_log (m_log, "PDU_Assoc::send_PDU failed, m_cs == 0"); return -1; } while (*pq) @@ -389,8 +389,8 @@ int PDU_Assoc::send_PDU(const char *buf, int len) if (is_idle) return flush_PDU (); else - yaz_log (m_log, "PDU_Assoc::cannot send_PDU fd=%d", - cs_fileno(m_cs)); + yaz_log (m_log, "PDU_Assoc::cannot send_PDU fd=%d", + cs_fileno(m_cs)); return 0; } @@ -414,7 +414,7 @@ int PDU_Assoc::listen(IPDU_Observer *observer, const char *addr) m_socketObservable->addObserver(cs_fileno(m_cs), this); yaz_log(m_log, "maskObserver 9"); m_socketObservable->maskObserver(this, SOCKET_OBSERVE_READ| - SOCKET_OBSERVE_EXCEPT); + SOCKET_OBSERVE_EXCEPT); yaz_log (m_log, "PDU_Assoc::listen ok fd=%d", cs_fileno(m_cs)); m_state = Listen; return 0; @@ -435,39 +435,39 @@ int PDU_Assoc::connect(IPDU_Observer *observer, const char *addr) void *ap; m_cs = comstack(addr, &ap); if (!m_cs) - return -1; + return -1; int res = cs_connect (m_cs, ap); yaz_log (m_log, "PDU_Assoc::connect fd=%d res=%d", cs_fileno(m_cs), - res); + res); m_socketObservable->addObserver(cs_fileno(m_cs), this); if (res == 0) { // Connect complete - m_state = Connecting; - unsigned mask = SOCKET_OBSERVE_EXCEPT; - mask |= SOCKET_OBSERVE_WRITE; - mask |= SOCKET_OBSERVE_READ; - yaz_log(m_log, "maskObserver 11"); - m_socketObservable->maskObserver(this, mask); + m_state = Connecting; + unsigned mask = SOCKET_OBSERVE_EXCEPT; + mask |= SOCKET_OBSERVE_WRITE; + mask |= SOCKET_OBSERVE_READ; + yaz_log(m_log, "maskObserver 11"); + m_socketObservable->maskObserver(this, mask); } else if (res > 0) { // Connect pending - m_state = Connecting; - unsigned mask = SOCKET_OBSERVE_EXCEPT; - if (m_cs->io_pending & CS_WANT_WRITE) - mask |= SOCKET_OBSERVE_WRITE; - if (m_cs->io_pending & CS_WANT_READ) - mask |= SOCKET_OBSERVE_READ; - yaz_log(m_log, "maskObserver 11"); - m_socketObservable->maskObserver(this, mask); + m_state = Connecting; + unsigned mask = SOCKET_OBSERVE_EXCEPT; + if (m_cs->io_pending & CS_WANT_WRITE) + mask |= SOCKET_OBSERVE_WRITE; + if (m_cs->io_pending & CS_WANT_READ) + mask |= SOCKET_OBSERVE_READ; + yaz_log(m_log, "maskObserver 11"); + m_socketObservable->maskObserver(this, mask); } else { // Connect failed immediately - // Since m_state is Closed we can distinguish this case from + // Since m_state is Closed we can distinguish this case from // normal connect in socketNotify handler - yaz_log(m_log, "maskObserver 12"); - m_socketObservable->maskObserver(this, SOCKET_OBSERVE_WRITE| - SOCKET_OBSERVE_EXCEPT); + yaz_log(m_log, "maskObserver 12"); + m_socketObservable->maskObserver(this, SOCKET_OBSERVE_WRITE| + SOCKET_OBSERVE_EXCEPT); } return 0; } @@ -476,7 +476,7 @@ int PDU_Assoc::connect(IPDU_Observer *observer, const char *addr) void PDU_Assoc::childNotify(COMSTACK cs) { PDU_Assoc *new_observable = - new PDU_Assoc (m_socketObservable, cs); + new PDU_Assoc (m_socketObservable, cs); new_observable->m_next = m_children; m_children = new_observable; @@ -484,12 +484,20 @@ void PDU_Assoc::childNotify(COMSTACK cs) // Clone PDU Observer new_observable->m_PDU_Observer = m_PDU_Observer->sessionNotify - (new_observable, cs_fileno(cs)); + (new_observable, cs_fileno(cs)); } const char*PDU_Assoc::getpeername() { if (!m_cs) - return 0; + return 0; return cs_addrstr(m_cs); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-socket-manager.cpp b/src/yaz-socket-manager.cpp index 0d4fc30..bfee990 100644 --- a/src/yaz-socket-manager.cpp +++ b/src/yaz-socket-manager.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: yaz-socket-manager.cpp,v 1.34 2005-06-21 17:36:46 adam Exp $ + * $Id: yaz-socket-manager.cpp,v 1.35 2005-06-25 15:53:19 adam Exp $ */ #ifdef WIN32 #include @@ -33,8 +33,8 @@ SocketManager::SocketEntry **SocketManager::lookupObserver( SocketEntry **se; for (se = &m_observers; *se; se = &(*se)->next) - if ((*se)->observer == observer) - break; + if ((*se)->observer == observer) + break; return se; } @@ -45,10 +45,10 @@ void SocketManager::addObserver(int fd, ISocketObserver *observer) se = *lookupObserver(observer); if (!se) { - se = new SocketEntry; - se->next= m_observers; - m_observers = se; - se->observer = observer; + se = new SocketEntry; + se->next= m_observers; + m_observers = se; + se->observer = observer; } se->fd = fd; se->mask = 0; @@ -61,10 +61,10 @@ void SocketManager::deleteObserver(ISocketObserver *observer) SocketEntry **se = lookupObserver(observer); if (*se) { - removeEvent (observer); - SocketEntry *se_tmp = *se; - *se = (*se)->next; - delete se_tmp; + removeEvent (observer); + SocketEntry *se_tmp = *se; + *se = (*se)->next; + delete se_tmp; } } @@ -74,9 +74,9 @@ void SocketManager::deleteObservers() while (se) { - SocketEntry *se_next = se->next; - delete se; - se = se_next; + SocketEntry *se_next = se->next; + delete se; + se = se_next; } m_observers = 0; } @@ -86,23 +86,23 @@ void SocketManager::maskObserver(ISocketObserver *observer, int mask) SocketEntry *se; yaz_log(m_log, "obs=%p read=%d write=%d except=%d", observer, - mask & SOCKET_OBSERVE_READ, - mask & SOCKET_OBSERVE_WRITE, - mask & SOCKET_OBSERVE_EXCEPT); + mask & SOCKET_OBSERVE_READ, + mask & SOCKET_OBSERVE_WRITE, + mask & SOCKET_OBSERVE_EXCEPT); se = *lookupObserver(observer); if (se) - se->mask = mask; + se->mask = mask; } void SocketManager::timeoutObserver(ISocketObserver *observer, - int timeout) + int timeout) { SocketEntry *se; se = *lookupObserver(observer); if (se) - se->timeout = timeout; + se->timeout = timeout; } int SocketManager::processEvent() @@ -113,9 +113,9 @@ int SocketManager::processEvent() yaz_log (m_log, "SocketManager::processEvent manager=%p", this); if (event) { - event->observer->socketNotify(event->event); - delete event; - return 1; + event->observer->socketNotify(event->event); + delete event; + return 1; } fd_set in, out, except; @@ -130,52 +130,52 @@ int SocketManager::processEvent() time_t now = time(0); for (p = m_observers; p; p = p->next) { - int fd = p->fd; - if (p->mask) - no++; - if (p->mask & SOCKET_OBSERVE_READ) + int fd = p->fd; + if (p->mask) + no++; + if (p->mask & SOCKET_OBSERVE_READ) { yaz_log (m_log, "SocketManager::select fd=%d read", fd); - FD_SET(fd, &in); + FD_SET(fd, &in); } - if (p->mask & SOCKET_OBSERVE_WRITE) + if (p->mask & SOCKET_OBSERVE_WRITE) { yaz_log (m_log, "SocketManager::select fd=%d write", fd); - FD_SET(fd, &out); + FD_SET(fd, &out); } - if (p->mask & SOCKET_OBSERVE_EXCEPT) + if (p->mask & SOCKET_OBSERVE_EXCEPT) { yaz_log (m_log, "SocketManager::select fd=%d except", fd); - FD_SET(fd, &except); + FD_SET(fd, &except); } - if (fd > max) - max = fd; - if (p->timeout > 0 || - (p->timeout == 0 && (p->mask & SOCKET_OBSERVE_WRITE) == 0)) - { - int timeout_this; - timeout_this = p->timeout; - if (p->last_activity) - timeout_this -= now - p->last_activity; - else - p->last_activity = now; - if (timeout_this < 0 || timeout_this > 2147483646) - timeout_this = 0; - if (timeout == -1 || timeout_this < timeout) - timeout = timeout_this; + if (fd > max) + max = fd; + if (p->timeout > 0 || + (p->timeout == 0 && (p->mask & SOCKET_OBSERVE_WRITE) == 0)) + { + int timeout_this; + timeout_this = p->timeout; + if (p->last_activity) + timeout_this -= now - p->last_activity; + else + p->last_activity = now; + if (timeout_this < 0 || timeout_this > 2147483646) + timeout_this = 0; + if (timeout == -1 || timeout_this < timeout) + timeout = timeout_this; p->timeout_this = timeout_this; yaz_log (m_log, "SocketManager::select timeout_this=%d", p->timeout_this); - } - else - p->timeout_this = -1; + } + else + p->timeout_this = -1; } if (!no) { - yaz_log (m_log, "no pending events return 0"); - if (!m_observers) - yaz_log (m_log, "no observers"); - return 0; + yaz_log (m_log, "no pending events return 0"); + if (!m_observers) + yaz_log (m_log, "no observers"); + return 0; } struct timeval to; @@ -186,57 +186,57 @@ int SocketManager::processEvent() no, timeout); int pass = 0; while ((res = select(max + 1, &in, &out, &except, - timeout== -1 ? 0 : &to)) < 0) - if (errno != EINTR) - { - yaz_log(YLOG_ERRNO|YLOG_WARN, "select"); - yaz_log(YLOG_WARN, "errno=%d max=%d timeout=%d", - errno, max, timeout); - if (++pass > 10) - return -1; - } + timeout== -1 ? 0 : &to)) < 0) + if (errno != EINTR) + { + yaz_log(YLOG_ERRNO|YLOG_WARN, "select"); + yaz_log(YLOG_WARN, "errno=%d max=%d timeout=%d", + errno, max, timeout); + if (++pass > 10) + return -1; + } yaz_log(m_log, "select returned res=%d", res); now = time(0); for (p = m_observers; p; p = p->next) { - int fd = p->fd; - int mask = 0; - if (FD_ISSET(fd, &in)) - mask |= SOCKET_OBSERVE_READ; + int fd = p->fd; + int mask = 0; + if (FD_ISSET(fd, &in)) + mask |= SOCKET_OBSERVE_READ; - if (FD_ISSET(fd, &out)) - mask |= SOCKET_OBSERVE_WRITE; + if (FD_ISSET(fd, &out)) + mask |= SOCKET_OBSERVE_WRITE; - if (FD_ISSET(fd, &except)) - mask |= SOCKET_OBSERVE_EXCEPT; - - if (mask) - { - SocketEvent *event = new SocketEvent; - p->last_activity = now; - event->observer = p->observer; - event->event = mask; - putEvent (event); + if (FD_ISSET(fd, &except)) + mask |= SOCKET_OBSERVE_EXCEPT; + + if (mask) + { + SocketEvent *event = new SocketEvent; + p->last_activity = now; + event->observer = p->observer; + event->event = mask; + putEvent (event); - yaz_log (m_log, "putEvent I/O mask=%d", mask); - } - else if (res == 0 && p->timeout_this == timeout) - { - SocketEvent *event = new SocketEvent; + yaz_log (m_log, "putEvent I/O mask=%d", mask); + } + else if (res == 0 && p->timeout_this == timeout) + { + SocketEvent *event = new SocketEvent; assert (p->last_activity); - yaz_log (m_log, "putEvent timeout fd=%d, now = %ld last_activity=%ld timeout=%d", + yaz_log (m_log, "putEvent timeout fd=%d, now = %ld last_activity=%ld timeout=%d", p->fd, now, p->last_activity, p->timeout); - p->last_activity = now; - event->observer = p->observer; - event->event = SOCKET_OBSERVE_TIMEOUT; - putEvent (event); - } + p->last_activity = now; + event->observer = p->observer; + event->event = SOCKET_OBSERVE_TIMEOUT; + putEvent (event); + } } if ((event = getEvent())) { - event->observer->socketNotify(event->event); - delete event; - return 1; + event->observer->socketNotify(event->event); + delete event; + return 1; } yaz_log(YLOG_WARN, "unhandled event in processEvent res=%d", res); return 1; @@ -251,13 +251,13 @@ void SocketManager::putEvent(SocketEvent *event) // put in back of queue if (m_queue_back) { - m_queue_back->prev = event; - assert (m_queue_front); + m_queue_back->prev = event; + assert (m_queue_front); } else { - assert (!m_queue_front); - m_queue_front = event; + assert (!m_queue_front); + m_queue_front = event; } event->next = m_queue_back; event->prev = 0; @@ -269,16 +269,16 @@ SocketManager::SocketEvent *SocketManager::getEvent() // get from front of queue SocketEvent *event = m_queue_front; if (!event) - return 0; + return 0; assert (m_queue_back); m_queue_front = event->prev; if (m_queue_front) { - assert (m_queue_back); - m_queue_front->next = 0; + assert (m_queue_back); + m_queue_front->next = 0; } else - m_queue_back = 0; + m_queue_back = 0; return event; } @@ -287,20 +287,20 @@ void SocketManager::removeEvent(ISocketObserver *observer) SocketEvent *ev = m_queue_back; while (ev) { - SocketEvent *ev_next = ev->next; - if (observer == ev->observer) - { - if (ev->prev) - ev->prev->next = ev->next; - else - m_queue_back = ev->next; - if (ev->next) - ev->next->prev = ev->prev; - else - m_queue_front = ev->prev; - delete ev; - } - ev = ev_next; + SocketEvent *ev_next = ev->next; + if (observer == ev->observer) + { + if (ev->prev) + ev->prev->next = ev->next; + else + m_queue_back = ev->next; + if (ev->next) + ev->next->prev = ev->prev; + else + m_queue_front = ev->prev; + delete ev; + } + ev = ev_next; } } @@ -316,3 +316,11 @@ SocketManager::~SocketManager() { deleteObservers(); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-assoc.cpp b/src/yaz-z-assoc.cpp index 6e75c30..3764293 100644 --- a/src/yaz-z-assoc.cpp +++ b/src/yaz-z-assoc.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-assoc.cpp,v 1.37 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-z-assoc.cpp,v 1.38 2005-06-25 15:53:19 adam Exp $ */ #include @@ -41,23 +41,23 @@ void Z_Assoc::set_APDU_log(const char *fname) { if (m_APDU_file && m_APDU_file != stderr) { - fclose (m_APDU_file); - m_APDU_file = 0; + fclose (m_APDU_file); + m_APDU_file = 0; } delete [] m_APDU_fname; m_APDU_fname = 0; if (fname) { - m_APDU_fname = new char[strlen(fname)+1]; - strcpy (m_APDU_fname, fname); - if (!strcmp(fname, "-")) - m_APDU_file = stderr; - else if (*fname == '\0') - m_APDU_file = 0; - else - m_APDU_file = fopen (fname, "a"); - odr_setprint(m_odr_print, m_APDU_file); + m_APDU_fname = new char[strlen(fname)+1]; + strcpy (m_APDU_fname, fname); + if (!strcmp(fname, "-")) + m_APDU_file = stderr; + else if (*fname == '\0') + m_APDU_file = 0; + else + m_APDU_file = fopen (fname, "a"); + odr_setprint(m_odr_print, m_APDU_file); } } @@ -90,12 +90,12 @@ void Z_Assoc::recv_PDU(const char *buf, int len) Z_GDU *apdu = decode_GDU (buf, len); if (apdu) { - recv_GDU (apdu, len); + recv_GDU (apdu, len); } else { - close(); - failNotify(); + close(); + failNotify(); } } @@ -104,11 +104,11 @@ Z_APDU *Z_Assoc::create_Z_PDU(int type) Z_APDU *apdu = zget_APDU(m_odr_out, type); if (apdu->which == Z_APDU_initRequest) { - Z_InitRequest * p = apdu->u.initRequest; - char *newName = (char*) odr_malloc(m_odr_out, 50); - strcpy (newName, p->implementationName); - strcat (newName, " YAZ++"); - p->implementationName = newName; + Z_InitRequest * p = apdu->u.initRequest; + char *newName = (char*) odr_malloc(m_odr_out, 50); + strcpy (newName, p->implementationName); + strcat (newName, " YAZ++"); + p->implementationName = newName; } return apdu; } @@ -118,51 +118,51 @@ Z_ReferenceId **Z_Assoc::get_referenceIdP(Z_APDU *apdu) switch (apdu->which) { case Z_APDU_initRequest: - return &apdu->u.initRequest->referenceId; + return &apdu->u.initRequest->referenceId; case Z_APDU_initResponse: - return &apdu->u.initResponse->referenceId; + return &apdu->u.initResponse->referenceId; case Z_APDU_searchRequest: - return &apdu->u.searchRequest->referenceId; + return &apdu->u.searchRequest->referenceId; case Z_APDU_searchResponse: - return &apdu->u.searchResponse->referenceId; + return &apdu->u.searchResponse->referenceId; case Z_APDU_presentRequest: - return &apdu->u.presentRequest->referenceId; + return &apdu->u.presentRequest->referenceId; case Z_APDU_presentResponse: - return &apdu->u.presentResponse->referenceId; + return &apdu->u.presentResponse->referenceId; case Z_APDU_deleteResultSetRequest: - return &apdu->u.deleteResultSetRequest->referenceId; + return &apdu->u.deleteResultSetRequest->referenceId; case Z_APDU_deleteResultSetResponse: - return &apdu->u.deleteResultSetResponse->referenceId; + return &apdu->u.deleteResultSetResponse->referenceId; case Z_APDU_accessControlRequest: - return &apdu->u.accessControlRequest->referenceId; + return &apdu->u.accessControlRequest->referenceId; case Z_APDU_accessControlResponse: - return &apdu->u.accessControlResponse->referenceId; + return &apdu->u.accessControlResponse->referenceId; case Z_APDU_resourceControlRequest: - return &apdu->u.resourceControlRequest->referenceId; + return &apdu->u.resourceControlRequest->referenceId; case Z_APDU_resourceControlResponse: - return &apdu->u.resourceControlResponse->referenceId; + return &apdu->u.resourceControlResponse->referenceId; case Z_APDU_triggerResourceControlRequest: - return &apdu->u.triggerResourceControlRequest->referenceId; + return &apdu->u.triggerResourceControlRequest->referenceId; case Z_APDU_resourceReportRequest: - return &apdu->u.resourceReportRequest->referenceId; + return &apdu->u.resourceReportRequest->referenceId; case Z_APDU_resourceReportResponse: - return &apdu->u.resourceReportResponse->referenceId; + return &apdu->u.resourceReportResponse->referenceId; case Z_APDU_scanRequest: - return &apdu->u.scanRequest->referenceId; + return &apdu->u.scanRequest->referenceId; case Z_APDU_scanResponse: - return &apdu->u.scanResponse->referenceId; + return &apdu->u.scanResponse->referenceId; case Z_APDU_sortRequest: - return &apdu->u.sortRequest->referenceId; + return &apdu->u.sortRequest->referenceId; case Z_APDU_sortResponse: - return &apdu->u.sortResponse->referenceId; + return &apdu->u.sortResponse->referenceId; case Z_APDU_segmentRequest: - return &apdu->u.segmentRequest->referenceId; + return &apdu->u.segmentRequest->referenceId; case Z_APDU_extendedServicesRequest: - return &apdu->u.extendedServicesRequest->referenceId; + return &apdu->u.extendedServicesRequest->referenceId; case Z_APDU_extendedServicesResponse: - return &apdu->u.extendedServicesResponse->referenceId; + return &apdu->u.extendedServicesResponse->referenceId; case Z_APDU_close: - return &apdu->u.close->referenceId; + return &apdu->u.close->referenceId; } return 0; } @@ -173,13 +173,13 @@ void Z_Assoc::transfer_referenceId(Z_APDU *from, Z_APDU *to) Z_ReferenceId **id_to = get_referenceIdP(to); if (id_from && *id_from && id_to) { - *id_to = (Z_ReferenceId*) odr_malloc (m_odr_out, sizeof(**id_to)); - (*id_to)->size = (*id_to)->len = (*id_from)->len; - (*id_to)->buf = (unsigned char*) odr_malloc (m_odr_out, (*id_to)->len); - memcpy ((*id_to)->buf, (*id_from)->buf, (*id_to)->len); + *id_to = (Z_ReferenceId*) odr_malloc (m_odr_out, sizeof(**id_to)); + (*id_to)->size = (*id_to)->len = (*id_from)->len; + (*id_to)->buf = (unsigned char*) odr_malloc (m_odr_out, (*id_to)->len); + memcpy ((*id_to)->buf, (*id_from)->buf, (*id_to)->len); } else if (id_to) - *id_to = 0; + *id_to = 0; } int Z_Assoc::send_Z_PDU(Z_APDU *apdu, int *plen) @@ -196,9 +196,9 @@ int Z_Assoc::send_GDU(Z_GDU *apdu, int *plen) int len; if (encode_GDU(apdu, &buf, &len) > 0) { - if (plen) - *plen = len; - return m_PDU_Observable->send_PDU(buf, len); + if (plen) + *plen = len; + return m_PDU_Observable->send_PDU(buf, len); } return -1; } @@ -212,31 +212,31 @@ Z_GDU *Z_Assoc::decode_GDU(const char *buf, int len) if (!z_GDU(m_odr_in, &apdu, 0, 0)) { - const char *element = odr_getelement(m_odr_in); + const char *element = odr_getelement(m_odr_in); yaz_log(YLOG_LOG, "PDU decode failed '%s' near byte %d. Element %s", - odr_errmsg(odr_geterror(m_odr_in)), - odr_offset(m_odr_in), - element ? element : "unknown"); + odr_errmsg(odr_geterror(m_odr_in)), + odr_offset(m_odr_in), + element ? element : "unknown"); yaz_log(YLOG_LOG, "PDU dump:"); odr_dumpBER(yaz_log_file(), buf, len); return 0; } else { - if (m_APDU_yazlog) - { // use YAZ log FILE - FILE *save = m_APDU_file; - - odr_setprint(m_odr_print, yaz_log_file()); - z_GDU(m_odr_print, &apdu, 0, "decode"); - m_APDU_file = save; - odr_setprint(m_odr_print, save); - } - if (m_APDU_file) + if (m_APDU_yazlog) + { // use YAZ log FILE + FILE *save = m_APDU_file; + + odr_setprint(m_odr_print, yaz_log_file()); + z_GDU(m_odr_print, &apdu, 0, "decode"); + m_APDU_file = save; + odr_setprint(m_odr_print, save); + } + if (m_APDU_file) { - z_GDU(m_odr_print, &apdu, 0, "decode"); - fflush(m_APDU_file); - } + z_GDU(m_odr_print, &apdu, 0, "decode"); + fflush(m_APDU_file); + } return apdu; } } @@ -247,27 +247,27 @@ int Z_Assoc::encode_GDU(Z_GDU *apdu, char **buf, int *len) int r = z_GDU(m_odr_out, &apdu, 0, 0); if (!r) // decoding failed. Get the failed element - element = odr_getelement(m_odr_out); + element = odr_getelement(m_odr_out); if (m_APDU_yazlog || !r) { - if (!r) - yaz_log (YLOG_LOG, "PDU encode failed. Element %s", - element ? element : "unknown"); - FILE *save = m_APDU_file; - FILE *yazf = yaz_log_file(); - odr_setprint(m_odr_print, yazf); // use YAZ log FILE - z_GDU(m_odr_print, &apdu, 0, "encode"); - m_APDU_file = save; - odr_setprint(m_odr_print, save); + if (!r) + yaz_log (YLOG_LOG, "PDU encode failed. Element %s", + element ? element : "unknown"); + FILE *save = m_APDU_file; + FILE *yazf = yaz_log_file(); + odr_setprint(m_odr_print, yazf); // use YAZ log FILE + z_GDU(m_odr_print, &apdu, 0, "encode"); + m_APDU_file = save; + odr_setprint(m_odr_print, save); } if (m_APDU_file) { - if (!r) - fprintf (m_APDU_file, "PDU encode failed. Element %s", - element ? element : "unknown"); - z_GDU(m_odr_print, &apdu, 0, "encode"); - fflush(m_APDU_file); + if (!r) + fprintf (m_APDU_file, "PDU encode failed. Element %s", + element ? element : "unknown"); + z_GDU(m_odr_print, &apdu, 0, "encode"); + fflush(m_APDU_file); } if (!r) // encoding failed return -1; @@ -326,20 +326,20 @@ void Z_Assoc::get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip) switch (apdu->which) { case Z_APDU_initRequest: - *oip = &apdu->u.initRequest->otherInfo; - break; + *oip = &apdu->u.initRequest->otherInfo; + break; case Z_APDU_searchRequest: - *oip = &apdu->u.searchRequest->otherInfo; - break; + *oip = &apdu->u.searchRequest->otherInfo; + break; case Z_APDU_presentRequest: - *oip = &apdu->u.presentRequest->otherInfo; - break; + *oip = &apdu->u.presentRequest->otherInfo; + break; case Z_APDU_sortRequest: - *oip = &apdu->u.sortRequest->otherInfo; - break; + *oip = &apdu->u.sortRequest->otherInfo; + break; case Z_APDU_scanRequest: - *oip = &apdu->u.scanRequest->otherInfo; - break; + *oip = &apdu->u.scanRequest->otherInfo; + break; case Z_APDU_extendedServicesRequest: *oip = &apdu->u.extendedServicesRequest->otherInfo; break; @@ -347,20 +347,20 @@ void Z_Assoc::get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip) *oip = &apdu->u.deleteResultSetRequest->otherInfo; break; case Z_APDU_initResponse: - *oip = &apdu->u.initResponse->otherInfo; - break; + *oip = &apdu->u.initResponse->otherInfo; + break; case Z_APDU_searchResponse: - *oip = &apdu->u.searchResponse->otherInfo; - break; + *oip = &apdu->u.searchResponse->otherInfo; + break; case Z_APDU_presentResponse: - *oip = &apdu->u.presentResponse->otherInfo; - break; + *oip = &apdu->u.presentResponse->otherInfo; + break; case Z_APDU_sortResponse: - *oip = &apdu->u.sortResponse->otherInfo; - break; + *oip = &apdu->u.sortResponse->otherInfo; + break; case Z_APDU_scanResponse: - *oip = &apdu->u.scanResponse->otherInfo; - break; + *oip = &apdu->u.scanResponse->otherInfo; + break; case Z_APDU_extendedServicesResponse: *oip = &apdu->u.extendedServicesResponse->otherInfo; break; @@ -368,8 +368,8 @@ void Z_Assoc::get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip) *oip = &apdu->u.deleteResultSetResponse->otherInfo; break; default: - *oip = 0; - break; + *oip = 0; + break; } } @@ -381,7 +381,7 @@ void Z_Assoc::set_otherInformationString ( Z_OtherInformation **otherInformation; get_otherInfoAPDU(apdu, &otherInformation); if (!otherInformation) - return; + return; set_otherInformationString(otherInformation, oidval, categoryValue, str); } @@ -396,7 +396,7 @@ void Z_Assoc::set_otherInformationString ( ent.oclass = CLASS_USERINFO; ent.value = (oid_value) oidval; if (!oid_ent_to_oid (&ent, oid)) - return ; + return ; set_otherInformationString(otherInformation, oid, categoryValue, str); } @@ -405,9 +405,9 @@ void Z_Assoc::set_otherInformationString ( int *oid, int categoryValue, const char *str) { Z_OtherInformationUnit *oi = - update_otherInformation(otherInformation, 1, oid, categoryValue, 0); + update_otherInformation(otherInformation, 1, oid, categoryValue, 0); if (!oi) - return; + return; oi->information.characterInfo = odr_strdup (odr_encode(), str); } @@ -416,8 +416,8 @@ Z_OtherInformationUnit *Z_Assoc::update_otherInformation ( int *oid, int categoryValue, int deleteFlag) { return yaz_oi_update (otherInformationP, - (createFlag ? odr_encode() : 0), - oid, categoryValue, deleteFlag); + (createFlag ? odr_encode() : 0), + oid, categoryValue, deleteFlag); } Z_ReferenceId* Z_Assoc::getRefID(char* str) @@ -433,3 +433,11 @@ Z_ReferenceId* Z_Assoc::getRefID(char* str) return id; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-cache.cpp b/src/yaz-z-cache.cpp index 366d19b..90c3c4b 100644 --- a/src/yaz-z-cache.cpp +++ b/src/yaz-z-cache.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-cache.cpp,v 1.13 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-z-cache.cpp,v 1.14 2005-06-25 15:53:19 adam Exp $ */ #include @@ -56,11 +56,11 @@ void RecordCache::copy_searchRequest(Z_SearchRequest *sr) int v = z_SearchRequest (encode, &sr, 1, 0); if (v) { - int len; - char *buf = odr_getbuf(encode, &len, 0); - odr_setbuf(decode, buf, len, 0); - z_SearchRequest(decode, &m_searchRequest, 1, 0); - nmem_transfer(m_mem, decode->mem); + int len; + char *buf = odr_getbuf(encode, &len, 0); + odr_setbuf(decode, buf, len, 0); + z_SearchRequest(decode, &m_searchRequest, 1, 0); + nmem_transfer(m_mem, decode->mem); } odr_destroy(encode); odr_destroy(decode); @@ -76,36 +76,36 @@ void RecordCache::copy_presentRequest(Z_PresentRequest *pr) int v = z_PresentRequest (encode, &pr, 1, 0); if (v) { - int len; - char *buf = odr_getbuf(encode, &len, 0); - odr_setbuf(decode, buf, len, 0); - z_PresentRequest(decode, &m_presentRequest, 1, 0); - nmem_transfer(m_mem, decode->mem); + int len; + char *buf = odr_getbuf(encode, &len, 0); + odr_setbuf(decode, buf, len, 0); + z_PresentRequest(decode, &m_presentRequest, 1, 0); + nmem_transfer(m_mem, decode->mem); } odr_destroy(encode); odr_destroy(decode); } void RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start, - int hits) + int hits) { if (nmem_total(m_mem) > m_max_size) - return; + return; // Build appropriate compspec for this response Z_RecordComposition *comp = 0; if (hits == -1 && m_presentRequest) - comp = m_presentRequest->recordComposition; + comp = m_presentRequest->recordComposition; else if (hits > 0 && m_searchRequest) { - Z_ElementSetNames *esn; - - if (hits <= *m_searchRequest->smallSetUpperBound) - esn = m_searchRequest->smallSetElementSetNames; - else - esn = m_searchRequest->mediumSetElementSetNames; - comp = (Z_RecordComposition *) nmem_malloc(m_mem, sizeof(*comp)); - comp->which = Z_RecordComp_simple; - comp->u.simple = esn; + Z_ElementSetNames *esn; + + if (hits <= *m_searchRequest->smallSetUpperBound) + esn = m_searchRequest->smallSetElementSetNames; + else + esn = m_searchRequest->mediumSetElementSetNames; + comp = (Z_RecordComposition *) nmem_malloc(m_mem, sizeof(*comp)); + comp->which = Z_RecordComp_simple; + comp->u.simple = esn; } // Z_NamePlusRecordList *npr to be owned by m_mem.. @@ -117,23 +117,23 @@ void RecordCache::add (ODR o, Z_NamePlusRecordList *npr, int start, int i; for (i = 0; inum_records; i++) { - RecordCache_Entry *entry = (RecordCache_Entry *) - nmem_malloc(m_mem, sizeof(*entry)); - entry->m_record = (Z_NamePlusRecord *) - nmem_malloc(m_mem, sizeof(*entry->m_record)); - entry->m_record->databaseName = npr->records[i]->databaseName; - entry->m_record->which = npr->records[i]->which; - entry->m_record->u.databaseRecord = npr->records[i]->u.databaseRecord; - entry->m_comp = comp; - entry->m_offset = i + start; - entry->m_next = m_entries; - m_entries = entry; + RecordCache_Entry *entry = (RecordCache_Entry *) + nmem_malloc(m_mem, sizeof(*entry)); + entry->m_record = (Z_NamePlusRecord *) + nmem_malloc(m_mem, sizeof(*entry->m_record)); + entry->m_record->databaseName = npr->records[i]->databaseName; + entry->m_record->which = npr->records[i]->which; + entry->m_record->u.databaseRecord = npr->records[i]->u.databaseRecord; + entry->m_comp = comp; + entry->m_offset = i + start; + entry->m_next = m_entries; + m_entries = entry; } } int RecordCache::match (RecordCache_Entry *entry, - Odr_oid *syntax, int offset, - Z_RecordComposition *comp) + Odr_oid *syntax, int offset, + Z_RecordComposition *comp) { // See if our compspec match... int match = 0; @@ -149,22 +149,22 @@ int RecordCache::match (RecordCache_Entry *entry, char *buf2 = odr_getbuf(o2, &len2, 0); if (buf1 && buf2 && len1 && len1 == len2 && !memcmp(buf1, buf2, len1)) - match = 1; + match = 1; else if (!buf1 && !buf2 && !len1 && !len2) - match = 1; + match = 1; odr_destroy(o1); odr_destroy(o2); if (!match) - return 0; + return 0; if (!syntax) - return 0; + return 0; // See if offset, OID match.. if (entry->m_offset == offset && - entry->m_record->which == Z_NamePlusRecord_databaseRecord && - !oid_oidcmp(entry->m_record->u.databaseRecord->direct_reference, - syntax)) - return 1; + entry->m_record->which == Z_NamePlusRecord_databaseRecord && + !oid_oidcmp(entry->m_record->u.databaseRecord->direct_reference, + syntax)) + return 1; #if 0 char mstr1[100]; oid_to_dotstring(entry->m_record->u.databaseRecord->direct_reference, mstr1); @@ -177,40 +177,48 @@ int RecordCache::match (RecordCache_Entry *entry, } int RecordCache::lookup (ODR o, Z_NamePlusRecordList **npr, - int start, int num, - Odr_oid *syntax, - Z_RecordComposition *comp) + int start, int num, + Odr_oid *syntax, + Z_RecordComposition *comp) { int i; yaz_log(YLOG_DEBUG, "cache lookup start=%d num=%d", start, num); for (i = 0; im_next) - if (match(entry, syntax, start+i, comp)) - break; - if (!entry) - return 0; + RecordCache_Entry *entry = m_entries; + for(; entry; entry = entry->m_next) + if (match(entry, syntax, start+i, comp)) + break; + if (!entry) + return 0; } *npr = (Z_NamePlusRecordList *) odr_malloc(o, sizeof(**npr)); (*npr)->num_records = num; (*npr)->records = (Z_NamePlusRecord **) - odr_malloc(o, num * sizeof(Z_NamePlusRecord *)); + odr_malloc(o, num * sizeof(Z_NamePlusRecord *)); for (i = 0; im_next) - if (match(entry, syntax, start+i, comp)) - break; - if (!entry) - return 0; - (*npr)->records[i] = (Z_NamePlusRecord *) - odr_malloc(o, sizeof(Z_NamePlusRecord)); - (*npr)->records[i]->databaseName = entry->m_record->databaseName; - (*npr)->records[i]->which = entry->m_record->which; - (*npr)->records[i]->u.databaseRecord = - entry->m_record->u.databaseRecord; + RecordCache_Entry *entry = m_entries; + for(; entry; entry = entry->m_next) + if (match(entry, syntax, start+i, comp)) + break; + if (!entry) + return 0; + (*npr)->records[i] = (Z_NamePlusRecord *) + odr_malloc(o, sizeof(Z_NamePlusRecord)); + (*npr)->records[i]->databaseName = entry->m_record->databaseName; + (*npr)->records[i]->which = entry->m_record->which; + (*npr)->records[i]->u.databaseRecord = + entry->m_record->u.databaseRecord; } return 1; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-databases.cpp b/src/yaz-z-databases.cpp index 66807d9..5e1112d 100644 --- a/src/yaz-z-databases.cpp +++ b/src/yaz-z-databases.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-databases.cpp,v 1.5 2005-06-02 06:40:21 adam Exp $ + * $Id: yaz-z-databases.cpp,v 1.6 2005-06-25 15:53:19 adam Exp $ */ #include @@ -65,3 +65,11 @@ int Yaz_Z_Databases::match (int num, const char **db) return 0; return 1; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-query.cpp b/src/yaz-z-query.cpp index 641934c..b852f9f 100644 --- a/src/yaz-z-query.cpp +++ b/src/yaz-z-query.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-query.cpp,v 1.16 2005-06-02 06:40:21 adam Exp $ + * $Id: yaz-z-query.cpp,v 1.17 2005-06-25 15:53:19 adam Exp $ */ #include @@ -25,9 +25,9 @@ int Yaz_Z_Query::set_rpn (const char *rpn) query->which = Z_Query_type_1; query->u.type_1 = p_query_rpn (odr_encode, PROTO_Z3950, rpn); if (!query->u.type_1) - return -1; + return -1; if (!z_Query (odr_encode, &query, 0, 0)) - return -1; + return -1; // z_Query(odr_print, &query, 0, 0); m_buf = odr_getbuf (odr_encode, &m_len, 0); return m_len; @@ -38,7 +38,7 @@ void Yaz_Z_Query::set_Z_Query(Z_Query *z_query) m_buf = 0; odr_reset (odr_encode); if (!z_Query (odr_encode, &z_query, 0, 0)) - return; + return; m_buf = odr_getbuf (odr_encode, &m_len, 0); } @@ -53,11 +53,11 @@ Z_Query *Yaz_Z_Query::get_Z_Query () { Z_Query *query; if (!m_buf) - return 0; + return 0; odr_reset(odr_decode); odr_setbuf(odr_decode, m_buf, m_len, 0); if (!z_Query(odr_decode, &query, 0, 0)) - return 0; + return 0; return query; } @@ -66,21 +66,21 @@ void Yaz_Z_Query::print(char *str, int len) Z_Query *query; *str = 0; if (!m_buf) - return; + return; odr_setbuf (odr_decode, m_buf, m_len, 0); if (!z_Query(odr_decode, &query, 0, 0)) - return; + return; WRBUF wbuf = zquery2pquery(query); if (wbuf) { - if (wrbuf_len(wbuf) > len-1) - { - memcpy(str, wrbuf_buf(wbuf), len-1); - str[len-1] = '\0'; - } - else - strcpy(str, wrbuf_buf(wbuf)); - wrbuf_free(wbuf,1); + if (wrbuf_len(wbuf) > len-1) + { + memcpy(str, wrbuf_buf(wbuf), len-1); + str[len-1] = '\0'; + } + else + strcpy(str, wrbuf_buf(wbuf)); + wrbuf_free(wbuf,1); } odr_reset(odr_decode); } @@ -88,22 +88,22 @@ void Yaz_Z_Query::print(char *str, int len) int Yaz_Z_Query::match(Yaz_Z_Query *other) { if (m_len != other->m_len) - return 0; + return 0; if (!m_buf || !other->m_buf) - return 0; + return 0; if (memcmp(m_buf, other->m_buf, m_len)) - return 0; + return 0; return 1; } void Yaz_Z_Query::oid2str(Odr_oid *o, WRBUF buf) { for (; *o >= 0; o++) { - char ibuf[16]; - sprintf(ibuf, "%d", *o); - wrbuf_puts(buf, ibuf); - if (o[1] > 0) - wrbuf_putc(buf, '.'); + char ibuf[16]; + sprintf(ibuf, "%d", *o); + wrbuf_puts(buf, ibuf); + if (o[1] > 0) + wrbuf_putc(buf, '.'); } } @@ -113,10 +113,10 @@ void Yaz_Z_Query::pr_term(WRBUF wbuf, char *buf, int len) wrbuf_putc(wbuf, '"'); for (i = 0; iwhich == Z_RPNStructure_simple) { - Z_Operand *o = s->u.simple; - - if (o->which == Z_Operand_APT) - { - Z_AttributesPlusTerm *at = s->u.simple->u.attributesPlusTerm; - if (at->attributes) { - int i; - for (i = 0; i < at->attributes->num_attributes; i++) { - wrbuf_puts(buf, "@attr "); - if (at->attributes->attributes[i]->attributeSet) { - oid2str(at->attributes->attributes[i]->attributeSet, buf); - wrbuf_putc(buf, ' '); - } - wrbuf_printf(buf, "%d=", *at->attributes->attributes[i]->attributeType); - wrbuf_printf(buf, "%d ", *at->attributes->attributes[i]->value.numeric); - } - } - if (at->term->which == Z_Term_general) - { - pr_term(buf, (char*) at->term->u.general->buf, - at->term->u.general->len); - } - else if (at->term->which == Z_Term_characterString) - { - wrbuf_puts(buf, "@term string "); - pr_term(buf, at->term->u.characterString, - strlen(at->term->u.characterString)); - - } - } - else if (o->which == Z_Operand_resultSetId) - { - wrbuf_printf(buf, "@set %s ", o->u.resultSetId); - } + Z_Operand *o = s->u.simple; + + if (o->which == Z_Operand_APT) + { + Z_AttributesPlusTerm *at = s->u.simple->u.attributesPlusTerm; + if (at->attributes) { + int i; + for (i = 0; i < at->attributes->num_attributes; i++) { + wrbuf_puts(buf, "@attr "); + if (at->attributes->attributes[i]->attributeSet) { + oid2str(at->attributes->attributes[i]->attributeSet, buf); + wrbuf_putc(buf, ' '); + } + wrbuf_printf(buf, "%d=", *at->attributes->attributes[i]->attributeType); + wrbuf_printf(buf, "%d ", *at->attributes->attributes[i]->value.numeric); + } + } + if (at->term->which == Z_Term_general) + { + pr_term(buf, (char*) at->term->u.general->buf, + at->term->u.general->len); + } + else if (at->term->which == Z_Term_characterString) + { + wrbuf_puts(buf, "@term string "); + pr_term(buf, at->term->u.characterString, + strlen(at->term->u.characterString)); + + } + } + else if (o->which == Z_Operand_resultSetId) + { + wrbuf_printf(buf, "@set %s ", o->u.resultSetId); + } } else if (s->which == Z_RPNStructure_complex) { - Z_Complex *c = s->u.complex; - - switch (c->roperator->which) { - case Z_Operator_and: wrbuf_puts(buf, "@and "); break; - case Z_Operator_or: wrbuf_puts(buf, "@or "); break; - case Z_Operator_and_not: wrbuf_puts(buf, "@not "); break; - case Z_Operator_prox: wrbuf_puts(buf, "@prox "); break; - default: wrbuf_puts(buf, "@unknown "); - } - if (!rpn2pquery(c->s1, buf)) - return 0; - if (!rpn2pquery(c->s2, buf)) - return 0; + Z_Complex *c = s->u.complex; + + switch (c->roperator->which) { + case Z_Operator_and: wrbuf_puts(buf, "@and "); break; + case Z_Operator_or: wrbuf_puts(buf, "@or "); break; + case Z_Operator_and_not: wrbuf_puts(buf, "@not "); break; + case Z_Operator_prox: wrbuf_puts(buf, "@prox "); break; + default: wrbuf_puts(buf, "@unknown "); + } + if (!rpn2pquery(c->s1, buf)) + return 0; + if (!rpn2pquery(c->s2, buf)) + return 0; } return 1; } @@ -182,15 +182,23 @@ int Yaz_Z_Query::rpn2pquery(Z_RPNStructure *s, WRBUF buf) WRBUF Yaz_Z_Query::zquery2pquery(Z_Query *q) { if (q->which != Z_Query_type_1 && q->which != Z_Query_type_101) - return 0; + return 0; WRBUF buf = wrbuf_alloc(); if (q->u.type_1->attributeSetId) { - /* Output attribute set ID */ - wrbuf_puts(buf, "@attrset "); - oid2str(q->u.type_1->attributeSetId, buf); - wrbuf_putc(buf, ' '); + /* Output attribute set ID */ + wrbuf_puts(buf, "@attrset "); + oid2str(q->u.type_1->attributeSetId, buf); + wrbuf_putc(buf, ' '); } return rpn2pquery(q->u.type_1->RPNStructure, buf) ? buf : 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-server-ill.cpp b/src/yaz-z-server-ill.cpp index aa6ca38..add09e9 100644 --- a/src/yaz-z-server-ill.cpp +++ b/src/yaz-z-server-ill.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2000-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-server-ill.cpp,v 1.13 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-z-server-ill.cpp,v 1.14 2005-06-25 15:53:19 adam Exp $ */ #include @@ -11,13 +11,13 @@ using namespace yazpp_1; int Yaz_Facility_ILL::init(Z_Server *s, Z_InitRequest *initRequest, - Z_InitResponse *initResponse) + 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); + ODR_MASK_SET(res, Z_Options_extendedServices); return 1; } @@ -26,7 +26,7 @@ int Yaz_Facility_ILL::recv(Z_Server *s, Z_APDU *apdu_request) Z_APDU *apdu_response; if (apdu_request->which != Z_APDU_extendedServicesRequest) - return 0; + return 0; Z_ExtendedServicesRequest *req = apdu_request->u.extendedServicesRequest; if (!req->taskSpecificParameters || req->taskSpecificParameters->which != Z_External_itemOrder) @@ -39,3 +39,11 @@ int Yaz_Facility_ILL::recv(Z_Server *s, Z_APDU *apdu_request) s->send_Z_PDU(apdu_response, 0); return 1; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-server-sr.cpp b/src/yaz-z-server-sr.cpp index fdddaa5..401b8e3 100644 --- a/src/yaz-z-server-sr.cpp +++ b/src/yaz-z-server-sr.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2000-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-server-sr.cpp,v 1.10 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-z-server-sr.cpp,v 1.11 2005-06-25 15:53:19 adam Exp $ * */ @@ -12,19 +12,19 @@ using namespace yazpp_1; Z_Records *Yaz_Facility_Retrieval::pack_records (Z_Server *s, - const char *resultSetName, - int start, int xnum, - Z_RecordComposition *comp, - int *next, int *pres, - int *format) + 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 (odr_encode(), sizeof(*records)); + (Z_Records *) odr_malloc (odr_encode(), sizeof(*records)); Z_NamePlusRecordList *reclist = - (Z_NamePlusRecordList *) odr_malloc (odr_encode(), sizeof(*reclist)); + (Z_NamePlusRecordList *) odr_malloc (odr_encode(), sizeof(*reclist)); Z_NamePlusRecord **list = - (Z_NamePlusRecord **) odr_malloc (odr_encode(), sizeof(*list) * toget); + (Z_NamePlusRecord **) odr_malloc (odr_encode(), sizeof(*list) * toget); records->which = Z_Records_DBOSD; records->u.databaseOrSurDiagnostics = reclist; @@ -35,79 +35,79 @@ Z_Records *Yaz_Facility_Retrieval::pack_records (Z_Server *s, for (recno = start; reclist->num_records < toget; recno++) { - Z_NamePlusRecord *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; - - int this_length = 0; - - sr_record (resultSetName, recno, format, comp, this_rec, records); - - if (records->which != Z_Records_DBOSD) - { - *pres = Z_PRES_FAILURE; - return records; - } - - if (this_rec->which == Z_NamePlusRecord_databaseRecord && - this_rec->u.databaseRecord == 0) - { // handler did not return a record.. - 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(odr_encode()) - dumped_records; - this_length = odr_total(odr_encode()) - total_length; - if (this_length + total_length > m_preferredMessageSize) - { - /* record is small enough, really */ - if (this_length <= m_preferredMessageSize) - { - *pres = Z_PRES_PARTIAL_2; - break; - } - if (this_length >= m_maximumRecordSize) - { /* too big entirely */ - reclist->records[reclist->num_records] = this_rec; - create_surrogateDiagnostics(odr_encode(), this_rec, - this_rec->databaseName, 17, 0); - reclist->num_records++; - *next = recno + 1; - dumped_records += this_length; - continue; - } - else /* record can only be fetched by itself */ - { - if (toget > 1) - { - yaz_log(YLOG_DEBUG, " Dropped it"); - reclist->records[reclist->num_records] = this_rec; - create_surrogateDiagnostics(odr_encode(), this_rec, - this_rec->databaseName, - 16, 0); - reclist->num_records++; - // *next = freq.last_in_set ? 0 : recno + 1; - *next = recno + 1; - dumped_records += this_length; - continue; - } - } - } - reclist->records[reclist->num_records] = this_rec; - reclist->num_records++; - *next = recno + 1; + Z_NamePlusRecord *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; + + int this_length = 0; + + sr_record (resultSetName, recno, format, comp, this_rec, records); + + if (records->which != Z_Records_DBOSD) + { + *pres = Z_PRES_FAILURE; + return records; + } + + if (this_rec->which == Z_NamePlusRecord_databaseRecord && + this_rec->u.databaseRecord == 0) + { // handler did not return a record.. + 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(odr_encode()) - dumped_records; + this_length = odr_total(odr_encode()) - total_length; + if (this_length + total_length > m_preferredMessageSize) + { + /* record is small enough, really */ + if (this_length <= m_preferredMessageSize) + { + *pres = Z_PRES_PARTIAL_2; + break; + } + if (this_length >= m_maximumRecordSize) + { /* too big entirely */ + reclist->records[reclist->num_records] = this_rec; + create_surrogateDiagnostics(odr_encode(), this_rec, + this_rec->databaseName, 17, 0); + reclist->num_records++; + *next = recno + 1; + dumped_records += this_length; + continue; + } + else /* record can only be fetched by itself */ + { + if (toget > 1) + { + yaz_log(YLOG_DEBUG, " Dropped it"); + reclist->records[reclist->num_records] = this_rec; + create_surrogateDiagnostics(odr_encode(), this_rec, + this_rec->databaseName, + 16, 0); + reclist->num_records++; + // *next = freq.last_in_set ? 0 : recno + 1; + *next = recno + 1; + dumped_records += this_length; + continue; + } + } + } + reclist->records[reclist->num_records] = this_rec; + reclist->num_records++; + *next = recno + 1; } return records; } void Yaz_Facility_Retrieval::fetch_via_piggyback (Z_Server *s, - Z_SearchRequest *req, - Z_SearchResponse *res) + Z_SearchRequest *req, + Z_SearchResponse *res) { bool_t *sr = (bool_t *)odr_malloc (odr_encode(), sizeof(*sr)); *sr = 1; @@ -124,73 +124,73 @@ void Yaz_Facility_Retrieval::fetch_via_piggyback (Z_Server *s, /* how many records does the user agent want, then? */ if (hits <= *req->smallSetUpperBound) { - toget = hits; - if ((comp.u.simple = req->smallSetElementSetNames)) - compp = ∁ + toget = hits; + if ((comp.u.simple = req->smallSetElementSetNames)) + compp = ∁ } else if (hits < *req->largeSetLowerBound) { - toget = *req->mediumSetPresentNumber; - if (toget > hits) - toget = hits; - if ((comp.u.simple = req->mediumSetElementSetNames)) - compp = ∁ + toget = *req->mediumSetPresentNumber; + if (toget > hits) + toget = hits; + if ((comp.u.simple = req->mediumSetElementSetNames)) + compp = ∁ } if (toget && !res->records) { - res->presentStatus = (int *) odr_malloc (odr_encode(), sizeof(int)); - *res->presentStatus = Z_PRES_SUCCESS; - res->records = - pack_records(s, req->resultSetName, 1, toget, compp, - res->nextResultSetPosition, - res->presentStatus, - req->preferredRecordSyntax); - if (!res->records) - return; - if (res->records->which == Z_Records_DBOSD) - *res->numberOfRecordsReturned = - res->records->u.databaseOrSurDiagnostics->num_records; - res->searchStatus = sr; - res->resultSetStatus = 0; + res->presentStatus = (int *) odr_malloc (odr_encode(), sizeof(int)); + *res->presentStatus = Z_PRES_SUCCESS; + res->records = + pack_records(s, req->resultSetName, 1, toget, compp, + res->nextResultSetPosition, + res->presentStatus, + req->preferredRecordSyntax); + if (!res->records) + return; + if (res->records->which == Z_Records_DBOSD) + *res->numberOfRecordsReturned = + res->records->u.databaseOrSurDiagnostics->num_records; + res->searchStatus = sr; + res->resultSetStatus = 0; } else { - if (hits) - *res->nextResultSetPosition = 1; - res->numberOfRecordsReturned = nulint; - res->searchStatus = sr; - res->resultSetStatus = 0; - res->presentStatus = 0; + if (hits) + *res->nextResultSetPosition = 1; + res->numberOfRecordsReturned = nulint; + res->searchStatus = sr; + res->resultSetStatus = 0; + res->presentStatus = 0; } } void Yaz_Facility_Retrieval::fetch_via_present (Z_Server *s, - Z_PresentRequest *req, - Z_PresentResponse *res) + Z_PresentRequest *req, + Z_PresentResponse *res) { res->records = - pack_records (s, req->resultSetId,*req->resultSetStartPoint, - *req->numberOfRecordsRequested, - req->recordComposition, - res->nextResultSetPosition, - res->presentStatus, - req->preferredRecordSyntax); + 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; + *res->numberOfRecordsReturned = + res->records->u.databaseOrSurDiagnostics->num_records; } int Yaz_Facility_Retrieval::init(Z_Server *s, Z_InitRequest *initRequest, - Z_InitResponse *initResponse) + Z_InitResponse *initResponse) { Z_Options *req = initRequest->options; Z_Options *res = initResponse->options; if (ODR_MASK_GET(req, Z_Options_search)) - ODR_MASK_SET(res, Z_Options_search); + ODR_MASK_SET(res, Z_Options_search); if (ODR_MASK_GET(req, Z_Options_present)) - ODR_MASK_SET(res, Z_Options_present); + ODR_MASK_SET(res, Z_Options_present); m_preferredMessageSize = *initRequest->preferredMessageSize; m_maximumRecordSize = *initRequest->maximumRecordSize; return sr_init (initRequest, initResponse); @@ -214,27 +214,35 @@ int Yaz_Facility_Retrieval::recv(Z_Server *s, Z_APDU *apdu_request) switch (apdu_request->which) { case Z_APDU_searchRequest: - apdu_response = s->create_Z_PDU(Z_APDU_searchResponse); - s->transfer_referenceId(apdu_request, apdu_response); - sr_search (apdu_request->u.searchRequest, - apdu_response->u.searchResponse); - if (!apdu_response->u.searchResponse->records) - { - fetch_via_piggyback(s, apdu_request->u.searchRequest, - apdu_response->u.searchResponse); - } - s->send_Z_PDU(apdu_response, 0); - return 1; + apdu_response = s->create_Z_PDU(Z_APDU_searchResponse); + s->transfer_referenceId(apdu_request, apdu_response); + sr_search (apdu_request->u.searchRequest, + apdu_response->u.searchResponse); + if (!apdu_response->u.searchResponse->records) + { + fetch_via_piggyback(s, apdu_request->u.searchRequest, + apdu_response->u.searchResponse); + } + s->send_Z_PDU(apdu_response, 0); + return 1; case Z_APDU_presentRequest: - apdu_response = s->create_Z_PDU(Z_APDU_presentResponse); - s->transfer_referenceId(apdu_request, apdu_response); - sr_present (apdu_request->u.presentRequest, - apdu_response->u.presentResponse); - if (!apdu_response->u.presentResponse->records) - fetch_via_present(s, apdu_request->u.presentRequest, - apdu_response->u.presentResponse); - s->send_Z_PDU(apdu_response, 0); - return 1; + apdu_response = s->create_Z_PDU(Z_APDU_presentResponse); + s->transfer_referenceId(apdu_request, apdu_response); + sr_present (apdu_request->u.presentRequest, + apdu_response->u.presentResponse); + if (!apdu_response->u.presentResponse->records) + fetch_via_present(s, apdu_request->u.presentRequest, + apdu_response->u.presentResponse); + s->send_Z_PDU(apdu_response, 0); + return 1; } return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-server-update.cpp b/src/yaz-z-server-update.cpp index 81b0530..2d5dc1e 100644 --- a/src/yaz-z-server-update.cpp +++ b/src/yaz-z-server-update.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2000-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-server-update.cpp,v 1.10 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-z-server-update.cpp,v 1.11 2005-06-25 15:53:19 adam Exp $ */ #include @@ -11,13 +11,13 @@ using namespace yazpp_1; int Yaz_Facility_Update::init(Z_Server *s, Z_InitRequest *initRequest, - Z_InitResponse *initResponse) + 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); + ODR_MASK_SET(res, Z_Options_extendedServices); return 1; } @@ -26,27 +26,35 @@ int Yaz_Facility_Update::recv(Z_Server *s, Z_APDU *apdu_request) Z_APDU *apdu_response; if (apdu_request->which != Z_APDU_extendedServicesRequest) - return 0; + return 0; Z_ExtendedServicesRequest *req = apdu_request->u.extendedServicesRequest; if (req->taskSpecificParameters && req->taskSpecificParameters->which == Z_External_update) { - apdu_response = s->create_Z_PDU(Z_APDU_extendedServicesResponse); - update_service(req, req->taskSpecificParameters->u.update, - apdu_response->u.extendedServicesResponse); - s->transfer_referenceId(apdu_request, apdu_response); - s->send_Z_PDU(apdu_response, 0); - return 1; + apdu_response = s->create_Z_PDU(Z_APDU_extendedServicesResponse); + update_service(req, req->taskSpecificParameters->u.update, + apdu_response->u.extendedServicesResponse); + s->transfer_referenceId(apdu_request, apdu_response); + s->send_Z_PDU(apdu_response, 0); + return 1; } else if (req->taskSpecificParameters && - req->taskSpecificParameters->which == Z_External_update0) + req->taskSpecificParameters->which == Z_External_update0) { - apdu_response = s->create_Z_PDU(Z_APDU_extendedServicesResponse); - update_service0 (req, req->taskSpecificParameters->u.update0, - apdu_response->u.extendedServicesResponse); - s->transfer_referenceId(apdu_request, apdu_response); - s->send_Z_PDU(apdu_response, 0); - return 1; + apdu_response = s->create_Z_PDU(Z_APDU_extendedServicesResponse); + update_service0 (req, req->taskSpecificParameters->u.update0, + apdu_response->u.extendedServicesResponse); + s->transfer_referenceId(apdu_request, apdu_response); + s->send_Z_PDU(apdu_response, 0); + return 1; } return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/yaz-z-server.cpp b/src/yaz-z-server.cpp index 06992b7..68bab4c 100644 --- a/src/yaz-z-server.cpp +++ b/src/yaz-z-server.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2000-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-z-server.cpp,v 1.22 2005-06-08 13:28:06 adam Exp $ + * $Id: yaz-z-server.cpp,v 1.23 2005-06-25 15:53:19 adam Exp $ */ #include @@ -26,21 +26,21 @@ void Z_Server::facility_reset () Z_Server_Facility_Info *p = m_facilities; while (p) { - Z_Server_Facility_Info *p_next = p->m_next; + Z_Server_Facility_Info *p_next = p->m_next; - delete [] p->m_name; - delete p; - p = p_next; + delete [] p->m_name; + delete p; + p = p_next; } m_facilities = 0; } void Z_Server::facility_add(IServer_Facility *facility, - const char *name) + const char *name) { Z_Server_Facility_Info **p = &m_facilities; while (*p) - p = &(*p)->m_next; + p = &(*p)->m_next; *p = new Z_Server_Facility_Info; @@ -53,9 +53,9 @@ void Z_Server::facility_add(IServer_Facility *facility, void Z_Server::recv_GDU (Z_GDU *apdu, int len) { if (apdu->which == Z_GDU_Z3950) - recv_Z_PDU(apdu->u.z3950, len); + recv_Z_PDU(apdu->u.z3950, len); else - delete this; + delete this; } void Z_Server::recv_Z_PDU (Z_APDU *apdu_request, int len) @@ -64,47 +64,47 @@ void Z_Server::recv_Z_PDU (Z_APDU *apdu_request, int len) if (apdu_request->which == Z_APDU_initRequest) { - Z_APDU *apdu_response = create_Z_PDU(Z_APDU_initResponse); - - Z_InitRequest *req = apdu_request->u.initRequest; - Z_InitResponse *resp = apdu_response->u.initResponse; - - if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1)) - { - ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1); - } - if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2)) - { - ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2); - } - if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3)) - { - ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3); - } - while (f) - { - f->m_facility->init(this, req, resp); - f = f->m_next; - } - transfer_referenceId(apdu_request, apdu_response); - send_Z_PDU(apdu_response, 0); + Z_APDU *apdu_response = create_Z_PDU(Z_APDU_initResponse); + + Z_InitRequest *req = apdu_request->u.initRequest; + Z_InitResponse *resp = apdu_response->u.initResponse; + + if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1)) + { + ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1); + } + if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2)) + { + ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2); + } + if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3)) + { + ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3); + } + while (f) + { + f->m_facility->init(this, req, resp); + f = f->m_next; + } + transfer_referenceId(apdu_request, apdu_response); + send_Z_PDU(apdu_response, 0); } else { - f = m_facilities; - int taken = 0; - while (f) - { - taken = f->m_facility->recv(this, apdu_request); - if (taken) - break; - f = f->m_next; - } - if (!taken) - { - yaz_log (YLOG_WARN, "unhandled request = %d", apdu_request->which); - delete this; - } + f = m_facilities; + int taken = 0; + while (f) + { + taken = f->m_facility->recv(this, apdu_request); + if (taken) + break; + f = f->m_next; + } + if (!taken) + { + yaz_log (YLOG_WARN, "unhandled request = %d", apdu_request->which); + delete this; + } } } @@ -118,7 +118,7 @@ void Z_ServerUtility::create_databaseRecord ( 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); + (const char *) buf, len); } /* @@ -131,7 +131,7 @@ void Z_ServerUtility::create_surrogateDiagnostics( 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)); + odr_malloc (odr, sizeof(*dr)); yaz_log(YLOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo); *err = error; @@ -192,3 +192,11 @@ void Z_ServerUtility::create_diagnostics ( dr->which = Z_DefaultDiagFormat_v2Addinfo; dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : ""); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/main.cpp b/zlint/main.cpp index 7e34e64..f05e61a 100644 --- a/zlint/main.cpp +++ b/zlint/main.cpp @@ -11,9 +11,9 @@ int main(int argc, char **argv) Zlint z(new PDU_Assoc(&mySocketManager)); if (argc > 1) - z.set_host(argv[1]); + z.set_host(argv[1]); else - z.set_host("localhost:9999"); + z.set_host("localhost:9999"); Zlint_test_init_01 t01; z.add_test(&t01); @@ -46,7 +46,15 @@ int main(int argc, char **argv) z.add_test(&scan01); while (mySocketManager.processEvent() > 0) - ; + ; exit (0); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-01.cpp b/zlint/test-init-01.cpp index 092baf1..569cb31 100644 --- a/zlint/test-init-01.cpp +++ b/zlint/test-init-01.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-01.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-01.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -33,8 +33,8 @@ Zlint_code Zlint_test_init_01::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -42,24 +42,32 @@ Zlint_code Zlint_test_init_01::init(Zlint *z) Zlint_code Zlint_test_init_01::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - if (ver > 3 || ver < 2) - z->msg_check_fail("got version %d, expected 2 or 3", ver); - if (!result) - { - z->msg_check_fail("init rejected (result false)"); - return TEST_FINISHED; - } - else - z->msg_check_ok(); + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + if (ver > 3 || ver < 2) + z->msg_check_fail("got version %d, expected 2 or 3", ver); + if (!result) + { + z->msg_check_fail("init rejected (result false)"); + return TEST_FINISHED; + } + else + z->msg_check_ok(); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-02.cpp b/zlint/test-init-02.cpp index 97b7348..8820d4e 100644 --- a/zlint/test-init-02.cpp +++ b/zlint/test-init-02.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-02.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-02.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -32,8 +32,8 @@ Zlint_code Zlint_test_init_02::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -41,19 +41,27 @@ Zlint_code Zlint_test_init_02::init(Zlint *z) Zlint_code Zlint_test_init_02::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - if (ver != 2) - z->msg_check_fail("got version %d, expected 2", ver); - z->msg_check_ok(); + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + if (ver != 2) + z->msg_check_fail("got version %d, expected 2", ver); + z->msg_check_ok(); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-03.cpp b/zlint/test-init-03.cpp index 64f8ae6..40c1218 100644 --- a/zlint/test-init-03.cpp +++ b/zlint/test-init-03.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-03.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-03.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -28,13 +28,13 @@ Zlint_code Zlint_test_init_03::init(Zlint *z) ODR_MASK_ZERO(init->protocolVersion); int i; for (i = 0; i< 9; i++) - ODR_MASK_SET(init->protocolVersion, i); + ODR_MASK_SET(init->protocolVersion, i); int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -42,19 +42,27 @@ Zlint_code Zlint_test_init_03::init(Zlint *z) Zlint_code Zlint_test_init_03::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; - if (ver < 2 || ver > 5) - z->msg_check_fail("%sgot version %d, expected 2-5", ver); - z->msg_check_ok(); + if (ver < 2 || ver > 5) + z->msg_check_fail("%sgot version %d, expected 2-5", ver); + z->msg_check_ok(); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-04.cpp b/zlint/test-init-04.cpp index 14e9ac7..297396d 100644 --- a/zlint/test-init-04.cpp +++ b/zlint/test-init-04.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-04.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-04.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -34,8 +34,8 @@ Zlint_code Zlint_test_init_04::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -43,21 +43,29 @@ Zlint_code Zlint_test_init_04::init(Zlint *z) Zlint_code Zlint_test_init_04::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - - if (!init->referenceId) - z->msg_check_fail("missing referenceID from init response"); - else if (init->referenceId->len != REFID_LEN1 - || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1)) - z->msg_check_fail("reference ID does not match"); - z->msg_check_ok(); + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + + if (!init->referenceId) + z->msg_check_fail("missing referenceID from init response"); + else if (init->referenceId->len != REFID_LEN1 + || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1)) + z->msg_check_fail("reference ID does not match"); + z->msg_check_ok(); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-05.cpp b/zlint/test-init-05.cpp index 87433f9..59ae15c 100644 --- a/zlint/test-init-05.cpp +++ b/zlint/test-init-05.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-05.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-05.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -39,10 +39,10 @@ Zlint_code Zlint_test_init_05::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } - + apdu = z->create_Z_PDU(Z_APDU_initRequest); init = apdu->u.initRequest; @@ -54,8 +54,8 @@ Zlint_code Zlint_test_init_05::init(Zlint *z) r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -63,58 +63,66 @@ Zlint_code Zlint_test_init_05::init(Zlint *z) Zlint_code Zlint_test_init_05::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - - if (m_init_response_no == 0) - { - if (!init->referenceId) - { - z->msg_check_fail("missing referenceID from " - "first init response"); - return TEST_FINISHED; - } - else if (init->referenceId->len != REFID_LEN1 - || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1)) - { - z->msg_check_fail("reference ID does not match from " - "first init response"); - return TEST_FINISHED; - } - } - else - { - if (!init->referenceId) - z->msg_check_fail("missing referenceID from " - "second init response"); - else if (init->referenceId->len != REFID_LEN2 - || memcmp(init->referenceId->buf, REFID_BUF2, REFID_LEN2)) - z->msg_check_fail("reference ID does not match from " - "second init response"); - } - - if (!result) - { - z->msg_check_fail("init rejected (result false)"); - return TEST_FINISHED; - } - else - { - if (m_init_response_no == 0) - { - m_init_response_no++; - return TEST_CONTINUE; - } - else - z->msg_check_ok(); - } + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + + if (m_init_response_no == 0) + { + if (!init->referenceId) + { + z->msg_check_fail("missing referenceID from " + "first init response"); + return TEST_FINISHED; + } + else if (init->referenceId->len != REFID_LEN1 + || memcmp(init->referenceId->buf, REFID_BUF1, REFID_LEN1)) + { + z->msg_check_fail("reference ID does not match from " + "first init response"); + return TEST_FINISHED; + } + } + else + { + if (!init->referenceId) + z->msg_check_fail("missing referenceID from " + "second init response"); + else if (init->referenceId->len != REFID_LEN2 + || memcmp(init->referenceId->buf, REFID_BUF2, REFID_LEN2)) + z->msg_check_fail("reference ID does not match from " + "second init response"); + } + + if (!result) + { + z->msg_check_fail("init rejected (result false)"); + return TEST_FINISHED; + } + else + { + if (m_init_response_no == 0) + { + m_init_response_no++; + return TEST_CONTINUE; + } + else + z->msg_check_ok(); + } } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-06.cpp b/zlint/test-init-06.cpp index 2d40f35..a2956b3 100644 --- a/zlint/test-init-06.cpp +++ b/zlint/test-init-06.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-06.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-06.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -30,13 +30,13 @@ Zlint_code Zlint_test_init_06::init(Zlint *z) ODR_MASK_ZERO(init->options); int i; for (i = 0; i <= 24; i++) - ODR_MASK_SET(init->options, i); + ODR_MASK_SET(init->options, i); int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -44,38 +44,46 @@ Zlint_code Zlint_test_init_06::init(Zlint *z) Zlint_code Zlint_test_init_06::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - - if (init->options) - { - int i; - int no_set = 0; - int no_reset = 0; - for (i = 0; i <= 24; i++) - if (ODR_MASK_GET(init->options, i)) - no_set++; - else - no_reset++; - if (no_set < 2) - { - z->msg_check_fail("suspicuously few option bits set"); - return TEST_FINISHED; - } - if (no_reset == 0) - { - z->msg_check_fail("suspicuously many option bits set"); - return TEST_FINISHED; - } - } - z->msg_check_ok(); + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + + if (init->options) + { + int i; + int no_set = 0; + int no_reset = 0; + for (i = 0; i <= 24; i++) + if (ODR_MASK_GET(init->options, i)) + no_set++; + else + no_reset++; + if (no_set < 2) + { + z->msg_check_fail("suspicuously few option bits set"); + return TEST_FINISHED; + } + if (no_reset == 0) + { + z->msg_check_fail("suspicuously many option bits set"); + return TEST_FINISHED; + } + } + z->msg_check_ok(); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-07.cpp b/zlint/test-init-07.cpp index e586c92..eb72b30 100644 --- a/zlint/test-init-07.cpp +++ b/zlint/test-init-07.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-07.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-07.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -33,38 +33,38 @@ Zlint_code Zlint_test_init_07::init(Zlint *z) yaz_oi_APDU(apdu, &oi); if (!oi) { - z->msg_check_fail("encoding failure"); - return TEST_FINISHED; + z->msg_check_fail("encoding failure"); + return TEST_FINISHED; } else { - Z_OtherInformationUnit *p0; - const char *negotiationCharset[] = { - "UTF-8", - "UTF-16", - "UCS-2", - "UCS-4", - "ISO-8859-1" - }; - char *yazLang = 0; - - if ((p0=yaz_oi_update(oi, z->odr_encode(), NULL, 0, 0))) { - ODR_MASK_SET(init->options, Z_Options_negotiationModel); - - p0->which = Z_OtherInfo_externallyDefinedInfo; - p0->information.externallyDefinedInfo = - - yaz_set_proposal_charneg( - z->odr_encode(), - negotiationCharset, 5, - (const char**)&yazLang, yazLang ? 1 : 0, 1); - } + Z_OtherInformationUnit *p0; + const char *negotiationCharset[] = { + "UTF-8", + "UTF-16", + "UCS-2", + "UCS-4", + "ISO-8859-1" + }; + char *yazLang = 0; + + if ((p0=yaz_oi_update(oi, z->odr_encode(), NULL, 0, 0))) { + ODR_MASK_SET(init->options, Z_Options_negotiationModel); + + p0->which = Z_OtherInfo_externallyDefinedInfo; + p0->information.externallyDefinedInfo = + + yaz_set_proposal_charneg( + z->odr_encode(), + negotiationCharset, 5, + (const char**)&yazLang, yazLang ? 1 : 0, 1); + } } int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -72,38 +72,46 @@ Zlint_code Zlint_test_init_07::init(Zlint *z) Zlint_code Zlint_test_init_07::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; - if (ODR_MASK_GET(init->options, Z_Options_negotiationModel)) - { - Z_CharSetandLanguageNegotiation *p = - yaz_get_charneg_record(init->otherInfo); - - if (p) { - - char *charset=NULL, *lang=NULL; - int selected; - NMEM m = nmem_create(); - - yaz_get_response_charneg(m, p, &charset, &lang, - &selected); - z->msg_check_ok(); - z->msg_check_info("Accepted character set : %s", charset); - z->msg_check_info("Accepted code language : %s", lang ? lang : "none"); - z->msg_check_info("Accepted records in ...: %d", selected ); - nmem_destroy(m); - return TEST_FINISHED; - } - } - z->msg_check_notapp(); + if (ODR_MASK_GET(init->options, Z_Options_negotiationModel)) + { + Z_CharSetandLanguageNegotiation *p = + yaz_get_charneg_record(init->otherInfo); + + if (p) { + + char *charset=NULL, *lang=NULL; + int selected; + NMEM m = nmem_create(); + + yaz_get_response_charneg(m, p, &charset, &lang, + &selected); + z->msg_check_ok(); + z->msg_check_info("Accepted character set : %s", charset); + z->msg_check_info("Accepted code language : %s", lang ? lang : "none"); + z->msg_check_info("Accepted records in ...: %d", selected ); + nmem_destroy(m); + return TEST_FINISHED; + } + } + z->msg_check_notapp(); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-init-08.cpp b/zlint/test-init-08.cpp index 43a9010..63b001b 100644 --- a/zlint/test-init-08.cpp +++ b/zlint/test-init-08.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-init-08.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-init-08.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -37,8 +37,8 @@ Zlint_code Zlint_test_init_08::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -46,25 +46,25 @@ Zlint_code Zlint_test_init_08::init(Zlint *z) Zlint_code Zlint_test_init_08::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - - if (m_no * m_no * 100000 + 2000 < *init->maximumRecordSize) - z->msg_check_fail("maximumRecordSize bigger than proposed size"); - if (m_no * m_no * 100000 + 2000 < *init->preferredMessageSize) - z->msg_check_fail("preferredMessage bigger than proposed size"); - z->msg_check_ok(); - if (m_no < 2) - { - m_no++; - return TEST_REOPEN; - } + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + + if (m_no * m_no * 100000 + 2000 < *init->maximumRecordSize) + z->msg_check_fail("maximumRecordSize bigger than proposed size"); + if (m_no * m_no * 100000 + 2000 < *init->preferredMessageSize) + z->msg_check_fail("preferredMessage bigger than proposed size"); + z->msg_check_ok(); + if (m_no < 2) + { + m_no++; + return TEST_REOPEN; + } } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } @@ -73,9 +73,17 @@ Zlint_code Zlint_test_init_08::recv_fail(Zlint *z, int reason) z->msg_check_fail("target closed connection"); if (m_no < 2) { - m_no++; - return TEST_REOPEN; + m_no++; + return TEST_REOPEN; } return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-scan-01.cpp b/zlint/test-scan-01.cpp index dd113b0..3033f39 100644 --- a/zlint/test-scan-01.cpp +++ b/zlint/test-scan-01.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-scan-01.cpp,v 1.3 2004-12-13 20:50:54 adam Exp $ + * $Id: test-scan-01.cpp,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -40,8 +40,8 @@ Zlint_code Zlint_test_scan_01::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -50,76 +50,76 @@ Zlint_code Zlint_test_scan_01::sendTest(Zlint *z) { if (try_scan[m_scan_no]) { - int len; - z->msg_check_for("scan support %s", try_scan[m_scan_no]); + int len; + z->msg_check_for("scan support %s", try_scan[m_scan_no]); - Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_scanRequest); - YAZ_PQF_Parser pqf_parser = yaz_pqf_create (); - Z_ScanRequest *sr = apdu->u.scanRequest; - sr->termListAndStartPoint = yaz_pqf_scan(pqf_parser, - z->odr_encode(), - &sr->attributeSet, - try_scan[m_scan_no]); - - z->getDatabase(&sr->databaseNames, &sr->num_databaseNames); - - yaz_pqf_destroy (pqf_parser); - z->send_Z_PDU(apdu, &len); - return TEST_CONTINUE; + Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_scanRequest); + YAZ_PQF_Parser pqf_parser = yaz_pqf_create (); + Z_ScanRequest *sr = apdu->u.scanRequest; + sr->termListAndStartPoint = yaz_pqf_scan(pqf_parser, + z->odr_encode(), + &sr->attributeSet, + try_scan[m_scan_no]); + + z->getDatabase(&sr->databaseNames, &sr->num_databaseNames); + + yaz_pqf_destroy (pqf_parser); + z->send_Z_PDU(apdu, &len); + return TEST_CONTINUE; } else - return TEST_FINISHED; + return TEST_FINISHED; } Zlint_code Zlint_test_scan_01::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - if (ver > 3 || ver < 2) - z->msg_check_fail("got version %d, expected 2 or 3", ver); - if (!result) - { - z->msg_check_fail("init rejected (result false)"); - return TEST_FINISHED; - } - else if (!ODR_MASK_GET(init->options, Z_Options_scan)) - { - z->msg_check_notapp(); - z->msg_check_info("scan unsupported"); - return TEST_FINISHED; - } - else - { - sendTest(z); - return TEST_CONTINUE; - } + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + if (ver > 3 || ver < 2) + z->msg_check_fail("got version %d, expected 2 or 3", ver); + if (!result) + { + z->msg_check_fail("init rejected (result false)"); + return TEST_FINISHED; + } + else if (!ODR_MASK_GET(init->options, Z_Options_scan)) + { + z->msg_check_notapp(); + z->msg_check_info("scan unsupported"); + return TEST_FINISHED; + } + else + { + sendTest(z); + return TEST_CONTINUE; + } } else if (gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_scanResponse) { - Z_ScanResponse *sr = gdu->u.z3950->u.scanResponse; - if (sr->entries->nonsurrogateDiagnostics) - { - z->msg_check_ok(); - z->msg_check_info("scan NSD for %s", try_scan[m_scan_no]); - } - else if (sr->entries->entries && sr->entries->num_entries > 0) - { - z->msg_check_ok(); - } - else - { - z->msg_check_fail("scan no entries/diagnostics for %s", - try_scan[m_scan_no]); - } - m_scan_no++; - return sendTest(z); + Z_ScanResponse *sr = gdu->u.z3950->u.scanResponse; + if (sr->entries->nonsurrogateDiagnostics) + { + z->msg_check_ok(); + z->msg_check_info("scan NSD for %s", try_scan[m_scan_no]); + } + else if (sr->entries->entries && sr->entries->num_entries > 0) + { + z->msg_check_ok(); + } + else + { + z->msg_check_fail("scan no entries/diagnostics for %s", + try_scan[m_scan_no]); + } + m_scan_no++; + return sendTest(z); } else - z->msg_check_fail("did not receive init response as expected"); + z->msg_check_fail("did not receive init response as expected"); return TEST_FINISHED; } @@ -129,3 +129,11 @@ Zlint_code Zlint_test_scan_01::recv_fail(Zlint *z, int reason) z->msg_check_fail("target closed connection"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/test-search-01.cpp b/zlint/test-search-01.cpp index d99a22f..f537bc3 100644 --- a/zlint/test-search-01.cpp +++ b/zlint/test-search-01.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: test-search-01.cpp,v 1.4 2004-12-13 20:50:54 adam Exp $ + * $Id: test-search-01.cpp,v 1.5 2005-06-25 15:53:21 adam Exp $ */ #include @@ -78,8 +78,8 @@ Zlint_code Zlint_test_search_01::init(Zlint *z) int r = z->send_Z_PDU(apdu, &len); if (r < 0) { - z->msg_check_fail("unable to send init request"); - return TEST_FINISHED; + z->msg_check_fail("unable to send init request"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -88,81 +88,81 @@ Zlint_code Zlint_test_search_01::sendTest(Zlint *z) { if (!m_got_result_set) { - Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_searchRequest); - Z_SearchRequest *sr; - sr = apdu->u.searchRequest; - sr->query = (Z_Query *) odr_malloc(z->odr_encode(), sizeof(*sr->query)); - if (try_query[m_query_no] && sr) - { - sr->query->which = Z_Query_type_1; - Z_RPNQuery *rpn; - YAZ_PQF_Parser pqf_parser = yaz_pqf_create (); - - z->getDatabase(&sr->databaseNames, &sr->num_databaseNames); - - rpn = yaz_pqf_parse(pqf_parser, z->odr_encode(), - try_query[m_query_no]); - - yaz_pqf_destroy (pqf_parser); - - if (!rpn) - { - z->msg_check_fail("Query %s invalid", try_query[m_query_no]); - return TEST_FINISHED; - } - int len; - sr->query->u.type_1 = rpn; - z->send_Z_PDU(apdu, &len); - } - else - { - z->msg_check_notapp(); - z->msg_check_info("unable to get any hit count"); - return TEST_FINISHED; - } + Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_searchRequest); + Z_SearchRequest *sr; + sr = apdu->u.searchRequest; + sr->query = (Z_Query *) odr_malloc(z->odr_encode(), sizeof(*sr->query)); + if (try_query[m_query_no] && sr) + { + sr->query->which = Z_Query_type_1; + Z_RPNQuery *rpn; + YAZ_PQF_Parser pqf_parser = yaz_pqf_create (); + + z->getDatabase(&sr->databaseNames, &sr->num_databaseNames); + + rpn = yaz_pqf_parse(pqf_parser, z->odr_encode(), + try_query[m_query_no]); + + yaz_pqf_destroy (pqf_parser); + + if (!rpn) + { + z->msg_check_fail("Query %s invalid", try_query[m_query_no]); + return TEST_FINISHED; + } + int len; + sr->query->u.type_1 = rpn; + z->send_Z_PDU(apdu, &len); + } + else + { + z->msg_check_notapp(); + z->msg_check_info("unable to get any hit count"); + return TEST_FINISHED; + } } else if (m_got_result_set && try_syntax[m_record_syntax_no]) { - int len; - Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_presentRequest); - Z_PresentRequest *pr = apdu->u.presentRequest; - *pr->numberOfRecordsRequested = 1; - *pr->resultSetStartPoint = 1; + int len; + Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_presentRequest); + Z_PresentRequest *pr = apdu->u.presentRequest; + *pr->numberOfRecordsRequested = 1; + *pr->resultSetStartPoint = 1; - z->msg_check_for("record syntax %s", try_syntax[m_record_syntax_no]); - pr->preferredRecordSyntax = - yaz_str_to_z3950oid(z->odr_encode(), CLASS_RECSYN, - try_syntax[m_record_syntax_no]); - z->send_Z_PDU(apdu, &len); - return TEST_CONTINUE; + z->msg_check_for("record syntax %s", try_syntax[m_record_syntax_no]); + pr->preferredRecordSyntax = + yaz_str_to_z3950oid(z->odr_encode(), CLASS_RECSYN, + try_syntax[m_record_syntax_no]); + z->send_Z_PDU(apdu, &len); + return TEST_CONTINUE; } else if(m_got_result_set && !try_syntax[m_record_syntax_no]) { - Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_sortRequest); - if (apdu && try_sort[m_sort_no]) - { - z->msg_check_for("sort %s", try_sort[m_sort_no]); + Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_sortRequest); + if (apdu && try_sort[m_sort_no]) + { + z->msg_check_for("sort %s", try_sort[m_sort_no]); - char *setstring = "default"; - int len; - Z_SortRequest *sr = apdu->u.sortRequest; - - sr->num_inputResultSetNames = 1; - sr->num_inputResultSetNames = 1; - sr->inputResultSetNames = (Z_InternationalString **) - odr_malloc (z->odr_encode(), sizeof(*sr->inputResultSetNames)); - sr->inputResultSetNames[0] = odr_strdup (z->odr_encode(), setstring); - sr->sortedResultSetName = odr_strdup(z->odr_encode(), setstring); - sr->sortSequence = yaz_sort_spec(z->odr_encode(), try_sort[m_sort_no]); - z->send_Z_PDU(apdu, &len); - } - else - return TEST_FINISHED; + char *setstring = "default"; + int len; + Z_SortRequest *sr = apdu->u.sortRequest; + + sr->num_inputResultSetNames = 1; + sr->num_inputResultSetNames = 1; + sr->inputResultSetNames = (Z_InternationalString **) + odr_malloc (z->odr_encode(), sizeof(*sr->inputResultSetNames)); + sr->inputResultSetNames[0] = odr_strdup (z->odr_encode(), setstring); + sr->sortedResultSetName = odr_strdup(z->odr_encode(), setstring); + sr->sortSequence = yaz_sort_spec(z->odr_encode(), try_sort[m_sort_no]); + z->send_Z_PDU(apdu, &len); + } + else + return TEST_FINISHED; } else { - printf ("finished...\n"); - return TEST_FINISHED; + printf ("finished...\n"); + return TEST_FINISHED; } return TEST_CONTINUE; } @@ -170,103 +170,103 @@ Zlint_code Zlint_test_search_01::sendTest(Zlint *z) Zlint_code Zlint_test_search_01::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { - Z_InitResponse *init = gdu->u.z3950->u.initResponse; - int ver = z->initResponseGetVersion(init); - int result = init->result ? *init->result : 0; - if (!result) - { - z->msg_check_notapp(); - z->msg_check_info ("init rejected (result false)"); - return TEST_FINISHED; - } - return sendTest(z); + Z_InitResponse *init = gdu->u.z3950->u.initResponse; + int ver = z->initResponseGetVersion(init); + int result = init->result ? *init->result : 0; + if (!result) + { + z->msg_check_notapp(); + z->msg_check_info ("init rejected (result false)"); + return TEST_FINISHED; + } + return sendTest(z); } else if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_searchResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_searchResponse) { - Z_SearchResponse *sr = gdu->u.z3950->u.searchResponse; - if (sr->records && (sr->records->which == Z_Records_NSD - || - sr->records->which == Z_Records_multipleNSD)) - m_query_no++; - else if (!sr->resultCount || *sr->resultCount == 0) - m_query_no++; - else - { - z->msg_check_ok(); - z->msg_check_info("got %d result count with %s", *sr->resultCount, - try_query[m_query_no]); - m_got_result_set = 1; - } - return sendTest(z); + Z_SearchResponse *sr = gdu->u.z3950->u.searchResponse; + if (sr->records && (sr->records->which == Z_Records_NSD + || + sr->records->which == Z_Records_multipleNSD)) + m_query_no++; + else if (!sr->resultCount || *sr->resultCount == 0) + m_query_no++; + else + { + z->msg_check_ok(); + z->msg_check_info("got %d result count with %s", *sr->resultCount, + try_query[m_query_no]); + m_got_result_set = 1; + } + return sendTest(z); } else if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_presentResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_presentResponse) { - Z_PresentResponse *sr = gdu->u.z3950->u.presentResponse; - if (sr->records && (sr->records->which == Z_Records_NSD - || - sr->records->which == Z_Records_multipleNSD)) - { - z->msg_check_ok(); - z->msg_check_info("present returned NSD for %s", - try_syntax[m_record_syntax_no]); - } - else if (sr->records && sr->records->which == Z_Records_DBOSD - && sr->records->u.databaseOrSurDiagnostics->num_records>0 - && sr->records->u.databaseOrSurDiagnostics->records[0]) - { - if (sr->records->u.databaseOrSurDiagnostics->records[0]->which == Z_NamePlusRecord_databaseRecord) - { - Z_External *ext = sr->records->u.databaseOrSurDiagnostics->records[0]->u.databaseRecord; - Odr_oid *expectRecordSyntax = - yaz_str_to_z3950oid(z->odr_decode(), CLASS_RECSYN, - try_syntax[m_record_syntax_no]); - if (oid_oidcmp(expectRecordSyntax, - ext->direct_reference)) - { - z->msg_check_fail("Got Record in different syntax " - "from that requested %s", - try_syntax[m_record_syntax_no]); - } - else - z->msg_check_ok(); - } - else if (sr->records->u.databaseOrSurDiagnostics->records[0]->which == Z_NamePlusRecord_surrogateDiagnostic) - { - z->msg_check_ok(); - z->msg_check_info("present returned SD %s", - try_syntax[m_record_syntax_no]); - } - else - { - z->msg_check_ok(); - z->msg_check_info("present returned fragment %s", - try_syntax[m_record_syntax_no]); - } - } - else - { - z->msg_check_fail("present returned no records or diagnostics"); - } - m_record_syntax_no++; - return sendTest(z); + Z_PresentResponse *sr = gdu->u.z3950->u.presentResponse; + if (sr->records && (sr->records->which == Z_Records_NSD + || + sr->records->which == Z_Records_multipleNSD)) + { + z->msg_check_ok(); + z->msg_check_info("present returned NSD for %s", + try_syntax[m_record_syntax_no]); + } + else if (sr->records && sr->records->which == Z_Records_DBOSD + && sr->records->u.databaseOrSurDiagnostics->num_records>0 + && sr->records->u.databaseOrSurDiagnostics->records[0]) + { + if (sr->records->u.databaseOrSurDiagnostics->records[0]->which == Z_NamePlusRecord_databaseRecord) + { + Z_External *ext = sr->records->u.databaseOrSurDiagnostics->records[0]->u.databaseRecord; + Odr_oid *expectRecordSyntax = + yaz_str_to_z3950oid(z->odr_decode(), CLASS_RECSYN, + try_syntax[m_record_syntax_no]); + if (oid_oidcmp(expectRecordSyntax, + ext->direct_reference)) + { + z->msg_check_fail("Got Record in different syntax " + "from that requested %s", + try_syntax[m_record_syntax_no]); + } + else + z->msg_check_ok(); + } + else if (sr->records->u.databaseOrSurDiagnostics->records[0]->which == Z_NamePlusRecord_surrogateDiagnostic) + { + z->msg_check_ok(); + z->msg_check_info("present returned SD %s", + try_syntax[m_record_syntax_no]); + } + else + { + z->msg_check_ok(); + z->msg_check_info("present returned fragment %s", + try_syntax[m_record_syntax_no]); + } + } + else + { + z->msg_check_fail("present returned no records or diagnostics"); + } + m_record_syntax_no++; + return sendTest(z); } else if (gdu->which == Z_GDU_Z3950 && - gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_sortResponse) + gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_sortResponse) { - Z_SortResponse *sr = gdu->u.z3950->u.sortResponse; - z->msg_check_ok(); - if (sr->diagnostics) - z->msg_check_info( "sort NSD for %s", try_sort[m_sort_no]); - m_sort_no++; - return sendTest(z); + Z_SortResponse *sr = gdu->u.z3950->u.sortResponse; + z->msg_check_ok(); + if (sr->diagnostics) + z->msg_check_info( "sort NSD for %s", try_sort[m_sort_no]); + m_sort_no++; + return sendTest(z); } else - z->msg_check_fail("did not receive init/search/present response " - "as expected"); + z->msg_check_fail("did not receive init/search/present response " + "as expected"); return TEST_FINISHED; } @@ -275,3 +275,11 @@ Zlint_code Zlint_test_search_01::recv_fail(Zlint *z, int reason) z->msg_check_fail("target closed connection"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/zlint.cpp b/zlint/zlint.cpp index 46cbf8e..c8325e0 100644 --- a/zlint/zlint.cpp +++ b/zlint/zlint.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: zlint.cpp,v 1.10 2005-06-08 13:28:06 adam Exp $ + * $Id: zlint.cpp,v 1.11 2005-06-25 15:53:21 adam Exp $ */ #include @@ -44,9 +44,9 @@ Zlint::~Zlint() { while (m_tests) { - Zlint_t *t = m_tests; - m_tests = t->m_next; - delete t; + Zlint_t *t = m_tests; + m_tests = t->m_next; + delete t; } xfree(m_host); xfree(m_database); @@ -62,7 +62,7 @@ void Zlint::set_host(const char *cp) const char *basep; cs_get_host_args(m_host, &basep); if (!basep || !*basep) - basep = "Default"; + basep = "Default"; xfree(m_database); m_database = xstrdup(basep); } @@ -71,13 +71,13 @@ void Zlint::timeoutNotify() { if (m_cur_test) { - if (m_cur_test->m_t->recv_fail(this, 2) != TEST_FINISHED) - { - close(); - client(m_host); - timeout(30); - return; - } + if (m_cur_test->m_t->recv_fail(this, 2) != TEST_FINISHED) + { + close(); + client(m_host); + timeout(30); + return; + } } close_goto_next(); } @@ -86,13 +86,13 @@ void Zlint::failNotify() { if (m_cur_test) { - if (m_cur_test->m_t->recv_fail(this, 1) != TEST_FINISHED) - { - close(); - client(m_host); - timeout(30); - return; - } + if (m_cur_test->m_t->recv_fail(this, 1) != TEST_FINISHED) + { + close(); + client(m_host); + timeout(30); + return; + } } close_goto_next(); } @@ -101,8 +101,8 @@ void Zlint::connectNotify() { if (m_cur_test) { - if (m_cur_test->m_t->init(this) != TEST_FINISHED) - return; + if (m_cur_test->m_t->init(this) != TEST_FINISHED) + return; } close_goto_next(); } @@ -111,16 +111,16 @@ void Zlint::recv_GDU(Z_GDU *gdu, int len) { if (m_cur_test) { - int r = m_cur_test->m_t->recv_gdu(this, gdu); - if (r == TEST_CONTINUE) - return; - if (r == TEST_REOPEN) - { - close(); - client(m_host); - timeout(30); - return; - } + int r = m_cur_test->m_t->recv_gdu(this, gdu); + if (r == TEST_CONTINUE) + return; + if (r == TEST_REOPEN) + { + close(); + client(m_host); + timeout(30); + return; + } } close_goto_next(); } @@ -129,9 +129,9 @@ void Zlint::close_goto_next() { close(); if (m_cur_test) - m_cur_test = m_cur_test->m_next; + m_cur_test = m_cur_test->m_next; if (m_cur_test) - client(m_host); + client(m_host); timeout(30); } @@ -144,7 +144,7 @@ IPDU_Observer *Zlint::sessionNotify( Z_ReferenceId *Zlint::mk_refid(const char *buf, int len) { Z_ReferenceId *id = - (Z_ReferenceId *) odr_malloc(odr_encode(), sizeof(*id)); + (Z_ReferenceId *) odr_malloc(odr_encode(), sizeof(*id)); id->size = id->len = len; id->buf = (unsigned char*) odr_malloc(odr_encode(), len); memcpy(id->buf, buf, len); @@ -157,12 +157,12 @@ int Zlint::initResponseGetVersion(Z_InitResponse *init) int off = 0; int i; for (i = 0; i<12; i++) - if (ODR_MASK_GET(init->protocolVersion, no)) - { - no = i+1; - } - else - off = 1; + if (ODR_MASK_GET(init->protocolVersion, no)) + { + no = i+1; + } + else + off = 1; return no; } @@ -170,10 +170,10 @@ void Zlint::add_test(Zlint_test *t) { Zlint_t **d = &m_tests; while (*d) - d = &(*d)->m_next; + d = &(*d)->m_next; *d = new Zlint_t(t); if (!m_cur_test) - m_cur_test = m_tests; + m_cur_test = m_tests; } void Zlint::msg_check_for(const char *fmt, ...) @@ -204,9 +204,9 @@ void Zlint::msg_check_ok() { if (!m_cur_test->m_test_reported) { - m_cur_test->m_test_ok = 1; - m_cur_test->m_test_reported = 1; - printf ("OK\n"); + m_cur_test->m_test_ok = 1; + m_cur_test->m_test_reported = 1; + printf ("OK\n"); } } @@ -214,9 +214,9 @@ void Zlint::msg_check_fail(const char *fmt, ...) { if (!m_cur_test->m_test_reported) { - m_cur_test->m_test_ok = 0; - m_cur_test->m_test_reported = 1; - printf ("Fail\n"); + m_cur_test->m_test_ok = 0; + m_cur_test->m_test_reported = 1; + printf ("Fail\n"); } va_list ap; va_start(ap, fmt); @@ -230,9 +230,9 @@ void Zlint::msg_check_notapp() { if (!m_cur_test->m_test_reported) { - m_cur_test->m_test_ok = 2; - m_cur_test->m_test_reported = 1; - printf ("Unsupported\n"); + m_cur_test->m_test_ok = 2; + m_cur_test->m_test_reported = 1; + printf ("Unsupported\n"); } } @@ -263,3 +263,11 @@ Zlint_code Zlint_test_simple::recv_fail(Zlint *z, int reason) z->msg_check_fail("target closed connection"); return TEST_FINISHED; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zlint/zlint.h b/zlint/zlint.h index d9dbca6..8c0302a 100644 --- a/zlint/zlint.h +++ b/zlint/zlint.h @@ -2,7 +2,7 @@ * Copyright (c) 2004, Index Data. * See the file LICENSE for details. * - * $Id: zlint.h,v 1.3 2005-06-08 13:28:06 adam Exp $ + * $Id: zlint.h,v 1.4 2005-06-25 15:53:21 adam Exp $ */ #include @@ -151,3 +151,11 @@ public: Zlint_code recv_gdu(Zlint *z, Z_GDU *gdu); Zlint_code recv_fail(Zlint *z, int reason); }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/canonical.cpp b/zoom/canonical.cpp index 940ae6a..01437c0 100644 --- a/zoom/canonical.cpp +++ b/zoom/canonical.cpp @@ -14,3 +14,11 @@ int main(int argc, char **argv) const record rec(rs, 0); std::cout << rec.render() << std::endl; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/zclient.cpp b/zoom/zclient.cpp index 7938b0d..aa3f603 100644 --- a/zoom/zclient.cpp +++ b/zoom/zclient.cpp @@ -1,8 +1,8 @@ -// $Id: zclient.cpp,v 1.7 2003-07-02 10:25:13 adam Exp $ +// $Id: zclient.cpp,v 1.8 2005-06-25 15:53:21 adam Exp $ // Simple sample client -#include // for atoi() +#include // for atoi() #include #include "zoom.h" @@ -10,39 +10,47 @@ int main(int argc, char **argv) { if (argc != 5) { - std::cerr << "Usage: " << - argv[0] << " <@prefix-search>\n"; - return 1; + std::cerr << "Usage: " << + argv[0] << " <@prefix-search>\n"; + return 1; } using namespace ZOOM; try { - connection conn(argv[1], atoi(argv[2])); - conn.option("databaseName", argv[3]); - conn.option("preferredRecordSyntax", - record::syntax(record::syntax::XML)); - prefixQuery pq(argv[4]); - resultSet rs(conn, pq); - - size_t n = rs.size(); - std::cout << "found " << n << " records:\n"; - for (size_t i = 0; i < n; i++) { - const record rec(rs, i); - std::cout << "=== record " << i+1 << - " (record-syntax " << (std::string) rec.recsyn() << ")" << - " ===\n" << rec.render(); - } + connection conn(argv[1], atoi(argv[2])); + conn.option("databaseName", argv[3]); + conn.option("preferredRecordSyntax", + record::syntax(record::syntax::XML)); + prefixQuery pq(argv[4]); + resultSet rs(conn, pq); + + size_t n = rs.size(); + std::cout << "found " << n << " records:\n"; + for (size_t i = 0; i < n; i++) { + const record rec(rs, i); + std::cout << "=== record " << i+1 << + " (record-syntax " << (std::string) rec.recsyn() << ")" << + " ===\n" << rec.render(); + } } catch(bib1Exception& err) { - std::cerr << argv[0] << ": bib1Exception " << - err.errmsg() << " (" << err.addinfo() << ")\n"; - return 2; + std::cerr << argv[0] << ": bib1Exception " << + err.errmsg() << " (" << err.addinfo() << ")\n"; + return 2; } catch(ZOOM::exception& err) { - std::cerr << argv[0] << ": exception " << - err.errmsg() << "\n"; - return 3; + std::cerr << argv[0] << ": exception " << + err.errmsg() << "\n"; + return 3; } return 0; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/zconn.cpp b/zoom/zconn.cpp index 4edb20c..8d9e88c 100644 --- a/zoom/zconn.cpp +++ b/zoom/zconn.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zconn.cpp,v 1.8 2005-05-03 16:29:52 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zconn.cpp,v 1.9 2005-06-25 15:53:21 adam Exp $ // Z39.50 Connection class @@ -7,43 +7,51 @@ namespace ZOOM { connection::connection() { - ZOOM_options o = ZOOM_options_create(); - c = ZOOM_connection_create(o); + ZOOM_options o = ZOOM_options_create(); + c = ZOOM_connection_create(o); } void connection::connect(const std::string &hostname, int portnum) { - const char *line_printer_size_hostname = hostname.c_str(); - //###cerr << "opening " << hostname << ":" << portnum << "\n"; - ZOOM_connection_connect(c, line_printer_size_hostname, portnum); - //###cerr << "opened\n"; - - int errcode; - const char *errmsg; // unused: carries same info as `errcode' - const char *addinfo; - if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) { - //###cerr << "oops: no connect, errcode=" << errcode << "\n"; - throw bib1Exception(errcode, addinfo); - } + const char *line_printer_size_hostname = hostname.c_str(); + //###cerr << "opening " << hostname << ":" << portnum << "\n"; + ZOOM_connection_connect(c, line_printer_size_hostname, portnum); + //###cerr << "opened\n"; + + int errcode; + const char *errmsg; // unused: carries same info as `errcode' + const char *addinfo; + if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) { + //###cerr << "oops: no connect, errcode=" << errcode << "\n"; + throw bib1Exception(errcode, addinfo); + } } connection::connection(const std::string &hostname, int portnum) { - ZOOM_options o = ZOOM_options_create(); - c = ZOOM_connection_create(o); - connect(hostname, portnum); + ZOOM_options o = ZOOM_options_create(); + c = ZOOM_connection_create(o); + connect(hostname, portnum); } std::string connection::option(const std::string &key) const { - const char* val = ZOOM_connection_option_get(c, key.c_str()); - return (val) ? val : std::string(); + const char* val = ZOOM_connection_option_get(c, key.c_str()); + return (val) ? val : std::string(); } bool connection::option(const std::string &key, const std::string &val) { - // No way to tell whether ZOOM_connection_option_set() accepts key - ZOOM_connection_option_set(c, key.c_str(), val.c_str()); - return true; + // No way to tell whether ZOOM_connection_option_set() accepts key + ZOOM_connection_option_set(c, key.c_str(), val.c_str()); + return true; } connection::~connection() { - ZOOM_connection_destroy(c); + ZOOM_connection_destroy(c); } } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp index 6a684f0..36fef06 100644 --- a/zoom/zexcept.cpp +++ b/zoom/zexcept.cpp @@ -1,105 +1,113 @@ -// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.10 2003-09-22 12:30:01 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.11 2005-06-25 15:53:21 adam Exp $ // Z39.50 Exception classes #include #include -#include // for strerror(), strlen(), strcpy() +#include // for strerror(), strlen(), strcpy() #include #include "zoom.h" namespace ZOOM { exception::exception(int errcode) { - code = errcode; + code = errcode; } exception::~exception() { - // Nothing to do, but G++ requires this to be explicit anyway + // Nothing to do, but G++ requires this to be explicit anyway } int exception::errcode() const { - return code; + return code; } std::string exception::errmsg() const { - char buf[40]; - sprintf(buf, "error #%d", code); - return buf; + char buf[40]; + sprintf(buf, "error #%d", code); + return buf; } systemException::systemException() : exception(errno){ - code = errno; + code = errno; } std::string systemException::errmsg() const { - // For thread safety on linux (and most unix systems), we need - // to use the reentrant version of the error translation - // function. Microsoft's strerror() is thread safe, since it - // returns a pointer to thread local storage. Unfortunately - // there several different reentrant versions. Here, we check - // for glibc, since we are using gcc. It appears at least the - // current version of gcc has strerror_r() available by - // default. - #ifdef __GLIBC__ - char buf[1024]; - // PJD: result not necessarily equal to buf - const char* result = strerror_r(code, buf, sizeof(buf)); - if (result != 0) - return result; - return exception::errmsg(); - #else - return strerror(code); - #endif + // For thread safety on linux (and most unix systems), we need + // to use the reentrant version of the error translation + // function. Microsoft's strerror() is thread safe, since it + // returns a pointer to thread local storage. Unfortunately + // there several different reentrant versions. Here, we check + // for glibc, since we are using gcc. It appears at least the + // current version of gcc has strerror_r() available by + // default. + #ifdef __GLIBC__ + char buf[1024]; + // PJD: result not necessarily equal to buf + const char* result = strerror_r(code, buf, sizeof(buf)); + if (result != 0) + return result; + return exception::errmsg(); + #else + return strerror(code); + #endif } bib1Exception::bib1Exception(int errcode, const std::string &addinfo) : - exception(errcode), info(addinfo) { - // std::cerr << "WARNING: made bib1Exception(" << errcode << "=" << - // ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n"; + exception(errcode), info(addinfo) { + // std::cerr << "WARNING: made bib1Exception(" << errcode << "=" << + // ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n"; } bib1Exception::~bib1Exception() { - //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n", - //(long) this, code, (long) info, info); - //delete info; - // ### Don't actually do the deletion for now. Exception - // reference semantics are too weird for me to grok so I'm - // doing The Wrong Thing in the knowledge that it will more - // or less work -- it just leaks memory. (Or does it?) + //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n", + //(long) this, code, (long) info, info); + //delete info; + // ### Don't actually do the deletion for now. Exception + // reference semantics are too weird for me to grok so I'm + // doing The Wrong Thing in the knowledge that it will more + // or less work -- it just leaks memory. (Or does it?) } std::string bib1Exception::errmsg() const { - return ZOOM_diag_str(code); + return ZOOM_diag_str(code); } std::string bib1Exception::addinfo() const { - return info; + return info; } queryException::queryException(int qtype, const std::string &source) : - exception(qtype), q(source) {} + exception(qtype), q(source) {} queryException::~queryException() { - //delete q; // ### see comment on bib1Exception destructor + //delete q; // ### see comment on bib1Exception destructor } std::string queryException::errmsg() const { - switch (code) { - case PREFIX: return "bad prefix search"; - case CCL: return "bad CCL search"; - default: break; - } - return "bad search (unknown type)"; + switch (code) { + case PREFIX: return "bad prefix search"; + case CCL: return "bad CCL search"; + default: break; + } + return "bad search (unknown type)"; } std::string queryException::addinfo() const { - return q; + return q; } } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/zquery.cpp b/zoom/zquery.cpp index d2f699d..8bc757a 100644 --- a/zoom/zquery.cpp +++ b/zoom/zquery.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zquery.cpp,v 1.6 2003-09-22 13:01:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zquery.cpp,v 1.7 2005-06-25 15:53:21 adam Exp $ // Z39.50 Query classes @@ -9,13 +9,13 @@ namespace ZOOM { query::query() : q(ZOOM_query_create()) { } query::~query() { - ZOOM_query_destroy(q); + ZOOM_query_destroy(q); } prefixQuery::prefixQuery(const std::string &pqn) { - if (ZOOM_query_prefix(q, pqn.c_str()) == -1) { - throw queryException(queryException::PREFIX, pqn); - } + if (ZOOM_query_prefix(q, pqn.c_str()) == -1) { + throw queryException(queryException::PREFIX, pqn); + } } // The binding specification says we have to have destructors for @@ -39,9 +39,17 @@ namespace ZOOM { CCLQuery::CCLQuery(const std::string &, void *) { - throw "Oops. No CCL support in ZOOM-C yet. Sorry."; + throw "Oops. No CCL support in ZOOM-C yet. Sorry."; } CCLQuery::~CCLQuery() { } } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/zrec.cpp b/zoom/zrec.cpp index 38cce34..f43662e 100644 --- a/zoom/zrec.cpp +++ b/zoom/zrec.cpp @@ -1,57 +1,57 @@ -// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.7 2003-09-22 13:06:27 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.8 2005-06-25 15:53:21 adam Exp $ // Z39.50 Record class #include "zoom.h" -#include // for yaz_matchstr() +#include // for yaz_matchstr() namespace ZOOM { record::syntax::syntax (value rs): val(rs) {} record::syntax::operator std::string() const { - switch (val) { - case GRS1: return "grs1"; - case SUTRS: return "sutrs"; - case USMARC: return "usmarc"; - case UKMARC: return "ukmarc"; - case XML: return "xml"; - default: break; - } - return "unknown"; + switch (val) { + case GRS1: return "grs1"; + case SUTRS: return "sutrs"; + case USMARC: return "usmarc"; + case UKMARC: return "ukmarc"; + case XML: return "xml"; + default: break; + } + return "unknown"; } bool record::syntax::operator==(const record::syntax &s) const { - return s.val == val; + return s.val == val; } bool record::syntax::operator==(record::syntax::value rs) const { - return rs == val; + return rs == val; } record::syntax::operator record::syntax::value() const { - return val; + return val; } record::record(resultSet &rs, size_t i): owner(rs) { - if ((r = ZOOM_resultset_record(rs._getYazResultSet(), i)) == 0) { - const char *errmsg; // unused: carries same info as `errcode' - const char *addinfo; - int errcode = ZOOM_connection_error(rs._getYazConnection(), - &errmsg, &addinfo); - throw bib1Exception(errcode, addinfo); - } - - // Memory management is odd here. The ZOOM-C record we've - // just fetched (`r') is owned by the ZOOM-C result-set we - // fetched it from (`rs.rs'), so the underlying (ZOOM-C) - // record is _not_ destroyed when this object is destroyed: - // it's done when the underlying result-set is deleted. + if ((r = ZOOM_resultset_record(rs._getYazResultSet(), i)) == 0) { + const char *errmsg; // unused: carries same info as `errcode' + const char *addinfo; + int errcode = ZOOM_connection_error(rs._getYazConnection(), + &errmsg, &addinfo); + throw bib1Exception(errcode, addinfo); + } + + // Memory management is odd here. The ZOOM-C record we've + // just fetched (`r') is owned by the ZOOM-C result-set we + // fetched it from (`rs.rs'), so the underlying (ZOOM-C) + // record is _not_ destroyed when this object is destroyed: + // it's done when the underlying result-set is deleted. } record::~record() { - // Nothing to do -- see comment in constructor + // Nothing to do -- see comment in constructor } // It's tempting to modify this method just to return either the @@ -61,36 +61,44 @@ namespace ZOOM { // if we did that. // record::syntax record::recsyn() const { - const char *syn = ZOOM_record_get(r, "syntax", 0); - - // These string constants are from yaz/util/oid.c - if (!yaz_matchstr(syn, "xml")) - return syntax::XML; - else if (!yaz_matchstr(syn, "GRS-1")) - return syntax::GRS1; - else if (!yaz_matchstr(syn, "SUTRS")) - return syntax::SUTRS; - else if (!yaz_matchstr(syn, "USmarc")) - return syntax::USMARC; - else if (!yaz_matchstr(syn, "UKmarc")) - return syntax::UKMARC; - else if (!yaz_matchstr(syn, "XML") || - !yaz_matchstr(syn, "text-XML") || - !yaz_matchstr(syn, "application-XML")) - return syntax::XML; - - return syntax::UNKNOWN; + const char *syn = ZOOM_record_get(r, "syntax", 0); + + // These string constants are from yaz/util/oid.c + if (!yaz_matchstr(syn, "xml")) + return syntax::XML; + else if (!yaz_matchstr(syn, "GRS-1")) + return syntax::GRS1; + else if (!yaz_matchstr(syn, "SUTRS")) + return syntax::SUTRS; + else if (!yaz_matchstr(syn, "USmarc")) + return syntax::USMARC; + else if (!yaz_matchstr(syn, "UKmarc")) + return syntax::UKMARC; + else if (!yaz_matchstr(syn, "XML") || + !yaz_matchstr(syn, "text-XML") || + !yaz_matchstr(syn, "application-XML")) + return syntax::XML; + + return syntax::UNKNOWN; } std::string record::render() const { - int len; - const char* data = ZOOM_record_get(r, "render", &len); - return std::string(data, len); + int len; + const char* data = ZOOM_record_get(r, "render", &len); + return std::string(data, len); } std::string record::rawdata() const { - int len; - const char* data = ZOOM_record_get(r, "raw", &len); - return std::string(data, len); + int len; + const char* data = ZOOM_record_get(r, "raw", &len); + return std::string(data, len); } } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/zoom/zrs.cpp b/zoom/zrs.cpp index aa8ae41..b33e27c 100644 --- a/zoom/zrs.cpp +++ b/zoom/zrs.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zrs.cpp,v 1.6 2003-09-22 13:04:52 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zrs.cpp,v 1.7 2005-06-25 15:53:21 adam Exp $ // Z39.50 Result Set class @@ -7,32 +7,40 @@ namespace ZOOM { resultSet::resultSet(connection &c, const query &q) : owner(c) { - ZOOM_connection yazc = c._getYazConnection(); - rs = ZOOM_connection_search(yazc, q._getYazQuery()); - int errcode; - const char *errmsg; // unused: carries same info as `errcode' - const char *addinfo; - - if ((errcode = ZOOM_connection_error(yazc, &errmsg, &addinfo)) != 0) { - ZOOM_resultset_destroy(rs); - throw bib1Exception(errcode, addinfo); - } + ZOOM_connection yazc = c._getYazConnection(); + rs = ZOOM_connection_search(yazc, q._getYazQuery()); + int errcode; + const char *errmsg; // unused: carries same info as `errcode' + const char *addinfo; + + if ((errcode = ZOOM_connection_error(yazc, &errmsg, &addinfo)) != 0) { + ZOOM_resultset_destroy(rs); + throw bib1Exception(errcode, addinfo); + } } resultSet::~resultSet() { - ZOOM_resultset_destroy(rs); + ZOOM_resultset_destroy(rs); } std::string resultSet::option(const std::string &key) const { - return ZOOM_resultset_option_get(rs, key.c_str()); + return ZOOM_resultset_option_get(rs, key.c_str()); } bool resultSet::option(const std::string &key, const std::string &val) { ZOOM_resultset_option_set(rs, key.c_str(), val.c_str()); - return true; + return true; } size_t resultSet::size() const { - return ZOOM_resultset_size(rs); + return ZOOM_resultset_size(rs); } } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + -- 1.7.10.4