2 * Copyright (c) 1998-2001, Index Data.
3 * See the file LICENSE for details.
5 * $Log: yaz-my-server.cpp,v $
6 * Revision 1.7 2001-08-13 16:39:12 adam
7 * PDU_Assoc keeps track of children. Using yaz_log instead of logf.
9 * Revision 1.6 2001/05/17 14:18:03 adam
10 * New handler for old version item update for server:
11 * void update_service0 (Z_ExtendedServicesRequest *req,
12 * Z_IU0Update *io, Z_ExtendedServicesResponse *res)
14 * Revision 1.5 2001/05/03 12:39:39 adam
15 * Added Update server service.
17 * Revision 1.4 2001/04/05 13:09:44 adam
18 * Removed ursula dependancy.
20 * Revision 1.3 2001/04/04 14:02:49 adam
21 * URSULA / Z-ruth service.
23 * Revision 1.2 2001/03/29 15:14:26 adam
26 * Revision 1.1 2001/03/27 14:47:45 adam
27 * New server facility scheme.
29 * Revision 1.15 2001/03/26 14:43:49 adam
30 * New threaded PDU association.
32 * Revision 1.14 2000/11/01 14:22:59 adam
33 * Added fd parameter for method IYaz_PDU_Observer::clone.
35 * Revision 1.13 2000/10/11 11:58:16 adam
36 * Moved header files to include/yaz++. Switched to libtool and automake.
37 * Configure script creates yaz++-config script.
39 * Revision 1.12 2000/09/21 21:43:20 adam
40 * Better high-level server API.
42 * Revision 1.11 2000/09/12 16:23:49 adam
43 * Updated server example.
45 * Revision 1.10 2000/09/12 16:04:17 adam
46 * Added comstack method for Yaz_PDU_Assoc..
48 * Revision 1.9 2000/09/12 12:09:53 adam
49 * More work on high-level server.
51 * Revision 1.8 2000/09/08 10:23:42 adam
52 * Added skeleton of yaz-z-server.
54 * Revision 1.7 1999/12/06 13:52:45 adam
55 * Modified for new location of YAZ header files. Experimental threaded
58 * Revision 1.6 1999/04/21 12:09:01 adam
59 * Many improvements. Modified to proxy server to work with "sessions"
62 * Revision 1.5 1999/04/09 11:46:57 adam
63 * Added object Yaz_Z_Assoc. Much more functional client.
65 * Revision 1.4 1999/03/23 14:17:57 adam
66 * More work on timeout handling. Work on yaz-client.
68 * Revision 1.3 1999/02/02 14:01:22 adam
69 * First WIN32 port of YAZ++.
71 * Revision 1.2 1999/01/28 13:08:47 adam
72 * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
73 * yaz-socket-manager.cc.
75 * Revision 1.1.1.1 1999/01/28 09:41:07 adam
76 * First implementation of YAZ++.
81 #include <yaz/options.h>
82 #include <yaz++/yaz-z-server.h>
83 #include <yaz++/yaz-pdu-assoc.h>
84 #include <yaz++/yaz-socket-manager.h>
86 class MyILL : public Yaz_Facility_ILL {
88 void ill_service (Z_ExtendedServicesRequest *req,
90 Z_ExtendedServicesResponse *res);
93 class MyUpdate : public Yaz_Facility_Update {
95 void update_service (Z_ExtendedServicesRequest *req,
97 Z_ExtendedServicesResponse *res);
98 void update_service0 (Z_ExtendedServicesRequest *req,
100 Z_ExtendedServicesResponse *res);
104 class MyRetrieval : public Yaz_Facility_Retrieval, Yaz_USMARC {
106 int sr_init (Z_InitRequest *initRequest,
107 Z_InitResponse *initResponse);
108 void sr_search (Z_SearchRequest *searchRequest,
109 Z_SearchResponse *searchResponse);
110 void sr_present (Z_PresentRequest *presentRequest,
111 Z_PresentResponse *presentResponse);
112 void sr_record (const char *resultSetName,
115 Z_RecordComposition *comp,
116 Z_NamePlusRecord *namePlusRecord,
120 #if HAVE_YAZ_URSULA_H
121 class MyUrsula : public Yaz_Facility_Ursula {
123 void ursula_service (Z_ExtendedServicesRequest *req,
125 Z_ExtendedServicesResponse *res);
129 class MyServer : public Yaz_Z_Server {
132 MyServer(IYaz_PDU_Observable *the_PDU_Observable);
133 IYaz_PDU_Observer* sessionNotify(IYaz_PDU_Observable *the_PDU_Observable,
136 void timeoutNotify();
137 void connectNotify();
140 MyRetrieval m_retrieval;
143 #if HAVE_YAZ_URSULA_H
149 void MyILL::ill_service (Z_ExtendedServicesRequest *req,
151 Z_ExtendedServicesResponse *res)
153 yaz_log (LOG_LOG, "MyServer::ill_service");
156 void MyUpdate::update_service (Z_ExtendedServicesRequest *req,
158 Z_ExtendedServicesResponse *res)
160 yaz_log (LOG_LOG, "MyServer::update_service (v1.1)");
163 void MyUpdate::update_service0 (Z_ExtendedServicesRequest *req,
165 Z_ExtendedServicesResponse *res)
167 yaz_log (LOG_LOG, "MyServer::update_service (v1.0)");
170 #if HAVE_YAZ_URSULA_H
171 void MyUrsula::ursula_service (Z_ExtendedServicesRequest *req,
173 Z_ExtendedServicesResponse *res)
175 yaz_log (LOG_LOG, "MyServer::ursula_service");
178 case Z_UrsPDU_request:
179 yaz_log(LOG_LOG, "request");
180 if (u->u.request->libraryNo)
181 yaz_log (LOG_LOG, "libraryNo: %s", u->u.request->libraryNo);
183 case Z_UrsPDU_update:
184 yaz_log(LOG_LOG, "request");
186 case Z_UrsPDU_reservation:
187 yaz_log(LOG_LOG, "request");
189 case Z_UrsPDU_renewal:
190 yaz_log(LOG_LOG, "request");
193 yaz_log(LOG_LOG, "unknown");
199 int MyRetrieval::sr_init (Z_InitRequest *initRequest,
200 Z_InitResponse *initResponse)
202 yaz_log (LOG_LOG, "MyServer::sr_init");
206 void MyRetrieval::sr_search (Z_SearchRequest *searchRequest,
207 Z_SearchResponse *searchResponse)
209 yaz_log (LOG_LOG, "MyServer::recv_Z_search");
210 if (searchRequest->query->which == Z_Query_type_1)
212 Z_RPNStructure *s = searchRequest->query->u.type_1->RPNStructure;
213 if (s->which == Z_RPNStructure_simple &&
214 s->u.simple->which == Z_Operand_APT &&
215 s->u.simple->u.attributesPlusTerm->term->which == Z_Term_general)
217 Odr_oct *term = s->u.simple->u.attributesPlusTerm->term->u.general;
218 char *str = (char *) odr_malloc (odr_encode(), term->len+1);
220 memcpy (str, term->buf, term->len);
221 str[term->len] = '\0';
222 *searchResponse->resultCount = atoi(str);
227 void MyRetrieval::sr_present (Z_PresentRequest *presentRequest,
228 Z_PresentResponse *presentResponse)
230 yaz_log (LOG_LOG, "MyServer::recv_Z_present");
233 void MyRetrieval::sr_record (const char *resultSetName,
236 Z_RecordComposition *comp,
237 Z_NamePlusRecord *namePlusRecord,
240 yaz_log (LOG_LOG, "MyServer::recv_Z_record");
241 const char *rec = get_record(position);
242 create_databaseRecord (odr_encode(), namePlusRecord, 0, VAL_USMARC, rec,
246 MyServer::~MyServer()
250 IYaz_PDU_Observer *MyServer::sessionNotify(
251 IYaz_PDU_Observable *the_PDU_Observable, int fd)
253 MyServer *new_server;
255 new_server = new MyServer(the_PDU_Observable);
256 new_server->timeout(900);
257 new_server->facility_add(&new_server->m_retrieval, "my sr");
258 new_server->facility_add(&new_server->m_ill, "my ill");
259 new_server->facility_add(&new_server->m_update, "my update");
260 #if HAVE_YAZ_URSULA_H
261 new_server->facility_add(&new_server->m_ursula, "my ursula");
264 new_server->set_APDU_log(get_APDU_log());
269 MyServer::MyServer(IYaz_PDU_Observable *the_PDU_Observable) :
270 Yaz_Z_Server (the_PDU_Observable)
275 void MyServer::timeoutNotify()
277 yaz_log (LOG_LOG, "connection timed out");
281 void MyServer::failNotify()
283 yaz_log (LOG_LOG, "connection closed by client");
287 void MyServer::connectNotify()
291 void usage(char *prog)
293 fprintf (stderr, "%s: [-a log] [-v level] [-T] @:port\n", prog);
297 int main(int argc, char **argv)
302 char *addr = "tcp:@:9999";
305 Yaz_SocketManager mySocketManager;
307 Yaz_PDU_Assoc *my_PDU_Assoc = 0;
312 while ((ret = options("a:v:T", argv, argc, &arg)) != -2)
320 apdu_log = xstrdup(arg);
323 yaz_log_init_level (yaz_log_mask_str(arg));
334 my_PDU_Assoc = new Yaz_PDU_AssocThread(&mySocketManager);
336 my_PDU_Assoc = new Yaz_PDU_Assoc(&mySocketManager);
338 z = new MyServer(my_PDU_Assoc);
342 yaz_log (LOG_LOG, "set_APDU_log %s", apdu_log);
343 z->set_APDU_log(apdu_log);
346 while (mySocketManager.processEvent() > 0)