From: Adam Dickmeiss Date: Thu, 23 Oct 2008 07:14:03 +0000 (+0200) Subject: Smaller example GFS. Added match-str.h for string match functions. X-Git-Tag: v3.0.38~13 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=93f4285bbf2ed5a42fe62f92c7c4618df5f20583 Smaller example GFS. Added match-str.h for string match functions. --- diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index cc34d34..9792cdb 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -19,5 +19,5 @@ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h rpn2cql.h comstack.h \ z-grs.h z-mterm2.h z-opac.h z-rrf1.h z-rrf2.h z-sum.h z-sutrs.h z-uifr1.h \ z-univ.h z-oclcui.h zes-expi.h zes-exps.h zes-order.h zes-pquery.h \ zes-psched.h zes-admin.h zes-pset.h zes-update.h zes-update0.h \ - zoom.h z-charneg.h charneg.h soap.h srw.h zgdu.h + zoom.h z-charneg.h charneg.h soap.h srw.h zgdu.h match-str.h diff --git a/include/yaz/match-str.h b/include/yaz/match-str.h new file mode 100644 index 0000000..b776907 --- /dev/null +++ b/include/yaz/match-str.h @@ -0,0 +1,81 @@ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2008 Index Data. + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Index Data nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file match-str.h + * \brief Header for YAZ iconv interface + */ + +#ifndef YAZ_MATCH_STR_H +#define YAZ_MATCH_STR_H + +#include +#include + +YAZ_BEGIN_CDECL + +/** \brief match strings - independent of case and '-' + \param s1 first string + \param s2 second string (May include wildcard ? and .) + \retval 0 strings are similar + \retval !=0 strings are different +*/ +YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2); + +/** \brief match a and b with some delimitor for b + \param a first second + \param b second string + \param b_del delimitor for b + \retval 0 strings are similar + \retval !=0 strings are different +*/ +YAZ_EXPORT int yaz_strcmp_del(const char *a, const char *b, const char *b_del); + + +/** \brief compares two buffers of different size + \param a first buffer + \param b second buffer + \param len_a length of first buffer + \retval len_b length of second buffer + \retval 0 buffers are equal + \retval >0 a > b + \retval <0 a < b +*/ +int yaz_memcmp(const void *a, const void *b, size_t len_a, size_t len_b); + + +YAZ_END_CDECL + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/include/yaz/proto.h b/include/yaz/proto.h index 651125e..96a0cde 100644 --- a/include/yaz/proto.h +++ b/include/yaz/proto.h @@ -65,6 +65,7 @@ #include #include #include +#include #include #include diff --git a/include/yaz/yaz-iconv.h b/include/yaz/yaz-iconv.h index 4768805..65a23e1 100644 --- a/include/yaz/yaz-iconv.h +++ b/include/yaz/yaz-iconv.h @@ -65,44 +65,6 @@ YAZ_EXPORT int yaz_iconv_close (yaz_iconv_t cd); /** \brief tests whether conversion is handled by YAZ' iconv or system iconv */ YAZ_EXPORT int yaz_iconv_isbuiltin(yaz_iconv_t cd); -/** \brief match strings - independent of case and '-' - \param s1 first string - \param s2 second string (May include wildcard ? and .) - \retval 0 strings are similar - \retval !=0 strings are different -*/ -YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2); - -/** \brief match a and b with some delimitor for b - \param a first second - \param b second string - \param b_del delimitor for b - \retval 0 strings are similar - \retval !=0 strings are different -*/ -YAZ_EXPORT int yaz_strcmp_del(const char *a, const char *b, const char *b_del); - - -/** \brief compares two buffers of different size - \param a first buffer - \param b second buffer - \param len_a length of first buffer - \retval len_b length of second buffer - \retval 0 buffers are equal - \retval >0 a > b - \retval <0 a < b -*/ -int yaz_memcmp(const void *a, const void *b, size_t len_a, size_t len_b); - - -/** \brief decodes UTF-8 sequence - \param inp input buffer with UTF-8 bytes - \param inbytesleft length of input buffer - \param no_read holds number of bytes read if conversion is successful - \param error pointer to error code if error occurs - \retval 0 if error - \retval >0 if conversion is successful -*/ YAZ_EXPORT unsigned long yaz_read_UTF8_char(unsigned char *inp, size_t inbytesleft, size_t *no_read, diff --git a/include/yaz/yaz-util.h b/include/yaz/yaz-util.h index 09bc159..baac768 100644 --- a/include/yaz/yaz-util.h +++ b/include/yaz/yaz-util.h @@ -46,6 +46,7 @@ #include #include #include +#include /** \mainpage YAZ \section intro_sec Introduction diff --git a/src/cqltransform.c b/src/cqltransform.c index 996fd63..ea41036 100644 --- a/src/cqltransform.c +++ b/src/cqltransform.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include diff --git a/src/http.c b/src/http.c index 018fbca..3362438 100644 --- a/src/http.c +++ b/src/http.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #ifdef WIN32 diff --git a/src/iconv-p.h b/src/iconv-p.h index f78f2ac..2586b7b 100644 --- a/src/iconv-p.h +++ b/src/iconv-p.h @@ -34,6 +34,7 @@ #include +#include #include void yaz_iconv_set_errno(yaz_iconv_t cd, int no); diff --git a/src/matchstr.c b/src/matchstr.c index e2a1da3..cd5af55 100644 --- a/src/matchstr.c +++ b/src/matchstr.c @@ -5,7 +5,7 @@ /** * \file matchstr.c - * \brief Implements loose string matching + * \brief a couple of string utilities */ #if HAVE_CONFIG_H @@ -16,7 +16,7 @@ #include #include #include -#include +#include int yaz_matchstr(const char *s1, const char *s2) { diff --git a/src/srwutil.c b/src/srwutil.c index 44b1d97..9ebd82d 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -9,6 +9,7 @@ #include #include +#include #include static int hex_digit (int ch) diff --git a/ztest/Makefile.am b/ztest/Makefile.am index 3028b57..9243a3b 100644 --- a/ztest/Makefile.am +++ b/ztest/Makefile.am @@ -2,11 +2,13 @@ ## Copyright (C) 1995-2008 Index Data bin_PROGRAMS=yaz-ztest +noinst_PROGRAMS=gfs-example yaz_ztest_SOURCES=ztest.c read-grs.c read-marc.c dummy-opac.c ztest.h +gfs_example_SOURCES=gfs-example.c EXTRA_DIST=dummy-records dummy-words dummy-grs ztest.pem config1.xml -yaz_ztest_LDADD=../src/libyaz_server.la $(PTHREAD_LIBS) +LDADD=../src/libyaz_server.la $(PTHREAD_LIBS) AM_CPPFLAGS=-I$(top_srcdir)/include $(XML2_CFLAGS) diff --git a/ztest/gfs-example.c b/ztest/gfs-example.c new file mode 100644 index 0000000..258c83f --- /dev/null +++ b/ztest/gfs-example.c @@ -0,0 +1,103 @@ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2008 Index Data + * See the file LICENSE for details. + */ + +/** \file + * \brief Demonstration of Generic Frontend Server API + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +static int my_search(void *handle, bend_search_rr *rr) +{ + if (rr->num_bases != 1) + { + rr->errcode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP; + return 0; + } + /* Throw Database unavailable if other than Default or Slow */ + if (!yaz_matchstr (rr->basenames[0], "Default")) + ; /* Default is OK in our test */ + else + { + rr->errcode = YAZ_BIB1_DATABASE_UNAVAILABLE; + rr->errstring = rr->basenames[0]; + return 0; + } + + rr->hits = 123; /* dummy hit count */ + return 0; +} + +/* retrieval of a single record (present, and piggy back search) */ +static int my_fetch(void *handle, bend_fetch_rr *r) +{ + const Odr_oid *oid = r->request_format; + + r->last_in_set = 0; + r->basename = "Default"; + r->output_format = r->request_format; + + /* if no record syntax was given assume XML */ + if (!oid || !oid_oidcmp(oid, yaz_oid_recsyn_xml)) + { + char buf[40]; + yaz_snprintf(buf, sizeof(buf), "%d\n", r->number); + + r->record = odr_strdup(r->stream, buf); + r->len = strlen(r->record); + } + else + { /* only xml syntax supported . Return diagnostic */ + char buf[OID_STR_MAX]; + r->errcode = YAZ_BIB1_RECORD_SYNTAX_UNSUPP; + r->errstring = odr_strdup(r->stream, oid_oid_to_dotstring(oid, buf)); + } + return 0; +} + +static bend_initresult *my_init(bend_initrequest *q) +{ + bend_initresult *r = (bend_initresult *) + odr_malloc (q->stream, sizeof(*r)); + int *counter = (int *) xmalloc (sizeof(int)); + + *counter = 0; + r->errcode = 0; + r->errstring = 0; + r->handle = counter; /* user handle, in this case a simple int */ + q->bend_search = my_search; /* register search handler */ + q->bend_fetch = my_fetch; /* register fetch handle */ + q->query_charset = "UTF-8"; + q->records_in_same_charset = 1; + + return r; +} + +static void my_close(void *handle) +{ + xfree(handle); /* release our user-defined handle */ + return; +} + +int main(int argc, char **argv) +{ + return statserv_main(argc, argv, my_init, my_close); +} +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/ztest/ztest.c b/ztest/ztest.c index 76dd459..d7beb82 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -4,7 +4,7 @@ */ /** \file - * \brief Demonstration of server + * \brief yaz-ztest Generic Frontend Server */ #include