YAZ 5.35.1
gfs-example.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
8#if HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#include <stdio.h>
13#include <stdlib.h>
14
15#include <yaz/log.h>
16#include <yaz/backend.h>
17#include <yaz/diagbib1.h>
18#include <yaz/matchstr.h>
19#include <yaz/snprintf.h>
20
21/* session handle . Put anything you like in here! */
22struct my_handle {
24};
25
26static int my_search(void *handle, bend_search_rr *rr)
27{
28 struct my_handle *my_p = (struct my_handle *) handle;
29
30 if (rr->num_bases != 1)
31 {
33 return 0;
34 }
35 /* Throw Database unavailable if other than Default */
36 if (!yaz_matchstr (rr->basenames[0], "Default"))
37 ; /* Default is OK in our test */
38 else
39 {
41 rr->errstring = rr->basenames[0];
42 return 0;
43 }
44
45 rr->hits = 123; /* dummy hit count */
46 my_p->counter++;
47 return 0;
48}
49
50/* retrieval of a single record (present, and piggy back search) */
51static int my_fetch(void *handle, bend_fetch_rr *r)
52{
53 const Odr_oid *oid = r->request_format;
54
55 r->last_in_set = 0;
56 r->basename = "Default";
58
59 /* if no record syntax was given assume XML */
60 if (!oid || !oid_oidcmp(oid, yaz_oid_recsyn_xml))
61 {
62 char buf[40];
63 yaz_snprintf(buf, sizeof(buf), "<record>%d</record>\n", r->number);
64
66 r->record = odr_strdup(r->stream, buf);
67 r->len = strlen(r->record);
68 }
69 else
70 { /* only xml syntax supported . Return diagnostic */
71 char buf[OID_STR_MAX];
74 }
75 return 0;
76}
77
79{
81 odr_malloc (q->stream, sizeof(*r));
82 struct my_handle *my_p = (struct my_handle *) xmalloc (sizeof(*my_p));
83
84 my_p->counter = 0;
85 r->errcode = 0;
86 r->errstring = 0;
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";
92
93 return r;
94}
95
96static void my_close(void *handle)
97{
98 xfree(handle); /* release our user-defined handle */
99 return;
100}
101
102int main(int argc, char **argv)
103{
104 return statserv_main(argc, argv, my_init, my_close);
105}
106/*
107 * Local variables:
108 * c-basic-offset: 4
109 * c-file-style: "Stroustrup"
110 * indent-tabs-mode: nil
111 * End:
112 * vim: shiftwidth=4 tabstop=8 expandtab
113 */
114
Header for GFS.
Diagnostics: Generated by csvtodiag.tcl from ./bib1.csv.
#define YAZ_BIB1_DATABASE_UNAVAILABLE
Definition diagbib1.h:53
#define YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP
Definition diagbib1.h:33
#define YAZ_BIB1_RECORD_SYNTAX_UNSUPP
Definition diagbib1.h:114
static void my_close(void *handle)
Definition gfs-example.c:96
static int my_search(void *handle, bend_search_rr *rr)
Definition gfs-example.c:26
int main(int argc, char **argv)
static bend_initresult * my_init(bend_initrequest *q)
Definition gfs-example.c:78
static int my_fetch(void *handle, bend_fetch_rr *r)
Definition gfs-example.c:51
Logging utility.
int yaz_matchstr(const char *s1, const char *s2)
match strings - independent of case and '-'
Definition matchstr.c:42
Header for YAZ iconv interface.
void * odr_malloc(ODR o, size_t size)
Definition odr_mem.c:31
char * odr_strdup(ODR o, const char *str)
Definition odr_mem.c:36
Odr_oid * odr_oiddup(ODR odr, const Odr_oid *o)
Definition odr_util.c:60
const Odr_oid yaz_oid_recsyn_xml[]
Definition oid_std.c:89
char * oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
converts OID to string (dot notation)
Definition oid_util.c:59
int oid_oidcmp(const Odr_oid *o1, const Odr_oid *o2)
compares OIDs
Definition oid_util.c:34
short Odr_oid
Definition oid_util.h:42
#define OID_STR_MAX
Definition oid_util.h:40
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Definition snprintf.c:31
Header for config file reading utilities.
int statserv_main(int argc, char **argv, bend_initresult *(*bend_init)(bend_initrequest *r), void(*bend_close)(void *handle))
Definition statserv.c:1504
Information for fetch record handler.
Definition backend.h:98
char * basename
Definition backend.h:107
char * record
Definition backend.h:109
Odr_oid * request_format
Definition backend.h:102
int last_in_set
Definition backend.h:110
Odr_oid * output_format
Definition backend.h:111
char * errstring
Definition backend.h:113
Information for the Init handler.
Definition backend.h:253
int records_in_same_charset
whether query_charset also applies to records
Definition backend.h:287
int(* bend_search)(void *handle, bend_search_rr *rr)
SRU/Z39.50 search handler.
Definition backend.h:296
int(* bend_fetch)(void *handle, bend_fetch_rr *rr)
SRU/Z39.50 fetch handler.
Definition backend.h:298
ODR stream
encoding stream (for results)
Definition backend.h:257
char * query_charset
character set (encoding) for query terms
Definition backend.h:280
result for init handler (must be filled by handler)
Definition backend.h:322
void * handle
Definition backend.h:325
char * errstring
Definition backend.h:324
Information for Z39.50/SRU search handler.
Definition backend.h:54
char ** basenames
Definition backend.h:58
Odr_int hits
Definition backend.h:66
char * errstring
Definition backend.h:68
#define xfree(x)
utility macro which calls xfree_f
Definition xmalloc.h:53
#define xmalloc(x)
utility macro which calls malloc_f
Definition xmalloc.h:49