From 20d1df123f3e5be61a77687223952430ac184cd9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 22 Sep 2006 10:18:06 +0000 Subject: [PATCH] Renamed main.c to zebraidx.c. Renamed zserver.c to zebrasrv.c. Removed zserver.h. --- index/Makefile.am | 8 +- index/main.c | 324 -------------------- index/zebraidx.c | 324 ++++++++++++++++++++ index/zebrasrv.c | 853 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index/zserver.c | 851 ---------------------------------------------------- index/zserver.h | 39 --- win/makefile | 6 +- 7 files changed, 1184 insertions(+), 1221 deletions(-) delete mode 100644 index/main.c create mode 100644 index/zebraidx.c create mode 100644 index/zebrasrv.c delete mode 100644 index/zserver.c delete mode 100644 index/zserver.h diff --git a/index/Makefile.am b/index/Makefile.am index 7a3949f..78b0596 100644 --- a/index/Makefile.am +++ b/index/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.54 2006-09-21 08:56:52 adam Exp $ +## $Id: Makefile.am,v 1.55 2006-09-22 10:18:08 adam Exp $ aux_libs = \ ../rset/libidzebra-rset.la \ @@ -82,12 +82,12 @@ libidzebra_2_0_la_SOURCES = \ recindex.c recindex.h recindxp.h reckeys.c reckeys.h recstat.c retrieve.c \ rpnscan.c rpnsearch.c sortidx.c symtab.c stream.c \ update_path.c update_file.c trunc.c untrans.c \ - zaptterm.c zebraapi.c zinfo.c zinfo.h zserver.h zsets.c + zaptterm.c zebraapi.c zinfo.c zinfo.h zsets.c bin_PROGRAMS = zebraidx zebrasrv -zebraidx_SOURCES = main.c -zebrasrv_SOURCES = zserver.c +zebraidx_SOURCES = zebraidx.c +zebrasrv_SOURCES = zebrasrv.c zebrash_SOURCES = zebrash.c apitest_SOURCES = apitest.c kdump_SOURCES = kdump.c diff --git a/index/main.c b/index/main.c deleted file mode 100644 index 6034820..0000000 --- a/index/main.c +++ /dev/null @@ -1,324 +0,0 @@ -/* $Id: main.c,v 1.131 2006-09-11 22:57:54 adam Exp $ - Copyright (C) 1995-2006 - Index Data ApS - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include -#include -#include -#ifdef WIN32 -#include -#endif -#if HAVE_UNISTD_H -#include -#endif -#if HAVE_SYS_TIME_H -#include -#endif -#include -#if HAVE_SYS_TIMES_H -#include -#endif - -#include -#include -#include - -char *prog; - -static void filter_cb(void *cd, const char *name) -{ - puts (name); -} - -static void show_filters(ZebraService zs) -{ - zebra_filter_info(zs, 0, filter_cb); -} - -int main (int argc, char **argv) -{ - int ret; - int cmd = 0; - char *arg; - char *configName = 0; - int nsections = 0; - int enable_commit = 1; - char *database = 0; - Res res = res_open(0, 0); - - int trans_started=0; -#if HAVE_SYS_TIMES_H - struct tms tms1, tms2; - double usec; -#endif -#if HAVE_SYS_TIME_H - struct timeval start_time, end_time; -#endif -#ifndef WIN32 - char nbuf[100]; -#endif - ZebraService zs = 0; - ZebraHandle zh = 0; - - nmem_init (); - -#ifdef WIN32 -#else - sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid()); - yaz_log_init_prefix (nbuf); -#endif -#if HAVE_SYS_TIMES_H - times(&tms1); -#endif -#if HAVE_SYS_TIME_H - gettimeofday(&start_time, 0); -#endif - prog = *argv; - if (argc < 2) - { - fprintf (stderr, "%s [options] command ...\n" - "Commands:\n" - " update Update index with files below .\n" - " If is empty filenames are read from stdin.\n" - " delete Delete index with files below .\n" - " create Create database \n" - " drop Drop database \n" - " commit Commit changes\n" - " clean Clean shadow files\n" - "Options:\n" - " -t Index files as (grs or text).\n" - " -c Read configuration file .\n" - " -g Index files according to group settings.\n" - " -d Records belong to Z39.50 database .\n" - " -m Use before flushing keys to disk.\n" - " -n Don't use shadow system.\n" - " -s Show analysis on stdout, but do no work.\n" - " -v Set logging to .\n" - " -l Write log to .\n" - " -L Don't follow symbolic links.\n" - " -f Display information for the first records.\n" - " -V Show version.\n", *argv - ); - exit (1); - } - while ((ret = options("sVt:c:g:d:m:v:nf:l:L", argv, argc, &arg)) != -2) - { - if (ret == 0) - { - if(cmd == 0) /* command */ - { - if (!zs) - { - const char *config = configName ? configName : "zebra.cfg"; - zs = zebra_start_res (config, 0, res); - if (!zs) - { - yaz_log (YLOG_FATAL, "Cannot read config %s", config); - exit (1); - } - zh = zebra_open (zs, 0); - zebra_shadow_enable (zh, enable_commit); - } - - if (database && - zebra_select_database (zh, database) == ZEBRA_FAIL) - { - yaz_log(YLOG_FATAL, "Could not select database %s " - "errCode=%d", - database, zebra_errCode(zh) ); - exit (1); - } - if (!strcmp (arg, "update")) - cmd = 'u'; - else if (!strcmp (arg, "update1")) - cmd = 'U'; - else if (!strcmp (arg, "update2")) - cmd = 'm'; - else if (!strcmp (arg, "dump")) - cmd = 's'; - else if (!strcmp (arg, "del") || !strcmp(arg, "delete")) - cmd = 'd'; - else if (!strcmp (arg, "init")) - { - zebra_init (zh); - } - else if (!strcmp(arg, "drop")) - { - cmd = 'D'; - } - else if (!strcmp(arg, "create")) - { - cmd = 'C'; - } - else if (!strcmp (arg, "commit")) - { - zebra_commit (zh); - } - else if (!strcmp (arg, "clean")) - { - zebra_clean (zh); - } - else if (!strcmp (arg, "stat") || !strcmp (arg, "status")) - { - zebra_register_statistics (zh,0); - } - else if (!strcmp (arg, "dumpdict")) - { - zebra_register_statistics (zh,1); - } - else if (!strcmp (arg, "compact")) - { - zebra_compact (zh); - } - else if (!strcmp (arg, "filters")) - { - show_filters(zs); - } - else - { - yaz_log (YLOG_FATAL, "unknown command: %s", arg); - exit (1); - } - } - else - { - ZEBRA_RES res = ZEBRA_OK; - if (!trans_started) - { - trans_started=1; - if (zebra_begin_trans (zh, 1) != ZEBRA_OK) - exit(1); - } - switch (cmd) - { - case 'u': - res = zebra_repository_update (zh, arg); - break; - case 'd': - res = zebra_repository_delete (zh, arg); - break; - case 's': - res = zebra_repository_show (zh, arg); - nsections = 0; - break; - case 'C': - res = zebra_create_database(zh, arg); - break; - case 'D': - res = zebra_drop_database(zh, arg); - break; - default: - nsections = 0; - } - if (res != ZEBRA_OK) - { - const char *add = zebra_errAdd(zh); - yaz_log(YLOG_FATAL, "Operation failed: %s %s", - zebra_errString(zh), add ? add : ""); - - if (trans_started) - if (zebra_end_trans (zh) != ZEBRA_OK) - yaz_log (YLOG_WARN, "zebra_end_trans failed"); - - - zebra_close (zh); - zebra_stop (zs); - exit(1); - } - log_event_end (NULL, NULL); - } - } - else if (ret == 'V') - { - printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE); - printf(" (C) 1994-2006, Index Data ApS\n"); -#ifdef WIN32 -#ifdef _DEBUG - printf(" WIN32 Debug\n"); -#else - printf(" WIN32 Release\n"); -#endif -#endif -#if HAVE_BZLIB_H - printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n"); -#endif - } - else if (ret == 'v') - yaz_log_init_level (yaz_log_mask_str(arg)); - else if (ret == 'l') - yaz_log_init_file (arg); - else if (ret == 'm') - res_set(res, "memMax", arg); - else if (ret == 'd') - database = arg; - else if (ret == 's') - res_set(res, "openRW", "0"); - else if (ret == 'g') - res_set(res, "group", arg); - else if (ret == 'f') - res_set(res, "fileVerboseLimit", arg); - else if (ret == 'c') - configName = arg; - else if (ret == 't') - res_set(res, "recordType", arg); - else if (ret == 'n') - enable_commit = 0; - else if (ret == 'L') - res_set(res, "followLinks", "0"); - else - yaz_log (YLOG_WARN, "unknown option '-%s'", arg); - } /* while arg */ - - if (trans_started) - if (zebra_end_trans (zh) != ZEBRA_OK) - yaz_log (YLOG_WARN, "zebra_end_trans failed"); - - zebra_close (zh); - zebra_stop (zs); -#if HAVE_SYS_TIMES_H -#if HAVE_SYS_TIME_H - if (trans_started) - { - gettimeofday(&end_time, 0); - usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 + - end_time.tv_usec - start_time.tv_usec; - times(&tms2); - yaz_log (YLOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f", - usec / 1000000, - (double) (tms2.tms_utime - tms1.tms_utime)/100, - (double) (tms2.tms_stime - tms1.tms_stime)/100); - } -#endif -#endif - nmem_exit(); - exit (0); - return 0; -} - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/index/zebraidx.c b/index/zebraidx.c new file mode 100644 index 0000000..d07d76f --- /dev/null +++ b/index/zebraidx.c @@ -0,0 +1,324 @@ +/* $Id: zebraidx.c,v 1.1 2006-09-22 10:18:08 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_SYS_TIME_H +#include +#endif +#include +#if HAVE_SYS_TIMES_H +#include +#endif + +#include +#include +#include + +char *prog; + +static void filter_cb(void *cd, const char *name) +{ + puts (name); +} + +static void show_filters(ZebraService zs) +{ + zebra_filter_info(zs, 0, filter_cb); +} + +int main (int argc, char **argv) +{ + int ret; + int cmd = 0; + char *arg; + char *configName = 0; + int nsections = 0; + int enable_commit = 1; + char *database = 0; + Res res = res_open(0, 0); + + int trans_started=0; +#if HAVE_SYS_TIMES_H + struct tms tms1, tms2; + double usec; +#endif +#if HAVE_SYS_TIME_H + struct timeval start_time, end_time; +#endif +#ifndef WIN32 + char nbuf[100]; +#endif + ZebraService zs = 0; + ZebraHandle zh = 0; + + nmem_init (); + +#ifdef WIN32 +#else + sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid()); + yaz_log_init_prefix (nbuf); +#endif +#if HAVE_SYS_TIMES_H + times(&tms1); +#endif +#if HAVE_SYS_TIME_H + gettimeofday(&start_time, 0); +#endif + prog = *argv; + if (argc < 2) + { + fprintf (stderr, "%s [options] command ...\n" + "Commands:\n" + " update Update index with files below .\n" + " If is empty filenames are read from stdin.\n" + " delete Delete index with files below .\n" + " create Create database \n" + " drop Drop database \n" + " commit Commit changes\n" + " clean Clean shadow files\n" + "Options:\n" + " -t Index files as (grs or text).\n" + " -c Read configuration file .\n" + " -g Index files according to group settings.\n" + " -d Records belong to Z39.50 database .\n" + " -m Use before flushing keys to disk.\n" + " -n Don't use shadow system.\n" + " -s Show analysis on stdout, but do no work.\n" + " -v Set logging to .\n" + " -l Write log to .\n" + " -L Don't follow symbolic links.\n" + " -f Display information for the first records.\n" + " -V Show version.\n", *argv + ); + exit (1); + } + while ((ret = options("sVt:c:g:d:m:v:nf:l:L", argv, argc, &arg)) != -2) + { + if (ret == 0) + { + if(cmd == 0) /* command */ + { + if (!zs) + { + const char *config = configName ? configName : "zebra.cfg"; + zs = zebra_start_res (config, 0, res); + if (!zs) + { + yaz_log (YLOG_FATAL, "Cannot read config %s", config); + exit (1); + } + zh = zebra_open (zs, 0); + zebra_shadow_enable (zh, enable_commit); + } + + if (database && + zebra_select_database (zh, database) == ZEBRA_FAIL) + { + yaz_log(YLOG_FATAL, "Could not select database %s " + "errCode=%d", + database, zebra_errCode(zh) ); + exit (1); + } + if (!strcmp (arg, "update")) + cmd = 'u'; + else if (!strcmp (arg, "update1")) + cmd = 'U'; + else if (!strcmp (arg, "update2")) + cmd = 'm'; + else if (!strcmp (arg, "dump")) + cmd = 's'; + else if (!strcmp (arg, "del") || !strcmp(arg, "delete")) + cmd = 'd'; + else if (!strcmp (arg, "init")) + { + zebra_init (zh); + } + else if (!strcmp(arg, "drop")) + { + cmd = 'D'; + } + else if (!strcmp(arg, "create")) + { + cmd = 'C'; + } + else if (!strcmp (arg, "commit")) + { + zebra_commit (zh); + } + else if (!strcmp (arg, "clean")) + { + zebra_clean (zh); + } + else if (!strcmp (arg, "stat") || !strcmp (arg, "status")) + { + zebra_register_statistics (zh,0); + } + else if (!strcmp (arg, "dumpdict")) + { + zebra_register_statistics (zh,1); + } + else if (!strcmp (arg, "compact")) + { + zebra_compact (zh); + } + else if (!strcmp (arg, "filters")) + { + show_filters(zs); + } + else + { + yaz_log (YLOG_FATAL, "unknown command: %s", arg); + exit (1); + } + } + else + { + ZEBRA_RES res = ZEBRA_OK; + if (!trans_started) + { + trans_started=1; + if (zebra_begin_trans (zh, 1) != ZEBRA_OK) + exit(1); + } + switch (cmd) + { + case 'u': + res = zebra_repository_update (zh, arg); + break; + case 'd': + res = zebra_repository_delete (zh, arg); + break; + case 's': + res = zebra_repository_show (zh, arg); + nsections = 0; + break; + case 'C': + res = zebra_create_database(zh, arg); + break; + case 'D': + res = zebra_drop_database(zh, arg); + break; + default: + nsections = 0; + } + if (res != ZEBRA_OK) + { + const char *add = zebra_errAdd(zh); + yaz_log(YLOG_FATAL, "Operation failed: %s %s", + zebra_errString(zh), add ? add : ""); + + if (trans_started) + if (zebra_end_trans (zh) != ZEBRA_OK) + yaz_log (YLOG_WARN, "zebra_end_trans failed"); + + + zebra_close (zh); + zebra_stop (zs); + exit(1); + } + log_event_end (NULL, NULL); + } + } + else if (ret == 'V') + { + printf("Zebra %s %s\n", ZEBRAVER, ZEBRADATE); + printf(" (C) 1994-2006, Index Data ApS\n"); +#ifdef WIN32 +#ifdef _DEBUG + printf(" WIN32 Debug\n"); +#else + printf(" WIN32 Release\n"); +#endif +#endif +#if HAVE_BZLIB_H + printf("Using: libbzip2, (C) 1996-1999 Julian R Seward. All rights reserved.\n"); +#endif + } + else if (ret == 'v') + yaz_log_init_level (yaz_log_mask_str(arg)); + else if (ret == 'l') + yaz_log_init_file (arg); + else if (ret == 'm') + res_set(res, "memMax", arg); + else if (ret == 'd') + database = arg; + else if (ret == 's') + res_set(res, "openRW", "0"); + else if (ret == 'g') + res_set(res, "group", arg); + else if (ret == 'f') + res_set(res, "fileVerboseLimit", arg); + else if (ret == 'c') + configName = arg; + else if (ret == 't') + res_set(res, "recordType", arg); + else if (ret == 'n') + enable_commit = 0; + else if (ret == 'L') + res_set(res, "followLinks", "0"); + else + yaz_log (YLOG_WARN, "unknown option '-%s'", arg); + } /* while arg */ + + if (trans_started) + if (zebra_end_trans (zh) != ZEBRA_OK) + yaz_log (YLOG_WARN, "zebra_end_trans failed"); + + zebra_close (zh); + zebra_stop (zs); +#if HAVE_SYS_TIMES_H +#if HAVE_SYS_TIME_H + if (trans_started) + { + gettimeofday(&end_time, 0); + usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 + + end_time.tv_usec - start_time.tv_usec; + times(&tms2); + yaz_log (YLOG_LOG, "zebraidx times: %5.2f %5.2f %5.2f", + usec / 1000000, + (double) (tms2.tms_utime - tms1.tms_utime)/100, + (double) (tms2.tms_stime - tms1.tms_stime)/100); + } +#endif +#endif + nmem_exit(); + exit (0); + return 0; +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/index/zebrasrv.c b/index/zebrasrv.c new file mode 100644 index 0000000..3283d5f --- /dev/null +++ b/index/zebrasrv.c @@ -0,0 +1,853 @@ +/* $Id: zebrasrv.c,v 1.1 2006-09-22 10:18:08 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#include +#include +#endif +#if HAVE_UNISTD_H +#include +#endif + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +static int bend_sort (void *handle, bend_sort_rr *rr); +static int bend_delete (void *handle, bend_delete_rr *rr); +static int bend_esrequest (void *handle, bend_esrequest_rr *rr); +static int bend_segment (void *handle, bend_segment_rr *rr); +static int bend_search (void *handle, bend_search_rr *r); +static int bend_fetch (void *handle, bend_fetch_rr *r); +static int bend_scan (void *handle, bend_scan_rr *r); + +bend_initresult *bend_init (bend_initrequest *q) +{ + bend_initresult *r = (bend_initresult *) + odr_malloc (q->stream, sizeof(*r)); + ZebraHandle zh; + struct statserv_options_block *sob; + char *user = NULL; + char *passwd = NULL; + + r->errcode = 0; + r->errstring = 0; + q->bend_sort = bend_sort; + q->bend_delete = bend_delete; + q->bend_esrequest = bend_esrequest; + q->bend_segment = bend_segment; + q->bend_search = bend_search; + q->bend_fetch = bend_fetch; + q->bend_scan = bend_scan; + + q->implementation_name = "Zebra Information Server"; + q->implementation_version = "Zebra " ZEBRAVER; + + yaz_log (YLOG_DEBUG, "bend_init"); + + sob = statserv_getcontrol (); + if (!(zh = zebra_open (sob->handle, 0))) + { + yaz_log (YLOG_WARN, "Failed to read config `%s'", sob->configname); + r->errcode = YAZ_BIB1_PERMANENT_SYSTEM_ERROR; + return r; + } + r->handle = zh; + if (q->auth) + { + if (q->auth->which == Z_IdAuthentication_open) + { + char *openpass = xstrdup (q->auth->u.open); + char *cp = strchr (openpass, '/'); + if (cp) + { + *cp = '\0'; + user = nmem_strdup (odr_getmem (q->stream), openpass); + passwd = nmem_strdup (odr_getmem (q->stream), cp+1); + } + xfree (openpass); + } + else if (q->auth->which == Z_IdAuthentication_idPass) + { + Z_IdPass *idPass = q->auth->u.idPass; + + user = idPass->userId; + passwd = idPass->password; + } + } + if (zebra_auth(zh, user, passwd) != ZEBRA_OK) + { + r->errcode = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD; + r->errstring = user; + return r; + } + if (q->charneg_request) /* characater set and langauge negotiation? */ + { + char **charsets = 0; + int num_charsets; + char **langs = 0; + int num_langs = 0; + int selected = 0; + int i; + NMEM nmem = nmem_create(); + + yaz_log (YLOG_LOG, "character set and language negotiation"); + + yaz_get_proposal_charneg (nmem, q->charneg_request, + &charsets, &num_charsets, + &langs, &num_langs, &selected); + + for (i = 0; i < num_charsets; i++) + { + const char *right_name = ""; + /* + * FIXME! It is like rudiment :-)) + * We have to support this short names of character sets, + * because a lot servers in Russia to use own in during + * character set and language negotiation still. + */ + + if (!yaz_matchstr(charsets[i], "win")) { + right_name = "WINDOWS-1251"; + } else if (!yaz_matchstr(charsets[i], "koi")) { + right_name = "KOI8-R"; + } else if (!yaz_matchstr(charsets[i], "iso")) { + right_name = "ISO-8859-5"; + } else if (!yaz_matchstr(charsets[i], "dos")) { + right_name = "CP866"; + } else if (!yaz_matchstr(charsets[i], "uni")) { + right_name = "UTF-8"; + } else { + right_name = charsets[i]; + } + if (odr_set_charset (q->decode, "UTF-8", right_name) == 0) + { + yaz_log (YLOG_LOG, "charset %d %s (proper name %s): OK", i, + charsets[i], right_name); + odr_set_charset (q->stream, right_name, "UTF-8"); + if (selected) + zebra_record_encoding(zh, right_name); + zebra_octet_term_encoding(zh, right_name); + q->charneg_response = + yaz_set_response_charneg (q->stream, charsets[i], + 0, selected); + break; + } else { + yaz_log (YLOG_LOG, "charset %d %s (proper name %s): unsupported", i, + charsets[i], right_name); + } + } + nmem_destroy(nmem); + } + return r; +} + +static void search_terms(ZebraHandle zh, bend_search_rr *r) +{ + int no_terms; + int i; + int type = Z_Term_general; + struct Z_External *ext; + Z_SearchInfoReport *sr; + + zebra_result_set_term_no(zh, r->setname, &no_terms); + if (!no_terms) + return; + + r->search_info = odr_malloc (r->stream, sizeof(*r->search_info)); + + r->search_info->num_elements = 1; + r->search_info->list = + odr_malloc (r->stream, sizeof(*r->search_info->list)); + r->search_info->list[0] = + odr_malloc (r->stream, sizeof(**r->search_info->list)); + r->search_info->list[0]->category = 0; + r->search_info->list[0]->which = Z_OtherInfo_externallyDefinedInfo; + ext = odr_malloc (r->stream, sizeof(*ext)); + r->search_info->list[0]->information.externallyDefinedInfo = ext; + ext->direct_reference = + yaz_oidval_to_z3950oid (r->stream, CLASS_USERINFO, VAL_SEARCHRES1); + ext->indirect_reference = 0; + ext->descriptor = 0; + ext->which = Z_External_searchResult1; + sr = odr_malloc (r->stream, sizeof(Z_SearchInfoReport)); + ext->u.searchResult1 = sr; + sr->num = no_terms; + sr->elements = odr_malloc (r->stream, sr->num * + sizeof(*sr->elements)); + for (i = 0; isetname, i, + &count, &approx, outbuf, &len, + &term_ref_id); + se = sr->elements[i] = odr_malloc (r->stream, sizeof(**sr->elements)); + se->subqueryId = term_ref_id ? + odr_strdup(r->stream, term_ref_id) : 0; + + se->fullQuery = odr_intdup(r->stream, 0); + se->subqueryExpression = + odr_malloc (r->stream, sizeof(Z_QueryExpression)); + se->subqueryExpression->which = + Z_QueryExpression_term; + se->subqueryExpression->u.term = + odr_malloc (r->stream, sizeof(Z_QueryExpressionTerm)); + term = odr_malloc (r->stream, sizeof(Z_Term)); + se->subqueryExpression->u.term->queryTerm = term; + switch (type) + { + case Z_Term_characterString: + term->which = Z_Term_characterString; + term->u.characterString = odr_strdup (r->stream, outbuf); + break; + case Z_Term_general: + term->which = Z_Term_general; + term->u.general = odr_malloc (r->stream, sizeof(*term->u.general)); + term->u.general->size = term->u.general->len = len; + term->u.general->buf = odr_malloc (r->stream, len); + memcpy (term->u.general->buf, outbuf, len); + break; + default: + term->which = Z_Term_general; + term->u.null = odr_nullval(); + } + se->subqueryExpression->u.term->termComment = 0; + se->subqueryInterpretation = 0; + se->subqueryRecommendation = 0; + if (count > 2147483646) + count = 2147483647; + se->subqueryCount = odr_intdup(r->stream, CAST_ZINT_TO_INT(count)); + se->subqueryWeight = 0; + se->resultsByDB = 0; + } +} + +int bend_search(void *handle, bend_search_rr *r) +{ + ZebraHandle zh = (ZebraHandle) handle; + zint zhits = 0; + ZEBRA_RES res; + + res = zebra_select_databases (zh, r->num_bases, + (const char **) r->basenames); + if (res != ZEBRA_OK) + { + zebra_result (zh, &r->errcode, &r->errstring); + return 0; + } + yaz_log (YLOG_DEBUG, "ResultSet '%s'", r->setname); + switch (r->query->which) + { + case Z_Query_type_1: case Z_Query_type_101: + res = zebra_search_RPN(zh, r->stream, r->query->u.type_1, + r->setname, &zhits); + if (res != ZEBRA_OK) + zebra_result(zh, &r->errcode, &r->errstring); + else + { + if (zhits > 2147483646) + zhits = 2147483647; + r->hits = CAST_ZINT_TO_INT(zhits); + search_terms (zh, r); + } + break; + case Z_Query_type_2: + r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP; + r->errstring = "type-2"; + break; + default: + r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP; + } + return 0; +} + + +int bend_fetch (void *handle, bend_fetch_rr *r) +{ + ZebraHandle zh = (ZebraHandle) handle; + ZebraRetrievalRecord retrievalRecord; + ZEBRA_RES res; + + retrievalRecord.position = r->number; + + r->last_in_set = 0; + res = zebra_records_retrieve (zh, r->stream, r->setname, r->comp, + r->request_format, 1, &retrievalRecord); + if (res != ZEBRA_OK) + { + /* non-surrogate diagnostic */ + zebra_result (zh, &r->errcode, &r->errstring); + } + else if (retrievalRecord.errCode) + { + /* surrogate diagnostic (diagnostic per record) */ + r->surrogate_flag = 1; + r->errcode = retrievalRecord.errCode; + r->errstring = retrievalRecord.errString; + r->basename = retrievalRecord.base; + } + else + { + r->basename = retrievalRecord.base; + r->record = retrievalRecord.buf; + r->len = retrievalRecord.len; + r->output_format = retrievalRecord.format; + } + return 0; +} + +static int bend_scan (void *handle, bend_scan_rr *r) +{ + ZebraScanEntry *entries; + ZebraHandle zh = (ZebraHandle) handle; + int is_partial, i; + ZEBRA_RES res; + + res = zebra_select_databases(zh, r->num_bases, + (const char **) r->basenames); + if (res != ZEBRA_OK) + { + zebra_result (zh, &r->errcode, &r->errstring); + return 0; + } + if (r->step_size != 0 && *r->step_size != 0) { + r->errcode = YAZ_BIB1_ONLY_ZERO_STEP_SIZE_SUPPORTED_FOR_SCAN; + r->errstring = 0; + return 0; + } + r->entries = (struct scan_entry *) + odr_malloc (r->stream, sizeof(*r->entries) * r->num_entries); + res = zebra_scan(zh, r->stream, r->term, + r->attributeset, + &r->term_position, + &r->num_entries, &entries, &is_partial, + 0 /* setname */); + if (res == ZEBRA_OK) + { + if (is_partial) + r->status = BEND_SCAN_PARTIAL; + else + r->status = BEND_SCAN_SUCCESS; + for (i = 0; i < r->num_entries; i++) + { + r->entries[i].term = entries[i].term; + r->entries[i].occurrences = + CAST_ZINT_TO_INT(entries[i].occurrences); + } + } + else + { + r->status = BEND_SCAN_PARTIAL; + zebra_result(zh, &r->errcode, &r->errstring); + } + return 0; +} + +void bend_close (void *handle) +{ + zebra_close ((ZebraHandle) handle); + xmalloc_trav("bend_close"); + nmem_print_list(); +} + +int bend_sort (void *handle, bend_sort_rr *rr) +{ + ZebraHandle zh = (ZebraHandle) handle; + + if (zebra_sort (zh, rr->stream, + rr->num_input_setnames, (const char **) rr->input_setnames, + rr->output_setname, rr->sort_sequence, &rr->sort_status) + != ZEBRA_OK) + zebra_result (zh, &rr->errcode, &rr->errstring); + return 0; +} + +int bend_delete (void *handle, bend_delete_rr *rr) +{ + ZebraHandle zh = (ZebraHandle) handle; + + rr->delete_status = zebra_deleteResultSet(zh, rr->function, + rr->num_setnames, rr->setnames, + rr->statuses); + return 0; +} + +static void es_admin_request (bend_esrequest_rr *rr, ZebraHandle zh, Z_AdminEsRequest *r) +{ + ZEBRA_RES res = ZEBRA_OK; + if (r->toKeep->databaseName) + { + yaz_log(YLOG_LOG, "adm request database %s", r->toKeep->databaseName); + } + switch (r->toKeep->which) + { + case Z_ESAdminOriginPartToKeep_reIndex: + yaz_log(YLOG_LOG, "adm-reindex"); + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "adm-reindex not implemented yet"; + break; + case Z_ESAdminOriginPartToKeep_truncate: + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "adm-reindex not implemented yet"; + yaz_log(YLOG_LOG, "adm-truncate"); + break; + case Z_ESAdminOriginPartToKeep_drop: + yaz_log(YLOG_LOG, "adm-drop"); + res = zebra_drop_database (zh, r->toKeep->databaseName); + break; + case Z_ESAdminOriginPartToKeep_create: + yaz_log(YLOG_LOG, "adm-create %s", r->toKeep->databaseName); + res = zebra_create_database (zh, r->toKeep->databaseName); + break; + case Z_ESAdminOriginPartToKeep_import: + yaz_log(YLOG_LOG, "adm-import"); + res = zebra_admin_import_begin (zh, r->toKeep->databaseName, + r->toKeep->u.import->recordType); + break; + case Z_ESAdminOriginPartToKeep_refresh: + yaz_log(YLOG_LOG, "adm-refresh"); + break; + case Z_ESAdminOriginPartToKeep_commit: + yaz_log(YLOG_LOG, "adm-commit"); + if (r->toKeep->databaseName) + { + if (zebra_select_database(zh, r->toKeep->databaseName) != + ZEBRA_OK) + yaz_log(YLOG_WARN, "zebra_select_database failed in " + "adm-commit"); + } + zebra_commit(zh); + break; + case Z_ESAdminOriginPartToKeep_shutdown: + yaz_log(YLOG_LOG, "shutdown"); + res = zebra_admin_shutdown(zh); + break; + case Z_ESAdminOriginPartToKeep_start: + yaz_log(YLOG_LOG, "start"); + zebra_admin_start(zh); + break; + default: + yaz_log(YLOG_LOG, "unknown admin"); + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "adm-reindex not implemented yet"; + } + if (res != ZEBRA_OK) + zebra_result(zh, &rr->errcode, &rr->errstring); +} + +static void es_admin (bend_esrequest_rr *rr, ZebraHandle zh, Z_Admin *r) +{ + switch (r->which) + { + case Z_Admin_esRequest: + es_admin_request (rr, zh, r->u.esRequest); + return; + default: + break; + } + yaz_log (YLOG_WARN, "adm taskpackage (unhandled)"); + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "adm-task package (unhandled)"; +} + +int bend_segment (void *handle, bend_segment_rr *rr) +{ + ZebraHandle zh = (ZebraHandle) handle; + Z_Segment *segment = rr->segment; + + if (segment->num_segmentRecords) + zebra_admin_import_segment (zh, rr->segment); + else + zebra_admin_import_end (zh); + return 0; +} + +int bend_esrequest (void *handle, bend_esrequest_rr *rr) +{ + ZebraHandle zh = (ZebraHandle) handle; + + yaz_log(YLOG_LOG, "function: %d", *rr->esr->function); + if (rr->esr->packageName) + yaz_log(YLOG_LOG, "packagename: %s", rr->esr->packageName); + yaz_log(YLOG_LOG, "Waitaction: %d", *rr->esr->waitAction); + + if (!rr->esr->taskSpecificParameters) + { + yaz_log (YLOG_WARN, "No task specific parameters"); + } + else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin) + { + es_admin(rr, zh, rr->esr->taskSpecificParameters->u.adminService); + } + else if (rr->esr->taskSpecificParameters->which == Z_External_update) + { + Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update; + yaz_log (YLOG_LOG, "Received DB Update"); + if (up->which == Z_IUUpdate_esRequest) + { + Z_IUUpdateEsRequest *esRequest = up->u.esRequest; + Z_IUOriginPartToKeep *toKeep = esRequest->toKeep; + Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep; + + yaz_log (YLOG_LOG, "action"); + if (toKeep->action) + { + switch (*toKeep->action) + { + case Z_IUOriginPartToKeep_recordInsert: + yaz_log (YLOG_LOG, "recordInsert"); + break; + case Z_IUOriginPartToKeep_recordReplace: + yaz_log (YLOG_LOG, "recordUpdate"); + break; + case Z_IUOriginPartToKeep_recordDelete: + yaz_log (YLOG_LOG, "recordDelete"); + break; + case Z_IUOriginPartToKeep_elementUpdate: + yaz_log (YLOG_LOG, "elementUpdate"); + break; + case Z_IUOriginPartToKeep_specialUpdate: + yaz_log (YLOG_LOG, "specialUpdate"); + break; + case Z_ESAdminOriginPartToKeep_shutdown: + yaz_log (YLOG_LOG, "shutDown"); + break; + case Z_ESAdminOriginPartToKeep_start: + yaz_log (YLOG_LOG, "start"); + break; + default: + yaz_log (YLOG_LOG, " unknown (%d)", *toKeep->action); + } + } + if (toKeep->databaseName) + { + yaz_log (YLOG_LOG, "database: %s", toKeep->databaseName); + + if (zebra_select_database(zh, toKeep->databaseName)) + return 0; + } + else + { + yaz_log (YLOG_WARN, "no database supplied for ES Update"); + rr->errcode = + YAZ_BIB1_ES_MISSING_MANDATORY_PARAMETER_FOR_SPECIFIED_FUNCTION_; + rr->errstring = "database"; + return 0; + } + if (zebra_begin_trans(zh, 1) != ZEBRA_OK) + { + zebra_result(zh, &rr->errcode, &rr->errstring); + } + else + { + int i; + for (i = 0; notToKeep && i < notToKeep->num; i++) + { + Z_External *rec = notToKeep->elements[i]->record; + struct oident *oident = 0; + Odr_oct *opaque_recid = 0; + SYSNO *sysno = 0; + SYSNO sysno_tmp; + + if (notToKeep->elements[i]->u.opaque) + { + switch(notToKeep->elements[i]->which) + { + case Z_IUSuppliedRecords_elem_opaque: + opaque_recid = notToKeep->elements[i]->u.opaque; + break; /* OK, recid already set */ + case Z_IUSuppliedRecords_elem_number: + sysno_tmp = *notToKeep->elements[i]->u.number; + sysno = &sysno_tmp; + break; + } + } + if (rec->direct_reference) + { + oident = oid_getentbyoid(rec->direct_reference); + if (oident) + yaz_log (YLOG_LOG, "record %d type %s", i, + oident->desc); + } + switch (rec->which) + { + case Z_External_sutrs: + if (rec->u.octet_aligned->len > 170) + yaz_log (YLOG_LOG, "%d bytes:\n%.168s ...", + rec->u.sutrs->len, + rec->u.sutrs->buf); + else + yaz_log (YLOG_LOG, "%d bytes:\n%s", + rec->u.sutrs->len, + rec->u.sutrs->buf); + break; + case Z_External_octet: + if (rec->u.octet_aligned->len > 170) + yaz_log (YLOG_LOG, "%d bytes:\n%.168s ...", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); + else + yaz_log (YLOG_LOG, "%d bytes\n%s", + rec->u.octet_aligned->len, + rec->u.octet_aligned->buf); + } + if (oident && oident->value != VAL_TEXT_XML) + { + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "only XML update supported"; + break; + } + if (rec->which == Z_External_octet) + { + int action = 0; + + if (*toKeep->action == + Z_IUOriginPartToKeep_recordInsert) + action = 1; + if (*toKeep->action == + Z_IUOriginPartToKeep_recordReplace) + action = 2; + if (*toKeep->action == + Z_IUOriginPartToKeep_recordDelete) + action = 3; + if (*toKeep->action == + Z_IUOriginPartToKeep_specialUpdate) + action = 4; + + if (!action) + { + rr->errcode = + YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "unsupported ES Update action"; + break; + } + else if (opaque_recid) + { + int r = zebra_admin_exchange_record ( + zh, + (const char *) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len, + (const char *) opaque_recid->buf, + opaque_recid->len, + action); + if (r) + { + zebra_result(zh, &rr->errcode, + &rr->errstring); + break; + } + } + else + { + ZEBRA_RES r = ZEBRA_FAIL; + switch(action) { + case 1: + r = zebra_insert_record( + zh, + 0, /* recordType */ + sysno, + 0, /* match */ + 0, /* fname */ + (const char *) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len, + 0); + if (r == ZEBRA_FAIL) + { + rr->errcode = + YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "insert_record failed"; + } + break; + case 2: + case 4: + r = zebra_update_record( + zh, + 0, /* recordType */ + sysno, + 0, /* match */ + 0, /* fname */ + (const char *) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len, + 1); + if (r == ZEBRA_FAIL) + { + rr->errcode = + YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "update_record failed"; + } + break; + case 3: + r = zebra_delete_record( + zh, + 0, /* recordType */ + sysno, + 0, /* match */ + 0, /* fname */ + (const char *) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len, + 0); + if (r == ZEBRA_FAIL) + { + rr->errcode = + YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "delete_record failed"; + } + break; + } + } + } + } + if (zebra_end_trans (zh) != ZEBRA_OK) + { + yaz_log(YLOG_WARN, "zebra_end_trans failed for" + " extended service operation"); + } + } + } + } + else + { + yaz_log (YLOG_WARN, "Unknown Extended Service(%d)", + rr->esr->taskSpecificParameters->which); + rr->errcode = YAZ_BIB1_ES_EXTENDED_SERVICE_TYPE_UNSUPP; + + } + return 0; +} + +static void bend_start (struct statserv_options_block *sob) +{ + if (sob->handle) + zebra_stop((ZebraService) sob->handle); + sob->handle = zebra_start(sob->configname); + if (!sob->handle) + { + yaz_log (YLOG_FATAL, "Failed to read config `%s'", sob->configname); + exit (1); + } +#ifdef WIN32 + +#else + if (!sob->inetd) + { + char pidfname[4096]; + struct flock area; + int fd; + + zebra_pidfname(sob->handle, pidfname); + + fd = open (pidfname, O_EXCL|O_WRONLY|O_CREAT, 0666); + if (fd == -1) + { + if (errno != EEXIST) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "lock file %s", pidfname); + exit(1); + } + fd = open(pidfname, O_RDWR, 0666); + if (fd == -1) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "lock file %s", pidfname); + exit(1); + } + } + area.l_type = F_WRLCK; + area.l_whence = SEEK_SET; + area.l_len = area.l_start = 0L; + if (fcntl (fd, F_SETLK, &area) == -1) + { + yaz_log(YLOG_ERRNO|YLOG_FATAL, "Zebra server already running"); + exit(1); + } + else + { + char pidstr[30]; + + sprintf (pidstr, "%ld", (long) getpid ()); + write (fd, pidstr, strlen(pidstr)); + } + } +#endif +} + +static void bend_stop(struct statserv_options_block *sob) +{ +#ifdef WIN32 + +#else + if (!sob->inetd && sob->handle) + { + char pidfname[4096]; + zebra_pidfname(sob->handle, pidfname); + unlink (pidfname); + } +#endif + if (sob->handle) + { + ZebraService service = sob->handle; + zebra_stop(service); + } +} + +int main (int argc, char **argv) +{ + struct statserv_options_block *sob; + + sob = statserv_getcontrol (); + strcpy (sob->configname, "zebra.cfg"); + sob->bend_start = bend_start; + sob->bend_stop = bend_stop; +#ifdef WIN32 + strcpy (sob->service_display_name, "Zebra Server"); +#endif + statserv_setcontrol (sob); + + return statserv_main (argc, argv, bend_init, bend_close); +} +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/index/zserver.c b/index/zserver.c deleted file mode 100644 index ceeb56f..0000000 --- a/index/zserver.c +++ /dev/null @@ -1,851 +0,0 @@ -/* $Id: zserver.c,v 1.149 2006-08-14 10:40:15 adam Exp $ - Copyright (C) 1995-2006 - Index Data ApS - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include -#include -#include -#ifdef WIN32 -#include -#include -#include -#endif -#if HAVE_UNISTD_H -#include -#endif - -#include -#include -#include -#include -#include - -#include - -#include "zserver.h" - -static int bend_sort (void *handle, bend_sort_rr *rr); -static int bend_delete (void *handle, bend_delete_rr *rr); -static int bend_esrequest (void *handle, bend_esrequest_rr *rr); -static int bend_segment (void *handle, bend_segment_rr *rr); -static int bend_search (void *handle, bend_search_rr *r); -static int bend_fetch (void *handle, bend_fetch_rr *r); -static int bend_scan (void *handle, bend_scan_rr *r); - -bend_initresult *bend_init (bend_initrequest *q) -{ - bend_initresult *r = (bend_initresult *) - odr_malloc (q->stream, sizeof(*r)); - ZebraHandle zh; - struct statserv_options_block *sob; - char *user = NULL; - char *passwd = NULL; - - r->errcode = 0; - r->errstring = 0; - q->bend_sort = bend_sort; - q->bend_delete = bend_delete; - q->bend_esrequest = bend_esrequest; - q->bend_segment = bend_segment; - q->bend_search = bend_search; - q->bend_fetch = bend_fetch; - q->bend_scan = bend_scan; - - q->implementation_name = "Zebra Information Server"; - q->implementation_version = "Zebra " ZEBRAVER; - - yaz_log (YLOG_DEBUG, "bend_init"); - - sob = statserv_getcontrol (); - if (!(zh = zebra_open (sob->handle, 0))) - { - yaz_log (YLOG_WARN, "Failed to read config `%s'", sob->configname); - r->errcode = YAZ_BIB1_PERMANENT_SYSTEM_ERROR; - return r; - } - r->handle = zh; - if (q->auth) - { - if (q->auth->which == Z_IdAuthentication_open) - { - char *openpass = xstrdup (q->auth->u.open); - char *cp = strchr (openpass, '/'); - if (cp) - { - *cp = '\0'; - user = nmem_strdup (odr_getmem (q->stream), openpass); - passwd = nmem_strdup (odr_getmem (q->stream), cp+1); - } - xfree (openpass); - } - else if (q->auth->which == Z_IdAuthentication_idPass) - { - Z_IdPass *idPass = q->auth->u.idPass; - - user = idPass->userId; - passwd = idPass->password; - } - } - if (zebra_auth(zh, user, passwd) != ZEBRA_OK) - { - r->errcode = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD; - r->errstring = user; - return r; - } - if (q->charneg_request) /* characater set and langauge negotiation? */ - { - char **charsets = 0; - int num_charsets; - char **langs = 0; - int num_langs = 0; - int selected = 0; - int i; - NMEM nmem = nmem_create(); - - yaz_log (YLOG_LOG, "character set and language negotiation"); - - yaz_get_proposal_charneg (nmem, q->charneg_request, - &charsets, &num_charsets, - &langs, &num_langs, &selected); - - for (i = 0; i < num_charsets; i++) - { - const char *right_name = ""; - /* - * FIXME! It is like rudiment :-)) - * We have to support this short names of character sets, - * because a lot servers in Russia to use own in during - * character set and language negotiation still. - */ - - if (!yaz_matchstr(charsets[i], "win")) { - right_name = "WINDOWS-1251"; - } else if (!yaz_matchstr(charsets[i], "koi")) { - right_name = "KOI8-R"; - } else if (!yaz_matchstr(charsets[i], "iso")) { - right_name = "ISO-8859-5"; - } else if (!yaz_matchstr(charsets[i], "dos")) { - right_name = "CP866"; - } else if (!yaz_matchstr(charsets[i], "uni")) { - right_name = "UTF-8"; - } else { - right_name = charsets[i]; - } - if (odr_set_charset (q->decode, "UTF-8", right_name) == 0) - { - yaz_log (YLOG_LOG, "charset %d %s (proper name %s): OK", i, - charsets[i], right_name); - odr_set_charset (q->stream, right_name, "UTF-8"); - if (selected) - zebra_record_encoding(zh, right_name); - zebra_octet_term_encoding(zh, right_name); - q->charneg_response = - yaz_set_response_charneg (q->stream, charsets[i], - 0, selected); - break; - } else { - yaz_log (YLOG_LOG, "charset %d %s (proper name %s): unsupported", i, - charsets[i], right_name); - } - } - nmem_destroy(nmem); - } - return r; -} - -static void search_terms(ZebraHandle zh, bend_search_rr *r) -{ - int no_terms; - int i; - int type = Z_Term_general; - struct Z_External *ext; - Z_SearchInfoReport *sr; - - zebra_result_set_term_no(zh, r->setname, &no_terms); - if (!no_terms) - return; - - r->search_info = odr_malloc (r->stream, sizeof(*r->search_info)); - - r->search_info->num_elements = 1; - r->search_info->list = - odr_malloc (r->stream, sizeof(*r->search_info->list)); - r->search_info->list[0] = - odr_malloc (r->stream, sizeof(**r->search_info->list)); - r->search_info->list[0]->category = 0; - r->search_info->list[0]->which = Z_OtherInfo_externallyDefinedInfo; - ext = odr_malloc (r->stream, sizeof(*ext)); - r->search_info->list[0]->information.externallyDefinedInfo = ext; - ext->direct_reference = - yaz_oidval_to_z3950oid (r->stream, CLASS_USERINFO, VAL_SEARCHRES1); - ext->indirect_reference = 0; - ext->descriptor = 0; - ext->which = Z_External_searchResult1; - sr = odr_malloc (r->stream, sizeof(Z_SearchInfoReport)); - ext->u.searchResult1 = sr; - sr->num = no_terms; - sr->elements = odr_malloc (r->stream, sr->num * - sizeof(*sr->elements)); - for (i = 0; isetname, i, - &count, &approx, outbuf, &len, - &term_ref_id); - se = sr->elements[i] = odr_malloc (r->stream, sizeof(**sr->elements)); - se->subqueryId = term_ref_id ? - odr_strdup(r->stream, term_ref_id) : 0; - - se->fullQuery = odr_intdup(r->stream, 0); - se->subqueryExpression = - odr_malloc (r->stream, sizeof(Z_QueryExpression)); - se->subqueryExpression->which = - Z_QueryExpression_term; - se->subqueryExpression->u.term = - odr_malloc (r->stream, sizeof(Z_QueryExpressionTerm)); - term = odr_malloc (r->stream, sizeof(Z_Term)); - se->subqueryExpression->u.term->queryTerm = term; - switch (type) - { - case Z_Term_characterString: - term->which = Z_Term_characterString; - term->u.characterString = odr_strdup (r->stream, outbuf); - break; - case Z_Term_general: - term->which = Z_Term_general; - term->u.general = odr_malloc (r->stream, sizeof(*term->u.general)); - term->u.general->size = term->u.general->len = len; - term->u.general->buf = odr_malloc (r->stream, len); - memcpy (term->u.general->buf, outbuf, len); - break; - default: - term->which = Z_Term_general; - term->u.null = odr_nullval(); - } - se->subqueryExpression->u.term->termComment = 0; - se->subqueryInterpretation = 0; - se->subqueryRecommendation = 0; - if (count > 2147483646) - count = 2147483647; - se->subqueryCount = odr_intdup(r->stream, CAST_ZINT_TO_INT(count)); - se->subqueryWeight = 0; - se->resultsByDB = 0; - } -} - -int bend_search(void *handle, bend_search_rr *r) -{ - ZebraHandle zh = (ZebraHandle) handle; - zint zhits = 0; - ZEBRA_RES res; - - res = zebra_select_databases (zh, r->num_bases, - (const char **) r->basenames); - if (res != ZEBRA_OK) - { - zebra_result (zh, &r->errcode, &r->errstring); - return 0; - } - yaz_log (YLOG_DEBUG, "ResultSet '%s'", r->setname); - switch (r->query->which) - { - case Z_Query_type_1: case Z_Query_type_101: - res = zebra_search_RPN(zh, r->stream, r->query->u.type_1, - r->setname, &zhits); - if (res != ZEBRA_OK) - zebra_result(zh, &r->errcode, &r->errstring); - else - { - if (zhits > 2147483646) - zhits = 2147483647; - r->hits = CAST_ZINT_TO_INT(zhits); - search_terms (zh, r); - } - break; - case Z_Query_type_2: - r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP; - r->errstring = "type-2"; - break; - default: - r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP; - } - return 0; -} - - -int bend_fetch (void *handle, bend_fetch_rr *r) -{ - ZebraHandle zh = (ZebraHandle) handle; - ZebraRetrievalRecord retrievalRecord; - ZEBRA_RES res; - - retrievalRecord.position = r->number; - - r->last_in_set = 0; - res = zebra_records_retrieve (zh, r->stream, r->setname, r->comp, - r->request_format, 1, &retrievalRecord); - if (res != ZEBRA_OK) - { - /* non-surrogate diagnostic */ - zebra_result (zh, &r->errcode, &r->errstring); - } - else if (retrievalRecord.errCode) - { - /* surrogate diagnostic (diagnostic per record) */ - r->surrogate_flag = 1; - r->errcode = retrievalRecord.errCode; - r->errstring = retrievalRecord.errString; - r->basename = retrievalRecord.base; - } - else - { - r->basename = retrievalRecord.base; - r->record = retrievalRecord.buf; - r->len = retrievalRecord.len; - r->output_format = retrievalRecord.format; - } - return 0; -} - -static int bend_scan (void *handle, bend_scan_rr *r) -{ - ZebraScanEntry *entries; - ZebraHandle zh = (ZebraHandle) handle; - int is_partial, i; - ZEBRA_RES res; - - res = zebra_select_databases(zh, r->num_bases, - (const char **) r->basenames); - if (res != ZEBRA_OK) - { - zebra_result (zh, &r->errcode, &r->errstring); - return 0; - } - if (r->step_size != 0 && *r->step_size != 0) { - r->errcode = YAZ_BIB1_ONLY_ZERO_STEP_SIZE_SUPPORTED_FOR_SCAN; - r->errstring = 0; - return 0; - } - r->entries = (struct scan_entry *) - odr_malloc (r->stream, sizeof(*r->entries) * r->num_entries); - res = zebra_scan(zh, r->stream, r->term, - r->attributeset, - &r->term_position, - &r->num_entries, &entries, &is_partial, - 0 /* setname */); - if (res == ZEBRA_OK) - { - if (is_partial) - r->status = BEND_SCAN_PARTIAL; - else - r->status = BEND_SCAN_SUCCESS; - for (i = 0; i < r->num_entries; i++) - { - r->entries[i].term = entries[i].term; - r->entries[i].occurrences = - CAST_ZINT_TO_INT(entries[i].occurrences); - } - } - else - { - r->status = BEND_SCAN_PARTIAL; - zebra_result(zh, &r->errcode, &r->errstring); - } - return 0; -} - -void bend_close (void *handle) -{ - zebra_close ((ZebraHandle) handle); - xmalloc_trav("bend_close"); - nmem_print_list(); -} - -int bend_sort (void *handle, bend_sort_rr *rr) -{ - ZebraHandle zh = (ZebraHandle) handle; - - if (zebra_sort (zh, rr->stream, - rr->num_input_setnames, (const char **) rr->input_setnames, - rr->output_setname, rr->sort_sequence, &rr->sort_status) - != ZEBRA_OK) - zebra_result (zh, &rr->errcode, &rr->errstring); - return 0; -} - -int bend_delete (void *handle, bend_delete_rr *rr) -{ - ZebraHandle zh = (ZebraHandle) handle; - - rr->delete_status = zebra_deleteResultSet(zh, rr->function, - rr->num_setnames, rr->setnames, - rr->statuses); - return 0; -} - -static void es_admin_request (bend_esrequest_rr *rr, ZebraHandle zh, Z_AdminEsRequest *r) -{ - ZEBRA_RES res = ZEBRA_OK; - if (r->toKeep->databaseName) - { - yaz_log(YLOG_LOG, "adm request database %s", r->toKeep->databaseName); - } - switch (r->toKeep->which) - { - case Z_ESAdminOriginPartToKeep_reIndex: - yaz_log(YLOG_LOG, "adm-reindex"); - rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "adm-reindex not implemented yet"; - break; - case Z_ESAdminOriginPartToKeep_truncate: - rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "adm-reindex not implemented yet"; - yaz_log(YLOG_LOG, "adm-truncate"); - break; - case Z_ESAdminOriginPartToKeep_drop: - yaz_log(YLOG_LOG, "adm-drop"); - res = zebra_drop_database (zh, r->toKeep->databaseName); - break; - case Z_ESAdminOriginPartToKeep_create: - yaz_log(YLOG_LOG, "adm-create %s", r->toKeep->databaseName); - res = zebra_create_database (zh, r->toKeep->databaseName); - break; - case Z_ESAdminOriginPartToKeep_import: - yaz_log(YLOG_LOG, "adm-import"); - res = zebra_admin_import_begin (zh, r->toKeep->databaseName, - r->toKeep->u.import->recordType); - break; - case Z_ESAdminOriginPartToKeep_refresh: - yaz_log(YLOG_LOG, "adm-refresh"); - break; - case Z_ESAdminOriginPartToKeep_commit: - yaz_log(YLOG_LOG, "adm-commit"); - if (r->toKeep->databaseName) - { - if (zebra_select_database(zh, r->toKeep->databaseName) != - ZEBRA_OK) - yaz_log(YLOG_WARN, "zebra_select_database failed in " - "adm-commit"); - } - zebra_commit(zh); - break; - case Z_ESAdminOriginPartToKeep_shutdown: - yaz_log(YLOG_LOG, "shutdown"); - res = zebra_admin_shutdown(zh); - break; - case Z_ESAdminOriginPartToKeep_start: - yaz_log(YLOG_LOG, "start"); - zebra_admin_start(zh); - break; - default: - yaz_log(YLOG_LOG, "unknown admin"); - rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "adm-reindex not implemented yet"; - } - if (res != ZEBRA_OK) - zebra_result(zh, &rr->errcode, &rr->errstring); -} - -static void es_admin (bend_esrequest_rr *rr, ZebraHandle zh, Z_Admin *r) -{ - switch (r->which) - { - case Z_Admin_esRequest: - es_admin_request (rr, zh, r->u.esRequest); - return; - default: - break; - } - yaz_log (YLOG_WARN, "adm taskpackage (unhandled)"); - rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "adm-task package (unhandled)"; -} - -int bend_segment (void *handle, bend_segment_rr *rr) -{ - ZebraHandle zh = (ZebraHandle) handle; - Z_Segment *segment = rr->segment; - - if (segment->num_segmentRecords) - zebra_admin_import_segment (zh, rr->segment); - else - zebra_admin_import_end (zh); - return 0; -} - -int bend_esrequest (void *handle, bend_esrequest_rr *rr) -{ - ZebraHandle zh = (ZebraHandle) handle; - - yaz_log(YLOG_LOG, "function: %d", *rr->esr->function); - if (rr->esr->packageName) - yaz_log(YLOG_LOG, "packagename: %s", rr->esr->packageName); - yaz_log(YLOG_LOG, "Waitaction: %d", *rr->esr->waitAction); - - if (!rr->esr->taskSpecificParameters) - { - yaz_log (YLOG_WARN, "No task specific parameters"); - } - else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin) - { - es_admin(rr, zh, rr->esr->taskSpecificParameters->u.adminService); - } - else if (rr->esr->taskSpecificParameters->which == Z_External_update) - { - Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update; - yaz_log (YLOG_LOG, "Received DB Update"); - if (up->which == Z_IUUpdate_esRequest) - { - Z_IUUpdateEsRequest *esRequest = up->u.esRequest; - Z_IUOriginPartToKeep *toKeep = esRequest->toKeep; - Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep; - - yaz_log (YLOG_LOG, "action"); - if (toKeep->action) - { - switch (*toKeep->action) - { - case Z_IUOriginPartToKeep_recordInsert: - yaz_log (YLOG_LOG, "recordInsert"); - break; - case Z_IUOriginPartToKeep_recordReplace: - yaz_log (YLOG_LOG, "recordUpdate"); - break; - case Z_IUOriginPartToKeep_recordDelete: - yaz_log (YLOG_LOG, "recordDelete"); - break; - case Z_IUOriginPartToKeep_elementUpdate: - yaz_log (YLOG_LOG, "elementUpdate"); - break; - case Z_IUOriginPartToKeep_specialUpdate: - yaz_log (YLOG_LOG, "specialUpdate"); - break; - case Z_ESAdminOriginPartToKeep_shutdown: - yaz_log (YLOG_LOG, "shutDown"); - break; - case Z_ESAdminOriginPartToKeep_start: - yaz_log (YLOG_LOG, "start"); - break; - default: - yaz_log (YLOG_LOG, " unknown (%d)", *toKeep->action); - } - } - if (toKeep->databaseName) - { - yaz_log (YLOG_LOG, "database: %s", toKeep->databaseName); - - if (zebra_select_database(zh, toKeep->databaseName)) - return 0; - } - else - { - yaz_log (YLOG_WARN, "no database supplied for ES Update"); - rr->errcode = - YAZ_BIB1_ES_MISSING_MANDATORY_PARAMETER_FOR_SPECIFIED_FUNCTION_; - rr->errstring = "database"; - return 0; - } - if (zebra_begin_trans(zh, 1) != ZEBRA_OK) - { - zebra_result(zh, &rr->errcode, &rr->errstring); - } - else - { - int i; - for (i = 0; notToKeep && i < notToKeep->num; i++) - { - Z_External *rec = notToKeep->elements[i]->record; - struct oident *oident = 0; - Odr_oct *opaque_recid = 0; - SYSNO *sysno = 0; - SYSNO sysno_tmp; - - if (notToKeep->elements[i]->u.opaque) - { - switch(notToKeep->elements[i]->which) - { - case Z_IUSuppliedRecords_elem_opaque: - opaque_recid = notToKeep->elements[i]->u.opaque; - break; /* OK, recid already set */ - case Z_IUSuppliedRecords_elem_number: - sysno_tmp = *notToKeep->elements[i]->u.number; - sysno = &sysno_tmp; - break; - } - } - if (rec->direct_reference) - { - oident = oid_getentbyoid(rec->direct_reference); - if (oident) - yaz_log (YLOG_LOG, "record %d type %s", i, - oident->desc); - } - switch (rec->which) - { - case Z_External_sutrs: - if (rec->u.octet_aligned->len > 170) - yaz_log (YLOG_LOG, "%d bytes:\n%.168s ...", - rec->u.sutrs->len, - rec->u.sutrs->buf); - else - yaz_log (YLOG_LOG, "%d bytes:\n%s", - rec->u.sutrs->len, - rec->u.sutrs->buf); - break; - case Z_External_octet: - if (rec->u.octet_aligned->len > 170) - yaz_log (YLOG_LOG, "%d bytes:\n%.168s ...", - rec->u.octet_aligned->len, - rec->u.octet_aligned->buf); - else - yaz_log (YLOG_LOG, "%d bytes\n%s", - rec->u.octet_aligned->len, - rec->u.octet_aligned->buf); - } - if (oident && oident->value != VAL_TEXT_XML) - { - rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "only XML update supported"; - break; - } - if (rec->which == Z_External_octet) - { - int action = 0; - - if (*toKeep->action == - Z_IUOriginPartToKeep_recordInsert) - action = 1; - if (*toKeep->action == - Z_IUOriginPartToKeep_recordReplace) - action = 2; - if (*toKeep->action == - Z_IUOriginPartToKeep_recordDelete) - action = 3; - if (*toKeep->action == - Z_IUOriginPartToKeep_specialUpdate) - action = 4; - - if (!action) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "unsupported ES Update action"; - break; - } - else if (opaque_recid) - { - int r = zebra_admin_exchange_record ( - zh, - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - (const char *) opaque_recid->buf, - opaque_recid->len, - action); - if (r) - { - zebra_result(zh, &rr->errcode, - &rr->errstring); - break; - } - } - else - { - ZEBRA_RES r = ZEBRA_FAIL; - switch(action) { - case 1: - r = zebra_insert_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "insert_record failed"; - } - break; - case 2: - case 4: - r = zebra_update_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 1); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "update_record failed"; - } - break; - case 3: - r = zebra_delete_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "delete_record failed"; - } - break; - } - } - } - } - if (zebra_end_trans (zh) != ZEBRA_OK) - { - yaz_log(YLOG_WARN, "zebra_end_trans failed for" - " extended service operation"); - } - } - } - } - else - { - yaz_log (YLOG_WARN, "Unknown Extended Service(%d)", - rr->esr->taskSpecificParameters->which); - rr->errcode = YAZ_BIB1_ES_EXTENDED_SERVICE_TYPE_UNSUPP; - - } - return 0; -} - -static void bend_start (struct statserv_options_block *sob) -{ - if (sob->handle) - zebra_stop((ZebraService) sob->handle); - sob->handle = zebra_start(sob->configname); - if (!sob->handle) - { - yaz_log (YLOG_FATAL, "Failed to read config `%s'", sob->configname); - exit (1); - } -#ifdef WIN32 - -#else - if (!sob->inetd) - { - char pidfname[4096]; - struct flock area; - int fd; - - zebra_pidfname(sob->handle, pidfname); - - fd = open (pidfname, O_EXCL|O_WRONLY|O_CREAT, 0666); - if (fd == -1) - { - if (errno != EEXIST) - { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "lock file %s", pidfname); - exit(1); - } - fd = open(pidfname, O_RDWR, 0666); - if (fd == -1) - { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "lock file %s", pidfname); - exit(1); - } - } - area.l_type = F_WRLCK; - area.l_whence = SEEK_SET; - area.l_len = area.l_start = 0L; - if (fcntl (fd, F_SETLK, &area) == -1) - { - yaz_log(YLOG_ERRNO|YLOG_FATAL, "Zebra server already running"); - exit(1); - } - else - { - char pidstr[30]; - - sprintf (pidstr, "%ld", (long) getpid ()); - write (fd, pidstr, strlen(pidstr)); - } - } -#endif -} - -static void bend_stop(struct statserv_options_block *sob) -{ -#ifdef WIN32 - -#else - if (!sob->inetd && sob->handle) - { - char pidfname[4096]; - zebra_pidfname(sob->handle, pidfname); - unlink (pidfname); - } -#endif - if (sob->handle) - { - ZebraService service = sob->handle; - zebra_stop(service); - } -} - -int main (int argc, char **argv) -{ - struct statserv_options_block *sob; - - sob = statserv_getcontrol (); - strcpy (sob->configname, "zebra.cfg"); - sob->bend_start = bend_start; - sob->bend_stop = bend_stop; -#ifdef WIN32 - strcpy (sob->service_display_name, "Zebra Server"); -#endif - statserv_setcontrol (sob); - - return statserv_main (argc, argv, bend_init, bend_close); -} -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/index/zserver.h b/index/zserver.h deleted file mode 100644 index 6c76f3c..0000000 --- a/index/zserver.h +++ /dev/null @@ -1,39 +0,0 @@ -/* $Id: zserver.h,v 1.61 2006-08-14 10:40:15 adam Exp $ - Copyright (C) 1995-2006 - Index Data ApS - -This file is part of the Zebra server. - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - - - -#include -#include -#include - -YAZ_BEGIN_CDECL - -YAZ_END_CDECL -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/win/makefile b/win/makefile index b440142..a9205aa 100644 --- a/win/makefile +++ b/win/makefile @@ -1,5 +1,5 @@ # Zebra makefile for MS NMAKE -# $Id: makefile,v 1.56 2006-09-21 08:59:32 adam Exp $ +# $Id: makefile,v 1.57 2006-09-22 10:18:06 adam Exp $ ########################################################### ############### Parameters @@ -305,10 +305,10 @@ LINK_PROGRAM= $(LINK) \ # need to be specified, though ZSERVER_OBJS= \ - $(OBJDIR)\zserver.obj + $(OBJDIR)\zebrasrv.obj ZEBRAIDX_OBJS= \ - $(OBJDIR)\main.obj + $(OBJDIR)\zebraidx.obj TSTFLOCK_OBJS= \ $(OBJDIR)\tstflock.obj -- 1.7.10.4