/*
- * Copyright (C) 1995-2006, Index Data ApS
+ * Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
* NT threaded server code by
* Chas Woodfield, Fretwell Downing Informatics.
*
- * $Id: statserv.c,v 1.40 2006-07-07 13:02:21 marc Exp $
+ * $Id: statserv.c,v 1.47 2007-01-19 10:29:13 adam Exp $
*/
/**
/*
* default behavior.
*/
-#define STAT_DEFAULT_LOG_LEVEL "none,fatal,warn,log,server,session,request"
-/* the 'none' clears yaz' own default settings, including [log] */
+#define STAT_DEFAULT_LOG_LEVEL "server,session,request"
int check_options(int argc, char **argv);
statserv_options_block control_block = {
#endif
#if YAZ_HAVE_XML2
-static xmlNodePtr xml_config_get_root()
+static xmlNodePtr xml_config_get_root(void)
{
xmlNodePtr ptr = 0;
if (xml_config_doc)
}
#endif
-static struct gfs_server * gfs_server_new()
+static struct gfs_server * gfs_server_new(void)
{
struct gfs_server *n = nmem_malloc(gfs_nmem, sizeof(*n));
memcpy(&n->cb, &control_block, sizeof(control_block));
assoc->server = gfs;
assoc->last_control = &gfs->cb;
statserv_setcontrol(&gfs->cb);
+
gfs_server_chdir(gfs);
- yaz_log(YLOG_DEBUG, "server select: %s", gfs->cb.configname);
- return 1;
+ break;
}
}
- statserv_setcontrol(0);
- assoc->last_control = 0;
- yaz_log(YLOG_DEBUG, "server select: no match");
- return 0;
+ if (!gfs)
+ {
+ statserv_setcontrol(0);
+ assoc->last_control = 0;
+ return 0;
+ }
}
else
{
statserv_setcontrol(&control_block);
assoc->last_control = &control_block;
- yaz_log(YLOG_DEBUG, "server select: config=%s", control_block.configname);
- return 1;
}
+ yaz_log(YLOG_DEBUG, "server select: config=%s",
+ assoc->last_control->configname);
+
+ assoc->maximumRecordSize = assoc->last_control->maxrecordsize;
+ assoc->preferredMessageSize = assoc->last_control->maxrecordsize;
+ cs_set_max_recv_bytes(assoc->client_link, assoc->maximumRecordSize);
+ return 1;
}
-static void xml_config_read()
+static void xml_config_read(void)
{
struct gfs_server **gfsp = &gfs_server_list;
struct gfs_listen **gfslp = &gfs_listen_list;
xmlNodePtr ptr;
const char *listenref = 0;
const char *id = 0;
+ struct gfs_server *gfs;
for ( ; attr; attr = attr->next)
if (!xmlStrcmp(attr->name, BAD_CAST "listenref")
else
yaz_log(YLOG_WARN, "Unknown attribute '%s' for server",
attr->name);
- *gfsp = gfs_server_new();
- (*gfsp)->server_node_ptr = ptr_server;
+ gfs = *gfsp = gfs_server_new();
+ gfs->server_node_ptr = ptr_server;
if (listenref)
{
int id_no;
for (id_no = 1; gl; gl = gl->next, id_no++)
if (gl->id && !strcmp(gl->id, listenref))
{
- (*gfsp)->listen_ref = id_no;
+ gfs->listen_ref = id_no;
break;
}
if (!gl)
continue;
if (!strcmp((const char *) ptr->name, "host"))
{
- (*gfsp)->host = nmem_dup_xml_content(gfs_nmem,
+ gfs->host = nmem_dup_xml_content(gfs_nmem,
ptr->children);
}
else if (!strcmp((const char *) ptr->name, "config"))
{
- strcpy((*gfsp)->cb.configname,
+ strcpy(gfs->cb.configname,
nmem_dup_xml_content(gfs_nmem, ptr->children));
}
else if (!strcmp((const char *) ptr->name, "cql2rpn"))
{
- (*gfsp)->cql_transform = cql_transform_open_fname(
+ gfs->cql_transform = cql_transform_open_fname(
nmem_dup_xml_content(gfs_nmem, ptr->children)
);
}
else if (!strcmp((const char *) ptr->name, "directory"))
{
- (*gfsp)->directory =
+ gfs->directory =
nmem_dup_xml_content(gfs_nmem, ptr->children);
}
else if (!strcmp((const char *) ptr->name, "docpath"))
{
- (*gfsp)->docpath =
+ gfs->docpath =
nmem_dup_xml_content(gfs_nmem, ptr->children);
}
+ else if (!strcmp((const char *) ptr->name, "maximumrecordsize"))
+ {
+ gfs->cb.maxrecordsize = atoi(
+ nmem_dup_xml_content(gfs_nmem, ptr->children));
+ }
else if (!strcmp((const char *) ptr->name, "stylesheet"))
{
char *s = nmem_dup_xml_content(gfs_nmem, ptr->children);
- (*gfsp)->stylesheet =
+ gfs->stylesheet =
nmem_malloc(gfs_nmem, strlen(s) + 2);
- sprintf((*gfsp)->stylesheet, "/%s", s);
+ sprintf(gfs->stylesheet, "/%s", s);
}
else if (!strcmp((const char *) ptr->name, "explain"))
{
}
else if (!strcmp((const char *) ptr->name, "retrievalinfo"))
{
- if (yaz_retrieval_configure((*gfsp)->retrieval, ptr))
+ if (yaz_retrieval_configure(gfs->retrieval, ptr))
{
yaz_log(YLOG_FATAL, "%s in config %s",
- yaz_retrieval_get_error((*gfsp)->retrieval),
+ yaz_retrieval_get_error(gfs->retrieval),
control_block.xml_config);
exit(1);
}
*gfsp = 0;
}
-static void xml_config_open()
+static void xml_config_open(void)
{
if (!getcwd(gfs_root_dir, FILENAME_MAX))
{
#endif
}
-static void xml_config_close()
+static void xml_config_close(void)
{
#if YAZ_HAVE_XML2
if (xml_config_doc)
#endif
}
-static void xml_config_add_listeners()
+static void xml_config_add_listeners(void)
{
struct gfs_listen *gfs = gfs_listen_list;
int id_no;
}
}
-static void xml_config_bend_start()
+static void xml_config_bend_start(void)
{
if (control_block.xml_config[0])
{
}
}
-static void xml_config_bend_stop()
+static void xml_config_bend_stop(void)
{
if (control_block.xml_config[0])
{
if (event == EVENT_INPUT)
{
+ COMSTACK new_line;
+ IOCHAN new_chan;
+
if ((res = cs_listen(line, 0, 0)) < 0)
{
- yaz_log(YLOG_FATAL, "cs_listen failed");
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "cs_listen failed");
return;
}
else if (res == 1)
- return;
+ return; /* incomplete */
yaz_log(YLOG_DEBUG, "listen ok");
- iochan_setevent(h, EVENT_OUTPUT);
- iochan_setflags(h, EVENT_OUTPUT | EVENT_EXCEPT); /* set up for acpt */
- }
- else if (event == EVENT_OUTPUT)
- {
- COMSTACK new_line = cs_accept(line);
- IOCHAN new_chan;
- char *a = NULL;
-
- if (!new_line)
+ new_line = cs_accept(line);
+ if (!new_line)
{
yaz_log(YLOG_FATAL, "Accept failed.");
- iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT);
return;
}
yaz_log(YLOG_DEBUG, "Accept ok");
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;
}
int ret = 0, r;
char *arg;
- if (getenv("YAZ_LOG") == 0) {
- /*
- * Set default log level. We want to avoid doing this if the
- * user has already explicitly specified a preferred default
- * log-level, hence the inelegant peek at the YAZ_LOG
- * environment variable that will subsequently be interpreted
- * by the YAZ logging module itself.
- */
- yaz_log_init_level(yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL));
- }
-
+ yaz_log_init_level(yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL));
get_logbits(1);
- while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:",
+
+ while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:r:",
argv, argc, &arg)) != -2)
{
switch (ret)
}
yaz_log_time_format(arg);
break;
- case 'v': {
- int default_level = yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL);
- yaz_log_init_level(yaz_log_mask_str_x(arg, default_level));
+ case 'v':
+ yaz_log_init_level(yaz_log_mask_str(arg));
get_logbits(1);
break;
- }
case 'a':
option_copy(control_block.apdufile, arg);
break;
case 'D':
control_block.background = 1;
break;
+ case 'r':
+ if (!arg || !(r = atoi(arg)))
+ {
+ fprintf(stderr, "%s: Specify positive size for -r.\n", me);
+ return(1);
+ }
+ yaz_log_init_max_size(r * 1024);
+ break;
default:
fprintf(stderr, "Usage: %s [ -a <pdufile> -v <loglevel>"
" -l <logfile> -u <user> -c <config> -t <minutes>"