Added support for turbo xml (txml)
[pazpar2-moved-to-github.git] / src / client.c
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2010 Index Data
3
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 /** \file client.c
21     \brief Z39.50 client 
22 */
23
24 #if HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #if HAVE_SYS_TIME_H
32 #include <sys/time.h>
33 #endif
34 #if HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37 #include <signal.h>
38 #include <assert.h>
39
40 #include <yaz/marcdisp.h>
41 #include <yaz/comstack.h>
42 #include <yaz/tcpip.h>
43 #include <yaz/proto.h>
44 #include <yaz/readconf.h>
45 #include <yaz/pquery.h>
46 #include <yaz/otherinfo.h>
47 #include <yaz/yaz-util.h>
48 #include <yaz/nmem.h>
49 #include <yaz/query-charset.h>
50 #include <yaz/querytowrbuf.h>
51 #include <yaz/oid_db.h>
52 #include <yaz/diagbib1.h>
53 #include <yaz/snprintf.h>
54 #include <yaz/rpn2cql.h>
55
56 #define USE_TIMING 0
57 #if USE_TIMING
58 #include <yaz/timing.h>
59 #endif
60
61 #include "session.h"
62 #include "parameters.h"
63 #include "client.h"
64 #include "connection.h"
65 #include "settings.h"
66 #include "relevance.h"
67
68 /** \brief Represents client state for a connection to one search target */
69 struct client {
70     struct session_database *database;
71     struct connection *connection;
72     struct session *session;
73     char *pquery; // Current search
74     char *cqlquery; // used for SRU targets only
75     Odr_int hits;
76     int record_offset;
77     int maxrecs;
78     int startrecs;
79     int diagnostic;
80     enum client_state state;
81     struct show_raw *show_raw;
82     struct client *next;     // next client in session or next in free list
83     ZOOM_resultset resultset;
84 };
85
86 struct show_raw {
87     int active; // whether this request has been sent to the server
88     int position;
89     int binary;
90     char *syntax;
91     char *esn;
92     void (*error_handler)(void *data, const char *addinfo);
93     void (*record_handler)(void *data, const char *buf, size_t sz);
94     void *data;
95     struct show_raw *next;
96 };
97
98 static const char *client_states[] = {
99     "Client_Connecting",
100     "Client_Idle",
101     "Client_Working",
102     "Client_Error",
103     "Client_Failed",
104     "Client_Disconnected"
105 };
106
107 const char *client_get_state_str(struct client *cl)
108 {
109     return client_states[cl->state];
110 }
111
112 enum client_state client_get_state(struct client *cl)
113 {
114     return cl->state;
115 }
116
117 void client_set_state(struct client *cl, enum client_state st)
118 {
119     cl->state = st;
120     /* no need to check for all client being non-active if this one
121        already is. Note that session_active_clients also LOCKS session */
122     if (!client_is_active(cl) && cl->session)
123     {
124         int no_active = session_active_clients(cl->session);
125         if (no_active == 0)
126             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
127     }
128 }
129
130 static void client_show_raw_error(struct client *cl, const char *addinfo);
131
132 // Close connection and set state to error
133 void client_fatal(struct client *cl)
134 {
135     yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
136     connection_destroy(cl->connection);
137     client_set_state(cl, Client_Error);
138 }
139
140 struct connection *client_get_connection(struct client *cl)
141 {
142     return cl->connection;
143 }
144
145 struct session_database *client_get_database(struct client *cl)
146 {
147     return cl->database;
148 }
149
150 struct session *client_get_session(struct client *cl)
151 {
152     return cl->session;
153 }
154
155 const char *client_get_pquery(struct client *cl)
156 {
157     return cl->pquery;
158 }
159
160 static void client_send_raw_present(struct client *cl);
161 static int nativesyntax_to_type(struct session_database *sdb, char *type,
162                                 ZOOM_record rec);
163
164 static void client_show_immediate(
165     ZOOM_resultset resultset, struct session_database *sdb, int position,
166     void *data,
167     void (*error_handler)(void *data, const char *addinfo),
168     void (*record_handler)(void *data, const char *buf, size_t sz),
169     int binary)
170 {
171     ZOOM_record rec = 0;
172     char type[80];
173     const char *buf;
174     int len;
175
176     if (!resultset)
177     {
178         error_handler(data, "no resultset");
179         return;
180     }
181     rec = ZOOM_resultset_record(resultset, position-1);
182     if (!rec)
183     {
184         error_handler(data, "no record");
185         return;
186     }
187     if (binary)
188         strcpy(type, "raw");
189     else
190         nativesyntax_to_type(sdb, type, rec);
191     buf = ZOOM_record_get(rec, type, &len);
192     if (!buf)
193     {
194         error_handler(data, "no record");
195         return;
196     }
197     record_handler(data, buf, len);
198 }
199
200
201 int client_show_raw_begin(struct client *cl, int position,
202                           const char *syntax, const char *esn,
203                           void *data,
204                           void (*error_handler)(void *data, const char *addinfo),
205                           void (*record_handler)(void *data, const char *buf,
206                                                  size_t sz),
207                           int binary)
208 {
209     if (syntax == 0 && esn == 0)
210         client_show_immediate(cl->resultset, client_get_database(cl),
211                               position, data,
212                               error_handler, record_handler,
213                               binary);
214     else
215     {
216         struct show_raw *rr, **rrp;
217
218         if (!cl->connection)
219             return -1;
220     
221
222         rr = xmalloc(sizeof(*rr));
223         rr->position = position;
224         rr->active = 0;
225         rr->data = data;
226         rr->error_handler = error_handler;
227         rr->record_handler = record_handler;
228         rr->binary = binary;
229         if (syntax)
230             rr->syntax = xstrdup(syntax);
231         else
232             rr->syntax = 0;
233         if (esn)
234             rr->esn = xstrdup(esn);
235         else
236             rr->esn = 0;
237         rr->next = 0;
238         
239         for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
240             ;
241         *rrp = rr;
242         
243         if (cl->state == Client_Failed)
244         {
245             client_show_raw_error(cl, "client failed");
246         }
247         else if (cl->state == Client_Disconnected)
248         {
249             client_show_raw_error(cl, "client disconnected");
250         }
251         else
252         {
253             client_send_raw_present(cl);
254         }
255     }
256     return 0;
257 }
258
259 static void client_show_raw_delete(struct show_raw *r)
260 {
261     xfree(r->syntax);
262     xfree(r->esn);
263     xfree(r);
264 }
265
266 void client_show_raw_remove(struct client *cl, void *data)
267 {
268     struct show_raw *rr = data;
269     struct show_raw **rrp = &cl->show_raw;
270     while (*rrp != rr)
271         rrp = &(*rrp)->next;
272     if (*rrp)
273     {
274         *rrp = rr->next;
275         client_show_raw_delete(rr);
276     }
277 }
278
279 void client_show_raw_dequeue(struct client *cl)
280 {
281     struct show_raw *rr = cl->show_raw;
282
283     cl->show_raw = rr->next;
284     client_show_raw_delete(rr);
285 }
286
287 static void client_show_raw_error(struct client *cl, const char *addinfo)
288 {
289     while (cl->show_raw)
290     {
291         cl->show_raw->error_handler(cl->show_raw->data, addinfo);
292         client_show_raw_dequeue(cl);
293     }
294 }
295
296 static void client_send_raw_present(struct client *cl)
297 {
298     struct session_database *sdb = client_get_database(cl);
299     struct connection *co = client_get_connection(cl);
300     ZOOM_resultset set = cl->resultset;
301
302     int offset = cl->show_raw->position;
303     const char *syntax = 0;
304     const char *elements = 0;
305
306     assert(cl->show_raw);
307     assert(set);
308
309     yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
310             client_get_url(cl), 1, offset);
311
312     if (cl->show_raw->syntax)
313         syntax = cl->show_raw->syntax;
314     else
315         syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
316     ZOOM_resultset_option_set(set, "preferredRecordSyntax", syntax);
317
318     if (cl->show_raw->esn)
319         elements = cl->show_raw->esn;
320     else
321         elements = session_setting_oneval(sdb, PZ_ELEMENTS);
322     if (elements && *elements)
323         ZOOM_resultset_option_set(set, "elementSetName", elements);
324
325     ZOOM_resultset_records(set, 0, offset-1, 1);
326     cl->show_raw->active = 1;
327
328     connection_continue(co);
329 }
330
331 static int nativesyntax_to_type(struct session_database *sdb, char *type,
332                                 ZOOM_record rec)
333 {
334     const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
335
336     if (s && *s)
337     {
338         if (!strncmp(s, "iso2709", 7))
339         {
340             const char *cp = strchr(s, ';');
341             yaz_snprintf(type, 80, "xml; charset=%s", cp ? cp+1 : "marc-8s");
342         }
343         else if (!strncmp(s, "xml", 3))
344         {
345             strcpy(type, "xml");
346         }
347         else if (!strncmp(s, "txml", 4))
348         {
349             const char *cp = strchr(s, ';');
350             yaz_snprintf(type, 80, "txml; charset=%s", cp ? cp+1 : "marc-8s");
351         }
352         else
353             return -1;
354         return 0;
355     }
356     else  /* attempt to deduce structure */
357     {
358         const char *syntax = ZOOM_record_get(rec, "syntax", NULL);
359         if (syntax)
360         {
361             if (!strcmp(syntax, "XML"))
362             {
363                 strcpy(type, "xml");
364                 return 0;
365             }
366             else if (!strcmp(syntax, "TXML"))
367                 {
368                     strcpy(type, "txml");
369                     return 0;
370                 }
371             else if (!strcmp(syntax, "USmarc") || !strcmp(syntax, "MARC21"))
372             {
373                 strcpy(type, "xml; charset=marc8-s");
374                 return 0;
375             }
376             else return -1;
377         }
378         else return -1;
379     }
380 }
381
382 static void ingest_raw_record(struct client *cl, ZOOM_record rec)
383 {
384     const char *buf;
385     int len;
386     char type[80];
387
388     if (cl->show_raw->binary)
389         strcpy(type, "raw");
390     else
391     {
392         struct session_database *sdb = client_get_database(cl);
393         nativesyntax_to_type(sdb, type, rec);
394     }
395
396     buf = ZOOM_record_get(rec, type, &len);
397     cl->show_raw->record_handler(cl->show_raw->data,  buf, len);
398     client_show_raw_dequeue(cl);
399 }
400
401 void client_search_response(struct client *cl)
402 {
403     struct connection *co = cl->connection;
404     struct session *se = cl->session;
405     ZOOM_connection link = connection_get_link(co);
406     ZOOM_resultset resultset = cl->resultset;
407     const char *error, *addinfo;
408
409     if (ZOOM_connection_error(link, &error, &addinfo))
410     {
411         cl->hits = 0;
412         client_set_state(cl, Client_Error);
413         yaz_log(YLOG_WARN, "Search error %s (%s): %s",
414             error, addinfo, client_get_url(cl));
415     }
416     else
417     {
418         cl->record_offset = cl->startrecs;
419         cl->hits = ZOOM_resultset_size(resultset);
420         se->total_hits += cl->hits;
421     }
422 }
423
424
425 void client_record_response(struct client *cl)
426 {
427     struct connection *co = cl->connection;
428     ZOOM_connection link = connection_get_link(co);
429     ZOOM_resultset resultset = cl->resultset;
430     const char *error, *addinfo;
431
432     if (ZOOM_connection_error(link, &error, &addinfo))
433     {
434         client_set_state(cl, Client_Error);
435         yaz_log(YLOG_WARN, "Search error %s (%s): %s",
436             error, addinfo, client_get_url(cl));
437     }
438     else
439     {
440         ZOOM_record rec = 0;
441         const char *msg, *addinfo;
442         
443         if (cl->show_raw && cl->show_raw->active)
444         {
445             if ((rec = ZOOM_resultset_record(resultset,
446                                              cl->show_raw->position-1)))
447             {
448                 cl->show_raw->active = 0;
449                 ingest_raw_record(cl, rec);
450             }
451             else
452             {
453                 yaz_log(YLOG_WARN, "Expected record, but got NULL, offset=%d",
454                         cl->show_raw->position-1);
455             }
456         }
457         else
458         {
459             int offset = cl->record_offset;
460             if ((rec = ZOOM_resultset_record(resultset, offset)))
461             {
462                 cl->record_offset++;
463                 if (ZOOM_record_error(rec, &msg, &addinfo, 0))
464                     yaz_log(YLOG_WARN, "Record error %s (%s): %s (rec #%d)",
465                             error, addinfo, client_get_url(cl),
466                             cl->record_offset);
467                 else
468                 {
469                     struct session_database *sdb = client_get_database(cl);
470                     NMEM nmem = nmem_create();
471                     const char *xmlrec;
472                     char type[80];
473                     if (nativesyntax_to_type(sdb, type, rec))
474                         yaz_log(YLOG_WARN, "Failed to determine record type");
475                     if ((xmlrec = ZOOM_record_get(rec, type, NULL)))
476                     {
477                         if (!ingest_record(cl, xmlrec, cl->record_offset, nmem))
478                         {
479                             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
480                             session_alert_watch(cl->session, SESSION_WATCH_RECORD);
481                         }
482                         else
483                             yaz_log(YLOG_WARN, "Failed to ingest");
484                     }
485                     else
486                         yaz_log(YLOG_WARN, "Failed to extract ZOOM record");
487                     nmem_destroy(nmem);
488                 }
489
490             }
491             else
492             {
493                 yaz_log(YLOG_WARN, "Expected record, but got NULL, offset=%d",
494                         offset);
495             }
496         }
497     }
498 }
499
500 void client_start_search(struct client *cl)
501 {
502     struct session_database *sdb = client_get_database(cl);
503     struct connection *co = client_get_connection(cl);
504     ZOOM_connection link = connection_get_link(co);
505     ZOOM_resultset rs;
506     char *databaseName = sdb->database->databases[0];
507     const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
508     const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
509     const char *opt_elements = session_setting_oneval(sdb, PZ_ELEMENTS);
510     const char *opt_requestsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
511     const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
512     const char *opt_sru = session_setting_oneval(sdb, PZ_SRU);
513     const char *opt_sort = session_setting_oneval(sdb, PZ_SORT);
514     char maxrecs_str[24], startrecs_str[24];
515
516     assert(link);
517
518     cl->hits = -1;
519     cl->record_offset = 0;
520     cl->diagnostic = 0;
521     client_set_state(cl, Client_Working);
522
523     if (*opt_piggyback)
524         ZOOM_connection_option_set(link, "piggyback", opt_piggyback);
525     else
526         ZOOM_connection_option_set(link, "piggyback", "1");
527     if (*opt_queryenc)
528         ZOOM_connection_option_set(link, "rpnCharset", opt_queryenc);
529     if (*opt_sru && *opt_elements)
530         ZOOM_connection_option_set(link, "schema", opt_elements);
531     else if (*opt_elements)
532         ZOOM_connection_option_set(link, "elementSetName", opt_elements);
533     if (*opt_requestsyn)
534         ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn);
535
536     if (!*opt_maxrecs)
537     {
538         sprintf(maxrecs_str, "%d", cl->maxrecs);
539         opt_maxrecs = maxrecs_str;
540     }
541     ZOOM_connection_option_set(link, "count", opt_maxrecs);
542
543
544     if (atoi(opt_maxrecs) > 20)
545         ZOOM_connection_option_set(link, "presentChunk", "20");
546     else
547         ZOOM_connection_option_set(link, "presentChunk", opt_maxrecs);
548
549     sprintf(startrecs_str, "%d", cl->startrecs);
550     ZOOM_connection_option_set(link, "start", startrecs_str);
551
552     if (databaseName)
553         ZOOM_connection_option_set(link, "databaseName", databaseName);
554
555     if (cl->cqlquery)
556     {
557         ZOOM_query q = ZOOM_query_create();
558         yaz_log(YLOG_LOG, "Search %s CQL: %s", sdb->database->url, cl->cqlquery);
559         ZOOM_query_cql(q, cl->cqlquery);
560         if (*opt_sort)
561             ZOOM_query_sortby(q, opt_sort);
562         rs = ZOOM_connection_search(link, q);
563         ZOOM_query_destroy(q);
564     }
565     else
566     {
567         yaz_log(YLOG_LOG, "Search %s PQF: %s", sdb->database->url, cl->pquery);
568         rs = ZOOM_connection_search_pqf(link, cl->pquery);
569     }
570     ZOOM_resultset_destroy(cl->resultset);
571     cl->resultset = rs;
572     connection_continue(co);
573 }
574
575 struct client *client_create(void)
576 {
577     struct client *r = xmalloc(sizeof(*r));
578     r->maxrecs = 100;
579     r->startrecs = 0;
580     r->pquery = 0;
581     r->cqlquery = 0;
582     r->database = 0;
583     r->connection = 0;
584     r->session = 0;
585     r->hits = 0;
586     r->record_offset = 0;
587     r->diagnostic = 0;
588     r->state = Client_Disconnected;
589     r->show_raw = 0;
590     r->resultset = 0;
591     r->next = 0;
592     return r;
593 }
594
595 void client_destroy(struct client *c)
596 {
597     struct session *se = c->session;
598     if (c == se->clients)
599         se->clients = c->next;
600     else
601     {
602         struct client *cc;
603         for (cc = se->clients; cc && cc->next != c; cc = cc->next)
604             ;
605         if (cc)
606             cc->next = c->next;
607     }
608     xfree(c->pquery);
609     xfree(c->cqlquery);
610
611     if (c->connection)
612         connection_release(c->connection);
613
614     ZOOM_resultset_destroy(c->resultset);
615     xfree(c);
616 }
617
618 void client_set_connection(struct client *cl, struct connection *con)
619 {
620     cl->connection = con;
621 }
622
623 void client_disconnect(struct client *cl)
624 {
625     if (cl->state != Client_Idle)
626         client_set_state(cl, Client_Disconnected);
627     client_set_connection(cl, 0);
628 }
629
630 // Extract terms from query into null-terminated termlist
631 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
632 {
633     int num = 0;
634
635     pull_terms(nmem, query, termlist, &num);
636     termlist[num] = 0;
637 }
638
639 // Initialize CCL map for a target
640 static CCL_bibset prepare_cclmap(struct client *cl)
641 {
642     struct session_database *sdb = client_get_database(cl);
643     struct setting *s;
644     CCL_bibset res;
645
646     if (!sdb->settings)
647         return 0;
648     res = ccl_qual_mk();
649     for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
650     {
651         char *p = strchr(s->name + 3, ':');
652         if (!p)
653         {
654             yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
655             ccl_qual_rm(&res);
656             return 0;
657         }
658         p++;
659         ccl_qual_fitem(res, s->value, p);
660     }
661     return res;
662 }
663
664 // returns a xmalloced CQL query corresponding to the pquery in client
665 static char *make_cqlquery(struct client *cl)
666 {
667     cql_transform_t cqlt = cql_transform_create();
668     Z_RPNQuery *zquery;
669     char *r;
670     WRBUF wrb = wrbuf_alloc();
671     int status;
672     ODR odr_out = odr_createmem(ODR_ENCODE);
673
674     zquery = p_query_rpn(odr_out, cl->pquery);
675     yaz_log(YLOG_LOG, "PQF: %s", cl->pquery);
676     if ((status = cql_transform_rpn2cql_wrbuf(cqlt, wrb, zquery)))
677     {
678         yaz_log(YLOG_WARN, "Failed to generate CQL query, code=%d", status);
679         r = 0;
680     }
681     else
682     {
683         r = xstrdup(wrbuf_cstr(wrb));
684     }     
685     wrbuf_destroy(wrb);
686     odr_destroy(odr_out);
687     cql_transform_close(cqlt);
688     return r;
689 }
690
691 // Parse the query given the settings specific to this client
692 int client_parse_query(struct client *cl, const char *query)
693 {
694     struct session *se = client_get_session(cl);
695     struct session_database *sdb = client_get_database(cl);
696     struct ccl_rpn_node *cn;
697     int cerror, cpos;
698     CCL_bibset ccl_map = prepare_cclmap(cl);
699     const char *sru = session_setting_oneval(sdb, PZ_SRU);
700     const char *pqf_prefix = session_setting_oneval(sdb, PZ_PQF_PREFIX);
701     const char *pqf_strftime = session_setting_oneval(sdb, PZ_PQF_STRFTIME);
702
703     if (!ccl_map)
704         return -1;
705
706     cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
707     ccl_qual_rm(&ccl_map);
708     if (!cn)
709     {
710         client_set_state(cl, Client_Error);
711         yaz_log(YLOG_WARN, "Failed to parse CCL query %s for %s",
712                 query,
713                 client_get_database(cl)->database->url);
714         return -1;
715     }
716     wrbuf_rewind(se->wrbuf);
717     if (*pqf_prefix)
718     {
719         wrbuf_puts(se->wrbuf, pqf_prefix);
720         wrbuf_puts(se->wrbuf, " ");
721     }
722     if (!pqf_strftime || !*pqf_strftime)
723         ccl_pquery(se->wrbuf, cn);
724     else
725     {
726         time_t cur_time = time(0);
727         struct tm *tm =  localtime(&cur_time);
728         char tmp_str[300];
729         const char *cp = tmp_str;
730
731         /* see man strftime(3) for things .. In particular %% gets converted
732          to %.. And That's our original query .. */
733         strftime(tmp_str, sizeof(tmp_str)-1, pqf_strftime, tm);
734         for (; *cp; cp++)
735         {
736             if (cp[0] == '%')
737                 ccl_pquery(se->wrbuf, cn);
738             else
739                 wrbuf_putc(se->wrbuf, cp[0]);
740         }
741     }
742     xfree(cl->pquery);
743     cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
744
745     xfree(cl->cqlquery);
746     if (*sru)
747     {
748         if (!(cl->cqlquery = make_cqlquery(cl)))
749             return -1;
750     }
751     else
752         cl->cqlquery = 0;
753
754     if (!se->relevance)
755     {
756         // Initialize relevance structure with query terms
757         char *p[512];
758         extract_terms(se->nmem, cn, p);
759         se->relevance = relevance_create(
760             se->service->relevance_pct,
761             se->nmem, (const char **) p);
762     }
763
764     ccl_rpn_delete(cn);
765     return 0;
766 }
767
768 void client_set_session(struct client *cl, struct session *se)
769 {
770     cl->session = se;
771     cl->next = se->clients;
772     se->clients = cl;
773 }
774
775 int client_is_active(struct client *cl)
776 {
777     if (cl->connection && (cl->state == Client_Connecting ||
778                            cl->state == Client_Working))
779         return 1;
780     return 0;
781 }
782
783 struct client *client_next_in_session(struct client *cl)
784 {
785     if (cl)
786         return cl->next;
787     return 0;
788
789 }
790
791 Odr_int client_get_hits(struct client *cl)
792 {
793     return cl->hits;
794 }
795
796 int client_get_num_records(struct client *cl)
797 {
798     return cl->record_offset;
799 }
800
801 void client_set_diagnostic(struct client *cl, int diagnostic)
802 {
803     cl->diagnostic = diagnostic;
804 }
805
806 int client_get_diagnostic(struct client *cl)
807 {
808     return cl->diagnostic;
809 }
810
811 void client_set_database(struct client *cl, struct session_database *db)
812 {
813     cl->database = db;
814 }
815
816 struct host *client_get_host(struct client *cl)
817 {
818     return client_get_database(cl)->database->host;
819 }
820
821 const char *client_get_url(struct client *cl)
822 {
823     return client_get_database(cl)->database->url;
824 }
825
826 void client_set_maxrecs(struct client *cl, int v)
827 {
828     cl->maxrecs = v;
829 }
830
831 void client_set_startrecs(struct client *cl, int v)
832 {
833     cl->startrecs = v;
834 }
835
836 /*
837  * Local variables:
838  * c-basic-offset: 4
839  * c-file-style: "Stroustrup"
840  * indent-tabs-mode: nil
841  * End:
842  * vim: shiftwidth=4 tabstop=8 expandtab
843  */
844