1 /* $Id: client.c,v 1.28 2007-10-02 12:11:14 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
89 void (*error_handler)(void *data, const char *addinfo);
90 void (*record_handler)(void *data, const char *buf, size_t sz);
92 struct show_raw *next;
95 static const char *client_states[] = {
99 "Client_Initializing",
104 "Client_Disconnected",
109 static struct client *client_freelist = 0;
111 static int send_apdu(struct client *c, Z_APDU *a)
113 struct session_database *sdb = client_get_database(c);
114 const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
115 if (apdulog && *apdulog && *apdulog != '0')
117 ODR p = odr_createmem(ODR_PRINT);
118 yaz_log(YLOG_LOG, "send APDU %s", client_get_url(c));
120 odr_setprint(p, yaz_log_file());
122 odr_setprint(p, stderr);
125 return connection_send_apdu(client_get_connection(c), a);
129 const char *client_get_state_str(struct client *cl)
131 return client_states[cl->state];
134 enum client_state client_get_state(struct client *cl)
139 void client_set_state(struct client *cl, enum client_state st)
144 int no_active = session_active_clients(cl->session);
146 session_alert_watch(cl->session, SESSION_WATCH_SHOW);
150 static void client_show_raw_error(struct client *cl, const char *addinfo);
152 // Close connection and set state to error
153 void client_fatal(struct client *cl)
155 client_show_raw_error(cl, "client connection failure");
156 yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
157 connection_destroy(cl->connection);
158 client_set_state(cl, Client_Error);
162 static int diag_to_wrbuf(Z_DiagRec **pp, int num, WRBUF w)
166 for (i = 0; i<num; i++)
168 Z_DiagRec *p = pp[i];
171 if (p->which != Z_DiagRec_defaultFormat)
173 wrbuf_puts(w, "? Not in default format");
177 Z_DefaultDiagFormat *r = p->u.defaultFormat;
179 if (!r->diagnosticSetId)
180 wrbuf_puts(w, "? Missing diagset");
184 char diag_name_buf[OID_STR_MAX];
185 const char *diag_name = 0;
186 diag_name = yaz_oid_to_string_buf
187 (r->diagnosticSetId, &oclass, diag_name_buf);
188 wrbuf_puts(w, diag_name);
191 code = *r->condition;
192 wrbuf_printf(w, " %d %s", *r->condition,
193 diagbib1_str(*r->condition));
196 case Z_DefaultDiagFormat_v2Addinfo:
197 wrbuf_printf(w, " -- v2 addinfo '%s'", r->u.v2Addinfo);
199 case Z_DefaultDiagFormat_v3Addinfo:
200 wrbuf_printf(w, " -- v3 addinfo '%s'", r->u.v3Addinfo);
210 struct connection *client_get_connection(struct client *cl)
212 return cl->connection;
215 struct session_database *client_get_database(struct client *cl)
220 struct session *client_get_session(struct client *cl)
225 const char *client_get_pquery(struct client *cl)
230 void client_set_requestid(struct client *cl, int id)
235 int client_show_raw_begin(struct client *cl, int position,
236 const char *syntax, const char *esn,
238 void (*error_handler)(void *data, const char *addinfo),
239 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;
256 rr->syntax = xstrdup(syntax);
260 rr->esn = xstrdup(esn);
265 for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
269 if (cl->state == Client_Failed)
271 client_show_raw_error(cl, "client failed");
273 else if (cl->state == Client_Disconnected)
275 client_show_raw_error(cl, "client disconnected");
284 void client_show_raw_remove(struct client *cl, void *data)
286 struct show_raw *rr = data;
287 struct show_raw **rrp = &cl->show_raw;
297 void client_show_raw_dequeue(struct client *cl)
299 struct show_raw *rr = cl->show_raw;
301 cl->show_raw = rr->next;
305 static void client_show_raw_error(struct client *cl, const char *addinfo)
309 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
310 client_show_raw_dequeue(cl);
314 static void client_show_raw_cancel(struct client *cl)
318 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
319 client_show_raw_dequeue(cl);
323 static void client_present_syntax(Z_APDU *a, const char *syntax)
325 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
326 if (syntax && *syntax)
327 a->u.presentRequest->preferredRecordSyntax =
328 yaz_string_to_oid_odr(yaz_oid_std(),
329 CLASS_RECSYN, syntax,
330 global_parameters.odr_out);
333 static void client_present_elements(Z_APDU *a, const char *elements)
335 if (elements && *elements) // element set is optional
337 Z_ElementSetNames *elementSetNames =
338 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
339 Z_RecordComposition *compo =
340 odr_malloc(global_parameters.odr_out, sizeof(*compo));
341 a->u.presentRequest->recordComposition = compo;
343 compo->which = Z_RecordComp_simple;
344 compo->u.simple = elementSetNames;
346 elementSetNames->which = Z_ElementSetNames_generic;
347 elementSetNames->u.generic =
348 odr_strdup(global_parameters.odr_out, elements);
352 void client_send_raw_present(struct client *cl)
354 struct session_database *sdb = client_get_database(cl);
355 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
357 int start = cl->show_raw->position;
358 const char *syntax = 0;
359 const char *elements = 0;
361 assert(cl->show_raw);
363 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
364 client_get_url(cl), toget, start);
366 a->u.presentRequest->resultSetStartPoint = &start;
367 a->u.presentRequest->numberOfRecordsRequested = &toget;
369 if (cl->show_raw->syntax)
370 syntax = cl->show_raw->syntax;
372 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
374 client_present_syntax(a, syntax);
375 if (cl->show_raw->esn)
376 elements = cl->show_raw->esn;
378 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
379 client_present_elements(a, elements);
381 if (send_apdu(cl, a) >= 0)
383 cl->show_raw->active = 1;
384 cl->state = Client_Presenting;
388 client_show_raw_error(cl, "send_apdu failed");
389 cl->state = Client_Error;
391 odr_reset(global_parameters.odr_out);
394 void client_send_present(struct client *cl)
396 struct session_database *sdb = client_get_database(cl);
397 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
399 int start = cl->records + 1;
400 const char *syntax = 0;
401 const char *elements = 0;
403 toget = global_parameters.chunk;
404 if (toget > global_parameters.toget - cl->records)
405 toget = global_parameters.toget - cl->records;
406 if (toget > cl->hits - cl->records)
407 toget = cl->hits - cl->records;
409 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
412 a->u.presentRequest->resultSetStartPoint = &start;
413 a->u.presentRequest->numberOfRecordsRequested = &toget;
415 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
416 client_present_syntax(a, syntax);
418 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
419 client_present_elements(a, elements);
421 if (send_apdu(cl, a) >= 0)
422 cl->state = Client_Presenting;
424 cl->state = Client_Error;
425 odr_reset(global_parameters.odr_out);
429 void client_send_search(struct client *cl)
431 struct session *se = client_get_session(cl);
432 struct session_database *sdb = client_get_database(cl);
433 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
437 int ssub = 0, lslb = 100000, mspn = 10;
438 const char *piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
439 const char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
441 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
444 // constructing RPN query
445 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
447 zquery->which = Z_Query_type_1;
448 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
449 client_get_pquery(cl));
451 // converting to target encoding
452 if (queryenc && *queryenc)
454 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
456 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
457 global_parameters.odr_out,
459 yaz_iconv_close(iconv);
461 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
462 client_get_database(cl)->database->url, queryenc);
465 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
467 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
468 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
469 databaselist[ndb] = sdb->database->databases[ndb];
471 if (!piggyback || *piggyback == '1')
473 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
474 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
475 if (recsyn && *recsyn)
477 a->u.searchRequest->preferredRecordSyntax =
478 yaz_string_to_oid_odr(yaz_oid_std(),
479 CLASS_RECSYN, recsyn,
480 global_parameters.odr_out);
482 if (elements && *elements)
484 Z_ElementSetNames *esn =
485 odr_malloc(global_parameters.odr_out, sizeof(*esn));
486 esn->which = Z_ElementSetNames_generic;
487 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
489 a->u.searchRequest->smallSetElementSetNames = esn;
490 a->u.searchRequest->mediumSetElementSetNames = esn;
492 a->u.searchRequest->smallSetUpperBound = &ssub;
493 a->u.searchRequest->largeSetLowerBound = &lslb;
494 a->u.searchRequest->mediumSetPresentNumber = &mspn;
496 a->u.searchRequest->databaseNames = databaselist;
497 a->u.searchRequest->num_databaseNames = ndb;
500 { //scope for sending and logging queries
501 WRBUF wbquery = wrbuf_alloc();
502 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
505 if (send_apdu(cl, a) >= 0)
507 client_set_state(cl, Client_Searching);
508 client_set_requestid(cl, se->requestid);
509 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
510 client_get_database(cl)->database->url,
511 queryenc ? queryenc : "UTF-8",
512 wrbuf_cstr(wbquery));
515 client_set_state(cl, Client_Error);
516 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
517 client_get_database(cl)->database->url,
518 queryenc ? queryenc : "UTF-8",
519 wrbuf_cstr(wbquery));
522 wrbuf_destroy(wbquery);
525 odr_reset(global_parameters.odr_out);
528 void client_init_response(struct client *cl, Z_APDU *a)
530 Z_InitResponse *r = a->u.initResponse;
532 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
535 cl->state = Client_Continue;
537 cl->state = Client_Failed; // FIXME need to do something to the connection
541 static void ingest_raw_records(struct client *cl, Z_Records *r)
543 Z_NamePlusRecordList *rlist;
544 Z_NamePlusRecord *npr;
548 if (r->which != Z_Records_DBOSD)
550 client_show_raw_error(cl, "non-surrogate diagnostics");
554 rlist = r->u.databaseOrSurDiagnostics;
555 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
557 client_show_raw_error(cl, "no records");
560 npr = rlist->records[0];
561 if (npr->which != Z_NamePlusRecord_databaseRecord)
563 client_show_raw_error(cl, "surrogate diagnostic");
567 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
570 client_show_raw_error(cl, "unable to convert record to xml");
574 xmlDocDumpMemory(doc, &buf_out, &len_out);
579 cl->show_raw->record_handler(cl->show_raw->data,
580 (const char *) buf_out, len_out);
581 client_show_raw_dequeue(cl);
586 static void ingest_records(struct client *cl, Z_Records *r)
589 yaz_timing_t t = yaz_timing_create();
592 struct session *s = client_get_session(cl);
593 Z_NamePlusRecordList *rlist;
596 if (r->which != Z_Records_DBOSD)
598 rlist = r->u.databaseOrSurDiagnostics;
599 for (i = 0; i < rlist->num_records; i++)
601 Z_NamePlusRecord *npr = rlist->records[i];
604 if (npr->which != Z_NamePlusRecord_databaseRecord)
607 "Unexpected record type, probably diagnostic %s",
608 cl->database->database->url);
612 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
616 if (rlist->num_records)
617 session_alert_watch(s, SESSION_WATCH_SHOW);
618 if (rlist->num_records)
619 session_alert_watch(s, SESSION_WATCH_RECORD);
623 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
624 yaz_timing_get_real(t), yaz_timing_get_user(t),
625 yaz_timing_get_sys(t));
626 yaz_timing_destroy(&t);
631 void client_search_response(struct client *cl, Z_APDU *a)
633 struct session *se = cl->session;
634 Z_SearchResponse *r = a->u.searchResponse;
636 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
637 cl->database->database->url, *r->searchStatus);
639 if (*r->searchStatus)
641 cl->hits = *r->resultCount;
644 yaz_log(YLOG_WARN, "Target %s returns hit count %d",
645 cl->database->database->url, cl->hits);
648 se->total_hits += cl->hits;
649 if (r->presentStatus && !*r->presentStatus && r->records)
651 yaz_log(YLOG_DEBUG, "Records in search response %s",
652 cl->database->database->url);
653 ingest_records(cl, r->records);
655 cl->state = Client_Continue;
659 Z_Records *recs = r->records;
661 cl->state = Client_Error;
662 if (recs && recs->which == Z_Records_NSD)
664 WRBUF w = wrbuf_alloc();
666 Z_DiagRec dr, *dr_p = &dr;
667 dr.which = Z_DiagRec_defaultFormat;
668 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
670 wrbuf_printf(w, "Search response NSD %s: ",
671 cl->database->database->url);
673 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
675 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
677 cl->state = Client_Error;
680 else if (recs && recs->which == Z_Records_multipleNSD)
682 WRBUF w = wrbuf_alloc();
684 wrbuf_printf(w, "Search response multipleNSD %s: ",
685 cl->database->database->url);
687 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
688 recs->u.multipleNonSurDiagnostics->num_diagRecs,
690 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
691 cl->state = Client_Error;
697 void client_present_response(struct client *cl, Z_APDU *a)
699 Z_PresentResponse *r = a->u.presentResponse;
700 Z_Records *recs = r->records;
702 if (recs && recs->which == Z_Records_NSD)
704 WRBUF w = wrbuf_alloc();
706 Z_DiagRec dr, *dr_p = &dr;
707 dr.which = Z_DiagRec_defaultFormat;
708 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
710 wrbuf_printf(w, "Present response NSD %s: ",
711 cl->database->database->url);
713 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
715 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
717 cl->state = Client_Error;
720 client_show_raw_error(cl, "non surrogate diagnostics");
722 else if (recs && recs->which == Z_Records_multipleNSD)
724 WRBUF w = wrbuf_alloc();
726 wrbuf_printf(w, "Present response multipleNSD %s: ",
727 cl->database->database->url);
729 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
730 recs->u.multipleNonSurDiagnostics->num_diagRecs,
732 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
733 cl->state = Client_Error;
736 else if (recs && !*r->presentStatus && cl->state != Client_Error)
738 yaz_log(YLOG_DEBUG, "Good Present response %s",
739 cl->database->database->url);
741 // we can mix show raw and normal show ..
742 if (cl->show_raw && cl->show_raw->active)
744 cl->show_raw->active = 0; // no longer active
745 ingest_raw_records(cl, recs);
748 ingest_records(cl, recs);
749 cl->state = Client_Continue;
751 else if (*r->presentStatus)
753 yaz_log(YLOG_WARN, "Bad Present response %s",
754 cl->database->database->url);
755 cl->state = Client_Error;
756 client_show_raw_error(cl, "bad present response");
760 void client_close_response(struct client *cl, Z_APDU *a)
762 struct connection *co = cl->connection;
763 /* Z_Close *r = a->u.close; */
765 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
767 cl->state = Client_Failed;
768 connection_destroy(co);
771 int client_is_our_response(struct client *cl)
773 struct session *se = client_get_session(cl);
775 if (cl && (cl->requestid == se->requestid ||
776 cl->state == Client_Initializing))
781 // Set authentication token in init if one is set for the client
782 // TODO: Extend this to handle other schemes than open (should be simple)
783 static void init_authentication(struct client *cl, Z_InitRequest *req)
785 struct session_database *sdb = client_get_database(cl);
786 const char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
790 struct connection *co = client_get_connection(cl);
791 struct session *se = client_get_session(cl);
792 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
794 idAuth->which = Z_IdAuthentication_open;
795 idAuth->u.open = odr_strdup(global_parameters.odr_out, auth);
796 req->idAuthentication = idAuth;
797 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
801 static void init_zproxy(struct client *cl, Z_InitRequest *req)
803 struct session_database *sdb = client_get_database(cl);
804 char *ztarget = sdb->database->url;
805 //char *ztarget = sdb->url;
806 const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
809 yaz_oi_set_string_oid(&req->otherInfo,
810 global_parameters.odr_out,
811 yaz_oid_userinfo_proxy,
816 static void client_init_request(struct client *cl)
818 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
820 a->u.initRequest->implementationId = global_parameters.implementationId;
821 a->u.initRequest->implementationName = global_parameters.implementationName;
822 a->u.initRequest->implementationVersion =
823 global_parameters.implementationVersion;
824 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
825 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
826 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
828 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
829 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
830 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
832 init_authentication(cl, a->u.initRequest);
833 init_zproxy(cl, a->u.initRequest);
835 if (send_apdu(cl, a) >= 0)
836 client_set_state(cl, Client_Initializing);
838 client_set_state(cl, Client_Error);
839 odr_reset(global_parameters.odr_out);
842 void client_continue(struct client *cl)
844 if (cl->state == Client_Connected) {
845 client_init_request(cl);
847 if (cl->state == Client_Continue || cl->state == Client_Idle)
849 struct session *se = client_get_session(cl);
850 if (cl->requestid != se->requestid && cl->pquery) {
851 // we'll have to abort this because result set is to be deleted
852 client_show_raw_cancel(cl);
853 client_send_search(cl);
855 else if (cl->show_raw)
857 client_send_raw_present(cl);
859 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
860 cl->records < cl->hits) {
861 client_send_present(cl);
864 client_set_state(cl, Client_Idle);
868 struct client *client_create(void)
874 client_freelist = client_freelist->next;
877 r = xmalloc(sizeof(struct client));
887 r->state = Client_Disconnected;
893 void client_destroy(struct client *c)
895 struct session *se = c->session;
896 if (c == se->clients)
897 se->clients = c->next;
901 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
909 connection_release(c->connection);
910 c->next = client_freelist;
914 void client_set_connection(struct client *cl, struct connection *con)
916 cl->connection = con;
919 void client_disconnect(struct client *cl)
921 if (cl->state != Client_Idle)
922 client_set_state(cl, Client_Disconnected);
923 client_set_connection(cl, 0);
926 // Extract terms from query into null-terminated termlist
927 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
931 pull_terms(nmem, query, termlist, &num);
935 // Initialize CCL map for a target
936 static CCL_bibset prepare_cclmap(struct client *cl)
938 struct session_database *sdb = client_get_database(cl);
945 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
947 char *p = strchr(s->name + 3, ':');
950 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
955 ccl_qual_fitem(res, s->value, p);
960 // Parse the query given the settings specific to this client
961 int client_parse_query(struct client *cl, const char *query)
963 struct session *se = client_get_session(cl);
964 struct ccl_rpn_node *cn;
966 CCL_bibset ccl_map = prepare_cclmap(cl);
971 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
972 ccl_qual_rm(&ccl_map);
975 cl->state = Client_Error;
976 yaz_log(YLOG_WARN, "Failed to parse query for %s",
977 client_get_database(cl)->database->url);
980 wrbuf_rewind(se->wrbuf);
981 ccl_pquery(se->wrbuf, cn);
983 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
987 // Initialize relevance structure with query terms
989 extract_terms(se->nmem, cn, p);
990 se->relevance = relevance_create(
991 global_parameters.server->relevance_pct,
992 se->nmem, (const char **) p,
993 se->expected_maxrecs);
1000 void client_set_session(struct client *cl, struct session *se)
1003 cl->next = se->clients;
1007 int client_is_active(struct client *cl)
1009 if (cl->connection && (cl->state == Client_Continue ||
1010 cl->state == Client_Connecting ||
1011 cl->state == Client_Connected ||
1012 cl->state == Client_Initializing ||
1013 cl->state == Client_Searching ||
1014 cl->state == Client_Presenting))
1019 struct client *client_next_in_session(struct client *cl)
1027 int client_get_hits(struct client *cl)
1032 int client_get_num_records(struct client *cl)
1037 int client_get_diagnostic(struct client *cl)
1039 return cl->diagnostic;
1042 void client_set_database(struct client *cl, struct session_database *db)
1047 struct host *client_get_host(struct client *cl)
1049 return client_get_database(cl)->database->host;
1052 const char *client_get_url(struct client *cl)
1054 return client_get_database(cl)->database->url;
1060 * indent-tabs-mode: nil
1062 * vim: shiftwidth=4 tabstop=8 expandtab