Convert nativesyntax charset to ZOOM charset properly.
[pazpar2-moved-to-github.git] / src / client.c
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2008 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 #if HAVE_SYS_SOCKET_H
38 #include <sys/socket.h>
39 #endif
40 #if HAVE_NETDB_H
41 #include <netdb.h>
42 #endif
43 #include <signal.h>
44 #include <ctype.h>
45 #include <assert.h>
46
47 #include <yaz/marcdisp.h>
48 #include <yaz/comstack.h>
49 #include <yaz/tcpip.h>
50 #include <yaz/proto.h>
51 #include <yaz/readconf.h>
52 #include <yaz/pquery.h>
53 #include <yaz/otherinfo.h>
54 #include <yaz/yaz-util.h>
55 #include <yaz/nmem.h>
56 #include <yaz/query-charset.h>
57 #include <yaz/querytowrbuf.h>
58 #include <yaz/oid_db.h>
59 #include <yaz/diagbib1.h>
60 #include <yaz/snprintf.h>
61
62 #define USE_TIMING 0
63 #if USE_TIMING
64 #include <yaz/timing.h>
65 #endif
66
67 #if HAVE_NETINET_IN_H
68 #include <netinet/in.h>
69 #endif
70
71 #include "pazpar2.h"
72
73 #include "client.h"
74 #include "connection.h"
75 #include "settings.h"
76
77 /** \brief Represents client state for a connection to one search target */
78 struct client {
79     struct session_database *database;
80     struct connection *connection;
81     struct session *session;
82     char *pquery; // Current search
83     int hits;
84     int records;
85     int setno;
86     int requestid;            // ID of current outstanding request
87     int diagnostic;
88     enum client_state state;
89     struct show_raw *show_raw;
90     struct client *next;     // next client in session or next in free list
91 };
92
93 struct show_raw {
94     int active; // whether this request has been sent to the server
95     int position;
96     int binary;
97     char *syntax;
98     char *esn;
99     void (*error_handler)(void *data, const char *addinfo);
100     void (*record_handler)(void *data, const char *buf, size_t sz);
101     void *data;
102     struct show_raw *next;
103 };
104
105 static const char *client_states[] = {
106     "Client_Connecting",
107     "Client_Connected",
108     "Client_Idle",
109     "Client_Initializing",
110     "Client_Searching",
111     "Client_Presenting",
112     "Client_Error",
113     "Client_Failed",
114     "Client_Disconnected",
115     "Client_Stopped",
116     "Client_Continue"
117 };
118
119 static struct client *client_freelist = 0;
120
121 const char *client_get_state_str(struct client *cl)
122 {
123     return client_states[cl->state];
124 }
125
126 enum client_state client_get_state(struct client *cl)
127 {
128     return cl->state;
129 }
130
131 void client_set_state(struct client *cl, enum client_state st)
132 {
133     cl->state = st;
134     if (cl->session)
135     {
136         int no_active = session_active_clients(cl->session);
137         if (no_active == 0)
138             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
139     }
140 }
141
142 static void client_show_raw_error(struct client *cl, const char *addinfo);
143
144 // Close connection and set state to error
145 void client_fatal(struct client *cl)
146 {
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     client_set_state(cl, Client_Error);
151 }
152
153 struct connection *client_get_connection(struct client *cl)
154 {
155     return cl->connection;
156 }
157
158 struct session_database *client_get_database(struct client *cl)
159 {
160     return cl->database;
161 }
162
163 struct session *client_get_session(struct client *cl)
164 {
165     return cl->session;
166 }
167
168 const char *client_get_pquery(struct client *cl)
169 {
170     return cl->pquery;
171 }
172
173 void client_set_requestid(struct client *cl, int id)
174 {
175     cl->requestid = id;
176 }
177
178
179 static void client_send_raw_present(struct client *cl);
180
181 int client_show_raw_begin(struct client *cl, int position,
182                           const char *syntax, const char *esn,
183                           void *data,
184                           void (*error_handler)(void *data, const char *addinfo),
185                           void (*record_handler)(void *data, const char *buf,
186                                                  size_t sz),
187                           void **data2,
188                           int binary)
189 {
190     struct show_raw *rr, **rrp;
191     if (!cl->connection)
192     {   /* the client has no connection */
193         return -1;
194     }
195     rr = xmalloc(sizeof(*rr));
196     *data2 = rr;
197     rr->position = position;
198     rr->active = 0;
199     rr->data = data;
200     rr->error_handler = error_handler;
201     rr->record_handler = record_handler;
202     rr->binary = binary;
203     if (syntax)
204         rr->syntax = xstrdup(syntax);
205     else
206         rr->syntax = 0;
207     if (esn)
208         rr->esn = xstrdup(esn);
209     else
210         rr->esn = 0;
211     rr->next = 0;
212     
213     for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
214         ;
215     *rrp = rr;
216     
217     if (cl->state == Client_Failed)
218     {
219         client_show_raw_error(cl, "client failed");
220     }
221     else if (cl->state == Client_Disconnected)
222     {
223         client_show_raw_error(cl, "client disconnected");
224     }
225     else
226     {
227         client_send_raw_present(cl);
228     }
229     return 0;
230 }
231
232 void client_show_raw_remove(struct client *cl, void *data)
233 {
234     struct show_raw *rr = data;
235     struct show_raw **rrp = &cl->show_raw;
236     while (*rrp != rr)
237         rrp = &(*rrp)->next;
238     if (*rrp)
239     {
240         *rrp = rr->next;
241         xfree(rr);
242     }
243 }
244
245 void client_show_raw_dequeue(struct client *cl)
246 {
247     struct show_raw *rr = cl->show_raw;
248
249     cl->show_raw = rr->next;
250     xfree(rr);
251 }
252
253 static void client_show_raw_error(struct client *cl, const char *addinfo)
254 {
255     while (cl->show_raw)
256     {
257         cl->show_raw->error_handler(cl->show_raw->data, addinfo);
258         client_show_raw_dequeue(cl);
259     }
260 }
261
262 static void client_show_raw_cancel(struct client *cl)
263 {
264     while (cl->show_raw)
265     {
266         cl->show_raw->error_handler(cl->show_raw->data, "cancel");
267         client_show_raw_dequeue(cl);
268     }
269 }
270
271 static void client_send_raw_present(struct client *cl)
272 {
273     struct session_database *sdb = client_get_database(cl);
274     struct connection *co = client_get_connection(cl);
275     ZOOM_resultset set = connection_get_resultset(co);
276
277     int offset = cl->show_raw->position;
278     const char *syntax = 0;
279     const char *elements = 0;
280
281     assert(cl->show_raw);
282     assert(set);
283
284     yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
285             client_get_url(cl), 1, offset);
286
287     if (cl->show_raw->syntax)
288         syntax = cl->show_raw->syntax;
289     else
290         syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
291     ZOOM_resultset_option_set(set, "preferredRecordSyntax", syntax);
292
293     if (cl->show_raw->esn)
294         elements = cl->show_raw->esn;
295     else
296         elements = session_setting_oneval(sdb, PZ_ELEMENTS);
297     if (elements && *elements)
298         ZOOM_resultset_option_set(set, "elementSetName", elements);
299
300     ZOOM_resultset_records(set, 0, offset-1, 1);
301     cl->show_raw->active = 1;
302
303     connection_continue(co);
304 }
305
306 static int nativesyntax_to_type(struct session_database *sdb, char *type)
307 {
308     const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
309
310     if (s && *s)
311     {
312         if (!strncmp(s, "iso2709", 7))
313         {
314             const char *cp = strchr(s, ';');
315             yaz_snprintf(type, 80, "xml; charset=%s", cp ? cp+1 : "marc-8s");
316         }
317         else if (!strncmp(s, "xml", 3))
318         {
319             strcpy(type, "xml");
320         }
321         else
322             return -1;
323         yaz_log(YLOG_LOG, "Returned type %s", type);
324         return 0;
325     }
326     return -1;
327 }
328
329 static void ingest_raw_record(struct client *cl, ZOOM_record rec)
330 {
331     const char *buf;
332     int len;
333     char type[80];
334
335     if (cl->show_raw->binary)
336         strcpy(type, "raw");
337     else
338     {
339         struct session_database *sdb = client_get_database(cl);
340         nativesyntax_to_type(sdb, type);
341     }
342
343     buf = ZOOM_record_get(rec, type, &len);
344     cl->show_raw->record_handler(cl->show_raw->data,  buf, len);
345     client_show_raw_dequeue(cl);
346 }
347
348 #ifdef RETIRED
349
350 static void ingest_raw_records(struct client *cl, Z_Records *r)
351 {
352     Z_NamePlusRecordList *rlist;
353     Z_NamePlusRecord *npr;
354     xmlDoc *doc;
355     xmlChar *buf_out;
356     int len_out;
357     if (r->which != Z_Records_DBOSD)
358     {
359         client_show_raw_error(cl, "non-surrogate diagnostics");
360         return;
361     }
362
363     rlist = r->u.databaseOrSurDiagnostics;
364     if (rlist->num_records != 1 || !rlist->records || !rlist->records[0])
365     {
366         client_show_raw_error(cl, "no records");
367         return;
368     }
369     npr = rlist->records[0];
370     if (npr->which != Z_NamePlusRecord_databaseRecord)
371     {
372         client_show_raw_error(cl, "surrogate diagnostic");
373         return;
374     }
375
376     if (cl->show_raw && cl->show_raw->binary)
377     {
378         Z_External *rec = npr->u.databaseRecord;
379         if (rec->which == Z_External_octet)
380         {
381             cl->show_raw->record_handler(cl->show_raw->data,
382                                          (const char *)
383                                          rec->u.octet_aligned->buf,
384                                          rec->u.octet_aligned->len);
385             client_show_raw_dequeue(cl);
386         }
387         else
388             client_show_raw_error(cl, "no records");
389     }
390
391     doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
392     if (!doc)
393     {
394         client_show_raw_error(cl, "unable to convert record to xml");
395         return;
396     }
397
398     xmlDocDumpMemory(doc, &buf_out, &len_out);
399     xmlFreeDoc(doc);
400
401     if (cl->show_raw)
402     {
403         cl->show_raw->record_handler(cl->show_raw->data,
404                                      (const char *) buf_out, len_out);
405         client_show_raw_dequeue(cl);
406     }
407     xmlFree(buf_out);
408 }
409
410 #endif // RETIRED show raw
411
412 void client_search_response(struct client *cl)
413 {
414     struct connection *co = cl->connection;
415     struct session *se = cl->session;
416     ZOOM_connection link = connection_get_link(co);
417     ZOOM_resultset resultset = connection_get_resultset(co);
418     const char *error, *addinfo;
419
420     if (ZOOM_connection_error(link, &error, &addinfo))
421     {
422         cl->hits = 0;
423         cl->state = Client_Error;
424         yaz_log(YLOG_WARN, "Search error %s (%s): %s",
425             error, addinfo, client_get_url(cl));
426     }
427     else
428     {
429         cl->hits = ZOOM_resultset_size(resultset);
430         se->total_hits += cl->hits;
431     }
432 }
433
434
435 void client_record_response(struct client *cl)
436 {
437     struct connection *co = cl->connection;
438     ZOOM_connection link = connection_get_link(co);
439     ZOOM_resultset resultset = connection_get_resultset(co);
440     const char *error, *addinfo;
441
442     yaz_log(YLOG_LOG, "client_record_response");
443     if (ZOOM_connection_error(link, &error, &addinfo))
444     {
445         cl->state = Client_Error;
446         yaz_log(YLOG_WARN, "Search error %s (%s): %s",
447             error, addinfo, client_get_url(cl));
448     }
449     else
450     {
451         ZOOM_record rec = 0;
452         const char *msg, *addinfo;
453         
454         yaz_log(YLOG_LOG, "show_raw=%p show_raw->active=%d",
455                 cl->show_raw, cl->show_raw ? cl->show_raw->active : 0);
456         if (cl->show_raw && cl->show_raw->active)
457         {
458             if ((rec = ZOOM_resultset_record(resultset,
459                                              cl->show_raw->position-1)))
460             {
461                 cl->show_raw->active = 0;
462                 ingest_raw_record(cl, rec);
463             }
464         }
465         else
466         {
467             int offset = cl->records;
468             if ((rec = ZOOM_resultset_record(resultset, offset)))
469             {
470                 yaz_log(YLOG_LOG, "Record with offset %d", offset);
471                 
472                 cl->records++;
473                 if (ZOOM_record_error(rec, &msg, &addinfo, 0))
474                     yaz_log(YLOG_WARN, "Record error %s (%s): %s (rec #%d)",
475                             error, addinfo, client_get_url(cl), cl->records);
476                 else
477                 {
478                     struct session_database *sdb = client_get_database(cl);
479                     const char *xmlrec;
480                     char type[80];
481                     nativesyntax_to_type(sdb, type);
482                     if ((xmlrec = ZOOM_record_get(rec, type, NULL)))
483                     {
484                         if (ingest_record(cl, xmlrec, cl->records))
485                         {
486                             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
487                             session_alert_watch(cl->session, SESSION_WATCH_RECORD);
488                         }
489                         else
490                             yaz_log(YLOG_WARN, "Failed to ingest");
491                     }
492                     else
493                         yaz_log(YLOG_WARN, "Failed to extract ZOOM record");
494                 }
495
496             }
497         }
498         if (!rec)
499             yaz_log(YLOG_WARN, "Expected record, but got NULL");
500     }
501 }
502
503 #ifdef RETIRED
504
505 void client_present_response(struct client *cl, Z_APDU *a)
506 {
507     Z_PresentResponse *r = a->u.presentResponse;
508     Z_Records *recs = r->records;
509         
510     if (recs && recs->which == Z_Records_NSD)
511     {
512         WRBUF w = wrbuf_alloc();
513         
514         Z_DiagRec dr, *dr_p = &dr;
515         dr.which = Z_DiagRec_defaultFormat;
516         dr.u.defaultFormat = recs->u.nonSurrogateDiagnostic;
517         
518         wrbuf_printf(w, "Present response NSD %s: ",
519                      cl->database->database->url);
520         
521         cl->diagnostic = diag_to_wrbuf(&dr_p, 1, w);
522         
523         yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
524         
525         cl->state = Client_Error;
526         wrbuf_destroy(w);
527
528         client_show_raw_error(cl, "non surrogate diagnostics");
529     }
530     else if (recs && recs->which == Z_Records_multipleNSD)
531     {
532         WRBUF w = wrbuf_alloc();
533         
534         wrbuf_printf(w, "Present response multipleNSD %s: ",
535                      cl->database->database->url);
536         cl->diagnostic = 
537             diag_to_wrbuf(recs->u.multipleNonSurDiagnostics->diagRecs,
538                           recs->u.multipleNonSurDiagnostics->num_diagRecs,
539                           w);
540         yaz_log(YLOG_WARN, "%s", wrbuf_cstr(w));
541         cl->state = Client_Error;
542         wrbuf_destroy(w);
543     }
544     else if (recs && !*r->presentStatus && cl->state != Client_Error)
545     {
546         yaz_log(YLOG_DEBUG, "Good Present response %s",
547                 cl->database->database->url);
548
549         // we can mix show raw and normal show ..
550         if (cl->show_raw && cl->show_raw->active)
551         {
552             cl->show_raw->active = 0; // no longer active
553             ingest_raw_records(cl, recs);
554         }
555         else
556             ingest_records(cl, recs);
557         cl->state = Client_Continue;
558     }
559     else if (*r->presentStatus) 
560     {
561         yaz_log(YLOG_WARN, "Bad Present response %s",
562                 cl->database->database->url);
563         cl->state = Client_Error;
564         client_show_raw_error(cl, "bad present response");
565     }
566 }
567
568 void client_close_response(struct client *cl, Z_APDU *a)
569 {
570     struct connection *co = cl->connection;
571     /* Z_Close *r = a->u.close; */
572
573     yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
574
575     cl->state = Client_Failed;
576     connection_destroy(co);
577 }
578
579 #endif // RETIRED show raw
580
581 #ifdef RETIRED
582 int client_is_our_response(struct client *cl)
583 {
584     struct session *se = client_get_session(cl);
585
586     if (cl && (cl->requestid == se->requestid || 
587                cl->state == Client_Initializing))
588         return 1;
589     return 0;
590 }
591 #endif
592
593 void client_start_search(struct client *cl)
594 {
595     struct session_database *sdb = client_get_database(cl);
596     struct connection *co = client_get_connection(cl);
597     ZOOM_connection link = connection_get_link(co);
598     ZOOM_resultset rs;
599     char *databaseName = sdb->database->databases[0];
600     const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK);
601     const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING);
602     const char *opt_elements = session_setting_oneval(sdb, PZ_ELEMENTS);
603     const char *opt_requestsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
604     const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
605
606     assert(link);
607
608     cl->hits = -1;
609     cl->records = 0;
610     cl->diagnostic = 0;
611
612     if (*opt_piggyback)
613         ZOOM_connection_option_set(link, "piggyback", opt_piggyback);
614     else
615         ZOOM_connection_option_set(link, "piggyback", "1");
616     if (*opt_queryenc)
617         ZOOM_connection_option_set(link, "rpnCharset", opt_queryenc);
618     if (*opt_elements)
619         ZOOM_connection_option_set(link, "elementSetName", opt_elements);
620     if (*opt_requestsyn)
621         ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn);
622     if (*opt_maxrecs)
623         ZOOM_connection_option_set(link, "count", opt_maxrecs);
624     else
625     {
626         char n[128];
627         sprintf(n, "%d", global_parameters.toget);
628         ZOOM_connection_option_set(link, "count", n);
629     }
630     if (!databaseName || !*databaseName)
631         databaseName = "Default";
632     ZOOM_connection_option_set(link, "databaseName", databaseName);
633
634     ZOOM_connection_option_set(link, "presentChunk", "20");
635
636     rs = ZOOM_connection_search_pqf(link, cl->pquery);
637     connection_set_resultset(co, rs);
638     connection_continue(co);
639 }
640
641 struct client *client_create(void)
642 {
643     struct client *r;
644     if (client_freelist)
645     {
646         r = client_freelist;
647         client_freelist = client_freelist->next;
648     }
649     else
650         r = xmalloc(sizeof(struct client));
651     r->pquery = 0;
652     r->database = 0;
653     r->connection = 0;
654     r->session = 0;
655     r->hits = 0;
656     r->records = 0;
657     r->setno = 0;
658     r->requestid = -1;
659     r->diagnostic = 0;
660     r->state = Client_Disconnected;
661     r->show_raw = 0;
662     r->next = 0;
663     return r;
664 }
665
666 void client_destroy(struct client *c)
667 {
668     struct session *se = c->session;
669     if (c == se->clients)
670         se->clients = c->next;
671     else
672     {
673         struct client *cc;
674         for (cc = se->clients; cc && cc->next != c; cc = cc->next)
675             ;
676         if (cc)
677             cc->next = c->next;
678     }
679     xfree(c->pquery);
680
681     if (c->connection)
682         connection_release(c->connection);
683     c->next = client_freelist;
684     client_freelist = c;
685 }
686
687 void client_set_connection(struct client *cl, struct connection *con)
688 {
689     cl->connection = con;
690 }
691
692 void client_disconnect(struct client *cl)
693 {
694     if (cl->state != Client_Idle)
695         client_set_state(cl, Client_Disconnected);
696     client_set_connection(cl, 0);
697 }
698
699 // Extract terms from query into null-terminated termlist
700 static void extract_terms(NMEM nmem, struct ccl_rpn_node *query, char **termlist)
701 {
702     int num = 0;
703
704     pull_terms(nmem, query, termlist, &num);
705     termlist[num] = 0;
706 }
707
708 // Initialize CCL map for a target
709 static CCL_bibset prepare_cclmap(struct client *cl)
710 {
711     struct session_database *sdb = client_get_database(cl);
712     struct setting *s;
713     CCL_bibset res;
714
715     if (!sdb->settings)
716         return 0;
717     res = ccl_qual_mk();
718     for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next)
719     {
720         char *p = strchr(s->name + 3, ':');
721         if (!p)
722         {
723             yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name);
724             ccl_qual_rm(&res);
725             return 0;
726         }
727         p++;
728         ccl_qual_fitem(res, s->value, p);
729     }
730     return res;
731 }
732
733 // Parse the query given the settings specific to this client
734 int client_parse_query(struct client *cl, const char *query)
735 {
736     struct session *se = client_get_session(cl);
737     struct ccl_rpn_node *cn;
738     int cerror, cpos;
739     CCL_bibset ccl_map = prepare_cclmap(cl);
740
741     if (!ccl_map)
742         return -1;
743
744     cn = ccl_find_str(ccl_map, query, &cerror, &cpos);
745     ccl_qual_rm(&ccl_map);
746     if (!cn)
747     {
748         cl->state = Client_Error;
749         yaz_log(YLOG_WARN, "Failed to parse query for %s",
750                          client_get_database(cl)->database->url);
751         return -1;
752     }
753     wrbuf_rewind(se->wrbuf);
754     ccl_pquery(se->wrbuf, cn);
755     xfree(cl->pquery);
756     cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf));
757
758     if (!se->relevance)
759     {
760         // Initialize relevance structure with query terms
761         char *p[512];
762         extract_terms(se->nmem, cn, p);
763         se->relevance = relevance_create(
764             global_parameters.server->relevance_pct,
765             se->nmem, (const char **) p,
766             se->expected_maxrecs);
767     }
768
769     ccl_rpn_delete(cn);
770     return 0;
771 }
772
773 void client_set_session(struct client *cl, struct session *se)
774 {
775     cl->session = se;
776     cl->next = se->clients;
777     se->clients = cl;
778 }
779
780 int client_is_active(struct client *cl)
781 {
782     if (cl->connection && (cl->state == Client_Continue ||
783                            cl->state == Client_Connecting ||
784                            cl->state == Client_Working))
785         return 1;
786     return 0;
787 }
788
789 struct client *client_next_in_session(struct client *cl)
790 {
791     if (cl)
792         return cl->next;
793     return 0;
794
795 }
796
797 int client_get_hits(struct client *cl)
798 {
799     return cl->hits;
800 }
801
802 int client_get_num_records(struct client *cl)
803 {
804     return cl->records;
805 }
806
807 int client_get_diagnostic(struct client *cl)
808 {
809     return cl->diagnostic;
810 }
811
812 void client_set_database(struct client *cl, struct session_database *db)
813 {
814     cl->database = db;
815 }
816
817 struct host *client_get_host(struct client *cl)
818 {
819     return client_get_database(cl)->database->host;
820 }
821
822 const char *client_get_url(struct client *cl)
823 {
824     return client_get_database(cl)->database->url;
825 }
826
827 /*
828  * Local variables:
829  * c-basic-offset: 4
830  * indent-tabs-mode: nil
831  * End:
832  * vim: shiftwidth=4 tabstop=8 expandtab
833  */