1 /* $Id: client.c,v 1.29 2007-10-08 13:19:23 adam Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 #include <sys/socket.h>
37 #include <yaz/marcdisp.h>
38 #include <yaz/comstack.h>
39 #include <yaz/tcpip.h>
40 #include <yaz/proto.h>
41 #include <yaz/readconf.h>
42 #include <yaz/pquery.h>
43 #include <yaz/otherinfo.h>
44 #include <yaz/yaz-util.h>
46 #include <yaz/query-charset.h>
47 #include <yaz/querytowrbuf.h>
48 #include <yaz/oid_db.h>
49 #include <yaz/diagbib1.h>
57 #include <yaz/timing.h>
60 #include <netinet/in.h>
65 #include "connection.h"
68 /** \brief Represents client state for a connection to one search target */
70 struct session_database *database;
71 struct connection *connection;
72 struct session *session;
73 char *pquery; // Current search
77 int requestid; // ID of current outstanding request
79 enum client_state state;
80 struct show_raw *show_raw;
81 struct client *next; // next client in session or next in free list
85 int active; // whether this request has been sent to the server
90 void (*error_handler)(void *data, const char *addinfo);
91 void (*record_handler)(void *data, const char *buf, size_t sz);
93 struct show_raw *next;
96 static const char *client_states[] = {
100 "Client_Initializing",
105 "Client_Disconnected",
110 static struct client *client_freelist = 0;
112 static int send_apdu(struct client *c, Z_APDU *a)
114 struct session_database *sdb = client_get_database(c);
115 const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
116 if (apdulog && *apdulog && *apdulog != '0')
118 ODR p = odr_createmem(ODR_PRINT);
119 yaz_log(YLOG_LOG, "send APDU %s", client_get_url(c));
121 odr_setprint(p, yaz_log_file());
123 odr_setprint(p, stderr);
126 return connection_send_apdu(client_get_connection(c), a);
130 const char *client_get_state_str(struct client *cl)
132 return client_states[cl->state];
135 enum client_state client_get_state(struct client *cl)
140 void client_set_state(struct client *cl, enum client_state st)
145 int no_active = session_active_clients(cl->session);
147 session_alert_watch(cl->session, SESSION_WATCH_SHOW);
151 static void client_show_raw_error(struct client *cl, const char *addinfo);
153 // Close connection and set state to error
154 void client_fatal(struct client *cl)
156 client_show_raw_error(cl, "client connection failure");
157 yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
158 connection_destroy(cl->connection);
159 client_set_state(cl, Client_Error);
163 static int diag_to_wrbuf(Z_DiagRec **pp, int num, WRBUF w)
167 for (i = 0; i<num; i++)
169 Z_DiagRec *p = pp[i];
172 if (p->which != Z_DiagRec_defaultFormat)
174 wrbuf_puts(w, "? Not in default format");
178 Z_DefaultDiagFormat *r = p->u.defaultFormat;
180 if (!r->diagnosticSetId)
181 wrbuf_puts(w, "? Missing diagset");
185 char diag_name_buf[OID_STR_MAX];
186 const char *diag_name = 0;
187 diag_name = yaz_oid_to_string_buf
188 (r->diagnosticSetId, &oclass, diag_name_buf);
189 wrbuf_puts(w, diag_name);
192 code = *r->condition;
193 wrbuf_printf(w, " %d %s", *r->condition,
194 diagbib1_str(*r->condition));
197 case Z_DefaultDiagFormat_v2Addinfo:
198 wrbuf_printf(w, " -- v2 addinfo '%s'", r->u.v2Addinfo);
200 case Z_DefaultDiagFormat_v3Addinfo:
201 wrbuf_printf(w, " -- v3 addinfo '%s'", r->u.v3Addinfo);
211 struct connection *client_get_connection(struct client *cl)
213 return cl->connection;
216 struct session_database *client_get_database(struct client *cl)
221 struct session *client_get_session(struct client *cl)
226 const char *client_get_pquery(struct client *cl)
231 void client_set_requestid(struct client *cl, int id)
236 int client_show_raw_begin(struct client *cl, int position,
237 const char *syntax, const char *esn,
239 void (*error_handler)(void *data, const char *addinfo),
240 void (*record_handler)(void *data, const char *buf,
245 struct show_raw *rr, **rrp;
247 { /* the client has no connection */
250 rr = xmalloc(sizeof(*rr));
252 rr->position = position;
255 rr->error_handler = error_handler;
256 rr->record_handler = record_handler;
259 rr->syntax = xstrdup(syntax);
263 rr->esn = xstrdup(esn);
268 for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
272 if (cl->state == Client_Failed)
274 client_show_raw_error(cl, "client failed");
276 else if (cl->state == Client_Disconnected)
278 client_show_raw_error(cl, "client disconnected");
287 void client_show_raw_remove(struct client *cl, void *data)
289 struct show_raw *rr = data;
290 struct show_raw **rrp = &cl->show_raw;
300 void client_show_raw_dequeue(struct client *cl)
302 struct show_raw *rr = cl->show_raw;
304 cl->show_raw = rr->next;
308 static void client_show_raw_error(struct client *cl, const char *addinfo)
312 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
313 client_show_raw_dequeue(cl);
317 static void client_show_raw_cancel(struct client *cl)
321 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
322 client_show_raw_dequeue(cl);
326 static void client_present_syntax(Z_APDU *a, const char *syntax)
328 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
329 if (syntax && *syntax)
330 a->u.presentRequest->preferredRecordSyntax =
331 yaz_string_to_oid_odr(yaz_oid_std(),
332 CLASS_RECSYN, syntax,
333 global_parameters.odr_out);
336 static void client_present_elements(Z_APDU *a, const char *elements)
338 if (elements && *elements) // element set is optional
340 Z_ElementSetNames *elementSetNames =
341 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
342 Z_RecordComposition *compo =
343 odr_malloc(global_parameters.odr_out, sizeof(*compo));
344 a->u.presentRequest->recordComposition = compo;
346 compo->which = Z_RecordComp_simple;
347 compo->u.simple = elementSetNames;
349 elementSetNames->which = Z_ElementSetNames_generic;
350 elementSetNames->u.generic =
351 odr_strdup(global_parameters.odr_out, elements);
355 void client_send_raw_present(struct client *cl)
357 struct session_database *sdb = client_get_database(cl);
358 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
360 int start = cl->show_raw->position;
361 const char *syntax = 0;
362 const char *elements = 0;
364 assert(cl->show_raw);
366 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
367 client_get_url(cl), toget, start);
369 a->u.presentRequest->resultSetStartPoint = &start;
370 a->u.presentRequest->numberOfRecordsRequested = &toget;
372 if (cl->show_raw->syntax)
373 syntax = cl->show_raw->syntax;
375 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
377 client_present_syntax(a, syntax);
378 if (cl->show_raw->esn)
379 elements = cl->show_raw->esn;
381 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
382 client_present_elements(a, elements);
384 if (send_apdu(cl, a) >= 0)
386 cl->show_raw->active = 1;
387 cl->state = Client_Presenting;
391 client_show_raw_error(cl, "send_apdu failed");
392 cl->state = Client_Error;
394 odr_reset(global_parameters.odr_out);
397 void client_send_present(struct client *cl)
399 struct session_database *sdb = client_get_database(cl);
400 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
402 int start = cl->records + 1;
403 const char *syntax = 0;
404 const char *elements = 0;
406 toget = global_parameters.chunk;
407 if (toget > global_parameters.toget - cl->records)
408 toget = global_parameters.toget - cl->records;
409 if (toget > cl->hits - cl->records)
410 toget = cl->hits - cl->records;
412 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
415 a->u.presentRequest->resultSetStartPoint = &start;
416 a->u.presentRequest->numberOfRecordsRequested = &toget;
418 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
419 client_present_syntax(a, syntax);
421 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
422 client_present_elements(a, elements);
424 if (send_apdu(cl, a) >= 0)
425 cl->state = Client_Presenting;
427 cl->state = Client_Error;
428 odr_reset(global_parameters.odr_out);
432 void client_send_search(struct client *cl)
434 struct session *se = client_get_session(cl);
435 struct session_database *sdb = client_get_database(cl);
436 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
440 int ssub = 0, lslb = 100000, mspn = 10;
441 const char *piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
442 const char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
444 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
447 // constructing RPN query
448 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
450 zquery->which = Z_Query_type_1;
451 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
452 client_get_pquery(cl));
454 // converting to target encoding
455 if (queryenc && *queryenc)
457 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
459 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
460 global_parameters.odr_out,
462 yaz_iconv_close(iconv);
464 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
465 client_get_database(cl)->database->url, queryenc);
468 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
470 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
471 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
472 databaselist[ndb] = sdb->database->databases[ndb];
474 if (!piggyback || *piggyback == '1')
476 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
477 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
478 if (recsyn && *recsyn)
480 a->u.searchRequest->preferredRecordSyntax =
481 yaz_string_to_oid_odr(yaz_oid_std(),
482 CLASS_RECSYN, recsyn,
483 global_parameters.odr_out);
485 if (elements && *elements)
487 Z_ElementSetNames *esn =
488 odr_malloc(global_parameters.odr_out, sizeof(*esn));
489 esn->which = Z_ElementSetNames_generic;
490 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
492 a->u.searchRequest->smallSetElementSetNames = esn;
493 a->u.searchRequest->mediumSetElementSetNames = esn;
495 a->u.searchRequest->smallSetUpperBound = &ssub;
496 a->u.searchRequest->largeSetLowerBound = &lslb;
497 a->u.searchRequest->mediumSetPresentNumber = &mspn;
499 a->u.searchRequest->databaseNames = databaselist;
500 a->u.searchRequest->num_databaseNames = ndb;
503 { //scope for sending and logging queries
504 WRBUF wbquery = wrbuf_alloc();
505 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
508 if (send_apdu(cl, a) >= 0)
510 client_set_state(cl, Client_Searching);
511 client_set_requestid(cl, se->requestid);
512 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
513 client_get_database(cl)->database->url,
514 queryenc ? queryenc : "UTF-8",
515 wrbuf_cstr(wbquery));
518 client_set_state(cl, Client_Error);
519 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
520 client_get_database(cl)->database->url,
521 queryenc ? queryenc : "UTF-8",
522 wrbuf_cstr(wbquery));
525 wrbuf_destroy(wbquery);
528 odr_reset(global_parameters.odr_out);
531 void client_init_response(struct client *cl, Z_APDU *a)
533 Z_InitResponse *r = a->u.initResponse;
535 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
538 cl->state = Client_Continue;
540 cl->state = Client_Failed; // FIXME need to do something to the connection
544 static void ingest_raw_records(struct client *cl, Z_Records *r)
546 Z_NamePlusRecordList *rlist;
547 Z_NamePlusRecord *npr;
551 if (r->which != Z_Records_DBOSD)
553 client_show_raw_error(cl, "non-surrogate diagnostics");
557 rlist = r->u.databaseOrSurDiagnostics;
558 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
560 client_show_raw_error(cl, "no records");
563 npr = rlist->records[0];
564 if (npr->which != Z_NamePlusRecord_databaseRecord)
566 client_show_raw_error(cl, "surrogate diagnostic");
570 if (cl->show_raw && cl->show_raw->binary)
572 Z_External *rec = npr->u.databaseRecord;
573 if (rec->which == Z_External_octet)
575 cl->show_raw->record_handler(cl->show_raw->data,
577 rec->u.octet_aligned->buf,
578 rec->u.octet_aligned->len);
579 client_show_raw_dequeue(cl);
582 client_show_raw_error(cl, "no records");
585 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
588 client_show_raw_error(cl, "unable to convert record to xml");
592 xmlDocDumpMemory(doc, &buf_out, &len_out);
597 cl->show_raw->record_handler(cl->show_raw->data,
598 (const char *) buf_out, len_out);
599 client_show_raw_dequeue(cl);
604 static void ingest_records(struct client *cl, Z_Records *r)
607 yaz_timing_t t = yaz_timing_create();
610 struct session *s = client_get_session(cl);
611 Z_NamePlusRecordList *rlist;
614 if (r->which != Z_Records_DBOSD)
616 rlist = r->u.databaseOrSurDiagnostics;
617 for (i = 0; i < rlist->num_records; i++)
619 Z_NamePlusRecord *npr = rlist->records[i];
622 if (npr->which != Z_NamePlusRecord_databaseRecord)
625 "Unexpected record type, probably diagnostic %s",
626 cl->database->database->url);
630 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
634 if (rlist->num_records)
635 session_alert_watch(s, SESSION_WATCH_SHOW);
636 if (rlist->num_records)
637 session_alert_watch(s, SESSION_WATCH_RECORD);
641 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
642 yaz_timing_get_real(t), yaz_timing_get_user(t),
643 yaz_timing_get_sys(t));
644 yaz_timing_destroy(&t);
649 void client_search_response(struct client *cl, Z_APDU *a)
651 struct session *se = cl->session;
652 Z_SearchResponse *r = a->u.searchResponse;
654 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
655 cl->database->database->url, *r->searchStatus);
657 if (*r->searchStatus)
659 cl->hits = *r->resultCount;
662 yaz_log(YLOG_WARN, "Target %s returns hit count %d",
663 cl->database->database->url, cl->hits);
666 se->total_hits += cl->hits;
667 if (r->presentStatus && !*r->presentStatus && r->records)
669 yaz_log(YLOG_DEBUG, "Records in search response %s",
670 cl->database->database->url);
671 ingest_records(cl, r->records);
673 cl->state = Client_Continue;
677 Z_Records *recs = r->records;
679 cl->state = Client_Error;
680 if (recs && recs->which == Z_Records_NSD)
682 WRBUF w = wrbuf_alloc();
684 Z_DiagRec dr, *dr_p = &dr;
685 dr.which = Z_DiagRec_defaultFormat;
686 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
688 wrbuf_printf(w, "Search response NSD %s: ",
689 cl->database->database->url);
691 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
693 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
695 cl->state = Client_Error;
698 else if (recs && recs->which == Z_Records_multipleNSD)
700 WRBUF w = wrbuf_alloc();
702 wrbuf_printf(w, "Search response multipleNSD %s: ",
703 cl->database->database->url);
705 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
706 recs->u.multipleNonSurDiagnostics->num_diagRecs,
708 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
709 cl->state = Client_Error;
715 void client_present_response(struct client *cl, Z_APDU *a)
717 Z_PresentResponse *r = a->u.presentResponse;
718 Z_Records *recs = r->records;
720 if (recs && recs->which == Z_Records_NSD)
722 WRBUF w = wrbuf_alloc();
724 Z_DiagRec dr, *dr_p = &dr;
725 dr.which = Z_DiagRec_defaultFormat;
726 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
728 wrbuf_printf(w, "Present response NSD %s: ",
729 cl->database->database->url);
731 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
733 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
735 cl->state = Client_Error;
738 client_show_raw_error(cl, "non surrogate diagnostics");
740 else if (recs && recs->which == Z_Records_multipleNSD)
742 WRBUF w = wrbuf_alloc();
744 wrbuf_printf(w, "Present response multipleNSD %s: ",
745 cl->database->database->url);
747 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
748 recs->u.multipleNonSurDiagnostics->num_diagRecs,
750 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
751 cl->state = Client_Error;
754 else if (recs && !*r->presentStatus && cl->state != Client_Error)
756 yaz_log(YLOG_DEBUG, "Good Present response %s",
757 cl->database->database->url);
759 // we can mix show raw and normal show ..
760 if (cl->show_raw && cl->show_raw->active)
762 cl->show_raw->active = 0; // no longer active
763 ingest_raw_records(cl, recs);
766 ingest_records(cl, recs);
767 cl->state = Client_Continue;
769 else if (*r->presentStatus)
771 yaz_log(YLOG_WARN, "Bad Present response %s",
772 cl->database->database->url);
773 cl->state = Client_Error;
774 client_show_raw_error(cl, "bad present response");
778 void client_close_response(struct client *cl, Z_APDU *a)
780 struct connection *co = cl->connection;
781 /* Z_Close *r = a->u.close; */
783 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
785 cl->state = Client_Failed;
786 connection_destroy(co);
789 int client_is_our_response(struct client *cl)
791 struct session *se = client_get_session(cl);
793 if (cl && (cl->requestid == se->requestid ||
794 cl->state == Client_Initializing))
799 // Set authentication token in init if one is set for the client
800 // TODO: Extend this to handle other schemes than open (should be simple)
801 static void init_authentication(struct client *cl, Z_InitRequest *req)
803 struct session_database *sdb = client_get_database(cl);
804 const char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
808 struct connection *co = client_get_connection(cl);
809 struct session *se = client_get_session(cl);
810 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
812 idAuth->which = Z_IdAuthentication_open;
813 idAuth->u.open = odr_strdup(global_parameters.odr_out, auth);
814 req->idAuthentication = idAuth;
815 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
819 static void init_zproxy(struct client *cl, Z_InitRequest *req)
821 struct session_database *sdb = client_get_database(cl);
822 char *ztarget = sdb->database->url;
823 //char *ztarget = sdb->url;
824 const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
827 yaz_oi_set_string_oid(&req->otherInfo,
828 global_parameters.odr_out,
829 yaz_oid_userinfo_proxy,
834 static void client_init_request(struct client *cl)
836 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
838 a->u.initRequest->implementationId = global_parameters.implementationId;
839 a->u.initRequest->implementationName = global_parameters.implementationName;
840 a->u.initRequest->implementationVersion =
841 global_parameters.implementationVersion;
842 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
843 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
844 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
846 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
847 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
848 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
850 init_authentication(cl, a->u.initRequest);
851 init_zproxy(cl, a->u.initRequest);
853 if (send_apdu(cl, a) >= 0)
854 client_set_state(cl, Client_Initializing);
856 client_set_state(cl, Client_Error);
857 odr_reset(global_parameters.odr_out);
860 void client_continue(struct client *cl)
862 if (cl->state == Client_Connected) {
863 client_init_request(cl);
865 if (cl->state == Client_Continue || cl->state == Client_Idle)
867 struct session *se = client_get_session(cl);
868 if (cl->requestid != se->requestid && cl->pquery) {
869 // we'll have to abort this because result set is to be deleted
870 client_show_raw_cancel(cl);
871 client_send_search(cl);
873 else if (cl->show_raw)
875 client_send_raw_present(cl);
877 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
878 cl->records < cl->hits) {
879 client_send_present(cl);
882 client_set_state(cl, Client_Idle);
886 struct client *client_create(void)
892 client_freelist = client_freelist->next;
895 r = xmalloc(sizeof(struct client));
905 r->state = Client_Disconnected;
911 void client_destroy(struct client *c)
913 struct session *se = c->session;
914 if (c == se->clients)
915 se->clients = c->next;
919 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
927 connection_release(c->connection);
928 c->next = client_freelist;
932 void client_set_connection(struct client *cl, struct connection *con)
934 cl->connection = con;
937 void client_disconnect(struct client *cl)
939 if (cl->state != Client_Idle)
940 client_set_state(cl, Client_Disconnected);
941 client_set_connection(cl, 0);
944 // Extract terms from query into null-terminated termlist
945 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
949 pull_terms(nmem, query, termlist, &num);
953 // Initialize CCL map for a target
954 static CCL_bibset prepare_cclmap(struct client *cl)
956 struct session_database *sdb = client_get_database(cl);
963 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
965 char *p = strchr(s->name + 3, ':');
968 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
973 ccl_qual_fitem(res, s->value, p);
978 // Parse the query given the settings specific to this client
979 int client_parse_query(struct client *cl, const char *query)
981 struct session *se = client_get_session(cl);
982 struct ccl_rpn_node *cn;
984 CCL_bibset ccl_map = prepare_cclmap(cl);
989 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
990 ccl_qual_rm(&ccl_map);
993 cl->state = Client_Error;
994 yaz_log(YLOG_WARN, "Failed to parse query for %s",
995 client_get_database(cl)->database->url);
998 wrbuf_rewind(se->wrbuf);
999 ccl_pquery(se->wrbuf, cn);
1001 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
1005 // Initialize relevance structure with query terms
1007 extract_terms(se->nmem, cn, p);
1008 se->relevance = relevance_create(
1009 global_parameters.server->relevance_pct,
1010 se->nmem, (const char **) p,
1011 se->expected_maxrecs);
1018 void client_set_session(struct client *cl, struct session *se)
1021 cl->next = se->clients;
1025 int client_is_active(struct client *cl)
1027 if (cl->connection && (cl->state == Client_Continue ||
1028 cl->state == Client_Connecting ||
1029 cl->state == Client_Connected ||
1030 cl->state == Client_Initializing ||
1031 cl->state == Client_Searching ||
1032 cl->state == Client_Presenting))
1037 struct client *client_next_in_session(struct client *cl)
1045 int client_get_hits(struct client *cl)
1050 int client_get_num_records(struct client *cl)
1055 int client_get_diagnostic(struct client *cl)
1057 return cl->diagnostic;
1060 void client_set_database(struct client *cl, struct session_database *db)
1065 struct host *client_get_host(struct client *cl)
1067 return client_get_database(cl)->database->host;
1070 const char *client_get_url(struct client *cl)
1072 return client_get_database(cl)->database->url;
1078 * indent-tabs-mode: nil
1080 * vim: shiftwidth=4 tabstop=8 expandtab