2 * Copyright (c) 1998-2000, Index Data.
3 * See the file LICENSE for details.
5 * $Log: yaz-ir-assoc.cpp,v $
6 * Revision 1.15 2001-04-26 12:17:49 heikki
7 * Ursula stuff, mostly in the test client
9 * Revision 1.14 2000/10/11 11:58:16 adam
10 * Moved header files to include/yaz++. Switched to libtool and automake.
11 * Configure script creates yaz++-config script.
13 * Revision 1.13 2000/09/06 14:23:45 adam
16 * Revision 1.12 2000/05/10 11:36:58 ian
17 * Added default parameters for refid to request functions.
18 * Added default parameter for result set name to search and present request.
19 * Commented out forced logging of PDU contents.
20 * Added send_deleteResultSetRequest
22 * Revision 1.11 1999/12/06 13:52:45 adam
23 * Modified for new location of YAZ header files. Experimental threaded
26 * Revision 1.10 1999/04/29 07:33:28 adam
27 * Changed setting of host in connect/proxy setting. YAZ' strtoaddr now
28 * ignores database part of host.
30 * Revision 1.9 1999/04/28 13:29:14 adam
31 * Yet another fix regarding database settings.
33 * Revision 1.8 1999/04/28 13:04:03 adam
34 * Fixed setting of proxy otherInfo so that database(s) are removed.
36 * Revision 1.7 1999/04/21 12:09:01 adam
37 * Many improvements. Modified to proxy server to work with "sessions"
40 * Revision 1.6 1999/04/20 10:30:05 adam
41 * Implemented various stuff for client and proxy. Updated calls
42 * to ODR to reflect new name parameter.
44 * Revision 1.5 1999/04/09 11:46:57 adam
45 * Added object Yaz_Z_Assoc. Much more functional client.
51 #include <yaz++/yaz-ir-assoc.h>
53 Yaz_IR_Assoc::Yaz_IR_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
54 : Yaz_Z_Assoc(the_PDU_Observable)
56 m_num_databaseNames = 0;
58 m_preferredRecordSyntax = VAL_NONE;
59 m_elementSetNames = 0;
65 const char *db = "Default";
66 set_databaseNames(1, &db);
69 Yaz_IR_Assoc::~Yaz_IR_Assoc()
71 if (m_elementSetNames)
72 delete [] m_elementSetNames->u.generic;
73 delete [] m_elementSetNames;
79 void Yaz_IR_Assoc::get_databaseNames (int *num, char ***list)
81 *num = m_num_databaseNames;
82 *list = m_databaseNames;
86 void Yaz_IR_Assoc::set_databaseNames (int num, const char **list)
89 logf (m_log, "Yaz_IR_Assoc::set_databaseNames num=%d", num);
90 for (i = 0; i<m_num_databaseNames; i++)
91 delete [] m_databaseNames[i];
92 delete [] m_databaseNames;
93 m_num_databaseNames = num;
95 m_databaseNames = new char *[num];
96 for (i = 0; i<m_num_databaseNames; i++)
98 m_databaseNames[i] = new char[strlen(list[i])+1];
99 strcpy(m_databaseNames[i], list[i]);
103 void Yaz_IR_Assoc::set_databaseNames(const char *dblist, const char *sep)
105 const char **list = new const char* [strlen(dblist)];
106 char *dbtmp = new char[strlen(dblist)+1];
107 strcpy(dbtmp, dblist);
110 for (char *cp = dbtmp; ; cp++)
111 if (*cp && !strchr(sep, *cp))
117 list[num] = cp - len;
125 set_databaseNames (num, list);
130 void Yaz_IR_Assoc::set_preferredRecordSyntax (int value)
132 m_preferredRecordSyntax = value;
135 void Yaz_IR_Assoc::set_preferredRecordSyntax (const char *syntax)
137 m_preferredRecordSyntax = VAL_NONE;
138 if (syntax && *syntax)
139 m_preferredRecordSyntax = oid_getvalbyname (syntax);
142 void Yaz_IR_Assoc::get_preferredRecordSyntax (int *value)
144 *value = m_preferredRecordSyntax;
147 void Yaz_IR_Assoc::get_preferredRecordSyntax (const char **dst)
150 ent.proto = PROTO_Z3950;
151 ent.oclass = CLASS_RECSYN;
152 ent.value = (enum oid_value) m_preferredRecordSyntax;
155 oid_ent_to_oid (&ent, oid);
156 struct oident *entp = oid_getentbyoid (oid);
158 *dst = entp ? entp->desc : "";
161 void Yaz_IR_Assoc::set_elementSetName (const char *elementSetName)
163 if (m_elementSetNames)
164 delete [] m_elementSetNames->u.generic;
165 delete m_elementSetNames;
166 m_elementSetNames = 0;
167 if (elementSetName && *elementSetName)
169 m_elementSetNames = new Z_ElementSetNames;
170 m_elementSetNames->which = Z_ElementSetNames_generic;
171 m_elementSetNames->u.generic = new char[strlen(elementSetName)+1];
172 strcpy (m_elementSetNames->u.generic, elementSetName);
176 void Yaz_IR_Assoc::get_elementSetName (Z_ElementSetNames **elementSetNames)
178 *elementSetNames = m_elementSetNames;
181 void Yaz_IR_Assoc::get_elementSetName (const char **elementSetName)
183 if (!m_elementSetNames ||
184 m_elementSetNames->which != Z_ElementSetNames_generic)
189 *elementSetName = m_elementSetNames->u.generic;
192 void Yaz_IR_Assoc::recv_Z_PDU(Z_APDU *apdu)
194 logf (m_log, "recv_Z_PDU");
195 m_lastReceived = apdu->which;
198 case Z_APDU_initResponse:
199 logf (m_log, "recv InitResponse");
200 recv_initResponse(apdu->u.initResponse);
202 case Z_APDU_initRequest:
203 logf (m_log, "recv InitRequest");
204 recv_initRequest(apdu->u.initRequest);
206 case Z_APDU_searchRequest:
207 logf (m_log, "recv searchRequest");
208 recv_searchRequest(apdu->u.searchRequest);
210 case Z_APDU_searchResponse:
211 logf (m_log, "recv searchResponse");
212 recv_searchResponse(apdu->u.searchResponse);
214 case Z_APDU_presentRequest:
215 logf (m_log, "recv presentRequest");
216 recv_presentRequest(apdu->u.presentRequest);
218 case Z_APDU_presentResponse:
219 logf (m_log, "recv presentResponse");
220 recv_presentResponse(apdu->u.presentResponse);
222 case Z_APDU_extendedServicesResponse:
223 logf (m_log, "recv extendedServiceResponse");
224 recv_extendedServicesResponse(apdu->u.extendedServicesResponse);
229 int Yaz_IR_Assoc::send_searchRequest(Yaz_Z_Query *query,
233 Z_APDU *apdu = create_Z_PDU(Z_APDU_searchRequest);
234 Z_SearchRequest *req = apdu->u.searchRequest;
237 req->query = query->get_Z_Query();
240 get_databaseNames (&req->num_databaseNames, &req->databaseNames);
241 int oid_syntax[OID_SIZE];
243 get_preferredRecordSyntax(&recordSyntax);
244 if (recordSyntax != VAL_NONE)
246 prefsyn.proto = PROTO_Z3950;
247 prefsyn.oclass = CLASS_RECSYN;
248 prefsyn.value = (enum oid_value) recordSyntax;
249 oid_ent_to_oid(&prefsyn, oid_syntax);
250 req->preferredRecordSyntax = oid_syntax;
252 logf (m_log, "send_searchRequest");
253 assert (req->otherInfo == 0);
256 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
257 assert (req->otherInfo);
262 req->referenceId = getRefID(pRefId);
267 req->resultSetName = pResultSetId;
270 return send_Z_PDU(apdu);
273 int Yaz_IR_Assoc::send_presentRequest(int start,
278 Z_APDU *apdu = create_Z_PDU(Z_APDU_presentRequest);
279 Z_PresentRequest *req = apdu->u.presentRequest;
281 req->resultSetStartPoint = &start;
282 req->numberOfRecordsRequested = &number;
284 int oid_syntax[OID_SIZE];
287 get_preferredRecordSyntax (&recordSyntax);
288 if (recordSyntax != VAL_NONE)
290 prefsyn.proto = PROTO_Z3950;
291 prefsyn.oclass = CLASS_RECSYN;
292 prefsyn.value = (enum oid_value) recordSyntax;
293 oid_ent_to_oid(&prefsyn, oid_syntax);
294 req->preferredRecordSyntax = oid_syntax;
296 Z_RecordComposition compo;
297 Z_ElementSetNames *elementSetNames;
298 get_elementSetName (&elementSetNames);
301 req->recordComposition = &compo;
302 compo.which = Z_RecordComp_simple;
303 compo.u.simple = elementSetNames;
307 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
311 req->referenceId = getRefID(pRefId);
316 req->resultSetId = pResultSetId;
319 return send_Z_PDU(apdu);
322 void Yaz_IR_Assoc::set_proxy(const char *str)
328 m_proxy = new char[strlen(str)+1];
329 strcpy (m_proxy, str);
333 void Yaz_IR_Assoc::set_cookie(const char *str)
339 m_cookie = new char[strlen(str)+1];
340 strcpy(m_cookie, str);
344 const char *Yaz_IR_Assoc::get_cookie()
349 void Yaz_IR_Assoc::client(const char *addr)
352 m_host = new char[strlen(addr)+1];
353 strcpy(m_host, addr);
354 const char *dbpart = strchr(m_host, '/');
356 set_databaseNames (dbpart+1, "+ ");
357 Yaz_Z_Assoc::client(m_proxy ? m_proxy : m_host);
360 const char *Yaz_IR_Assoc::get_proxy()
365 const char *Yaz_IR_Assoc::get_host()
370 void Yaz_IR_Assoc::recv_searchRequest(Z_SearchRequest *searchRequest)
372 Z_APDU *apdu = create_Z_PDU(Z_APDU_searchResponse);
376 void Yaz_IR_Assoc::recv_presentRequest(Z_PresentRequest *presentRequest)
378 Z_APDU *apdu = create_Z_PDU(Z_APDU_presentResponse);
382 void Yaz_IR_Assoc::recv_initRequest(Z_InitRequest *initRequest)
384 Z_APDU *apdu = create_Z_PDU(Z_APDU_initResponse);
388 void Yaz_IR_Assoc::recv_searchResponse (Z_SearchResponse *searchResponse)
392 void Yaz_IR_Assoc::recv_presentResponse (Z_PresentResponse *presentResponse)
396 void Yaz_IR_Assoc::recv_initResponse(Z_InitResponse *initResponse)
400 void Yaz_IR_Assoc::recv_extendedServicesResponse(Z_ExtendedServicesResponse *ExtendedServicesResponse)
404 int Yaz_IR_Assoc::get_lastReceived()
406 return m_lastReceived;
409 void Yaz_IR_Assoc::set_lastReceived(int lastReceived)
411 m_lastReceived = lastReceived;
414 int Yaz_IR_Assoc::send_initRequest(char* pRefId)
416 Z_APDU *apdu = create_Z_PDU(Z_APDU_initRequest);
417 Z_InitRequest *req = apdu->u.initRequest;
419 ODR_MASK_SET(req->options, Z_Options_search);
420 ODR_MASK_SET(req->options, Z_Options_present);
421 ODR_MASK_SET(req->options, Z_Options_namedResultSets);
422 ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
423 ODR_MASK_SET(req->options, Z_Options_scan);
424 ODR_MASK_SET(req->options, Z_Options_sort);
425 ODR_MASK_SET(req->options, Z_Options_extendedServices);
426 ODR_MASK_SET(req->options, Z_Options_delSet);
428 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
429 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
430 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
434 req->referenceId = getRefID(pRefId);
437 if (m_proxy && m_host)
438 set_otherInformationString(&req->otherInfo, VAL_PROXY, 1, m_host);
440 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
441 return send_Z_PDU(apdu);
444 int Yaz_IR_Assoc::send_deleteResultSetRequest(char* pResultSetId, char* pRefId)
446 char* ResultSetIds[1];
448 Z_APDU *apdu = create_Z_PDU(Z_APDU_deleteResultSetRequest);
449 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
453 *req->deleteFunction = Z_DeleteResultSetRequest_list;
454 req->num_resultSetList = 1;
455 ResultSetIds[0] = pResultSetId;
456 req->resultSetList = ResultSetIds;
460 *req->deleteFunction = Z_DeleteResultSetRequest_all;
465 req->referenceId = getRefID(pRefId);
468 if (m_proxy && m_host)
469 set_otherInformationString(&req->otherInfo, VAL_PROXY, 1, m_host);
471 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
474 return send_Z_PDU(apdu);