1 /* $Id: client.c,v 1.27 2007-10-02 10:32:03 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);
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,
242 { /* raw show already in progress */
246 { /* the client has no connection */
249 cl->show_raw = xmalloc(sizeof(*cl->show_raw));
250 cl->show_raw->position = position;
251 cl->show_raw->active = 0;
252 cl->show_raw->data = data;
253 cl->show_raw->error_handler = error_handler;
254 cl->show_raw->record_handler = record_handler;
256 cl->show_raw->syntax = xstrdup(syntax);
258 cl->show_raw->syntax = 0;
260 cl->show_raw->esn = xstrdup(esn);
262 cl->show_raw->esn = 0;
265 if (cl->state == Client_Failed)
267 client_show_raw_error(cl, "client failed");
269 else if (cl->state == Client_Disconnected)
271 client_show_raw_error(cl, "client disconnected");
280 void client_show_raw_reset(struct client *cl)
286 static void client_show_raw_error(struct client *cl, const char *addinfo)
290 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
291 client_show_raw_reset(cl);
295 static void client_show_raw_cancel(struct client *cl)
299 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
300 client_show_raw_reset(cl);
304 static void client_present_syntax(Z_APDU *a, const char *syntax)
306 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
307 if (syntax && *syntax)
308 a->u.presentRequest->preferredRecordSyntax =
309 yaz_string_to_oid_odr(yaz_oid_std(),
310 CLASS_RECSYN, syntax,
311 global_parameters.odr_out);
314 static void client_present_elements(Z_APDU *a, const char *elements)
316 if (elements && *elements) // element set is optional
318 Z_ElementSetNames *elementSetNames =
319 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
320 Z_RecordComposition *compo =
321 odr_malloc(global_parameters.odr_out, sizeof(*compo));
322 a->u.presentRequest->recordComposition = compo;
324 compo->which = Z_RecordComp_simple;
325 compo->u.simple = elementSetNames;
327 elementSetNames->which = Z_ElementSetNames_generic;
328 elementSetNames->u.generic =
329 odr_strdup(global_parameters.odr_out, elements);
333 void client_send_raw_present(struct client *cl)
335 struct session_database *sdb = client_get_database(cl);
336 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
338 int start = cl->show_raw->position;
339 const char *syntax = 0;
340 const char *elements = 0;
342 assert(cl->show_raw);
344 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
345 client_get_url(cl), toget, start);
347 a->u.presentRequest->resultSetStartPoint = &start;
348 a->u.presentRequest->numberOfRecordsRequested = &toget;
350 if (cl->show_raw->syntax)
351 syntax = cl->show_raw->syntax;
353 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
355 client_present_syntax(a, syntax);
356 if (cl->show_raw->esn)
357 elements = cl->show_raw->esn;
359 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
360 client_present_elements(a, elements);
362 if (send_apdu(cl, a) >= 0)
364 cl->show_raw->active = 1;
365 cl->state = Client_Presenting;
369 client_show_raw_error(cl, "send_apdu failed");
370 cl->state = Client_Error;
372 odr_reset(global_parameters.odr_out);
375 void client_send_present(struct client *cl)
377 struct session_database *sdb = client_get_database(cl);
378 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
380 int start = cl->records + 1;
381 const char *syntax = 0;
382 const char *elements = 0;
384 toget = global_parameters.chunk;
385 if (toget > global_parameters.toget - cl->records)
386 toget = global_parameters.toget - cl->records;
387 if (toget > cl->hits - cl->records)
388 toget = cl->hits - cl->records;
390 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
393 a->u.presentRequest->resultSetStartPoint = &start;
394 a->u.presentRequest->numberOfRecordsRequested = &toget;
396 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
397 client_present_syntax(a, syntax);
399 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
400 client_present_elements(a, elements);
402 if (send_apdu(cl, a) >= 0)
403 cl->state = Client_Presenting;
405 cl->state = Client_Error;
406 odr_reset(global_parameters.odr_out);
410 void client_send_search(struct client *cl)
412 struct session *se = client_get_session(cl);
413 struct session_database *sdb = client_get_database(cl);
414 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
418 int ssub = 0, lslb = 100000, mspn = 10;
419 const char *piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
420 const char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
422 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
425 // constructing RPN query
426 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
428 zquery->which = Z_Query_type_1;
429 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
430 client_get_pquery(cl));
432 // converting to target encoding
433 if (queryenc && *queryenc)
435 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
437 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
438 global_parameters.odr_out,
440 yaz_iconv_close(iconv);
442 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
443 client_get_database(cl)->database->url, queryenc);
446 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
448 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
449 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
450 databaselist[ndb] = sdb->database->databases[ndb];
452 if (!piggyback || *piggyback == '1')
454 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
455 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
456 if (recsyn && *recsyn)
458 a->u.searchRequest->preferredRecordSyntax =
459 yaz_string_to_oid_odr(yaz_oid_std(),
460 CLASS_RECSYN, recsyn,
461 global_parameters.odr_out);
463 if (elements && *elements)
465 Z_ElementSetNames *esn =
466 odr_malloc(global_parameters.odr_out, sizeof(*esn));
467 esn->which = Z_ElementSetNames_generic;
468 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
470 a->u.searchRequest->smallSetElementSetNames = esn;
471 a->u.searchRequest->mediumSetElementSetNames = esn;
473 a->u.searchRequest->smallSetUpperBound = &ssub;
474 a->u.searchRequest->largeSetLowerBound = &lslb;
475 a->u.searchRequest->mediumSetPresentNumber = &mspn;
477 a->u.searchRequest->databaseNames = databaselist;
478 a->u.searchRequest->num_databaseNames = ndb;
481 { //scope for sending and logging queries
482 WRBUF wbquery = wrbuf_alloc();
483 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
486 if (send_apdu(cl, a) >= 0)
488 client_set_state(cl, Client_Searching);
489 client_set_requestid(cl, se->requestid);
490 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
491 client_get_database(cl)->database->url,
492 queryenc ? queryenc : "UTF-8",
493 wrbuf_cstr(wbquery));
496 client_set_state(cl, Client_Error);
497 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
498 client_get_database(cl)->database->url,
499 queryenc ? queryenc : "UTF-8",
500 wrbuf_cstr(wbquery));
503 wrbuf_destroy(wbquery);
506 odr_reset(global_parameters.odr_out);
509 void client_init_response(struct client *cl, Z_APDU *a)
511 Z_InitResponse *r = a->u.initResponse;
513 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
516 cl->state = Client_Continue;
518 cl->state = Client_Failed; // FIXME need to do something to the connection
522 static void ingest_raw_records(struct client *cl, Z_Records *r)
524 Z_NamePlusRecordList *rlist;
525 Z_NamePlusRecord *npr;
529 if (r->which != Z_Records_DBOSD)
531 client_show_raw_error(cl, "non-surrogate diagnostics");
535 rlist = r->u.databaseOrSurDiagnostics;
536 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
538 client_show_raw_error(cl, "no records");
541 npr = rlist->records[0];
542 if (npr->which != Z_NamePlusRecord_databaseRecord)
544 client_show_raw_error(cl, "surrogate diagnostic");
548 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
551 client_show_raw_error(cl, "unable to convert record to xml");
555 xmlDocDumpMemory(doc, &buf_out, &len_out);
558 cl->show_raw->record_handler(cl->show_raw->data,
559 (const char *) buf_out, len_out);
566 static void ingest_records(struct client *cl, Z_Records *r)
569 yaz_timing_t t = yaz_timing_create();
572 struct session *s = client_get_session(cl);
573 Z_NamePlusRecordList *rlist;
576 if (r->which != Z_Records_DBOSD)
578 rlist = r->u.databaseOrSurDiagnostics;
579 for (i = 0; i < rlist->num_records; i++)
581 Z_NamePlusRecord *npr = rlist->records[i];
584 if (npr->which != Z_NamePlusRecord_databaseRecord)
587 "Unexpected record type, probably diagnostic %s",
588 cl->database->database->url);
592 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
596 if (rlist->num_records)
597 session_alert_watch(s, SESSION_WATCH_SHOW);
598 if (rlist->num_records)
599 session_alert_watch(s, SESSION_WATCH_RECORD);
603 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
604 yaz_timing_get_real(t), yaz_timing_get_user(t),
605 yaz_timing_get_sys(t));
606 yaz_timing_destroy(&t);
611 void client_search_response(struct client *cl, Z_APDU *a)
613 struct session *se = cl->session;
614 Z_SearchResponse *r = a->u.searchResponse;
616 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
617 cl->database->database->url, *r->searchStatus);
619 if (*r->searchStatus)
621 cl->hits = *r->resultCount;
624 yaz_log(YLOG_WARN, "Target %s returns hit count %d",
625 cl->database->database->url, cl->hits);
628 se->total_hits += cl->hits;
629 if (r->presentStatus && !*r->presentStatus && r->records)
631 yaz_log(YLOG_DEBUG, "Records in search response %s",
632 cl->database->database->url);
633 ingest_records(cl, r->records);
635 cl->state = Client_Continue;
639 Z_Records *recs = r->records;
641 cl->state = Client_Error;
642 if (recs && recs->which == Z_Records_NSD)
644 WRBUF w = wrbuf_alloc();
646 Z_DiagRec dr, *dr_p = &dr;
647 dr.which = Z_DiagRec_defaultFormat;
648 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
650 wrbuf_printf(w, "Search response NSD %s: ",
651 cl->database->database->url);
653 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
655 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
657 cl->state = Client_Error;
660 else if (recs && recs->which == Z_Records_multipleNSD)
662 WRBUF w = wrbuf_alloc();
664 wrbuf_printf(w, "Search response multipleNSD %s: ",
665 cl->database->database->url);
667 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
668 recs->u.multipleNonSurDiagnostics->num_diagRecs,
670 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
671 cl->state = Client_Error;
677 void client_present_response(struct client *cl, Z_APDU *a)
679 Z_PresentResponse *r = a->u.presentResponse;
680 Z_Records *recs = r->records;
682 if (recs && recs->which == Z_Records_NSD)
684 WRBUF w = wrbuf_alloc();
686 Z_DiagRec dr, *dr_p = &dr;
687 dr.which = Z_DiagRec_defaultFormat;
688 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
690 wrbuf_printf(w, "Present response NSD %s: ",
691 cl->database->database->url);
693 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
695 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
697 cl->state = Client_Error;
700 client_show_raw_error(cl, "non surrogate diagnostics");
702 else if (recs && recs->which == Z_Records_multipleNSD)
704 WRBUF w = wrbuf_alloc();
706 wrbuf_printf(w, "Present response multipleNSD %s: ",
707 cl->database->database->url);
709 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
710 recs->u.multipleNonSurDiagnostics->num_diagRecs,
712 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
713 cl->state = Client_Error;
716 else if (recs && !*r->presentStatus && cl->state != Client_Error)
718 yaz_log(YLOG_DEBUG, "Good Present response %s",
719 cl->database->database->url);
721 // we can mix show raw and normal show ..
722 if (cl->show_raw && cl->show_raw->active)
724 cl->show_raw->active = 0; // no longer active
725 ingest_raw_records(cl, recs);
728 ingest_records(cl, recs);
729 cl->state = Client_Continue;
731 else if (*r->presentStatus)
733 yaz_log(YLOG_WARN, "Bad Present response %s",
734 cl->database->database->url);
735 cl->state = Client_Error;
736 client_show_raw_error(cl, "bad present response");
740 void client_close_response(struct client *cl, Z_APDU *a)
742 struct connection *co = cl->connection;
743 /* Z_Close *r = a->u.close; */
745 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
747 cl->state = Client_Failed;
748 connection_destroy(co);
751 int client_is_our_response(struct client *cl)
753 struct session *se = client_get_session(cl);
755 if (cl && (cl->requestid == se->requestid ||
756 cl->state == Client_Initializing))
761 // Set authentication token in init if one is set for the client
762 // TODO: Extend this to handle other schemes than open (should be simple)
763 static void init_authentication(struct client *cl, Z_InitRequest *req)
765 struct session_database *sdb = client_get_database(cl);
766 const char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
770 struct connection *co = client_get_connection(cl);
771 struct session *se = client_get_session(cl);
772 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
774 idAuth->which = Z_IdAuthentication_open;
775 idAuth->u.open = odr_strdup(global_parameters.odr_out, auth);
776 req->idAuthentication = idAuth;
777 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
781 static void init_zproxy(struct client *cl, Z_InitRequest *req)
783 struct session_database *sdb = client_get_database(cl);
784 char *ztarget = sdb->database->url;
785 //char *ztarget = sdb->url;
786 const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
789 yaz_oi_set_string_oid(&req->otherInfo,
790 global_parameters.odr_out,
791 yaz_oid_userinfo_proxy,
796 static void client_init_request(struct client *cl)
798 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
800 a->u.initRequest->implementationId = global_parameters.implementationId;
801 a->u.initRequest->implementationName = global_parameters.implementationName;
802 a->u.initRequest->implementationVersion =
803 global_parameters.implementationVersion;
804 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
805 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
806 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
808 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
809 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
810 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
812 init_authentication(cl, a->u.initRequest);
813 init_zproxy(cl, a->u.initRequest);
815 if (send_apdu(cl, a) >= 0)
816 client_set_state(cl, Client_Initializing);
818 client_set_state(cl, Client_Error);
819 odr_reset(global_parameters.odr_out);
822 void client_continue(struct client *cl)
824 if (cl->state == Client_Connected) {
825 client_init_request(cl);
827 if (cl->state == Client_Continue || cl->state == Client_Idle)
829 struct session *se = client_get_session(cl);
830 if (cl->requestid != se->requestid && cl->pquery) {
831 // we'll have to abort this because result set is to be deleted
832 client_show_raw_cancel(cl);
833 client_send_search(cl);
835 else if (cl->show_raw)
837 client_send_raw_present(cl);
839 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
840 cl->records < cl->hits) {
841 client_send_present(cl);
844 client_set_state(cl, Client_Idle);
848 struct client *client_create(void)
854 client_freelist = client_freelist->next;
857 r = xmalloc(sizeof(struct client));
867 r->state = Client_Disconnected;
873 void client_destroy(struct client *c)
875 struct session *se = c->session;
876 if (c == se->clients)
877 se->clients = c->next;
881 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
889 connection_release(c->connection);
890 c->next = client_freelist;
894 void client_set_connection(struct client *cl, struct connection *con)
896 cl->connection = con;
899 void client_disconnect(struct client *cl)
901 if (cl->state != Client_Idle)
902 client_set_state(cl, Client_Disconnected);
903 client_set_connection(cl, 0);
906 // Extract terms from query into null-terminated termlist
907 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
911 pull_terms(nmem, query, termlist, &num);
915 // Initialize CCL map for a target
916 static CCL_bibset prepare_cclmap(struct client *cl)
918 struct session_database *sdb = client_get_database(cl);
925 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
927 char *p = strchr(s->name + 3, ':');
930 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
935 ccl_qual_fitem(res, s->value, p);
940 // Parse the query given the settings specific to this client
941 int client_parse_query(struct client *cl, const char *query)
943 struct session *se = client_get_session(cl);
944 struct ccl_rpn_node *cn;
946 CCL_bibset ccl_map = prepare_cclmap(cl);
951 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
952 ccl_qual_rm(&ccl_map);
955 cl->state = Client_Error;
956 yaz_log(YLOG_WARN, "Failed to parse query for %s",
957 client_get_database(cl)->database->url);
960 wrbuf_rewind(se->wrbuf);
961 ccl_pquery(se->wrbuf, cn);
963 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
967 // Initialize relevance structure with query terms
969 extract_terms(se->nmem, cn, p);
970 se->relevance = relevance_create(
971 global_parameters.server->relevance_pct,
972 se->nmem, (const char **) p,
973 se->expected_maxrecs);
980 void client_set_session(struct client *cl, struct session *se)
983 cl->next = se->clients;
987 int client_is_active(struct client *cl)
989 if (cl->connection && (cl->state == Client_Continue ||
990 cl->state == Client_Connecting ||
991 cl->state == Client_Connected ||
992 cl->state == Client_Initializing ||
993 cl->state == Client_Searching ||
994 cl->state == Client_Presenting))
999 struct client *client_next_in_session(struct client *cl)
1007 int client_get_hits(struct client *cl)
1012 int client_get_num_records(struct client *cl)
1017 int client_get_diagnostic(struct client *cl)
1019 return cl->diagnostic;
1022 void client_set_database(struct client *cl, struct session_database *db)
1027 struct host *client_get_host(struct client *cl)
1029 return client_get_database(cl)->database->host;
1032 const char *client_get_url(struct client *cl)
1034 return client_get_database(cl)->database->url;
1040 * indent-tabs-mode: nil
1042 * vim: shiftwidth=4 tabstop=8 expandtab