X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fstatserv.c;h=c5c416a87e94e5485a2eefe7fa7304e4b0822af6;hp=4a8bad6769c89be7d2caf542b618005a5e92fb04;hb=e255616521c8ba665309bcaeccabb35b6efe35d7;hpb=ba1eb985bfd53a8cfbfd251e65688921dba56236 diff --git a/src/statserv.c b/src/statserv.c index 4a8bad6..c5c416a 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1,11 +1,6 @@ -/* - * Copyright (C) 1995-2006, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2008 Index Data * See the file LICENSE for details. - * - * NT threaded server code by - * Chas Woodfield, Fretwell Downing Informatics. - * - * $Id: statserv.c,v 1.45 2006-10-09 11:21:37 adam Exp $ */ /** @@ -17,12 +12,15 @@ #include #include #include + #ifdef WIN32 #include #include #include -#include "service.h" #endif + +#include + #if HAVE_SYS_TYPES_H #include #endif @@ -92,7 +90,6 @@ statserv_options_block control_block = { 1, /* dynamic mode */ 0, /* threaded mode */ 0, /* one shot (single session) */ - 0, /* __UNUSED_loglevel */ "", /* no PDUs */ "", /* diagnostic output to stderr */ "tcp:@:9999", /* default listener port */ @@ -184,7 +181,7 @@ static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr) len += xmlStrlen(p->content); } /* now allocate for the string */ - str = nmem_malloc(n, len); + str = (unsigned char *) nmem_malloc(n, len); *str = '\0'; /* so we can use strcat */ for (p = ptr; p; p = p->next) { @@ -213,12 +210,14 @@ static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr) static struct gfs_server * gfs_server_new(void) { - struct gfs_server *n = nmem_malloc(gfs_nmem, sizeof(*n)); + struct gfs_server *n = (struct gfs_server *) + nmem_malloc(gfs_nmem, sizeof(*n)); memcpy(&n->cb, &control_block, sizeof(control_block)); n->next = 0; n->host = 0; n->listen_ref = 0; n->cql_transform = 0; + n->ccl_transform = 0; n->server_node_ptr = 0; n->directory = 0; n->docpath = 0; @@ -232,7 +231,8 @@ static struct gfs_server * gfs_server_new(void) static struct gfs_listen * gfs_listen_new(const char *id, const char *address) { - struct gfs_listen *n = nmem_malloc(gfs_nmem, sizeof(*n)); + struct gfs_listen *n = (struct gfs_listen *) + nmem_malloc(gfs_nmem, sizeof(*n)); if (id) n->id = nmem_strdup(gfs_nmem, id); else @@ -402,7 +402,7 @@ static void xml_config_read(void) if (!strcmp((const char *) ptr->name, "host")) { gfs->host = nmem_dup_xml_content(gfs_nmem, - ptr->children); + ptr->children); } else if (!strcmp((const char *) ptr->name, "config")) { @@ -415,6 +415,20 @@ static void xml_config_read(void) nmem_dup_xml_content(gfs_nmem, ptr->children) ); } + else if (!strcmp((const char *) ptr->name, "ccl2rpn")) + { + char *name; + FILE *f; + + name = nmem_dup_xml_content(gfs_nmem, ptr->children); + if ((f = fopen(name, "r")) == 0) { + yaz_log(YLOG_FATAL, "can't open CCL file '%s'", name); + exit(1); + } + gfs->ccl_transform = ccl_qual_mk(); + ccl_qual_file (gfs->ccl_transform, f); + fclose(f); + } else if (!strcmp((const char *) ptr->name, "directory")) { gfs->directory = @@ -433,7 +447,7 @@ static void xml_config_read(void) else if (!strcmp((const char *) ptr->name, "stylesheet")) { char *s = nmem_dup_xml_content(gfs_nmem, ptr->children); - gfs->stylesheet = + gfs->stylesheet = (char *) nmem_malloc(gfs_nmem, strlen(s) + 2); sprintf(gfs->stylesheet, "/%s", s); } @@ -615,7 +629,7 @@ static void ThreadList_Initialize() /* Initialize the critical Sections */ InitializeCriticalSection(&Thread_CritSect); - /* Set the first thraed */ + /* Set the first thraed */ pFirstThread = NULL; /* we have been initialized */ @@ -683,7 +697,7 @@ void statserv_remove(IOCHAN pIOChannel) } /* WIN32 statserv_closedown */ -void statserv_closedown() +static void statserv_closedown() { /* Shouldn't do anything if we are not initialized */ if (bInitialized) @@ -755,7 +769,7 @@ void statserv_closedown() void __cdecl event_loop_thread (IOCHAN iochan) { - event_loop (&iochan); + iochan_event_loop (&iochan); } /* WIN32 listener */ @@ -856,7 +870,7 @@ void statserv_remove(IOCHAN pIOChannel) { } -void statserv_closedown() +static void statserv_closedown(void) { IOCHAN p; @@ -982,7 +996,7 @@ static void *new_session (void *vp) association *newas; IOCHAN new_chan; COMSTACK new_line = (COMSTACK) vp; - IOCHAN parent_chan = new_line->user; + IOCHAN parent_chan = (IOCHAN) new_line->user; unsigned cs_get_mask, cs_accept_mask, mask = ((new_line->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) | @@ -1027,7 +1041,7 @@ static void *new_session (void *vp) control_block.one_shot = 1; if (control_block.threads) { - event_loop(&new_chan); + iochan_event_loop(&new_chan); } else { @@ -1111,12 +1125,16 @@ static int add_listener(char *where, int listen_id) if (cs_bind(l, ap, CS_SERVER) < 0) { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to bind to %s", where); + if (cs_errno(l) == CSYSERR) + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to bind to %s", where); + else + yaz_log(YLOG_FATAL, "Failed to bind to %s: %s", where, + cs_strerror(l)); cs_close (l); return -1; } if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT | - EVENT_EXCEPT, listen_id))) + EVENT_EXCEPT, listen_id))) { yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to create IOCHAN-type"); cs_close (l); @@ -1150,7 +1168,8 @@ statserv_options_block *statserv_getcontrol(void) return &control_block; #elif YAZ_POSIX_THREADS if (init_control_tls) - return pthread_getspecific(current_control_tls); + return (statserv_options_block *) + pthread_getspecific(current_control_tls); else return &control_block; #else @@ -1178,7 +1197,7 @@ static void statserv_reset(void) { } -int statserv_start(int argc, char **argv) +static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) { char sep; #ifdef WIN32 @@ -1321,8 +1340,10 @@ int statserv_start(int argc, char **argv) #endif if (pListener == NULL) return 1; + if (s) + yaz_sc_running(s); yaz_log(YLOG_DEBUG, "Entering event loop."); - return event_loop(&pListener); + return iochan_event_loop(&pListener); } static void option_copy(char *dst, const char *src) @@ -1337,6 +1358,8 @@ int check_options(int argc, char **argv) char *arg; yaz_log_init_level(yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL)); + + yaz_log_xml_errors(0, YLOG_WARN); get_logbits(1); while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:r:", @@ -1459,86 +1482,43 @@ int check_options(int argc, char **argv) fprintf(stderr, "Usage: %s [ -a -v " " -l -u -c -t " " -k -d -p -C certfile" - " -ziDST1 -m -w ... ]\n", me); + " -ziDST1 -m -w ... ]\n", me); return 1; } } return 0; } -#ifdef WIN32 -typedef struct _Args -{ - char **argv; - int argc; -} Args; - -static Args ArgDetails; - -/* name of the executable */ -#define SZAPPNAME "server" - -/* list of service dependencies - "dep1\0dep2\0\0" */ -#define SZDEPENDENCIES "" - -int statserv_main(int argc, char **argv, - bend_initresult *(*bend_init)(bend_initrequest *r), - void (*bend_close)(void *handle)) +void statserv_sc_stop(yaz_sc_t s) { - struct statserv_options_block *cb = &control_block; - cb->bend_init = bend_init; - cb->bend_close = bend_close; - - /* Lets setup the Arg structure */ - ArgDetails.argc = argc; - ArgDetails.argv = argv; - - /* Now setup the service with the service controller */ - SetupService(argc, argv, &ArgDetails, SZAPPNAME, - cb->service_name, /* internal service name */ - cb->service_display_name, /* displayed name */ - SZDEPENDENCIES); - return 0; -} - -int StartAppService(void *pHandle, int argc, char **argv) -{ - /* Initializes the App */ - return 1; -} - -void RunAppService(void *pHandle) -{ - Args *pArgs = (Args *)pHandle; - - /* Starts the app running */ - statserv_start(pArgs->argc, pArgs->argv); -} - -void StopAppService(void *pHandle) -{ - /* Stops the app */ statserv_closedown(); statserv_reset(); } -/* WIN32 */ -#else -/* UNIX */ + int statserv_main(int argc, char **argv, bend_initresult *(*bend_init)(bend_initrequest *r), void (*bend_close)(void *handle)) { int ret; + struct statserv_options_block *cb = &control_block; + + /* control block does not have service_name member on Unix */ + yaz_sc_t s = yaz_sc_create( +#ifdef WIN32 + cb->service_name, cb->service_display_name +#else + 0, 0 +#endif + ); - control_block.bend_init = bend_init; - control_block.bend_close = bend_close; + cb->bend_init = bend_init; + cb->bend_close = bend_close; - ret = statserv_start (argc, argv); - statserv_closedown (); - statserv_reset(); + ret = yaz_sc_program(s, argc, argv, statserv_sc_main, statserv_sc_stop); + yaz_sc_destroy(&s); return ret; } -#endif + /* * Local variables: * c-basic-offset: 4