From 9ee952e04b4765c49f3b767813f8c8d5579ae005 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 23 May 2007 21:58:28 +0000 Subject: [PATCH] New pazpar2 option -X which puts pazpar2 in debug (insecure) mode. At this point (-X) only affects the session ID creation. --- src/http_command.c | 29 ++++++++++++++++++----------- src/logic.c | 5 +++-- src/parameters.h | 3 ++- src/pazpar2.c | 8 ++++++-- test/test_http.sh | 9 +++++++-- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index d0e68c9..dc98b6e 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.43 2007-05-23 09:57:54 adam Exp $ +/* $Id: http_command.c,v 1.44 2007-05-23 21:58:28 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ /* - * $Id: http_command.c,v 1.43 2007-05-23 09:57:54 adam Exp $ + * $Id: http_command.c,v 1.44 2007-05-23 21:58:28 adam Exp $ */ #include @@ -126,19 +126,26 @@ static void error(struct http_response *rs, unsigned int make_sessionid() { static int seq = 0; -#if 1 - return ++seq; -#else - struct timeval t; unsigned int res; seq++; - if (gettimeofday(&t, 0) < 0) - abort(); - res = t.tv_sec; - res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1); + if (global_parameters.debug_mode) + res = seq; + else + { + struct timeval t; + + if (gettimeofday(&t, 0) < 0) + { + yaz_log(YLOG_WARN|YLOG_ERRNO, "gettimeofday"); + exit(1); + } + /* at most 256 sessions per second .. + (long long would be more appropriate)*/ + res = t.tv_sec; + res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1); + } return res; -#endif } static struct http_session *locate_session(struct http_request *rq, struct http_response *rs) diff --git a/src/logic.c b/src/logic.c index 261febc..4ec42cf 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.31 2007-05-23 14:44:18 marc Exp $ +/* $Id: logic.c,v 1.32 2007-05-23 21:58:28 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -82,7 +82,8 @@ struct parameters global_parameters = "", "", 0, - 0, + 0, /* dump_records */ + 0, /* debug_mode */ 30, "81", "Index Data PazPar2", diff --git a/src/parameters.h b/src/parameters.h index ef4d54f..4b4ea71 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -1,4 +1,4 @@ -/* $Id: parameters.h,v 1.1 2007-04-23 21:05:23 adam Exp $ +/* $Id: parameters.h,v 1.2 2007-05-23 21:58:28 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -32,6 +32,7 @@ struct parameters { char settings_path_override[128]; struct conf_server *server; int dump_records; + int debug_mode; int timeout; /* operations timeout, in seconds */ char implementationId[128]; char implementationName[128]; diff --git a/src/pazpar2.c b/src/pazpar2.c index 7895117..117464c 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.84 2007-05-15 21:27:55 adam Exp $ +/* $Id: pazpar2.c,v 1.85 2007-05-23 21:58:28 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -41,7 +41,7 @@ int main(int argc, char **argv) yaz_log_init_prefix("pazpar2"); - while ((ret = options("f:h:p:z:t:l:d", argv, argc, &arg)) != -2) + while ((ret = options("f:h:p:z:t:l:dX", argv, argc, &arg)) != -2) { switch (ret) { @@ -67,6 +67,9 @@ int main(int argc, char **argv) case 'l': yaz_log_init_file(arg); break; + case 'X': + global_parameters.debug_mode = 1; + break; default: fprintf(stderr, "Usage: pazpar2\n" " -f configfile\n" @@ -76,6 +79,7 @@ int main(int argc, char **argv) " -t settings\n" " -d (show internal records)\n" " -l file log to file\n" + " -X debug mode\n" ); exit(1); } diff --git a/test/test_http.sh b/test/test_http.sh index 7d052ce..5e70836 100755 --- a/test/test_http.sh +++ b/test/test_http.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: test_http.sh,v 1.6 2007-05-16 13:07:18 adam Exp $ +# $Id: test_http.sh,v 1.7 2007-05-23 21:58:29 adam Exp $ # # Regression test using pazpar2 against z3950.indexdata.com/marc # Reads Pazpar2 URLs from test_http_urls @@ -22,7 +22,7 @@ fi # Fire up pazpar2 rm -f pazpar2.log -../src/pazpar2 -l pazpar2.log -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 & +../src/pazpar2 -X -l pazpar2.log -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 & PP2PID=$! # Give it a chance to start properly.. @@ -75,6 +75,11 @@ for f in `cat ${srcdir}/test_http_urls`; do else sleep $f fi + if ps -p $PP2PID >/dev/null 2>&1; then + : + else + echo "pazpar2 died" + fi done IFS="$oIFS" -- 1.7.10.4