client freelist removed (thus thread safe now)
[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 "pazpar2.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     if (cl->session)
121     {
122         int no_active = session_active_clients(cl->session);
123         if (no_active == 0)
124             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
125     }
126 }
127
128 static void client_show_raw_error(struct client *cl, const char *addinfo);
129
130 // Close connection and set state to error
131 void client_fatal(struct client *cl)
132 {
133     yaz_log(YLOG_WARN, "Fatal error from %s", client_get_url(cl));
134     connection_destroy(cl->connection);
135     client_set_state(cl, Client_Error);
136 }
137
138 struct connection *client_get_connection(struct client *cl)
139 {
140     return cl->connection;
141 }
142
143 struct session_database *client_get_database(struct client *cl)
144 {
145     return cl->database;
146 }
147
148 struct session *client_get_session(struct client *cl)
149 {
150     return cl->session;
151 }
152
153 const char *client_get_pquery(struct client *cl)
154 {
155     return cl->pquery;
156 }
157
158 static void client_send_raw_present(struct client *cl);
159 static int nativesyntax_to_type(struct session_database *sdb, char *type,
160                                 ZOOM_record rec);
161
162 static void client_show_immediate(
163     ZOOM_resultset resultset, struct session_database *sdb, int position,
164     void *data,
165     void (*error_handler)(void *data, const char *addinfo),
166     void (*record_handler)(void *data, const char *buf, size_t sz),
167     int binary)
168 {
169     ZOOM_record rec = 0;
170     char type[80];
171     const char *buf;
172     int len;
173
174     if (!resultset)
175     {
176         error_handler(data, "no resultset");
177         return;
178     }
179     rec = ZOOM_resultset_record(resultset, position-1);
180     if (!rec)
181     {
182         error_handler(data, "no record");
183         return;
184     }
185     if (binary)
186         strcpy(type, "raw");
187     else
188         nativesyntax_to_type(sdb, type, rec);
189     buf = ZOOM_record_get(rec, type, &len);
190     if (!buf)
191     {
192         error_handler(data, "no record");
193         return;
194     }
195     record_handler(data, buf, len);
196 }
197
198
199 int client_show_raw_begin(struct client *cl, int position,
200                           const char *syntax, const char *esn,
201                           void *data,
202                           void (*error_handler)(void *data, const char *addinfo),
203                           void (*record_handler)(void *data, const char *buf,
204                                                  size_t sz),
205                           int binary)
206 {
207     if (syntax == 0 && esn == 0)
208         client_show_immediate(cl->resultset, client_get_database(cl),
209                               position, data,
210                               error_handler, record_handler,
211                               binary);
212     else
213     {
214         struct show_raw *rr, **rrp;
215
216         if (!cl->connection)
217             return -1;
218     
219
220         rr = xmalloc(sizeof(*rr));
221         rr->position = position;
222         rr->active = 0;
223         rr->data = data;
224         rr->error_handler = error_handler;
225         rr->record_handler = record_handler;
226         rr->binary = binary;
227         if (syntax)
228             rr->syntax = xstrdup(syntax);
229         else
230             rr->syntax = 0;
231         if (esn)
232             rr->esn = xstrdup(esn);
233         else
234             rr->esn = 0;
235         rr->next = 0;
236         
237         for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
238             ;
239         *rrp = rr;
240         
241         if (cl->state == Client_Failed)
242         {
243             client_show_raw_error(cl, "client failed");
244         }
245         else if (cl->state == Client_Disconnected)
246         {
247             client_show_raw_error(cl, "client disconnected");
248         }
249         else
250         {
251             client_send_raw_present(cl);
252         }
253     }
254     return 0;
255 }
256
257 static void client_show_raw_delete(struct show_raw *r)
258 {
259     xfree(r->syntax);
260     xfree(r->esn);
261     xfree(r);
262 }
263
264 void client_show_raw_remove(struct client *cl, void *data)
265 {
266     struct show_raw *rr = data;
267     struct show_raw **rrp = &cl->show_raw;
268     while (*rrp != rr)
269         rrp = &(*rrp)->next;
270     if (*rrp)
271     {
272         *rrp = rr->next;
273         client_show_raw_delete(rr);
274     }
275 }
276
277 void client_show_raw_dequeue(struct client *cl)
278 {
279     struct show_raw *rr = cl->show_raw;
280
281     cl->show_raw = rr->next;
282     client_show_raw_delete(rr);
283 }
284
285 static void client_show_raw_error(struct client *cl, const char *addinfo)
286 {
287     while (cl->show_raw)
288     {
289         cl->show_raw->error_handler(cl->show_raw->data, addinfo);
290         client_show_raw_dequeue(cl);
291     }
292 }
293
294 static void client_send_raw_present(struct client *cl)
295 {
296     struct session_database *sdb = client_get_database(cl);
297     struct connection *co = client_get_connection(cl);
298     ZOOM_resultset set = cl->resultset;
299
300     int offset = cl->show_raw->position;
301     const char *syntax = 0;
302     const char *elements = 0;
303
304     assert(cl->show_raw);
305     assert(set);
306
307     yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
308             client_get_url(cl), 1, offset);
309
310     if (cl->show_raw->syntax)
311         syntax = cl->show_raw->syntax;
312     else
313         syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
314     ZOOM_resultset_option_set(set, "preferredRecordSyntax", syntax);
315
316     if (cl->show_raw->esn)
317         elements = cl->show_raw->esn;
318     else
319         elements = session_setting_oneval(sdb, PZ_ELEMENTS);
320     if (elements && *elements)
321         ZOOM_resultset_option_set(set, "elementSetName", elements);
322
323     ZOOM_resultset_records(set, 0, offset-1, 1);
324     cl->show_raw->active = 1;
325
326     connection_continue(co);
327 }
328
329 static int nativesyntax_to_type(struct session_database *sdb, char *type,
330                                 ZOOM_record rec)
331 {
332     const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
333
334     if (s && *s)
335     {
336         if (!strncmp(s, "iso2709", 7))
337         {
338             const char *cp = strchr(s, ';');
339             yaz_snprintf(type, 80, "xml; charset=%s", cp ? cp+1 : "marc-8s");
340         }
341         else if (!strncmp(s, "xml", 3))
342         {
343             strcpy(type, "xml");
344         }
345         else
346             return -1;
347         return 0;
348     }
349     else  /* attempt to deduce structure */
350     {
351         const char *syntax = ZOOM_record_get(rec, "syntax", NULL);
352         if (syntax)
353         {
354             if (!strcmp(syntax, "XML"))
355             {
356                 strcpy(type, "xml");
357                 return 0;
358             }
359             else if (!strcmp(syntax, "USmarc") || !strcmp(syntax, "MARC21"))
360             {
361                 strcpy(type, "xml; charset=marc8-s");
362                 return 0;
363             }
364             else return -1;
365         }
366         else return -1;
367     }
368 }
369
370 static void ingest_raw_record(struct client *cl, ZOOM_record rec)
371 {
372     const char *buf;
373     int len;
374     char type[80];
375
376     if (cl->show_raw->binary)
377         strcpy(type, "raw");
378     else
379     {
380         struct session_database *sdb = client_get_database(cl);
381         nativesyntax_to_type(sdb, type, rec);
382     }
383
384     buf = ZOOM_record_get(rec, type, &len);
385     cl->show_raw->record_handler(cl->show_raw->data,  buf, len);
386     client_show_raw_dequeue(cl);
387 }
388
389 void client_search_response(struct client *cl)
390 {
391     struct connection *co = cl->connection;
392     struct session *se = cl->session;
393     ZOOM_connection link = connection_get_link(co);
394     ZOOM_resultset resultset = cl->resultset;
395     const char *error, *addinfo;
396
397     if (ZOOM_connection_error(link, &error, &addinfo))
398     {
399         cl->hits = 0;
400         client_set_state(cl, Client_Error);
401         yaz_log(YLOG_WARN, "Search error %s (%s): %s",
402             error, addinfo, client_get_url(cl));
403     }
404     else
405     {
406         cl->record_offset = cl->startrecs;
407         cl->hits = ZOOM_resultset_size(resultset);
408         se->total_hits += cl->hits;
409     }
410 }
411
412
413 void client_record_response(struct client *cl)
414 {
415     struct connection *co = cl->connection;
416     ZOOM_connection link = connection_get_link(co);
417     ZOOM_resultset resultset = cl->resultset;
418     const char *error, *addinfo;
419
420     if (ZOOM_connection_error(link, &error, &addinfo))
421     {
422         client_set_state(cl, Client_Error);
423         yaz_log(YLOG_WARN, "Search error %s (%s): %s",
424             error, addinfo, client_get_url(cl));
425     }
426     else
427     {
428         ZOOM_record rec = 0;
429         const char *msg, *addinfo;
430         
431         if (cl->show_raw && cl->show_raw->active)
432         {
433             if ((rec = ZOOM_resultset_record(resultset,
434                                              cl->show_raw->position-1)))
435             {
436                 cl->show_raw->active = 0;
437                 ingest_raw_record(cl, rec);
438             }
439             else
440             {
441                 yaz_log(YLOG_WARN, "Expected record, but got NULL, offset=%d",
442                         cl->show_raw->position-1);
443             }
444         }
445         else
446         {
447             int offset = cl->record_offset;
448             if ((rec = ZOOM_resultset_record(resultset, offset)))
449             {
450                 cl->record_offset++;
451                 if (ZOOM_record_error(rec, &msg, &addinfo, 0))
452                     yaz_log(YLOG_WARN, "Record error %s (%s): %s (rec #%d)",
453                             error, addinfo, client_get_url(cl),
454                             cl->record_offset);
455                 else
456                 {
457                     struct session_database *sdb = client_get_database(cl);
458                     const char *xmlrec;
459                     char type[80];
460                     if (nativesyntax_to_type(sdb, type, rec))
461                         yaz_log(YLOG_WARN, "Failed to determine record type");
462                     if ((xmlrec = ZOOM_record_get(rec, type, NULL)))
463                     {
464                         if (ingest_record(cl, xmlrec, cl->record_offset))
465                         {
466                             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
467                             session_alert_watch(cl->session, SESSION_WATCH_RECORD);
468                         }
469                         else
470                             yaz_log(YLOG_WARN, "Failed to ingest");
471                     }
472                     else
473                         yaz_log(YLOG_WARN, "Failed to extract ZOOM record");
474                 }
475
476             }
477             else
478             {
479                 yaz_log(YLOG_WARN, "Expected record, but got NULL, offset=%d",
480                         offset);
481             }
482         }
483     }
484 }
485
486 void client_start_search(struct client *cl)
487 {
488     struct session_database *sdb = client_get_database(cl);
489     struct connection *co = client_get_connection(cl);
490     ZOOM_connection link = connection_get_link(co);
491     ZOOM_resultset rs;
492     char *databaseName = sdb->database->databases[0];
493     const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
494     const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
495     const char *opt_elements = session_setting_oneval(sdb, PZ_ELEMENTS);
496     const char *opt_requestsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
497     const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
498     const char *opt_sru = session_setting_oneval(sdb, PZ_SRU);
499     const char *opt_sort = session_setting_oneval(sdb, PZ_SORT);
500     char maxrecs_str[24], startrecs_str[24];
501
502     assert(link);
503
504     cl->hits = -1;
505     cl->record_offset = 0;
506     cl->diagnostic = 0;
507     client_set_state(cl, Client_Working);
508
509     if (*opt_piggyback)
510         ZOOM_connection_option_set(link, "piggyback", opt_piggyback);
511     else
512         ZOOM_connection_option_set(link, "piggyback", "1");
513     if (*opt_queryenc)
514         ZOOM_connection_option_set(link, "rpnCharset", opt_queryenc);
515     if (*opt_sru && *opt_elements)
516         ZOOM_connection_option_set(link, "schema", opt_elements);
517     else if (*opt_elements)
518         ZOOM_connection_option_set(link, "elementSetName", opt_elements);
519     if (*opt_requestsyn)
520         ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn);
521
522     if (!*opt_maxrecs)
523     {
524         sprintf(maxrecs_str, "%d", cl->maxrecs);
525         opt_maxrecs = maxrecs_str;
526     }
527     ZOOM_connection_option_set(link, "count", opt_maxrecs);
528
529
530     if (atoi(opt_maxrecs) > 20)
531         ZOOM_connection_option_set(link, "presentChunk", "20");
532     else
533         ZOOM_connection_option_set(link, "presentChunk", opt_maxrecs);
534
535     sprintf(startrecs_str, "%d", cl->startrecs);
536     ZOOM_connection_option_set(link, "start", startrecs_str);
537
538     if (databaseName)
539         ZOOM_connection_option_set(link, "databaseName", databaseName);
540
541     if (cl->cqlquery)
542     {
543         ZOOM_query q = ZOOM_query_create();
544         yaz_log(YLOG_LOG, "Search %s CQL: %s", sdb->database->url, cl->cqlquery);
545         ZOOM_query_cql(q, cl->cqlquery);
546         if (*opt_sort)
547             ZOOM_query_sortby(q, opt_sort);
548         rs = ZOOM_connection_search(link, q);
549         ZOOM_query_destroy(q);
550     }
551     else
552     {
553         yaz_log(YLOG_LOG, "Search %s PQF: %s", sdb->database->url, cl->pquery);
554         rs = ZOOM_connection_search_pqf(link, cl->pquery);
555     }
556     ZOOM_resultset_destroy(cl->resultset);
557     cl->resultset = rs;
558     connection_continue(co);
559 }
560
561 struct client *client_create(void)
562 {
563     struct client *r = xmalloc(sizeof(*r));
564     r->maxrecs = 100;
565     r->startrecs = 0;
566     r->pquery = 0;
567     r->cqlquery = 0;
568     r->database = 0;
569     r->connection = 0;
570     r->session = 0;
571     r->hits = 0;
572     r->record_offset = 0;
573     r->diagnostic = 0;
574     r->state = Client_Disconnected;
575     r->show_raw = 0;
576     r->resultset = 0;
577     r->next = 0;
578     return r;
579 }
580
581 void client_destroy(struct client *c)
582 {
583     struct session *se = c->session;
584     if (c == se->clients)
585         se->clients = c->next;
586     else
587     {
588         struct client *cc;
589         for (cc = se->clients; cc && cc->next != c; cc = cc->next)
590             ;
591         if (cc)
592             cc->next = c->next;
593     }
594     xfree(c->pquery);
595     xfree(c->cqlquery);
596
597     if (c->connection)
598         connection_release(c->connection);
599
600     ZOOM_resultset_destroy(c->resultset);
601     xfree(c);
602 }
603
604 void client_set_connection(struct client *cl, struct connection *con)
605 {
606     cl->connection = con;
607 }
608
609 void client_disconnect(struct client *cl)
610 {
611     if (cl->state != Client_Idle)
612         client_set_state(cl, Client_Disconnected);
613     client_set_connection(cl, 0);
614 }
615
616 // Extract terms from query into null-terminated termlist
617 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
618 {
619     int num = 0;
620
621     pull_terms(nmem, query, termlist, &num);
622     termlist[num] = 0;
623 }
624
625 // Initialize CCL map for a target
626 static CCL_bibset prepare_cclmap(struct client *cl)
627 {
628     struct session_database *sdb = client_get_database(cl);
629     struct setting *s;
630     CCL_bibset res;
631
632     if (!sdb->settings)
633         return 0;
634     res = ccl_qual_mk();
635     for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
636     {
637         char *p = strchr(s->name + 3, ':');
638         if (!p)
639         {
640             yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
641             ccl_qual_rm(&res);
642             return 0;
643         }
644         p++;
645         ccl_qual_fitem(res, s->value, p);
646     }
647     return res;
648 }
649
650 // returns a xmalloced CQL query corresponding to the pquery in client
651 static char *make_cqlquery(struct client *cl)
652 {
653     cql_transform_t cqlt = cql_transform_create();
654     Z_RPNQuery *zquery;
655     char *r;
656     WRBUF wrb = wrbuf_alloc();
657     int status;
658     ODR odr_out = odr_createmem(ODR_ENCODE);
659
660     zquery = p_query_rpn(odr_out, cl->pquery);
661     yaz_log(YLOG_LOG, "PQF: %s", cl->pquery);
662     if ((status = cql_transform_rpn2cql_wrbuf(cqlt, wrb, zquery)))
663     {
664         yaz_log(YLOG_WARN, "Failed to generate CQL query, code=%d", status);
665         r = 0;
666     }
667     else
668     {
669         r = xstrdup(wrbuf_cstr(wrb));
670     }     
671     wrbuf_destroy(wrb);
672     odr_destroy(odr_out);
673     cql_transform_close(cqlt);
674     return r;
675 }
676
677 // Parse the query given the settings specific to this client
678 int client_parse_query(struct client *cl, const char *query)
679 {
680     struct session *se = client_get_session(cl);
681     struct session_database *sdb = client_get_database(cl);
682     struct ccl_rpn_node *cn;
683     int cerror, cpos;
684     CCL_bibset ccl_map = prepare_cclmap(cl);
685     const char *sru = session_setting_oneval(sdb, PZ_SRU);
686     const char *pqf_prefix = session_setting_oneval(sdb, PZ_PQF_PREFIX);
687     const char *pqf_strftime = session_setting_oneval(sdb, PZ_PQF_STRFTIME);
688
689     if (!ccl_map)
690         return -1;
691
692     cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
693     ccl_qual_rm(&ccl_map);
694     if (!cn)
695     {
696         client_set_state(cl, Client_Error);
697         yaz_log(YLOG_WARN, "Failed to parse CCL query %s for %s",
698                 query,
699                 client_get_database(cl)->database->url);
700         return -1;
701     }
702     wrbuf_rewind(se->wrbuf);
703     if (*pqf_prefix)
704     {
705         wrbuf_puts(se->wrbuf, pqf_prefix);
706         wrbuf_puts(se->wrbuf, " ");
707     }
708     if (!pqf_strftime || !*pqf_strftime)
709         ccl_pquery(se->wrbuf, cn);
710     else
711     {
712         time_t cur_time = time(0);
713         struct tm *tm =  localtime(&cur_time);
714         char tmp_str[300];
715         const char *cp = tmp_str;
716
717         /* see man strftime(3) for things .. In particular %% gets converted
718          to %.. And That's our original query .. */
719         strftime(tmp_str, sizeof(tmp_str)-1, pqf_strftime, tm);
720         for (; *cp; cp++)
721         {
722             if (cp[0] == '%')
723                 ccl_pquery(se->wrbuf, cn);
724             else
725                 wrbuf_putc(se->wrbuf, cp[0]);
726         }
727     }
728     xfree(cl->pquery);
729     cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
730
731     xfree(cl->cqlquery);
732     if (*sru)
733     {
734         if (!(cl->cqlquery = make_cqlquery(cl)))
735             return -1;
736     }
737     else
738         cl->cqlquery = 0;
739
740     if (!se->relevance)
741     {
742         // Initialize relevance structure with query terms
743         char *p[512];
744         extract_terms(se->nmem, cn, p);
745         se->relevance = relevance_create(
746             se->service->relevance_pct,
747             se->nmem, (const char **) p);
748     }
749
750     ccl_rpn_delete(cn);
751     return 0;
752 }
753
754 void client_set_session(struct client *cl, struct session *se)
755 {
756     cl->session = se;
757     cl->next = se->clients;
758     se->clients = cl;
759 }
760
761 int client_is_active(struct client *cl)
762 {
763     if (cl->connection && (cl->state == Client_Connecting ||
764                            cl->state == Client_Working))
765         return 1;
766     return 0;
767 }
768
769 struct client *client_next_in_session(struct client *cl)
770 {
771     if (cl)
772         return cl->next;
773     return 0;
774
775 }
776
777 Odr_int client_get_hits(struct client *cl)
778 {
779     return cl->hits;
780 }
781
782 int client_get_num_records(struct client *cl)
783 {
784     return cl->record_offset;
785 }
786
787 void client_set_diagnostic(struct client *cl, int diagnostic)
788 {
789     cl->diagnostic = diagnostic;
790 }
791
792 int client_get_diagnostic(struct client *cl)
793 {
794     return cl->diagnostic;
795 }
796
797 void client_set_database(struct client *cl, struct session_database *db)
798 {
799     cl->database = db;
800 }
801
802 struct host *client_get_host(struct client *cl)
803 {
804     return client_get_database(cl)->database->host;
805 }
806
807 const char *client_get_url(struct client *cl)
808 {
809     return client_get_database(cl)->database->url;
810 }
811
812 void client_set_maxrecs(struct client *cl, int v)
813 {
814     cl->maxrecs = v;
815 }
816
817 void client_set_startrecs(struct client *cl, int v)
818 {
819     cl->startrecs = v;
820 }
821
822 /*
823  * Local variables:
824  * c-basic-offset: 4
825  * c-file-style: "Stroustrup"
826  * indent-tabs-mode: nil
827  * End:
828  * vim: shiftwidth=4 tabstop=8 expandtab
829  */
830