1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
6 * \brief Demonstration of Generic Frontend Server API
16 #include <yaz/backend.h>
17 #include <yaz/diagbib1.h>
18 #include <yaz/matchstr.h>
19 #include <yaz/snprintf.h>
21 /* session handle . Put anything you like in here! */
26 static int my_search(void *handle, bend_search_rr *rr)
28 struct my_handle *my_p = (struct my_handle *) handle;
30 if (rr->num_bases != 1)
32 rr->errcode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
35 /* Throw Database unavailable if other than Default */
36 if (!yaz_matchstr (rr->basenames[0], "Default"))
37 ; /* Default is OK in our test */
40 rr->errcode = YAZ_BIB1_DATABASE_UNAVAILABLE;
41 rr->errstring = rr->basenames[0];
45 rr->hits = 123; /* dummy hit count */
50 /* retrieval of a single record (present, and piggy back search) */
51 static int my_fetch(void *handle, bend_fetch_rr *r)
53 const Odr_oid *oid = r->request_format;
56 r->basename = "Default";
57 r->output_format = r->request_format;
59 /* if no record syntax was given assume XML */
60 if (!oid || !oid_oidcmp(oid, yaz_oid_recsyn_xml))
63 yaz_snprintf(buf, sizeof(buf), "<record>%d</record>\n", r->number);
65 r->output_format = odr_oiddup(r->stream, yaz_oid_recsyn_xml);
66 r->record = odr_strdup(r->stream, buf);
67 r->len = strlen(r->record);
70 { /* only xml syntax supported . Return diagnostic */
71 char buf[OID_STR_MAX];
72 r->errcode = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
73 r->errstring = odr_strdup(r->stream, oid_oid_to_dotstring(oid, buf));
78 static bend_initresult *my_init(bend_initrequest *q)
80 bend_initresult *r = (bend_initresult *)
81 odr_malloc (q->stream, sizeof(*r));
82 struct my_handle *my_p = (struct my_handle *) xmalloc (sizeof(*my_p));
87 r->handle = my_p; /* user handle */
88 q->bend_search = my_search; /* register search handler */
89 q->bend_fetch = my_fetch; /* register fetch handle */
90 q->query_charset = "UTF-8";
91 q->records_in_same_charset = 1;
96 static void my_close(void *handle)
98 xfree(handle); /* release our user-defined handle */
102 int main(int argc, char **argv)
104 return statserv_main(argc, argv, my_init, my_close);
109 * c-file-style: "Stroustrup"
110 * indent-tabs-mode: nil
112 * vim: shiftwidth=4 tabstop=8 expandtab