1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2008 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/socket.h>
35 #include <yaz/marcdisp.h>
36 #include <yaz/comstack.h>
37 #include <yaz/tcpip.h>
38 #include <yaz/proto.h>
39 #include <yaz/readconf.h>
40 #include <yaz/pquery.h>
41 #include <yaz/otherinfo.h>
42 #include <yaz/yaz-util.h>
44 #include <yaz/query-charset.h>
45 #include <yaz/querytowrbuf.h>
46 #include <yaz/oid_db.h>
47 #include <yaz/diagbib1.h>
55 #include <yaz/timing.h>
58 #include <netinet/in.h>
63 #include "connection.h"
66 /** \brief Represents client state for a connection to one search target */
68 struct session_database *database;
69 struct connection *connection;
70 struct session *session;
71 char *pquery; // Current search
75 int requestid; // ID of current outstanding request
77 enum client_state state;
78 struct show_raw *show_raw;
79 struct client *next; // next client in session or next in free list
83 int active; // whether this request has been sent to the server
88 void (*error_handler)(void *data, const char *addinfo);
89 void (*record_handler)(void *data, const char *buf, size_t sz);
91 struct show_raw *next;
94 static const char *client_states[] = {
98 "Client_Initializing",
103 "Client_Disconnected",
108 static struct client *client_freelist = 0;
110 static int send_apdu(struct client *c, Z_APDU *a)
112 struct session_database *sdb = client_get_database(c);
113 const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
114 if (apdulog && *apdulog && *apdulog != '0')
116 ODR p = odr_createmem(ODR_PRINT);
117 yaz_log(YLOG_LOG, "send APDU %s", client_get_url(c));
119 odr_setprint(p, yaz_log_file());
121 odr_setprint(p, stderr);
124 return connection_send_apdu(client_get_connection(c), a);
128 const char *client_get_state_str(struct client *cl)
130 return client_states[cl->state];
133 enum client_state client_get_state(struct client *cl)
138 void client_set_state(struct client *cl, enum client_state st)
143 int no_active = session_active_clients(cl->session);
145 session_alert_watch(cl->session, SESSION_WATCH_SHOW);
149 static void client_show_raw_error(struct client *cl, const char *addinfo);
151 // Close connection and set state to error
152 void client_fatal(struct client *cl)
154 client_show_raw_error(cl, "client connection failure");
155 yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
156 connection_destroy(cl->connection);
157 client_set_state(cl, Client_Error);
161 static int diag_to_wrbuf(Z_DiagRec **pp, int num, WRBUF w)
165 for (i = 0; i<num; i++)
167 Z_DiagRec *p = pp[i];
170 if (p->which != Z_DiagRec_defaultFormat)
172 wrbuf_puts(w, "? Not in default format");
176 Z_DefaultDiagFormat *r = p->u.defaultFormat;
178 if (!r->diagnosticSetId)
179 wrbuf_puts(w, "? Missing diagset");
183 char diag_name_buf[OID_STR_MAX];
184 const char *diag_name = 0;
185 diag_name = yaz_oid_to_string_buf
186 (r->diagnosticSetId, &oclass, diag_name_buf);
187 wrbuf_puts(w, diag_name);
190 code = *r->condition;
191 wrbuf_printf(w, " %d %s", *r->condition,
192 diagbib1_str(*r->condition));
195 case Z_DefaultDiagFormat_v2Addinfo:
196 wrbuf_printf(w, " -- v2 addinfo '%s'", r->u.v2Addinfo);
198 case Z_DefaultDiagFormat_v3Addinfo:
199 wrbuf_printf(w, " -- v3 addinfo '%s'", r->u.v3Addinfo);
209 struct connection *client_get_connection(struct client *cl)
211 return cl->connection;
214 struct session_database *client_get_database(struct client *cl)
219 struct session *client_get_session(struct client *cl)
224 const char *client_get_pquery(struct client *cl)
229 void client_set_requestid(struct client *cl, int id)
234 int client_show_raw_begin(struct client *cl, int position,
235 const char *syntax, const char *esn,
237 void (*error_handler)(void *data, const char *addinfo),
238 void (*record_handler)(void *data, const char *buf,
243 struct show_raw *rr, **rrp;
245 { /* the client has no connection */
248 rr = xmalloc(sizeof(*rr));
250 rr->position = position;
253 rr->error_handler = error_handler;
254 rr->record_handler = record_handler;
257 rr->syntax = xstrdup(syntax);
261 rr->esn = xstrdup(esn);
266 for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
270 if (cl->state == Client_Failed)
272 client_show_raw_error(cl, "client failed");
274 else if (cl->state == Client_Disconnected)
276 client_show_raw_error(cl, "client disconnected");
285 void client_show_raw_remove(struct client *cl, void *data)
287 struct show_raw *rr = data;
288 struct show_raw **rrp = &cl->show_raw;
298 void client_show_raw_dequeue(struct client *cl)
300 struct show_raw *rr = cl->show_raw;
302 cl->show_raw = rr->next;
306 static void client_show_raw_error(struct client *cl, const char *addinfo)
310 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
311 client_show_raw_dequeue(cl);
315 static void client_show_raw_cancel(struct client *cl)
319 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
320 client_show_raw_dequeue(cl);
324 static void client_present_syntax(Z_APDU *a, const char *syntax)
326 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
327 if (syntax && *syntax)
328 a->u.presentRequest->preferredRecordSyntax =
329 yaz_string_to_oid_odr(yaz_oid_std(),
330 CLASS_RECSYN, syntax,
331 global_parameters.odr_out);
334 static void client_present_elements(Z_APDU *a, const char *elements)
336 if (elements && *elements) // element set is optional
338 Z_ElementSetNames *elementSetNames =
339 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
340 Z_RecordComposition *compo =
341 odr_malloc(global_parameters.odr_out, sizeof(*compo));
342 a->u.presentRequest->recordComposition = compo;
344 compo->which = Z_RecordComp_simple;
345 compo->u.simple = elementSetNames;
347 elementSetNames->which = Z_ElementSetNames_generic;
348 elementSetNames->u.generic =
349 odr_strdup(global_parameters.odr_out, elements);
353 void client_send_raw_present(struct client *cl)
355 struct session_database *sdb = client_get_database(cl);
356 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
358 int start = cl->show_raw->position;
359 const char *syntax = 0;
360 const char *elements = 0;
362 assert(cl->show_raw);
364 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
365 client_get_url(cl), toget, start);
367 a->u.presentRequest->resultSetStartPoint = &start;
368 a->u.presentRequest->numberOfRecordsRequested = &toget;
370 if (cl->show_raw->syntax)
371 syntax = cl->show_raw->syntax;
373 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
375 client_present_syntax(a, syntax);
376 if (cl->show_raw->esn)
377 elements = cl->show_raw->esn;
379 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
380 client_present_elements(a, elements);
382 if (send_apdu(cl, a) >= 0)
384 cl->show_raw->active = 1;
385 cl->state = Client_Presenting;
389 client_show_raw_error(cl, "send_apdu failed");
390 cl->state = Client_Error;
392 odr_reset(global_parameters.odr_out);
395 void client_send_present(struct client *cl)
397 struct session_database *sdb = client_get_database(cl);
398 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
400 int start = cl->records + 1;
401 const char *syntax = 0;
402 const char *elements = 0;
404 toget = global_parameters.chunk;
405 if (toget > global_parameters.toget - cl->records)
406 toget = global_parameters.toget - cl->records;
407 if (toget > cl->hits - cl->records)
408 toget = cl->hits - cl->records;
410 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
413 a->u.presentRequest->resultSetStartPoint = &start;
414 a->u.presentRequest->numberOfRecordsRequested = &toget;
416 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
417 client_present_syntax(a, syntax);
419 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
420 client_present_elements(a, elements);
422 if (send_apdu(cl, a) >= 0)
423 cl->state = Client_Presenting;
425 cl->state = Client_Error;
426 odr_reset(global_parameters.odr_out);
430 void client_send_search(struct client *cl)
432 struct session *se = client_get_session(cl);
433 struct session_database *sdb = client_get_database(cl);
434 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
438 int ssub = 0, lslb = 100000, mspn = 10;
439 const char *piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
440 const char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
442 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
445 // constructing RPN query
446 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
448 zquery->which = Z_Query_type_1;
449 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
450 client_get_pquery(cl));
452 // converting to target encoding
453 if (queryenc && *queryenc)
455 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
457 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
458 global_parameters.odr_out,
460 yaz_iconv_close(iconv);
462 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
463 client_get_database(cl)->database->url, queryenc);
466 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
468 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
469 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
470 databaselist[ndb] = sdb->database->databases[ndb];
472 if (!piggyback || *piggyback == '1')
474 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
475 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
476 if (recsyn && *recsyn)
478 a->u.searchRequest->preferredRecordSyntax =
479 yaz_string_to_oid_odr(yaz_oid_std(),
480 CLASS_RECSYN, recsyn,
481 global_parameters.odr_out);
483 if (elements && *elements)
485 Z_ElementSetNames *esn =
486 odr_malloc(global_parameters.odr_out, sizeof(*esn));
487 esn->which = Z_ElementSetNames_generic;
488 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
490 a->u.searchRequest->smallSetElementSetNames = esn;
491 a->u.searchRequest->mediumSetElementSetNames = esn;
493 a->u.searchRequest->smallSetUpperBound = &ssub;
494 a->u.searchRequest->largeSetLowerBound = &lslb;
495 a->u.searchRequest->mediumSetPresentNumber = &mspn;
497 a->u.searchRequest->databaseNames = databaselist;
498 a->u.searchRequest->num_databaseNames = ndb;
501 { //scope for sending and logging queries
502 WRBUF wbquery = wrbuf_alloc();
503 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
506 if (send_apdu(cl, a) >= 0)
508 client_set_state(cl, Client_Searching);
509 client_set_requestid(cl, se->requestid);
510 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
511 client_get_database(cl)->database->url,
512 queryenc ? queryenc : "UTF-8",
513 wrbuf_cstr(wbquery));
516 client_set_state(cl, Client_Error);
517 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
518 client_get_database(cl)->database->url,
519 queryenc ? queryenc : "UTF-8",
520 wrbuf_cstr(wbquery));
523 wrbuf_destroy(wbquery);
526 odr_reset(global_parameters.odr_out);
529 void client_init_response(struct client *cl, Z_APDU *a)
531 Z_InitResponse *r = a->u.initResponse;
533 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
536 cl->state = Client_Continue;
538 cl->state = Client_Failed; // FIXME need to do something to the connection
542 static void ingest_raw_records(struct client *cl, Z_Records *r)
544 Z_NamePlusRecordList *rlist;
545 Z_NamePlusRecord *npr;
549 if (r->which != Z_Records_DBOSD)
551 client_show_raw_error(cl, "non-surrogate diagnostics");
555 rlist = r->u.databaseOrSurDiagnostics;
556 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
558 client_show_raw_error(cl, "no records");
561 npr = rlist->records[0];
562 if (npr->which != Z_NamePlusRecord_databaseRecord)
564 client_show_raw_error(cl, "surrogate diagnostic");
568 if (cl->show_raw && cl->show_raw->binary)
570 Z_External *rec = npr->u.databaseRecord;
571 if (rec->which == Z_External_octet)
573 cl->show_raw->record_handler(cl->show_raw->data,
575 rec->u.octet_aligned->buf,
576 rec->u.octet_aligned->len);
577 client_show_raw_dequeue(cl);
580 client_show_raw_error(cl, "no records");
583 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
586 client_show_raw_error(cl, "unable to convert record to xml");
590 xmlDocDumpMemory(doc, &buf_out, &len_out);
595 cl->show_raw->record_handler(cl->show_raw->data,
596 (const char *) buf_out, len_out);
597 client_show_raw_dequeue(cl);
602 static void ingest_records(struct client *cl, Z_Records *r)
605 yaz_timing_t t = yaz_timing_create();
608 struct session *s = client_get_session(cl);
609 Z_NamePlusRecordList *rlist;
612 if (r->which != Z_Records_DBOSD)
614 rlist = r->u.databaseOrSurDiagnostics;
615 for (i = 0; i < rlist->num_records; i++)
617 Z_NamePlusRecord *npr = rlist->records[i];
620 if (npr->which != Z_NamePlusRecord_databaseRecord)
623 "Unexpected record type, probably diagnostic %s",
624 cl->database->database->url);
628 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
632 if (rlist->num_records)
633 session_alert_watch(s, SESSION_WATCH_SHOW);
634 if (rlist->num_records)
635 session_alert_watch(s, SESSION_WATCH_RECORD);
639 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
640 yaz_timing_get_real(t), yaz_timing_get_user(t),
641 yaz_timing_get_sys(t));
642 yaz_timing_destroy(&t);
647 void client_search_response(struct client *cl, Z_APDU *a)
649 struct session *se = cl->session;
650 Z_SearchResponse *r = a->u.searchResponse;
652 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
653 cl->database->database->url, *r->searchStatus);
655 if (*r->searchStatus)
657 cl->hits = *r->resultCount;
660 yaz_log(YLOG_WARN, "Target %s returns hit count %d",
661 cl->database->database->url, cl->hits);
664 se->total_hits += cl->hits;
665 if (r->presentStatus && !*r->presentStatus && r->records)
667 yaz_log(YLOG_DEBUG, "Records in search response %s",
668 cl->database->database->url);
669 ingest_records(cl, r->records);
671 cl->state = Client_Continue;
675 Z_Records *recs = r->records;
677 cl->state = Client_Error;
678 if (recs && recs->which == Z_Records_NSD)
680 WRBUF w = wrbuf_alloc();
682 Z_DiagRec dr, *dr_p = &dr;
683 dr.which = Z_DiagRec_defaultFormat;
684 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
686 wrbuf_printf(w, "Search response NSD %s: ",
687 cl->database->database->url);
689 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
691 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
693 cl->state = Client_Error;
696 else if (recs && recs->which == Z_Records_multipleNSD)
698 WRBUF w = wrbuf_alloc();
700 wrbuf_printf(w, "Search response multipleNSD %s: ",
701 cl->database->database->url);
703 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
704 recs->u.multipleNonSurDiagnostics->num_diagRecs,
706 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
707 cl->state = Client_Error;
713 void client_present_response(struct client *cl, Z_APDU *a)
715 Z_PresentResponse *r = a->u.presentResponse;
716 Z_Records *recs = r->records;
718 if (recs && recs->which == Z_Records_NSD)
720 WRBUF w = wrbuf_alloc();
722 Z_DiagRec dr, *dr_p = &dr;
723 dr.which = Z_DiagRec_defaultFormat;
724 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
726 wrbuf_printf(w, "Present response NSD %s: ",
727 cl->database->database->url);
729 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
731 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
733 cl->state = Client_Error;
736 client_show_raw_error(cl, "non surrogate diagnostics");
738 else if (recs && recs->which == Z_Records_multipleNSD)
740 WRBUF w = wrbuf_alloc();
742 wrbuf_printf(w, "Present response multipleNSD %s: ",
743 cl->database->database->url);
745 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
746 recs->u.multipleNonSurDiagnostics->num_diagRecs,
748 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
749 cl->state = Client_Error;
752 else if (recs && !*r->presentStatus && cl->state != Client_Error)
754 yaz_log(YLOG_DEBUG, "Good Present response %s",
755 cl->database->database->url);
757 // we can mix show raw and normal show ..
758 if (cl->show_raw && cl->show_raw->active)
760 cl->show_raw->active = 0; // no longer active
761 ingest_raw_records(cl, recs);
764 ingest_records(cl, recs);
765 cl->state = Client_Continue;
767 else if (*r->presentStatus)
769 yaz_log(YLOG_WARN, "Bad Present response %s",
770 cl->database->database->url);
771 cl->state = Client_Error;
772 client_show_raw_error(cl, "bad present response");
776 void client_close_response(struct client *cl, Z_APDU *a)
778 struct connection *co = cl->connection;
779 /* Z_Close *r = a->u.close; */
781 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
783 cl->state = Client_Failed;
784 connection_destroy(co);
787 int client_is_our_response(struct client *cl)
789 struct session *se = client_get_session(cl);
791 if (cl && (cl->requestid == se->requestid ||
792 cl->state == Client_Initializing))
797 // Set authentication token in init if one is set for the client
798 // TODO: Extend this to handle other schemes than open (should be simple)
799 static void init_authentication(struct client *cl, Z_InitRequest *req)
801 struct session_database *sdb = client_get_database(cl);
802 const char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
806 struct connection *co = client_get_connection(cl);
807 struct session *se = client_get_session(cl);
808 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
810 idAuth->which = Z_IdAuthentication_open;
811 idAuth->u.open = odr_strdup(global_parameters.odr_out, auth);
812 req->idAuthentication = idAuth;
813 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
817 static void init_zproxy(struct client *cl, Z_InitRequest *req)
819 struct session_database *sdb = client_get_database(cl);
820 char *ztarget = sdb->database->url;
821 //char *ztarget = sdb->url;
822 const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
825 yaz_oi_set_string_oid(&req->otherInfo,
826 global_parameters.odr_out,
827 yaz_oid_userinfo_proxy,
832 static void client_init_request(struct client *cl)
834 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
836 a->u.initRequest->implementationId = global_parameters.implementationId;
837 a->u.initRequest->implementationName = global_parameters.implementationName;
838 a->u.initRequest->implementationVersion =
839 global_parameters.implementationVersion;
840 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
841 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
842 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
844 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
845 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
846 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
848 init_authentication(cl, a->u.initRequest);
849 init_zproxy(cl, a->u.initRequest);
851 if (send_apdu(cl, a) >= 0)
852 client_set_state(cl, Client_Initializing);
854 client_set_state(cl, Client_Error);
855 odr_reset(global_parameters.odr_out);
858 void client_continue(struct client *cl)
860 if (cl->state == Client_Connected) {
861 client_init_request(cl);
863 if (cl->state == Client_Continue || cl->state == Client_Idle)
865 struct session *se = client_get_session(cl);
866 if (cl->requestid != se->requestid && cl->pquery) {
867 // we'll have to abort this because result set is to be deleted
868 client_show_raw_cancel(cl);
869 client_send_search(cl);
871 else if (cl->show_raw)
873 client_send_raw_present(cl);
875 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
876 cl->records < cl->hits) {
877 client_send_present(cl);
880 client_set_state(cl, Client_Idle);
884 struct client *client_create(void)
890 client_freelist = client_freelist->next;
893 r = xmalloc(sizeof(struct client));
903 r->state = Client_Disconnected;
909 void client_destroy(struct client *c)
911 struct session *se = c->session;
912 if (c == se->clients)
913 se->clients = c->next;
917 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
925 connection_release(c->connection);
926 c->next = client_freelist;
930 void client_set_connection(struct client *cl, struct connection *con)
932 cl->connection = con;
935 void client_disconnect(struct client *cl)
937 if (cl->state != Client_Idle)
938 client_set_state(cl, Client_Disconnected);
939 client_set_connection(cl, 0);
942 // Extract terms from query into null-terminated termlist
943 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
947 pull_terms(nmem, query, termlist, &num);
951 // Initialize CCL map for a target
952 static CCL_bibset prepare_cclmap(struct client *cl)
954 struct session_database *sdb = client_get_database(cl);
961 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
963 char *p = strchr(s->name + 3, ':');
966 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
971 ccl_qual_fitem(res, s->value, p);
976 // Parse the query given the settings specific to this client
977 int client_parse_query(struct client *cl, const char *query)
979 struct session *se = client_get_session(cl);
980 struct ccl_rpn_node *cn;
982 CCL_bibset ccl_map = prepare_cclmap(cl);
987 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
988 ccl_qual_rm(&ccl_map);
991 cl->state = Client_Error;
992 yaz_log(YLOG_WARN, "Failed to parse query for %s",
993 client_get_database(cl)->database->url);
996 wrbuf_rewind(se->wrbuf);
997 ccl_pquery(se->wrbuf, cn);
999 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
1003 // Initialize relevance structure with query terms
1005 extract_terms(se->nmem, cn, p);
1006 se->relevance = relevance_create(
1007 global_parameters.server->relevance_pct,
1008 se->nmem, (const char **) p,
1009 se->expected_maxrecs);
1016 void client_set_session(struct client *cl, struct session *se)
1019 cl->next = se->clients;
1023 int client_is_active(struct client *cl)
1025 if (cl->connection && (cl->state == Client_Continue ||
1026 cl->state == Client_Connecting ||
1027 cl->state == Client_Connected ||
1028 cl->state == Client_Initializing ||
1029 cl->state == Client_Searching ||
1030 cl->state == Client_Presenting))
1035 struct client *client_next_in_session(struct client *cl)
1043 int client_get_hits(struct client *cl)
1048 int client_get_num_records(struct client *cl)
1053 int client_get_diagnostic(struct client *cl)
1055 return cl->diagnostic;
1058 void client_set_database(struct client *cl, struct session_database *db)
1063 struct host *client_get_host(struct client *cl)
1065 return client_get_database(cl)->database->host;
1068 const char *client_get_url(struct client *cl)
1070 return client_get_database(cl)->database->url;
1076 * indent-tabs-mode: nil
1078 * vim: shiftwidth=4 tabstop=8 expandtab