2 * Copyright (c) 2000-2001, Index Data.
3 * See the file LICENSE for details.
5 * $Log: yaz-z-server.cpp,v $
6 * Revision 1.11 2001-04-12 15:12:10 heikki
9 * Revision 1.10 2001/04/04 14:02:49 adam
10 * URSULA / Z-ruth service.
12 * Revision 1.9 2001/03/29 15:14:26 adam
15 * Revision 1.8 2001/03/27 14:47:45 adam
16 * New server facility scheme.
18 * Revision 1.7 2001/03/26 14:43:49 adam
19 * New threaded PDU association.
21 * Revision 1.6 2001/01/29 11:18:24 adam
22 * Server sets OPTIONS search and present.
24 * Revision 1.5 2000/10/24 12:29:57 adam
25 * Fixed bug in proxy where a Yaz_ProxyClient could be owned by
26 * two Yaz_Proxy's (fatal).
28 * Revision 1.4 2000/10/11 11:58:17 adam
29 * Moved header files to include/yaz++. Switched to libtool and automake.
30 * Configure script creates yaz++-config script.
32 * Revision 1.3 2000/09/21 21:43:20 adam
33 * Better high-level server API.
35 * Revision 1.2 2000/09/12 12:09:53 adam
36 * More work on high-level server.
38 * Revision 1.1 2000/09/08 10:23:42 adam
39 * Added skeleton of yaz-z-server.
44 #include <yaz++/yaz-z-server.h>
46 Yaz_Z_Server::Yaz_Z_Server(IYaz_PDU_Observable *the_PDU_Observable)
47 : Yaz_Z_Assoc(the_PDU_Observable)
52 Yaz_Z_Server::~Yaz_Z_Server()
57 void Yaz_Z_Server::facility_reset ()
59 Yaz_Z_Server_Facility_Info *p = m_facilities;
62 Yaz_Z_Server_Facility_Info *p_next = p->m_next;
71 void Yaz_Z_Server::facility_add(IYaz_Server_Facility *facility,
74 Yaz_Z_Server_Facility_Info **p = &m_facilities;
78 *p = new Yaz_Z_Server_Facility_Info;
81 (*p)->m_name = new char [strlen(name)+1];
82 strcpy ((*p)->m_name, name);
83 (*p)->m_facility = facility;
86 void Yaz_Z_Server::recv_Z_PDU (Z_APDU *apdu_request)
88 Yaz_Z_Server_Facility_Info *f = m_facilities;
90 if (apdu_request->which == Z_APDU_initRequest)
92 Z_APDU *apdu_response = create_Z_PDU(Z_APDU_initResponse);
94 Z_InitRequest *req = apdu_request->u.initRequest;
95 Z_InitResponse *resp = apdu_response->u.initResponse;
97 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1))
99 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1);
101 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2))
103 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2);
105 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3))
107 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3);
111 f->m_facility->init(this, req, resp);
114 send_Z_PDU(apdu_response);
122 taken = f->m_facility->recv(this, apdu_request);
129 yaz_log (LOG_LOG, "unhandled request = %d", apdu_request->which);
138 void Yaz_Z_ServerUtility::create_databaseRecord (
139 ODR odr, Z_NamePlusRecord *rec, const char *dbname, int format,
140 const void *buf, int len)
142 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
143 rec->which = Z_NamePlusRecord_databaseRecord;
144 rec->u.databaseRecord = z_ext_record (odr, format,
145 (const char *) buf, len);
149 * surrogate diagnostic.
151 void Yaz_Z_ServerUtility::create_surrogateDiagnostics(
152 ODR odr, Z_NamePlusRecord *rec, const char *dbname,
153 int error, char *const addinfo)
156 int *err = (int *)odr_malloc (odr, sizeof(*err));
158 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (odr, sizeof(*drec));
159 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
160 odr_malloc (odr, sizeof(*dr));
162 bib1.proto = PROTO_Z3950;
163 bib1.oclass = CLASS_DIAGSET;
164 bib1.value = VAL_BIB1;
166 yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
168 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
169 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
170 rec->u.surrogateDiagnostic = drec;
171 drec->which = Z_DiagRec_defaultFormat;
172 drec->u.defaultFormat = dr;
173 dr->diagnosticSetId = odr_oiddup (odr,
174 oid_ent_to_oid(&bib1, oid));
176 dr->which = Z_DefaultDiagFormat_v2Addinfo;
177 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
180 Z_Records *Yaz_Z_ServerUtility::create_nonSurrogateDiagnostics (
181 ODR odr, int error, const char *addinfo)
184 Z_Records *rec = (Z_Records *)
185 odr_malloc (odr, sizeof(*rec));
188 odr_malloc (odr, sizeof(*err));
189 Z_DiagRec *drec = (Z_DiagRec *)
190 odr_malloc (odr, sizeof(*drec));
191 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
192 odr_malloc (odr, sizeof(*dr));
194 bib1.proto = PROTO_Z3950;
195 bib1.oclass = CLASS_DIAGSET;
196 bib1.value = VAL_BIB1;
199 rec->which = Z_Records_NSD;
200 rec->u.nonSurrogateDiagnostic = dr;
201 dr->diagnosticSetId =
202 odr_oiddup (odr, oid_ent_to_oid(&bib1, oid));
204 dr->which = Z_DefaultDiagFormat_v2Addinfo;
205 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");