1 /* $Id: client.c,v 1.23 2007-09-20 08:13:27 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,
243 cl->show_raw = xmalloc(sizeof(*cl->show_raw));
244 cl->show_raw->position = position;
245 cl->show_raw->active = 0;
246 cl->show_raw->data = data;
247 cl->show_raw->error_handler = error_handler;
248 cl->show_raw->record_handler = record_handler;
250 cl->show_raw->syntax = xstrdup(syntax);
252 cl->show_raw->syntax = 0;
254 cl->show_raw->esn = xstrdup(esn);
256 cl->show_raw->esn = 0;
259 if (cl->state == Client_Failed)
261 client_show_raw_error(cl, "client failed");
263 else if (cl->state == Client_Disconnected)
265 client_show_raw_error(cl, "client disconnected");
274 void client_show_raw_reset(struct client *cl)
280 static void client_show_raw_error(struct client *cl, const char *addinfo)
284 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
285 client_show_raw_reset(cl);
289 static void client_show_raw_cancel(struct client *cl)
293 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
294 client_show_raw_reset(cl);
298 static void client_present_syntax(Z_APDU *a, const char *syntax)
300 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
301 if (syntax && *syntax)
302 a->u.presentRequest->preferredRecordSyntax =
303 yaz_string_to_oid_odr(yaz_oid_std(),
304 CLASS_RECSYN, syntax,
305 global_parameters.odr_out);
308 static void client_present_elements(Z_APDU *a, const char *elements)
310 if (elements && *elements) // element set is optional
312 Z_ElementSetNames *elementSetNames =
313 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
314 Z_RecordComposition *compo =
315 odr_malloc(global_parameters.odr_out, sizeof(*compo));
316 a->u.presentRequest->recordComposition = compo;
318 compo->which = Z_RecordComp_simple;
319 compo->u.simple = elementSetNames;
321 elementSetNames->which = Z_ElementSetNames_generic;
322 elementSetNames->u.generic =
323 odr_strdup(global_parameters.odr_out, elements);
327 void client_send_raw_present(struct client *cl)
329 struct session_database *sdb = client_get_database(cl);
330 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
332 int start = cl->show_raw->position;
333 const char *syntax = 0;
334 const char *elements = 0;
336 assert(cl->show_raw);
338 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
339 client_get_url(cl), toget, start);
341 a->u.presentRequest->resultSetStartPoint = &start;
342 a->u.presentRequest->numberOfRecordsRequested = &toget;
344 if (cl->show_raw->syntax)
345 syntax = cl->show_raw->syntax;
347 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
349 client_present_syntax(a, syntax);
350 if (cl->show_raw->esn)
351 elements = cl->show_raw->esn;
353 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
354 client_present_elements(a, elements);
356 if (send_apdu(cl, a) >= 0)
358 cl->show_raw->active = 1;
359 cl->state = Client_Presenting;
363 client_show_raw_error(cl, "send_apdu failed");
364 cl->state = Client_Error;
366 odr_reset(global_parameters.odr_out);
369 void client_send_present(struct client *cl)
371 struct session_database *sdb = client_get_database(cl);
372 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
374 int start = cl->records + 1;
375 const char *syntax = 0;
376 const char *elements = 0;
378 toget = global_parameters.chunk;
379 if (toget > global_parameters.toget - cl->records)
380 toget = global_parameters.toget - cl->records;
381 if (toget > cl->hits - cl->records)
382 toget = cl->hits - cl->records;
384 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
387 a->u.presentRequest->resultSetStartPoint = &start;
388 a->u.presentRequest->numberOfRecordsRequested = &toget;
390 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
391 client_present_syntax(a, syntax);
393 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
394 client_present_elements(a, elements);
396 if (send_apdu(cl, a) >= 0)
397 cl->state = Client_Presenting;
399 cl->state = Client_Error;
400 odr_reset(global_parameters.odr_out);
404 void client_send_search(struct client *cl)
406 struct session *se = client_get_session(cl);
407 struct session_database *sdb = client_get_database(cl);
408 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
412 int ssub = 0, lslb = 100000, mspn = 10;
413 const char *piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
414 const char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
416 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
419 // constructing RPN query
420 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
422 zquery->which = Z_Query_type_1;
423 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
424 client_get_pquery(cl));
426 // converting to target encoding
427 if (queryenc && *queryenc)
429 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
431 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
432 global_parameters.odr_out,
434 yaz_iconv_close(iconv);
436 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
437 client_get_database(cl)->database->url, queryenc);
440 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
442 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
443 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
444 databaselist[ndb] = sdb->database->databases[ndb];
446 if (!piggyback || *piggyback == '1')
448 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
449 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
450 if (recsyn && *recsyn)
452 a->u.searchRequest->preferredRecordSyntax =
453 yaz_string_to_oid_odr(yaz_oid_std(),
454 CLASS_RECSYN, recsyn,
455 global_parameters.odr_out);
457 if (elements && *elements)
459 Z_ElementSetNames *esn =
460 odr_malloc(global_parameters.odr_out, sizeof(*esn));
461 esn->which = Z_ElementSetNames_generic;
462 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
464 a->u.searchRequest->smallSetElementSetNames = esn;
465 a->u.searchRequest->mediumSetElementSetNames = esn;
467 a->u.searchRequest->smallSetUpperBound = &ssub;
468 a->u.searchRequest->largeSetLowerBound = &lslb;
469 a->u.searchRequest->mediumSetPresentNumber = &mspn;
471 a->u.searchRequest->databaseNames = databaselist;
472 a->u.searchRequest->num_databaseNames = ndb;
475 { //scope for sending and logging queries
476 WRBUF wbquery = wrbuf_alloc();
477 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
480 if (send_apdu(cl, a) >= 0)
482 client_set_state(cl, Client_Searching);
483 client_set_requestid(cl, se->requestid);
484 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
485 client_get_database(cl)->database->url,
486 queryenc ? queryenc : "UTF-8",
487 wrbuf_cstr(wbquery));
490 client_set_state(cl, Client_Error);
491 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
492 client_get_database(cl)->database->url,
493 queryenc ? queryenc : "UTF-8",
494 wrbuf_cstr(wbquery));
497 wrbuf_destroy(wbquery);
500 odr_reset(global_parameters.odr_out);
503 void client_init_response(struct client *cl, Z_APDU *a)
505 Z_InitResponse *r = a->u.initResponse;
507 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
510 cl->state = Client_Idle;
512 cl->state = Client_Failed; // FIXME need to do something to the connection
516 static void ingest_raw_records(struct client *cl, Z_Records *r)
518 Z_NamePlusRecordList *rlist;
519 Z_NamePlusRecord *npr;
523 if (r->which != Z_Records_DBOSD)
525 client_show_raw_error(cl, "non-surrogate diagnostics");
529 rlist = r->u.databaseOrSurDiagnostics;
530 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
532 client_show_raw_error(cl, "no records");
535 npr = rlist->records[0];
536 if (npr->which != Z_NamePlusRecord_databaseRecord)
538 client_show_raw_error(cl, "surrogate diagnostic");
542 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
545 client_show_raw_error(cl, "unable to convert record to xml");
549 xmlDocDumpMemory(doc, &buf_out, &len_out);
552 cl->show_raw->record_handler(cl->show_raw->data,
553 (const char *) buf_out, len_out);
560 static void ingest_records(struct client *cl, Z_Records *r)
563 yaz_timing_t t = yaz_timing_create();
566 struct session *s = client_get_session(cl);
567 Z_NamePlusRecordList *rlist;
570 if (r->which != Z_Records_DBOSD)
572 rlist = r->u.databaseOrSurDiagnostics;
573 for (i = 0; i < rlist->num_records; i++)
575 Z_NamePlusRecord *npr = rlist->records[i];
578 if (npr->which != Z_NamePlusRecord_databaseRecord)
581 "Unexpected record type, probably diagnostic %s",
582 cl->database->database->url);
586 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
590 if (rlist->num_records)
591 session_alert_watch(s, SESSION_WATCH_SHOW);
592 if (rlist->num_records)
593 session_alert_watch(s, SESSION_WATCH_RECORD);
597 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
598 yaz_timing_get_real(t), yaz_timing_get_user(t),
599 yaz_timing_get_sys(t));
600 yaz_timing_destroy(&t);
605 void client_search_response(struct client *cl, Z_APDU *a)
607 struct session *se = cl->session;
608 Z_SearchResponse *r = a->u.searchResponse;
610 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
611 cl->database->database->url, *r->searchStatus);
613 if (*r->searchStatus)
615 cl->hits = *r->resultCount;
618 yaz_log(YLOG_WARN, "Target %s returns hit count %d",
619 cl->database->database->url, cl->hits);
622 se->total_hits += cl->hits;
623 if (r->presentStatus && !*r->presentStatus && r->records)
625 yaz_log(YLOG_DEBUG, "Records in search response %s",
626 cl->database->database->url);
627 ingest_records(cl, r->records);
629 cl->state = Client_Idle;
633 Z_Records *recs = r->records;
635 cl->state = Client_Error;
636 if (recs && recs->which == Z_Records_NSD)
638 WRBUF w = wrbuf_alloc();
640 Z_DiagRec dr, *dr_p = &dr;
641 dr.which = Z_DiagRec_defaultFormat;
642 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
644 wrbuf_printf(w, "Search response NSD %s: ",
645 cl->database->database->url);
647 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
649 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
651 cl->state = Client_Error;
654 else if (recs && recs->which == Z_Records_multipleNSD)
656 WRBUF w = wrbuf_alloc();
658 wrbuf_printf(w, "Search response multipleNSD %s: ",
659 cl->database->database->url);
661 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
662 recs->u.multipleNonSurDiagnostics->num_diagRecs,
664 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
665 cl->state = Client_Error;
671 void client_present_response(struct client *cl, Z_APDU *a)
673 Z_PresentResponse *r = a->u.presentResponse;
674 Z_Records *recs = r->records;
676 if (recs && recs->which == Z_Records_NSD)
678 WRBUF w = wrbuf_alloc();
680 Z_DiagRec dr, *dr_p = &dr;
681 dr.which = Z_DiagRec_defaultFormat;
682 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
684 wrbuf_printf(w, "Present response NSD %s: ",
685 cl->database->database->url);
687 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
689 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
691 cl->state = Client_Error;
694 client_show_raw_error(cl, "non surrogate diagnostics");
696 else if (recs && recs->which == Z_Records_multipleNSD)
698 WRBUF w = wrbuf_alloc();
700 wrbuf_printf(w, "Present 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;
710 else if (recs && !*r->presentStatus && cl->state != Client_Error)
712 yaz_log(YLOG_DEBUG, "Good Present response %s",
713 cl->database->database->url);
715 // we can mix show raw and normal show ..
716 if (cl->show_raw && cl->show_raw->active)
718 cl->show_raw->active = 0; // no longer active
719 ingest_raw_records(cl, recs);
722 ingest_records(cl, recs);
723 cl->state = Client_Idle;
725 else if (*r->presentStatus)
727 yaz_log(YLOG_WARN, "Bad Present response %s",
728 cl->database->database->url);
729 cl->state = Client_Error;
730 client_show_raw_error(cl, "bad present response");
734 void client_close_response(struct client *cl, Z_APDU *a)
736 struct connection *co = cl->connection;
737 /* Z_Close *r = a->u.close; */
739 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
741 cl->state = Client_Failed;
742 connection_destroy(co);
745 int client_is_our_response(struct client *cl)
747 struct session *se = client_get_session(cl);
749 if (cl && (cl->requestid == se->requestid ||
750 cl->state == Client_Initializing))
755 // Set authentication token in init if one is set for the client
756 // TODO: Extend this to handle other schemes than open (should be simple)
757 static void init_authentication(struct client *cl, Z_InitRequest *req)
759 struct session_database *sdb = client_get_database(cl);
760 const char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
764 struct connection *co = client_get_connection(cl);
765 struct session *se = client_get_session(cl);
766 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
768 idAuth->which = Z_IdAuthentication_open;
769 idAuth->u.open = odr_strdup(global_parameters.odr_out, auth);
770 req->idAuthentication = idAuth;
771 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
775 static void init_zproxy(struct client *cl, Z_InitRequest *req)
777 struct session_database *sdb = client_get_database(cl);
778 char *ztarget = sdb->database->url;
779 //char *ztarget = sdb->url;
780 const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
783 yaz_oi_set_string_oid(&req->otherInfo,
784 global_parameters.odr_out,
785 yaz_oid_userinfo_proxy,
790 static void client_init_request(struct client *cl)
792 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
794 a->u.initRequest->implementationId = global_parameters.implementationId;
795 a->u.initRequest->implementationName = global_parameters.implementationName;
796 a->u.initRequest->implementationVersion =
797 global_parameters.implementationVersion;
798 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
799 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
800 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
802 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
803 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
804 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
806 init_authentication(cl, a->u.initRequest);
807 init_zproxy(cl, a->u.initRequest);
809 if (send_apdu(cl, a) >= 0)
810 client_set_state(cl, Client_Initializing);
812 client_set_state(cl, Client_Error);
813 odr_reset(global_parameters.odr_out);
816 void client_continue(struct client *cl)
818 if (cl->state == Client_Connected) {
819 client_init_request(cl);
821 if (cl->state == Client_Continue || cl->state == Client_Idle)
823 struct session *se = client_get_session(cl);
824 if (cl->requestid != se->requestid && cl->pquery) {
825 // we'll have to abort this because result set is to be deleted
826 client_show_raw_cancel(cl);
827 client_send_search(cl);
829 else if (cl->show_raw)
831 client_send_raw_present(cl);
833 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
834 cl->records < cl->hits) {
835 client_send_present(cl);
838 client_set_state(cl, Client_Idle);
842 struct client *client_create(void)
848 client_freelist = client_freelist->next;
851 r = xmalloc(sizeof(struct client));
861 r->state = Client_Disconnected;
867 void client_destroy(struct client *c)
869 struct session *se = c->session;
870 if (c == se->clients)
871 se->clients = c->next;
875 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
883 connection_release(c->connection);
884 c->next = client_freelist;
888 void client_set_connection(struct client *cl, struct connection *con)
890 cl->connection = con;
893 void client_disconnect(struct client *cl)
895 if (cl->state != Client_Idle)
896 cl->state = Client_Disconnected;
897 client_set_connection(cl, 0);
900 // Extract terms from query into null-terminated termlist
901 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
905 pull_terms(nmem, query, termlist, &num);
909 // Initialize CCL map for a target
910 static CCL_bibset prepare_cclmap(struct client *cl)
912 struct session_database *sdb = client_get_database(cl);
919 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
921 char *p = strchr(s->name + 3, ':');
924 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
929 ccl_qual_fitem(res, s->value, p);
934 // Parse the query given the settings specific to this client
935 int client_parse_query(struct client *cl, const char *query)
937 struct session *se = client_get_session(cl);
938 struct ccl_rpn_node *cn;
940 CCL_bibset ccl_map = prepare_cclmap(cl);
945 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
946 ccl_qual_rm(&ccl_map);
949 cl->state = Client_Error;
950 yaz_log(YLOG_WARN, "Failed to parse query for %s",
951 client_get_database(cl)->database->url);
954 wrbuf_rewind(se->wrbuf);
955 ccl_pquery(se->wrbuf, cn);
957 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
961 // Initialize relevance structure with query terms
963 extract_terms(se->nmem, cn, p);
964 se->relevance = relevance_create(
965 global_parameters.server->relevance_pct,
966 se->nmem, (const char **) p,
967 se->expected_maxrecs);
974 void client_set_session(struct client *cl, struct session *se)
977 cl->next = se->clients;
981 int client_is_active(struct client *cl)
983 if (cl->connection && (cl->state == Client_Continue ||
984 cl->state == Client_Connecting ||
985 cl->state == Client_Initializing ||
986 cl->state == Client_Searching ||
987 cl->state == Client_Presenting))
992 struct client *client_next_in_session(struct client *cl)
1000 int client_get_hits(struct client *cl)
1005 int client_get_num_records(struct client *cl)
1010 int client_get_diagnostic(struct client *cl)
1012 return cl->diagnostic;
1015 void client_set_database(struct client *cl, struct session_database *db)
1020 struct host *client_get_host(struct client *cl)
1022 return client_get_database(cl)->database->host;
1025 const char *client_get_url(struct client *cl)
1027 return client_get_database(cl)->database->url;
1033 * indent-tabs-mode: nil
1035 * vim: shiftwidth=4 tabstop=8 expandtab