1 /* $Id: client.c,v 1.22 2007-09-19 13:23:35 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",
107 static struct client *client_freelist = 0;
109 static int send_apdu(struct client *c, Z_APDU *a)
111 struct session_database *sdb = client_get_database(c);
112 const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
113 if (apdulog && *apdulog && *apdulog != '0')
115 ODR p = odr_createmem(ODR_PRINT);
116 yaz_log(YLOG_LOG, "send APDU %s", client_get_url(c));
118 odr_setprint(p, yaz_log_file());
120 odr_setprint(p, stderr);
123 return connection_send_apdu(client_get_connection(c), a);
127 const char *client_get_state_str(struct client *cl)
129 return client_states[cl->state];
132 enum client_state client_get_state(struct client *cl)
137 void client_set_state(struct client *cl, enum client_state st)
142 int no_active = session_active_clients(cl->session);
144 session_alert_watch(cl->session, SESSION_WATCH_SHOW);
148 static void client_show_raw_error(struct client *cl, const char *addinfo);
150 // Close connection and set state to error
151 void client_fatal(struct client *cl)
153 client_show_raw_error(cl, "client connection failure");
154 yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
155 connection_destroy(cl->connection);
156 client_set_state(cl, Client_Error);
160 static int diag_to_wrbuf(Z_DiagRec **pp, int num, WRBUF w)
164 for (i = 0; i<num; i++)
166 Z_DiagRec *p = pp[i];
169 if (p->which != Z_DiagRec_defaultFormat)
171 wrbuf_puts(w, "? Not in default format");
175 Z_DefaultDiagFormat *r = p->u.defaultFormat;
177 if (!r->diagnosticSetId)
178 wrbuf_puts(w, "? Missing diagset");
182 char diag_name_buf[OID_STR_MAX];
183 const char *diag_name = 0;
184 diag_name = yaz_oid_to_string_buf
185 (r->diagnosticSetId, &oclass, diag_name_buf);
186 wrbuf_puts(w, diag_name);
189 code = *r->condition;
190 wrbuf_printf(w, " %d %s", *r->condition,
191 diagbib1_str(*r->condition));
194 case Z_DefaultDiagFormat_v2Addinfo:
195 wrbuf_printf(w, " -- v2 addinfo '%s'", r->u.v2Addinfo);
197 case Z_DefaultDiagFormat_v3Addinfo:
198 wrbuf_printf(w, " -- v3 addinfo '%s'", r->u.v3Addinfo);
208 struct connection *client_get_connection(struct client *cl)
210 return cl->connection;
213 struct session_database *client_get_database(struct client *cl)
218 struct session *client_get_session(struct client *cl)
223 const char *client_get_pquery(struct client *cl)
228 void client_set_requestid(struct client *cl, int id)
233 int client_show_raw_begin(struct client *cl, int position,
234 const char *syntax, const char *esn,
236 void (*error_handler)(void *data, const char *addinfo),
237 void (*record_handler)(void *data, const char *buf,
242 cl->show_raw = xmalloc(sizeof(*cl->show_raw));
243 cl->show_raw->position = position;
244 cl->show_raw->active = 0;
245 cl->show_raw->data = data;
246 cl->show_raw->error_handler = error_handler;
247 cl->show_raw->record_handler = record_handler;
249 cl->show_raw->syntax = xstrdup(syntax);
251 cl->show_raw->syntax = 0;
253 cl->show_raw->esn = xstrdup(esn);
255 cl->show_raw->esn = 0;
258 if (cl->state == Client_Failed)
260 client_show_raw_error(cl, "client failed");
262 else if (cl->state == Client_Disconnected)
264 client_show_raw_error(cl, "client disconnected");
273 void client_show_raw_reset(struct client *cl)
279 static void client_show_raw_error(struct client *cl, const char *addinfo)
283 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
284 client_show_raw_reset(cl);
288 static void client_show_raw_cancel(struct client *cl)
292 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
293 client_show_raw_reset(cl);
297 static void client_present_syntax(Z_APDU *a, const char *syntax)
299 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
300 if (syntax && *syntax)
301 a->u.presentRequest->preferredRecordSyntax =
302 yaz_string_to_oid_odr(yaz_oid_std(),
303 CLASS_RECSYN, syntax,
304 global_parameters.odr_out);
307 static void client_present_elements(Z_APDU *a, const char *elements)
309 if (elements && *elements) // element set is optional
311 Z_ElementSetNames *elementSetNames =
312 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
313 Z_RecordComposition *compo =
314 odr_malloc(global_parameters.odr_out, sizeof(*compo));
315 a->u.presentRequest->recordComposition = compo;
317 compo->which = Z_RecordComp_simple;
318 compo->u.simple = elementSetNames;
320 elementSetNames->which = Z_ElementSetNames_generic;
321 elementSetNames->u.generic =
322 odr_strdup(global_parameters.odr_out, elements);
326 void client_send_raw_present(struct client *cl)
328 struct session_database *sdb = client_get_database(cl);
329 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
331 int start = cl->show_raw->position;
332 const char *syntax = 0;
333 const char *elements = 0;
335 assert(cl->show_raw);
337 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
338 client_get_url(cl), toget, start);
340 a->u.presentRequest->resultSetStartPoint = &start;
341 a->u.presentRequest->numberOfRecordsRequested = &toget;
343 if (cl->show_raw->syntax)
344 syntax = cl->show_raw->syntax;
346 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
348 client_present_syntax(a, syntax);
349 if (cl->show_raw->esn)
350 elements = cl->show_raw->esn;
352 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
353 client_present_elements(a, elements);
355 if (send_apdu(cl, a) >= 0)
357 cl->show_raw->active = 1;
358 cl->state = Client_Presenting;
362 client_show_raw_error(cl, "send_apdu failed");
363 cl->state = Client_Error;
365 odr_reset(global_parameters.odr_out);
368 void client_send_present(struct client *cl)
370 struct session_database *sdb = client_get_database(cl);
371 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
373 int start = cl->records + 1;
374 const char *syntax = 0;
375 const char *elements = 0;
377 toget = global_parameters.chunk;
378 if (toget > global_parameters.toget - cl->records)
379 toget = global_parameters.toget - cl->records;
380 if (toget > cl->hits - cl->records)
381 toget = cl->hits - cl->records;
383 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
386 a->u.presentRequest->resultSetStartPoint = &start;
387 a->u.presentRequest->numberOfRecordsRequested = &toget;
389 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
390 client_present_syntax(a, syntax);
392 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
393 client_present_elements(a, elements);
395 if (send_apdu(cl, a) >= 0)
396 cl->state = Client_Presenting;
398 cl->state = Client_Error;
399 odr_reset(global_parameters.odr_out);
403 void client_send_search(struct client *cl)
405 struct session *se = client_get_session(cl);
406 struct session_database *sdb = client_get_database(cl);
407 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
411 int ssub = 0, lslb = 100000, mspn = 10;
412 const char *piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
413 const char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
415 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
418 // constructing RPN query
419 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
421 zquery->which = Z_Query_type_1;
422 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
423 client_get_pquery(cl));
425 // converting to target encoding
426 if (queryenc && *queryenc)
428 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
430 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
431 global_parameters.odr_out,
433 yaz_iconv_close(iconv);
435 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
436 client_get_database(cl)->database->url, queryenc);
439 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
441 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
442 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
443 databaselist[ndb] = sdb->database->databases[ndb];
445 if (!piggyback || *piggyback == '1')
447 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
448 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
449 if (recsyn && *recsyn)
451 a->u.searchRequest->preferredRecordSyntax =
452 yaz_string_to_oid_odr(yaz_oid_std(),
453 CLASS_RECSYN, recsyn,
454 global_parameters.odr_out);
456 if (elements && *elements)
458 Z_ElementSetNames *esn =
459 odr_malloc(global_parameters.odr_out, sizeof(*esn));
460 esn->which = Z_ElementSetNames_generic;
461 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
463 a->u.searchRequest->smallSetElementSetNames = esn;
464 a->u.searchRequest->mediumSetElementSetNames = esn;
466 a->u.searchRequest->smallSetUpperBound = &ssub;
467 a->u.searchRequest->largeSetLowerBound = &lslb;
468 a->u.searchRequest->mediumSetPresentNumber = &mspn;
470 a->u.searchRequest->databaseNames = databaselist;
471 a->u.searchRequest->num_databaseNames = ndb;
474 { //scope for sending and logging queries
475 WRBUF wbquery = wrbuf_alloc();
476 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
479 if (send_apdu(cl, a) >= 0)
481 client_set_state(cl, Client_Searching);
482 client_set_requestid(cl, se->requestid);
483 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
484 client_get_database(cl)->database->url,
485 queryenc ? queryenc : "UTF-8",
486 wrbuf_cstr(wbquery));
489 client_set_state(cl, Client_Error);
490 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
491 client_get_database(cl)->database->url,
492 queryenc ? queryenc : "UTF-8",
493 wrbuf_cstr(wbquery));
496 wrbuf_destroy(wbquery);
499 odr_reset(global_parameters.odr_out);
502 void client_init_response(struct client *cl, Z_APDU *a)
504 Z_InitResponse *r = a->u.initResponse;
506 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
509 cl->state = Client_Idle;
511 cl->state = Client_Failed; // FIXME need to do something to the connection
515 static void ingest_raw_records(struct client *cl, Z_Records *r)
517 Z_NamePlusRecordList *rlist;
518 Z_NamePlusRecord *npr;
522 if (r->which != Z_Records_DBOSD)
524 client_show_raw_error(cl, "non-surrogate diagnostics");
528 rlist = r->u.databaseOrSurDiagnostics;
529 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
531 client_show_raw_error(cl, "no records");
534 npr = rlist->records[0];
535 if (npr->which != Z_NamePlusRecord_databaseRecord)
537 client_show_raw_error(cl, "surrogate diagnostic");
541 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
544 client_show_raw_error(cl, "unable to convert record to xml");
548 xmlDocDumpMemory(doc, &buf_out, &len_out);
551 cl->show_raw->record_handler(cl->show_raw->data,
552 (const char *) buf_out, len_out);
559 static void ingest_records(struct client *cl, Z_Records *r)
562 yaz_timing_t t = yaz_timing_create();
565 struct session *s = client_get_session(cl);
566 Z_NamePlusRecordList *rlist;
569 if (r->which != Z_Records_DBOSD)
571 rlist = r->u.databaseOrSurDiagnostics;
572 for (i = 0; i < rlist->num_records; i++)
574 Z_NamePlusRecord *npr = rlist->records[i];
577 if (npr->which != Z_NamePlusRecord_databaseRecord)
580 "Unexpected record type, probably diagnostic %s",
581 cl->database->database->url);
585 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
589 if (rlist->num_records)
590 session_alert_watch(s, SESSION_WATCH_SHOW);
591 if (rlist->num_records)
592 session_alert_watch(s, SESSION_WATCH_RECORD);
596 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
597 yaz_timing_get_real(t), yaz_timing_get_user(t),
598 yaz_timing_get_sys(t));
599 yaz_timing_destroy(&t);
604 void client_search_response(struct client *cl, Z_APDU *a)
606 struct session *se = cl->session;
607 Z_SearchResponse *r = a->u.searchResponse;
609 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
610 cl->database->database->url, *r->searchStatus);
612 if (*r->searchStatus)
614 cl->hits = *r->resultCount;
617 yaz_log(YLOG_WARN, "Target %s returns hit count %d",
618 cl->database->database->url, cl->hits);
621 se->total_hits += cl->hits;
622 if (r->presentStatus && !*r->presentStatus && r->records)
624 yaz_log(YLOG_DEBUG, "Records in search response %s",
625 cl->database->database->url);
626 ingest_records(cl, r->records);
628 cl->state = Client_Idle;
632 Z_Records *recs = r->records;
634 cl->state = Client_Error;
635 if (recs && recs->which == Z_Records_NSD)
637 WRBUF w = wrbuf_alloc();
639 Z_DiagRec dr, *dr_p = &dr;
640 dr.which = Z_DiagRec_defaultFormat;
641 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
643 wrbuf_printf(w, "Search response NSD %s: ",
644 cl->database->database->url);
646 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
648 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
650 cl->state = Client_Error;
653 else if (recs && recs->which == Z_Records_multipleNSD)
655 WRBUF w = wrbuf_alloc();
657 wrbuf_printf(w, "Search response multipleNSD %s: ",
658 cl->database->database->url);
660 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
661 recs->u.multipleNonSurDiagnostics->num_diagRecs,
663 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
664 cl->state = Client_Error;
670 void client_present_response(struct client *cl, Z_APDU *a)
672 Z_PresentResponse *r = a->u.presentResponse;
673 Z_Records *recs = r->records;
675 if (recs && recs->which == Z_Records_NSD)
677 WRBUF w = wrbuf_alloc();
679 Z_DiagRec dr, *dr_p = &dr;
680 dr.which = Z_DiagRec_defaultFormat;
681 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
683 wrbuf_printf(w, "Present response NSD %s: ",
684 cl->database->database->url);
686 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
688 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
690 cl->state = Client_Error;
693 client_show_raw_error(cl, "non surrogate diagnostics");
695 else if (recs && recs->which == Z_Records_multipleNSD)
697 WRBUF w = wrbuf_alloc();
699 wrbuf_printf(w, "Present response multipleNSD %s: ",
700 cl->database->database->url);
702 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
703 recs->u.multipleNonSurDiagnostics->num_diagRecs,
705 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
706 cl->state = Client_Error;
709 else if (recs && !*r->presentStatus && cl->state != Client_Error)
711 yaz_log(YLOG_DEBUG, "Good Present response %s",
712 cl->database->database->url);
714 // we can mix show raw and normal show ..
715 if (cl->show_raw && cl->show_raw->active)
717 cl->show_raw->active = 0; // no longer active
718 ingest_raw_records(cl, recs);
721 ingest_records(cl, recs);
722 cl->state = Client_Idle;
724 else if (*r->presentStatus)
726 yaz_log(YLOG_WARN, "Bad Present response %s",
727 cl->database->database->url);
728 cl->state = Client_Error;
729 client_show_raw_error(cl, "bad present response");
733 void client_close_response(struct client *cl, Z_APDU *a)
735 struct connection *co = cl->connection;
736 /* Z_Close *r = a->u.close; */
738 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
740 cl->state = Client_Failed;
741 connection_destroy(co);
744 int client_is_our_response(struct client *cl)
746 struct session *se = client_get_session(cl);
748 if (cl && (cl->requestid == se->requestid ||
749 cl->state == Client_Initializing))
754 // Set authentication token in init if one is set for the client
755 // TODO: Extend this to handle other schemes than open (should be simple)
756 static void init_authentication(struct client *cl, Z_InitRequest *req)
758 struct session_database *sdb = client_get_database(cl);
759 const char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
763 struct connection *co = client_get_connection(cl);
764 struct session *se = client_get_session(cl);
765 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
767 idAuth->which = Z_IdAuthentication_open;
768 idAuth->u.open = odr_strdup(global_parameters.odr_out, auth);
769 req->idAuthentication = idAuth;
770 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
774 static void init_zproxy(struct client *cl, Z_InitRequest *req)
776 struct session_database *sdb = client_get_database(cl);
777 char *ztarget = sdb->database->url;
778 //char *ztarget = sdb->url;
779 const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
782 yaz_oi_set_string_oid(&req->otherInfo,
783 global_parameters.odr_out,
784 yaz_oid_userinfo_proxy,
789 static void client_init_request(struct client *cl)
791 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
793 a->u.initRequest->implementationId = global_parameters.implementationId;
794 a->u.initRequest->implementationName = global_parameters.implementationName;
795 a->u.initRequest->implementationVersion =
796 global_parameters.implementationVersion;
797 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
798 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
799 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
801 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
802 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
803 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
805 init_authentication(cl, a->u.initRequest);
806 init_zproxy(cl, a->u.initRequest);
808 if (send_apdu(cl, a) >= 0)
809 client_set_state(cl, Client_Initializing);
811 client_set_state(cl, Client_Error);
812 odr_reset(global_parameters.odr_out);
815 void client_continue(struct client *cl)
817 if (cl->state == Client_Connected) {
818 client_init_request(cl);
820 if (cl->state == Client_Idle)
822 struct session *se = client_get_session(cl);
823 if (cl->requestid != se->requestid && cl->pquery) {
824 // we'll have to abort this because result set is to be deleted
825 client_show_raw_cancel(cl);
826 client_send_search(cl);
828 else if (cl->show_raw)
830 client_send_raw_present(cl);
832 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
833 cl->records < cl->hits) {
834 client_send_present(cl);
839 struct client *client_create(void)
845 client_freelist = client_freelist->next;
848 r = xmalloc(sizeof(struct client));
858 r->state = Client_Disconnected;
864 void client_destroy(struct client *c)
866 struct session *se = c->session;
867 if (c == se->clients)
868 se->clients = c->next;
872 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
880 connection_release(c->connection);
881 c->next = client_freelist;
885 void client_set_connection(struct client *cl, struct connection *con)
887 cl->connection = con;
890 void client_disconnect(struct client *cl)
892 if (cl->state != Client_Idle)
893 cl->state = Client_Disconnected;
894 client_set_connection(cl, 0);
897 // Extract terms from query into null-terminated termlist
898 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
902 pull_terms(nmem, query, termlist, &num);
906 // Initialize CCL map for a target
907 static CCL_bibset prepare_cclmap(struct client *cl)
909 struct session_database *sdb = client_get_database(cl);
916 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
918 char *p = strchr(s->name + 3, ':');
921 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
926 ccl_qual_fitem(res, s->value, p);
931 // Parse the query given the settings specific to this client
932 int client_parse_query(struct client *cl, const char *query)
934 struct session *se = client_get_session(cl);
935 struct ccl_rpn_node *cn;
937 CCL_bibset ccl_map = prepare_cclmap(cl);
942 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
943 ccl_qual_rm(&ccl_map);
946 cl->state = Client_Error;
947 yaz_log(YLOG_WARN, "Failed to parse query for %s",
948 client_get_database(cl)->database->url);
951 wrbuf_rewind(se->wrbuf);
952 ccl_pquery(se->wrbuf, cn);
954 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
958 // Initialize relevance structure with query terms
960 extract_terms(se->nmem, cn, p);
961 se->relevance = relevance_create(
962 global_parameters.server->relevance_pct,
963 se->nmem, (const char **) p,
964 se->expected_maxrecs);
971 void client_set_session(struct client *cl, struct session *se)
974 cl->next = se->clients;
978 int client_is_active(struct client *cl)
980 if (cl->connection && (cl->state == Client_Connecting ||
981 cl->state == Client_Initializing ||
982 cl->state == Client_Searching ||
983 cl->state == Client_Presenting))
988 struct client *client_next_in_session(struct client *cl)
996 int client_get_hits(struct client *cl)
1001 int client_get_num_records(struct client *cl)
1006 int client_get_diagnostic(struct client *cl)
1008 return cl->diagnostic;
1011 void client_set_database(struct client *cl, struct session_database *db)
1016 struct host *client_get_host(struct client *cl)
1018 return client_get_database(cl)->database->host;
1021 const char *client_get_url(struct client *cl)
1023 return client_get_database(cl)->database->url;
1029 * indent-tabs-mode: nil
1031 * vim: shiftwidth=4 tabstop=8 expandtab