1 /* $Id: client.c,v 1.17 2007-08-17 12:25:26 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 static void client_show_raw_error(struct client *cl, const char *addinfo);
144 // Close connection and set state to error
145 void client_fatal(struct client *cl)
147 client_show_raw_error(cl, "client connection failure");
148 yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
149 connection_destroy(cl->connection);
150 cl->state = Client_Error;
154 static int diag_to_wrbuf(Z_DiagRec **pp, int num, WRBUF w)
158 for (i = 0; i<num; i++)
160 Z_DiagRec *p = pp[i];
163 if (p->which != Z_DiagRec_defaultFormat)
165 wrbuf_puts(w, "? Not in default format");
169 Z_DefaultDiagFormat *r = p->u.defaultFormat;
171 if (!r->diagnosticSetId)
172 wrbuf_puts(w, "? Missing diagset");
176 char diag_name_buf[OID_STR_MAX];
177 const char *diag_name = 0;
178 diag_name = yaz_oid_to_string_buf
179 (r->diagnosticSetId, &oclass, diag_name_buf);
180 wrbuf_puts(w, diag_name);
183 code = *r->condition;
184 wrbuf_printf(w, " %d %s", *r->condition,
185 diagbib1_str(*r->condition));
188 case Z_DefaultDiagFormat_v2Addinfo:
189 wrbuf_printf(w, " -- v2 addinfo '%s'", r->u.v2Addinfo);
191 case Z_DefaultDiagFormat_v3Addinfo:
192 wrbuf_printf(w, " -- v3 addinfo '%s'", r->u.v3Addinfo);
202 struct connection *client_get_connection(struct client *cl)
204 return cl->connection;
207 struct session_database *client_get_database(struct client *cl)
212 struct session *client_get_session(struct client *cl)
217 const char *client_get_pquery(struct client *cl)
222 void client_set_requestid(struct client *cl, int id)
227 int client_show_raw_begin(struct client *cl, int position,
228 const char *syntax, const char *esn,
230 void (*error_handler)(void *data, const char *addinfo),
231 void (*record_handler)(void *data, const char *buf,
236 cl->show_raw = xmalloc(sizeof(*cl->show_raw));
237 cl->show_raw->position = position;
238 cl->show_raw->active = 0;
239 cl->show_raw->data = data;
240 cl->show_raw->error_handler = error_handler;
241 cl->show_raw->record_handler = record_handler;
243 cl->show_raw->syntax = xstrdup(syntax);
245 cl->show_raw->syntax = 0;
247 cl->show_raw->esn = xstrdup(esn);
249 cl->show_raw->esn = 0;
252 if (cl->state == Client_Failed)
254 client_show_raw_error(cl, "client failed");
256 else if (cl->state == Client_Disconnected)
258 client_show_raw_error(cl, "client disconnected");
267 void client_show_raw_reset(struct client *cl)
273 static void client_show_raw_error(struct client *cl, const char *addinfo)
277 cl->show_raw->error_handler(cl->show_raw->data, addinfo);
278 client_show_raw_reset(cl);
282 static void client_show_raw_cancel(struct client *cl)
286 cl->show_raw->error_handler(cl->show_raw->data, "cancel");
287 client_show_raw_reset(cl);
291 static void client_present_syntax(Z_APDU *a, const char *syntax)
293 // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL)
294 if (syntax && *syntax)
295 a->u.presentRequest->preferredRecordSyntax =
296 yaz_string_to_oid_odr(yaz_oid_std(),
297 CLASS_RECSYN, syntax,
298 global_parameters.odr_out);
301 static void client_present_elements(Z_APDU *a, const char *elements)
303 if (elements && *elements) // element set is optional
305 Z_ElementSetNames *elementSetNames =
306 odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
307 Z_RecordComposition *compo =
308 odr_malloc(global_parameters.odr_out, sizeof(*compo));
309 a->u.presentRequest->recordComposition = compo;
311 compo->which = Z_RecordComp_simple;
312 compo->u.simple = elementSetNames;
314 elementSetNames->which = Z_ElementSetNames_generic;
315 elementSetNames->u.generic =
316 odr_strdup(global_parameters.odr_out, elements);
320 void client_send_raw_present(struct client *cl)
322 struct session_database *sdb = client_get_database(cl);
323 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
325 int start = cl->show_raw->position;
326 const char *syntax = 0;
327 const char *elements = 0;
329 assert(cl->show_raw);
331 yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
332 client_get_url(cl), toget, start);
334 a->u.presentRequest->resultSetStartPoint = &start;
335 a->u.presentRequest->numberOfRecordsRequested = &toget;
337 if (cl->show_raw->syntax)
338 syntax = cl->show_raw->syntax;
340 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
342 client_present_syntax(a, syntax);
343 if (cl->show_raw->esn)
344 elements = cl->show_raw->esn;
346 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
347 client_present_elements(a, elements);
349 if (send_apdu(cl, a) >= 0)
351 cl->show_raw->active = 1;
352 cl->state = Client_Presenting;
356 client_show_raw_error(cl, "send_apdu failed");
357 cl->state = Client_Error;
359 odr_reset(global_parameters.odr_out);
362 void client_send_present(struct client *cl)
364 struct session_database *sdb = client_get_database(cl);
365 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
367 int start = cl->records + 1;
368 const char *syntax = 0;
369 const char *elements = 0;
371 toget = global_parameters.chunk;
372 if (toget > global_parameters.toget - cl->records)
373 toget = global_parameters.toget - cl->records;
374 if (toget > cl->hits - cl->records)
375 toget = cl->hits - cl->records;
377 yaz_log(YLOG_DEBUG, "Trying to present %d record(s) from %d",
380 a->u.presentRequest->resultSetStartPoint = &start;
381 a->u.presentRequest->numberOfRecordsRequested = &toget;
383 syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
384 client_present_syntax(a, syntax);
386 elements = session_setting_oneval(sdb, PZ_ELEMENTS);
387 client_present_elements(a, elements);
389 if (send_apdu(cl, a) >= 0)
390 cl->state = Client_Presenting;
392 cl->state = Client_Error;
393 odr_reset(global_parameters.odr_out);
397 void client_send_search(struct client *cl)
399 struct session *se = client_get_session(cl);
400 struct session_database *sdb = client_get_database(cl);
401 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
405 int ssub = 0, lslb = 100000, mspn = 10;
407 char *queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
409 yaz_log(YLOG_DEBUG, "Sending search to %s", sdb->database->url);
412 // constructing RPN query
413 a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
415 zquery->which = Z_Query_type_1;
416 zquery->u.type_1 = p_query_rpn(global_parameters.odr_out,
417 client_get_pquery(cl));
419 // converting to target encoding
420 if (queryenc && *queryenc)
422 yaz_iconv_t iconv = yaz_iconv_open(queryenc, "UTF-8");
424 yaz_query_charset_convert_rpnquery(zquery->u.type_1,
425 global_parameters.odr_out,
427 yaz_iconv_close(iconv);
429 yaz_log(YLOG_WARN, "Query encoding failed %s %s",
430 client_get_database(cl)->database->url, queryenc);
433 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
435 databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
436 for (ndb = 0; sdb->database->databases[ndb]; ndb++)
437 databaselist[ndb] = sdb->database->databases[ndb];
439 if (!(piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK))
440 || *piggyback == '1')
442 const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS);
443 const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
444 if (recsyn && *recsyn)
446 a->u.searchRequest->preferredRecordSyntax =
447 yaz_string_to_oid_odr(yaz_oid_std(),
448 CLASS_RECSYN, recsyn,
449 global_parameters.odr_out);
451 if (elements && *elements)
453 Z_ElementSetNames *esn =
454 odr_malloc(global_parameters.odr_out, sizeof(*esn));
455 esn->which = Z_ElementSetNames_generic;
456 esn->u.generic = odr_strdup(global_parameters.odr_out, elements);
458 a->u.searchRequest->smallSetElementSetNames = esn;
459 a->u.searchRequest->mediumSetElementSetNames = esn;
461 a->u.searchRequest->smallSetUpperBound = &ssub;
462 a->u.searchRequest->largeSetLowerBound = &lslb;
463 a->u.searchRequest->mediumSetPresentNumber = &mspn;
465 a->u.searchRequest->databaseNames = databaselist;
466 a->u.searchRequest->num_databaseNames = ndb;
469 { //scope for sending and logging queries
470 WRBUF wbquery = wrbuf_alloc();
471 yaz_query_to_wrbuf(wbquery, a->u.searchRequest->query);
474 if (send_apdu(cl, a) >= 0)
476 client_set_state(cl, Client_Searching);
477 client_set_requestid(cl, se->requestid);
478 yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
479 client_get_database(cl)->database->url,
480 queryenc ? queryenc : "UTF-8",
481 wrbuf_cstr(wbquery));
484 client_set_state(cl, Client_Error);
485 yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
486 client_get_database(cl)->database->url,
487 queryenc ? queryenc : "UTF-8",
488 wrbuf_cstr(wbquery));
491 wrbuf_destroy(wbquery);
494 odr_reset(global_parameters.odr_out);
497 void client_init_response(struct client *cl, Z_APDU *a)
499 Z_InitResponse *r = a->u.initResponse;
501 yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
504 cl->state = Client_Idle;
506 cl->state = Client_Failed; // FIXME need to do something to the connection
510 static void ingest_raw_records(struct client *cl, Z_Records *r)
512 Z_NamePlusRecordList *rlist;
513 Z_NamePlusRecord *npr;
517 if (r->which != Z_Records_DBOSD)
519 client_show_raw_error(cl, "non-surrogate diagnostics");
523 rlist = r->u.databaseOrSurDiagnostics;
524 if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
526 client_show_raw_error(cl, "no records");
529 npr = rlist->records[0];
530 if (npr->which != Z_NamePlusRecord_databaseRecord)
532 client_show_raw_error(cl, "surrogate diagnostic");
536 doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
539 client_show_raw_error(cl, "unable to convert record to xml");
543 xmlDocDumpMemory(doc, &buf_out, &len_out);
546 cl->show_raw->record_handler(cl->show_raw->data,
547 (const char *) buf_out, len_out);
554 static void ingest_records(struct client *cl, Z_Records *r)
557 yaz_timing_t t = yaz_timing_create();
560 struct session *s = client_get_session(cl);
561 Z_NamePlusRecordList *rlist;
564 if (r->which != Z_Records_DBOSD)
566 rlist = r->u.databaseOrSurDiagnostics;
567 for (i = 0; i < rlist->num_records; i++)
569 Z_NamePlusRecord *npr = rlist->records[i];
572 if (npr->which != Z_NamePlusRecord_databaseRecord)
575 "Unexpected record type, probably diagnostic %s",
576 cl->database->database->url);
580 rec = ingest_record(cl, npr->u.databaseRecord, cl->records);
584 if (rlist->num_records)
585 session_alert_watch(s, SESSION_WATCH_RECORDS);
589 yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f",
590 yaz_timing_get_real(t), yaz_timing_get_user(t),
591 yaz_timing_get_sys(t));
592 yaz_timing_destroy(&t);
597 void client_search_response(struct client *cl, Z_APDU *a)
599 struct session *se = cl->session;
600 Z_SearchResponse *r = a->u.searchResponse;
602 yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
603 cl->database->database->url, *r->searchStatus);
605 if (*r->searchStatus)
607 cl->hits = *r->resultCount;
608 se->total_hits += cl->hits;
609 if (r->presentStatus && !*r->presentStatus && r->records)
611 yaz_log(YLOG_DEBUG, "Records in search response %s",
612 cl->database->database->url);
613 ingest_records(cl, r->records);
615 cl->state = Client_Idle;
619 Z_Records *recs = r->records;
621 cl->state = Client_Error;
622 if (recs && recs->which == Z_Records_NSD)
624 WRBUF w = wrbuf_alloc();
626 Z_DiagRec dr, *dr_p = &dr;
627 dr.which = Z_DiagRec_defaultFormat;
628 dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
630 wrbuf_printf(w, "Search response NSD %s: ",
631 cl->database->database->url);
633 cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
635 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
637 cl->state = Client_Error;
640 else if (recs && recs->which == Z_Records_multipleNSD)
642 WRBUF w = wrbuf_alloc();
644 wrbuf_printf(w, "Search response multipleNSD %s: ",
645 cl->database->database->url);
647 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
648 recs->u.multipleNonSurDiagnostics->num_diagRecs,
650 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
651 cl->state = Client_Error;
657 void client_present_response(struct client *cl, Z_APDU *a)
659 Z_PresentResponse *r = a->u.presentResponse;
660 Z_Records *recs = r->records;
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, "Present 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 client_show_raw_error(cl, "non surrogate diagnostics");
682 else if (recs && recs->which == Z_Records_multipleNSD)
684 WRBUF w = wrbuf_alloc();
686 wrbuf_printf(w, "Present response multipleNSD %s: ",
687 cl->database->database->url);
689 diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
690 recs->u.multipleNonSurDiagnostics->num_diagRecs,
692 yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
693 cl->state = Client_Error;
696 else if (recs && !*r->presentStatus && cl->state != Client_Error)
698 yaz_log(YLOG_DEBUG, "Good Present response %s",
699 cl->database->database->url);
701 // we can mix show raw and normal show ..
702 if (cl->show_raw && cl->show_raw->active)
704 cl->show_raw->active = 0; // no longer active
705 ingest_raw_records(cl, recs);
708 ingest_records(cl, recs);
709 cl->state = Client_Idle;
711 else if (*r->presentStatus)
713 yaz_log(YLOG_WARN, "Bad Present response %s",
714 cl->database->database->url);
715 cl->state = Client_Error;
716 client_show_raw_error(cl, "bad present response");
720 void client_close_response(struct client *cl, Z_APDU *a)
722 struct connection *co = cl->connection;
723 /* Z_Close *r = a->u.close; */
725 yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
727 cl->state = Client_Failed;
728 connection_destroy(co);
731 int client_is_our_response(struct client *cl)
733 struct session *se = client_get_session(cl);
735 if (cl && (cl->requestid == se->requestid ||
736 cl->state == Client_Initializing))
741 // Set authentication token in init if one is set for the client
742 // TODO: Extend this to handle other schemes than open (should be simple)
743 static void init_authentication(struct client *cl, Z_InitRequest *req)
745 struct session_database *sdb = client_get_database(cl);
746 char *auth = session_setting_oneval(sdb, PZ_AUTHENTICATION);
750 struct connection *co = client_get_connection(cl);
751 struct session *se = client_get_session(cl);
752 Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out,
754 idAuth->which = Z_IdAuthentication_open;
755 idAuth->u.open = auth;
756 req->idAuthentication = idAuth;
757 connection_set_authentication(co, nmem_strdup(se->session_nmem, auth));
761 static void init_zproxy(struct client *cl, Z_InitRequest *req)
763 struct session_database *sdb = client_get_database(cl);
764 char *ztarget = sdb->database->url;
765 //char *ztarget = sdb->url;
766 char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
769 yaz_oi_set_string_oid(&req->otherInfo,
770 global_parameters.odr_out,
771 yaz_oid_userinfo_proxy,
776 static void client_init_request(struct client *cl)
778 Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
780 a->u.initRequest->implementationId = global_parameters.implementationId;
781 a->u.initRequest->implementationName = global_parameters.implementationName;
782 a->u.initRequest->implementationVersion =
783 global_parameters.implementationVersion;
784 ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
785 ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
786 ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
788 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
789 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
790 ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
792 init_authentication(cl, a->u.initRequest);
793 init_zproxy(cl, a->u.initRequest);
795 if (send_apdu(cl, a) >= 0)
796 client_set_state(cl, Client_Initializing);
798 client_set_state(cl, Client_Error);
799 odr_reset(global_parameters.odr_out);
802 void client_continue(struct client *cl)
804 if (cl->state == Client_Connected) {
805 client_init_request(cl);
807 if (cl->state == Client_Idle)
809 struct session *se = client_get_session(cl);
810 if (cl->requestid != se->requestid && cl->pquery) {
811 // we'll have to abort this because result set is to be deleted
812 client_show_raw_cancel(cl);
813 client_send_search(cl);
815 else if (cl->show_raw)
817 client_send_raw_present(cl);
819 else if (cl->hits > 0 && cl->records < global_parameters.toget &&
820 cl->records < cl->hits) {
821 client_send_present(cl);
826 struct client *client_create(void)
832 client_freelist = client_freelist->next;
835 r = xmalloc(sizeof(struct client));
845 r->state = Client_Disconnected;
851 void client_destroy(struct client *c)
853 struct session *se = c->session;
854 if (c == se->clients)
855 se->clients = c->next;
859 for (cc = se->clients; cc && cc->next != c; cc = cc->next)
867 connection_release(c->connection);
868 c->next = client_freelist;
872 void client_set_connection(struct client *cl, struct connection *con)
874 cl->connection = con;
877 void client_disconnect(struct client *cl)
879 if (cl->state != Client_Idle)
880 cl->state = Client_Disconnected;
881 client_set_connection(cl, 0);
884 // Extract terms from query into null-terminated termlist
885 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
889 pull_terms(nmem, query, termlist, &num);
893 // Initialize CCL map for a target
894 static CCL_bibset prepare_cclmap(struct client *cl)
896 struct session_database *sdb = client_get_database(cl);
903 for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
905 char *p = strchr(s->name + 3, ':');
908 yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
913 ccl_qual_fitem(res, s->value, p);
918 // Parse the query given the settings specific to this client
919 int client_parse_query(struct client *cl, const char *query)
921 struct session *se = client_get_session(cl);
922 struct ccl_rpn_node *cn;
924 CCL_bibset ccl_map = prepare_cclmap(cl);
929 cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
930 ccl_qual_rm(&ccl_map);
933 cl->state = Client_Error;
934 yaz_log(YLOG_WARN, "Failed to parse query for %s",
935 client_get_database(cl)->database->url);
938 wrbuf_rewind(se->wrbuf);
939 ccl_pquery(se->wrbuf, cn);
941 cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
945 // Initialize relevance structure with query terms
947 extract_terms(se->nmem, cn, p);
948 se->relevance = relevance_create(client_get_database(cl)->pct,
949 se->nmem, (const char **) p,
950 se->expected_maxrecs);
957 void client_set_session(struct client *cl, struct session *se)
960 cl->next = se->clients;
964 int client_is_active(struct client *cl)
966 if (cl->connection && (cl->state == Client_Connecting ||
967 cl->state == Client_Initializing ||
968 cl->state == Client_Searching ||
969 cl->state == Client_Presenting))
974 struct client *client_next_in_session(struct client *cl)
982 int client_get_hits(struct client *cl)
987 int client_get_num_records(struct client *cl)
992 int client_get_diagnostic(struct client *cl)
994 return cl->diagnostic;
997 void client_set_database(struct client *cl, struct session_database *db)
1002 struct host *client_get_host(struct client *cl)
1004 return client_get_database(cl)->database->host;
1007 const char *client_get_url(struct client *cl)
1009 return client_get_database(cl)->database->url;
1015 * indent-tabs-mode: nil
1017 * vim: shiftwidth=4 tabstop=8 expandtab