2 * Copyright (c) 1998-2000, Index Data.
3 * See the file LICENSE for details.
5 * $Log: yaz-ir-assoc.cpp,v $
6 * Revision 1.16 2001-08-13 16:39:12 adam
7 * PDU_Assoc keeps track of children. Using yaz_log instead of logf.
9 * Revision 1.15 2001/04/26 12:17:49 heikki
10 * Ursula stuff, mostly in the test client
12 * Revision 1.14 2000/10/11 11:58:16 adam
13 * Moved header files to include/yaz++. Switched to libtool and automake.
14 * Configure script creates yaz++-config script.
16 * Revision 1.13 2000/09/06 14:23:45 adam
19 * Revision 1.12 2000/05/10 11:36:58 ian
20 * Added default parameters for refid to request functions.
21 * Added default parameter for result set name to search and present request.
22 * Commented out forced logging of PDU contents.
23 * Added send_deleteResultSetRequest
25 * Revision 1.11 1999/12/06 13:52:45 adam
26 * Modified for new location of YAZ header files. Experimental threaded
29 * Revision 1.10 1999/04/29 07:33:28 adam
30 * Changed setting of host in connect/proxy setting. YAZ' strtoaddr now
31 * ignores database part of host.
33 * Revision 1.9 1999/04/28 13:29:14 adam
34 * Yet another fix regarding database settings.
36 * Revision 1.8 1999/04/28 13:04:03 adam
37 * Fixed setting of proxy otherInfo so that database(s) are removed.
39 * Revision 1.7 1999/04/21 12:09:01 adam
40 * Many improvements. Modified to proxy server to work with "sessions"
43 * Revision 1.6 1999/04/20 10:30:05 adam
44 * Implemented various stuff for client and proxy. Updated calls
45 * to ODR to reflect new name parameter.
47 * Revision 1.5 1999/04/09 11:46:57 adam
48 * Added object Yaz_Z_Assoc. Much more functional client.
54 #include <yaz++/yaz-ir-assoc.h>
56 Yaz_IR_Assoc::Yaz_IR_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
57 : Yaz_Z_Assoc(the_PDU_Observable)
59 m_num_databaseNames = 0;
61 m_preferredRecordSyntax = VAL_NONE;
62 m_elementSetNames = 0;
68 const char *db = "Default";
69 set_databaseNames(1, &db);
72 Yaz_IR_Assoc::~Yaz_IR_Assoc()
74 if (m_elementSetNames)
75 delete [] m_elementSetNames->u.generic;
76 delete [] m_elementSetNames;
82 void Yaz_IR_Assoc::get_databaseNames (int *num, char ***list)
84 *num = m_num_databaseNames;
85 *list = m_databaseNames;
89 void Yaz_IR_Assoc::set_databaseNames (int num, const char **list)
92 yaz_log (m_log, "Yaz_IR_Assoc::set_databaseNames num=%d", num);
93 for (i = 0; i<m_num_databaseNames; i++)
94 delete [] m_databaseNames[i];
95 delete [] m_databaseNames;
96 m_num_databaseNames = num;
98 m_databaseNames = new char *[num];
99 for (i = 0; i<m_num_databaseNames; i++)
101 m_databaseNames[i] = new char[strlen(list[i])+1];
102 strcpy(m_databaseNames[i], list[i]);
106 void Yaz_IR_Assoc::set_databaseNames(const char *dblist, const char *sep)
108 const char **list = new const char* [strlen(dblist)];
109 char *dbtmp = new char[strlen(dblist)+1];
110 strcpy(dbtmp, dblist);
113 for (char *cp = dbtmp; ; cp++)
114 if (*cp && !strchr(sep, *cp))
120 list[num] = cp - len;
128 set_databaseNames (num, list);
133 void Yaz_IR_Assoc::set_preferredRecordSyntax (int value)
135 m_preferredRecordSyntax = value;
138 void Yaz_IR_Assoc::set_preferredRecordSyntax (const char *syntax)
140 m_preferredRecordSyntax = VAL_NONE;
141 if (syntax && *syntax)
142 m_preferredRecordSyntax = oid_getvalbyname (syntax);
145 void Yaz_IR_Assoc::get_preferredRecordSyntax (int *value)
147 *value = m_preferredRecordSyntax;
150 void Yaz_IR_Assoc::get_preferredRecordSyntax (const char **dst)
153 ent.proto = PROTO_Z3950;
154 ent.oclass = CLASS_RECSYN;
155 ent.value = (enum oid_value) m_preferredRecordSyntax;
158 oid_ent_to_oid (&ent, oid);
159 struct oident *entp = oid_getentbyoid (oid);
161 *dst = entp ? entp->desc : "";
164 void Yaz_IR_Assoc::set_elementSetName (const char *elementSetName)
166 if (m_elementSetNames)
167 delete [] m_elementSetNames->u.generic;
168 delete m_elementSetNames;
169 m_elementSetNames = 0;
170 if (elementSetName && *elementSetName)
172 m_elementSetNames = new Z_ElementSetNames;
173 m_elementSetNames->which = Z_ElementSetNames_generic;
174 m_elementSetNames->u.generic = new char[strlen(elementSetName)+1];
175 strcpy (m_elementSetNames->u.generic, elementSetName);
179 void Yaz_IR_Assoc::get_elementSetName (Z_ElementSetNames **elementSetNames)
181 *elementSetNames = m_elementSetNames;
184 void Yaz_IR_Assoc::get_elementSetName (const char **elementSetName)
186 if (!m_elementSetNames ||
187 m_elementSetNames->which != Z_ElementSetNames_generic)
192 *elementSetName = m_elementSetNames->u.generic;
195 void Yaz_IR_Assoc::recv_Z_PDU(Z_APDU *apdu)
197 yaz_log (m_log, "recv_Z_PDU");
198 m_lastReceived = apdu->which;
201 case Z_APDU_initResponse:
202 yaz_log (m_log, "recv InitResponse");
203 recv_initResponse(apdu->u.initResponse);
205 case Z_APDU_initRequest:
206 yaz_log (m_log, "recv InitRequest");
207 recv_initRequest(apdu->u.initRequest);
209 case Z_APDU_searchRequest:
210 yaz_log (m_log, "recv searchRequest");
211 recv_searchRequest(apdu->u.searchRequest);
213 case Z_APDU_searchResponse:
214 yaz_log (m_log, "recv searchResponse");
215 recv_searchResponse(apdu->u.searchResponse);
217 case Z_APDU_presentRequest:
218 yaz_log (m_log, "recv presentRequest");
219 recv_presentRequest(apdu->u.presentRequest);
221 case Z_APDU_presentResponse:
222 yaz_log (m_log, "recv presentResponse");
223 recv_presentResponse(apdu->u.presentResponse);
225 case Z_APDU_extendedServicesResponse:
226 yaz_log (m_log, "recv extendedServiceResponse");
227 recv_extendedServicesResponse(apdu->u.extendedServicesResponse);
232 int Yaz_IR_Assoc::send_searchRequest(Yaz_Z_Query *query,
236 Z_APDU *apdu = create_Z_PDU(Z_APDU_searchRequest);
237 Z_SearchRequest *req = apdu->u.searchRequest;
240 req->query = query->get_Z_Query();
243 get_databaseNames (&req->num_databaseNames, &req->databaseNames);
244 int oid_syntax[OID_SIZE];
246 get_preferredRecordSyntax(&recordSyntax);
247 if (recordSyntax != VAL_NONE)
249 prefsyn.proto = PROTO_Z3950;
250 prefsyn.oclass = CLASS_RECSYN;
251 prefsyn.value = (enum oid_value) recordSyntax;
252 oid_ent_to_oid(&prefsyn, oid_syntax);
253 req->preferredRecordSyntax = oid_syntax;
255 yaz_log (m_log, "send_searchRequest");
256 assert (req->otherInfo == 0);
259 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
260 assert (req->otherInfo);
265 req->referenceId = getRefID(pRefId);
270 req->resultSetName = pResultSetId;
273 return send_Z_PDU(apdu);
276 int Yaz_IR_Assoc::send_presentRequest(int start,
281 Z_APDU *apdu = create_Z_PDU(Z_APDU_presentRequest);
282 Z_PresentRequest *req = apdu->u.presentRequest;
284 req->resultSetStartPoint = &start;
285 req->numberOfRecordsRequested = &number;
287 int oid_syntax[OID_SIZE];
290 get_preferredRecordSyntax (&recordSyntax);
291 if (recordSyntax != VAL_NONE)
293 prefsyn.proto = PROTO_Z3950;
294 prefsyn.oclass = CLASS_RECSYN;
295 prefsyn.value = (enum oid_value) recordSyntax;
296 oid_ent_to_oid(&prefsyn, oid_syntax);
297 req->preferredRecordSyntax = oid_syntax;
299 Z_RecordComposition compo;
300 Z_ElementSetNames *elementSetNames;
301 get_elementSetName (&elementSetNames);
304 req->recordComposition = &compo;
305 compo.which = Z_RecordComp_simple;
306 compo.u.simple = elementSetNames;
310 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
314 req->referenceId = getRefID(pRefId);
319 req->resultSetId = pResultSetId;
322 return send_Z_PDU(apdu);
325 void Yaz_IR_Assoc::set_proxy(const char *str)
331 m_proxy = new char[strlen(str)+1];
332 strcpy (m_proxy, str);
336 void Yaz_IR_Assoc::set_cookie(const char *str)
342 m_cookie = new char[strlen(str)+1];
343 strcpy(m_cookie, str);
347 const char *Yaz_IR_Assoc::get_cookie()
352 void Yaz_IR_Assoc::client(const char *addr)
355 m_host = new char[strlen(addr)+1];
356 strcpy(m_host, addr);
357 const char *dbpart = strchr(m_host, '/');
359 set_databaseNames (dbpart+1, "+ ");
360 Yaz_Z_Assoc::client(m_proxy ? m_proxy : m_host);
363 const char *Yaz_IR_Assoc::get_proxy()
368 const char *Yaz_IR_Assoc::get_host()
373 void Yaz_IR_Assoc::recv_searchRequest(Z_SearchRequest *searchRequest)
375 Z_APDU *apdu = create_Z_PDU(Z_APDU_searchResponse);
379 void Yaz_IR_Assoc::recv_presentRequest(Z_PresentRequest *presentRequest)
381 Z_APDU *apdu = create_Z_PDU(Z_APDU_presentResponse);
385 void Yaz_IR_Assoc::recv_initRequest(Z_InitRequest *initRequest)
387 Z_APDU *apdu = create_Z_PDU(Z_APDU_initResponse);
391 void Yaz_IR_Assoc::recv_searchResponse (Z_SearchResponse *searchResponse)
395 void Yaz_IR_Assoc::recv_presentResponse (Z_PresentResponse *presentResponse)
399 void Yaz_IR_Assoc::recv_initResponse(Z_InitResponse *initResponse)
403 void Yaz_IR_Assoc::recv_extendedServicesResponse(Z_ExtendedServicesResponse *ExtendedServicesResponse)
407 int Yaz_IR_Assoc::get_lastReceived()
409 return m_lastReceived;
412 void Yaz_IR_Assoc::set_lastReceived(int lastReceived)
414 m_lastReceived = lastReceived;
417 int Yaz_IR_Assoc::send_initRequest(char* pRefId)
419 Z_APDU *apdu = create_Z_PDU(Z_APDU_initRequest);
420 Z_InitRequest *req = apdu->u.initRequest;
422 ODR_MASK_SET(req->options, Z_Options_search);
423 ODR_MASK_SET(req->options, Z_Options_present);
424 ODR_MASK_SET(req->options, Z_Options_namedResultSets);
425 ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
426 ODR_MASK_SET(req->options, Z_Options_scan);
427 ODR_MASK_SET(req->options, Z_Options_sort);
428 ODR_MASK_SET(req->options, Z_Options_extendedServices);
429 ODR_MASK_SET(req->options, Z_Options_delSet);
431 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
432 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
433 ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
437 req->referenceId = getRefID(pRefId);
440 if (m_proxy && m_host)
441 set_otherInformationString(&req->otherInfo, VAL_PROXY, 1, m_host);
443 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
444 return send_Z_PDU(apdu);
447 int Yaz_IR_Assoc::send_deleteResultSetRequest(char* pResultSetId, char* pRefId)
449 char* ResultSetIds[1];
451 Z_APDU *apdu = create_Z_PDU(Z_APDU_deleteResultSetRequest);
452 Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
456 *req->deleteFunction = Z_DeleteResultSetRequest_list;
457 req->num_resultSetList = 1;
458 ResultSetIds[0] = pResultSetId;
459 req->resultSetList = ResultSetIds;
463 *req->deleteFunction = Z_DeleteResultSetRequest_all;
468 req->referenceId = getRefID(pRefId);
471 if (m_proxy && m_host)
472 set_otherInformationString(&req->otherInfo, VAL_PROXY, 1, m_host);
474 set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie);
477 return send_Z_PDU(apdu);