* Sebastian Hammer, Adam Dickmeiss
*
* $Log: bfile.c,v $
- * Revision 1.31 1999-12-08 15:03:11 adam
+ * Revision 1.32 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.31 1999/12/08 15:03:11 adam
* Implemented bf_reset.
*
* Revision 1.30 1999/10/14 14:33:49 adam
int bf_close (BFile bf)
{
+ zebra_lock_rdwr_destroy (&bf->rdwr_lock);
if (bf->cf)
cf_close (bf->cf);
mf_close (bf->mf);
xfree (tmp);
return 0;
}
+ zebra_lock_rdwr_init (&tmp->rdwr_lock);
return(tmp);
}
{
int r;
- if (bf->cf && (r=cf_read (bf->cf, no, offset, nbytes, buf)) != -1)
- return r;
- return mf_read (bf->mf, no, offset, nbytes, buf);
+ zebra_lock_rdwr_rlock (&bf->rdwr_lock);
+ if (bf->cf)
+ {
+ if ((r = cf_read (bf->cf, no, offset, nbytes, buf)) == -1)
+ r = mf_read (bf->mf, no, offset, nbytes, buf);
+ }
+ else
+ r = mf_read (bf->mf, no, offset, nbytes, buf);
+ zebra_lock_rdwr_runlock (&bf->rdwr_lock);
+ return r;
}
int bf_write (BFile bf, int no, int offset, int nbytes, const void *buf)
{
+ int r;
+ zebra_lock_rdwr_wlock (&bf->rdwr_lock);
if (bf->cf)
- return cf_write (bf->cf, no, offset, nbytes, buf);
- return mf_write (bf->mf, no, offset, nbytes, buf);
+ r = cf_write (bf->cf, no, offset, nbytes, buf);
+ else
+ r = mf_write (bf->mf, no, offset, nbytes, buf);
+ zebra_lock_rdwr_wunlock (&bf->rdwr_lock);
+ return r;
}
int bf_commitExists (BFiles bfs)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: mfile.c,v $
- * Revision 1.36 1999-12-08 15:03:11 adam
+ * Revision 1.37 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.36 1999/12/08 15:03:11 adam
* Implemented bf_reset.
*
* Revision 1.35 1999/10/14 14:33:50 adam
#include <assert.h>
#include <errno.h>
+#include <zebra-lock.h>
#include <zebrautl.h>
#include <mfile.h>
for (;;)
{
const char *ad0 = ad;
- int i = 0, fact = 1, multi, size = 0;
+ int i = 0, fact = 1, multi;
+ off_t size = 0;
while (*ad == ' ' || *ad == '\t')
ad++;
size = size*10 + (*ad++ - '0');
switch (*ad)
{
- case 'B': case 'b': multi = 1; break;
- case 'K': case 'k': multi = 1024; break;
- case 'M': case 'm': multi = 1048576; break;
+ case 'B': case 'b': multi = 1; break;
+ case 'K': case 'k': multi = 1024; break;
+ case 'M': case 'm': multi = 1048576; break;
+ case 'G': case 'g': multi = 1073741824; break;
case '\0':
logf (LOG_FATAL, "Missing unit: %s", ad0);
return -1;
{
xfree (m->files[i].path);
}
+ zebra_mutex_destroy (&meta_f->mutex);
meta_f = meta_f->next;
xfree (m);
}
mnew = (meta_file *) xmalloc(sizeof(*mnew));
strcpy(mnew->name, name);
/* allocate one, empty file */
+ zebra_mutex_init (&mnew->mutex);
mnew->no_files = 1;
- mnew->files[0].bytes = mnew->files[0].blocks = 0;
+ mnew->files[0].bytes = 0;
+ mnew->files[0].blocks = 0;
mnew->files[0].top = -1;
mnew->files[0].number = 0;
mnew->files[0].fd = -1;
{
int rd, toread;
+ zebra_mutex_lock (&mf->mutex);
if ((rd = file_position(mf, no, offset)) < 0)
{
if (rd == -2)
mf->files[mf->cur_file].path);
exit(1);
}
- else if (rd < toread)
+ zebra_mutex_unlock (&mf->mutex);
+ if (rd < toread)
return 0;
else
return 1;
char tmp[FILENAME_MAX+1];
unsigned char dummych = '\xff';
+ zebra_mutex_lock (&mf->mutex);
if ((ps = file_position(mf, no, offset)) < 0)
exit(1);
/* file needs to grow */
mf->name, mf->cur_file);
exit(1);
}
+ zebra_mutex_unlock (&mf->mutex);
return 0;
}
ac_help="$ac_help
--with-yazconfig=DIR yaz-config in DIR (example /home/yaz-1.5)"
ac_help="$ac_help
+ --disable-threads disable threads"
+ac_help="$ac_help
--with-tclconfig=DIR tclConfig.sh in DIR"
# Initialize some variables set by options.
# Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:543: checking for $ac_word" >&5
+echo "configure:545: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:573: checking for $ac_word" >&5
+echo "configure:575: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "cl", so it can be a program name with args.
set dummy cl; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:624: checking for $ac_word" >&5
+echo "configure:626: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:656: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:658: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
ac_ext=c
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
cat > conftest.$ac_ext << EOF
-#line 667 "configure"
+#line 669 "configure"
#include "confdefs.h"
main(){return(0);}
EOF
-if { (eval echo configure:672: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:674: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
ac_cv_prog_cc_works=yes
# If we can't run a trivial program, we are probably using a cross compiler.
if (./conftest; exit) 2>/dev/null; then
{ echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:698: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:700: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
cross_compiling=$ac_cv_prog_cc_cross
echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:703: checking whether we are using GNU C" >&5
+echo "configure:705: checking whether we are using GNU C" >&5
if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
yes;
#endif
EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:712: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:714: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
ac_cv_prog_gcc=yes
else
ac_cv_prog_gcc=no
ac_save_CFLAGS="$CFLAGS"
CFLAGS=
echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:731: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:733: checking whether ${CC-cc} accepts -g" >&5
if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
fi
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:763: checking how to run the C preprocessor" >&5
+echo "configure:765: checking how to run the C preprocessor" >&5
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
CPP=
# On the NeXT, cc -E runs the code through the compiler's parser,
# not just through cpp.
cat > conftest.$ac_ext <<EOF
-#line 778 "configure"
+#line 780 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:784: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:786: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
rm -rf conftest*
CPP="${CC-cc} -E -traditional-cpp"
cat > conftest.$ac_ext <<EOF
-#line 795 "configure"
+#line 797 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:801: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:803: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
rm -rf conftest*
CPP="${CC-cc} -nologo -E"
cat > conftest.$ac_ext <<EOF
-#line 812 "configure"
+#line 814 "configure"
#include "confdefs.h"
#include <assert.h>
Syntax Error
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:818: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:820: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
:
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# ./install, which can be erroneously created by make from ./install.sh.
echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:873: checking for a BSD compatible install" >&5
+echo "configure:875: checking for a BSD compatible install" >&5
if test -z "$INSTALL"; then
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
# Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:928: checking for $ac_word" >&5
+echo "configure:930: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "yaz-config", so it can be a program name with args.
set dummy yaz-config; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:992: checking for $ac_word" >&5
+echo "configure:994: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_yazconfig'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
fi
fi
echo $ac_n "checking for YAZ""... $ac_c" 1>&6
-echo "configure:1028: checking for YAZ" >&5
+echo "configure:1030: checking for YAZ" >&5
if test -r $yazconfig; then
. $yazconfig
echo "$ac_t""$yazconfig" 1>&6
else
echo "$ac_t""Not found" 1>&6
fi
+# Check whether --enable-threads or --disable-threads was given.
+if test "${enable_threads+set}" = set; then
+ enableval="$enable_threads"
+ enable_threads=$enableval
+else
+ enable_threads=yes
+fi
+
+if test "$enable_threads" = "yes"; then
+ echo $ac_n "checking for main in -lpthread""... $ac_c" 1>&6
+echo "configure:1047: checking for main in -lpthread" >&5
+ac_lib_var=`echo pthread'_'main | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ ac_save_LIBS="$LIBS"
+LIBS="-lpthread $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1055 "configure"
+#include "confdefs.h"
+
+int main() {
+main()
+; return 0; }
+EOF
+if { (eval echo configure:1062: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ rm -rf conftest*
+ eval "ac_cv_lib_$ac_lib_var=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_lib=HAVE_LIB`echo pthread | sed -e 's/[^a-zA-Z0-9_]/_/g' \
+ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_lib 1
+EOF
+
+ LIBS="-lpthread $LIBS"
+
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+ echo $ac_n "checking for working POSIX Threads""... $ac_c" 1>&6
+echo "configure:1090: checking for working POSIX Threads" >&5
+ cat > conftest.$ac_ext <<EOF
+#line 1092 "configure"
+#include "confdefs.h"
+#include <pthread.h>
+ int func(void *p) { return 0; }
+
+int main() {
+
+ pthread_t pthread_id;
+ int r = pthread_create (&pthread_id, 0, func, 0);
+; return 0; }
+EOF
+if { (eval echo configure:1103: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ rm -rf conftest*
+ thread_ok=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ thread_ok=no
+fi
+rm -f conftest*
+ if test "$thread_ok" = "yes"; then
+ echo "$ac_t""yes" 1>&6
+ cat >> confdefs.h <<\EOF
+#define HAVE_PTHREAD_H 1
+EOF
+
+ cat >> confdefs.h <<\EOF
+#define _REENTRANT 1
+EOF
+
+ else
+ echo "$ac_t""no" 1>&6
+ fi
+fi
TCL_LIB=""
TCL_INCLUDE=""
tclconfig=NONE
# Extract the first word of "tclsh", so it can be a program name with args.
set dummy tclsh; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1051: checking for $ac_word" >&5
+echo "configure:1143: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_TCLSH'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
prefix=${saveprefix}
fi
echo $ac_n "checking for Tcl""... $ac_c" 1>&6
-echo "configure:1092: checking for Tcl" >&5
+echo "configure:1184: checking for Tcl" >&5
if test -r ${tclconfig}/tclConfig.sh; then
. ${tclconfig}/tclConfig.sh
if test -r ${tclconfig}/../generic/tcl.h; then
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1116: checking for $ac_hdr" >&5
+echo "configure:1208: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1121 "configure"
+#line 1213 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1126: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1218: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
done
echo $ac_n "checking for bzCompressInit in -lbz2""... $ac_c" 1>&6
-echo "configure:1153: checking for bzCompressInit in -lbz2" >&5
+echo "configure:1245: checking for bzCompressInit in -lbz2" >&5
ac_lib_var=`echo bz2'_'bzCompressInit | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lbz2 $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 1161 "configure"
+#line 1253 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
bzCompressInit()
; return 0; }
EOF
-if { (eval echo configure:1172: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1264: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1204: checking for $ac_hdr" >&5
+echo "configure:1296: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1209 "configure"
+#line 1301 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1214: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1306: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
fi
echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:1242: checking for ANSI C header files" >&5
+echo "configure:1334: checking for ANSI C header files" >&5
if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1247 "configure"
+#line 1339 "configure"
#include "confdefs.h"
#include <stdlib.h>
#include <stdarg.h>
#include <float.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1255: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1347: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
if test $ac_cv_header_stdc = yes; then
# SunOS 4.x string.h does not declare mem*, contrary to ANSI.
cat > conftest.$ac_ext <<EOF
-#line 1272 "configure"
+#line 1364 "configure"
#include "confdefs.h"
#include <string.h>
EOF
if test $ac_cv_header_stdc = yes; then
# ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
cat > conftest.$ac_ext <<EOF
-#line 1290 "configure"
+#line 1382 "configure"
#include "confdefs.h"
#include <stdlib.h>
EOF
:
else
cat > conftest.$ac_ext <<EOF
-#line 1311 "configure"
+#line 1403 "configure"
#include "confdefs.h"
#include <ctype.h>
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
exit (0); }
EOF
-if { (eval echo configure:1322: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1414: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
:
else
dnl Zebra, Index Data Aps, 1994-1999
-dnl $Id: configure.in,v 1.16 2000-03-01 10:02:04 adam Exp $
+dnl $Id: configure.in,v 1.17 2000-03-15 15:00:30 adam Exp $
dnl See the file LICENSE.2 for details.
dnl
AC_INIT(include/zebraver.h)
AC_MSG_RESULT(Not found)
fi
dnl
+dnl ------ Threads
+AC_ARG_ENABLE(threads, [ --disable-threads disable threads],[enable_threads=$enableval],[enable_threads=yes])
+if test "$enable_threads" = "yes"; then
+ AC_CHECK_LIB(pthread,main)
+ AC_MSG_CHECKING(for working POSIX Threads)
+ AC_TRY_LINK([#include <pthread.h>
+ int func(void *p) { return 0; }
+ ],[
+ pthread_t pthread_id;
+ int r = pthread_create (&pthread_id, 0, func, 0);],
+ thread_ok=yes,thread_ok=no)
+ if test "$thread_ok" = "yes"; then
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_PTHREAD_H)
+ AC_DEFINE(_REENTRANT)
+ else
+ AC_MSG_RESULT(no)
+ fi
+fi
+dnl
dnl ------ Look for Tcl
dnl See if user has specified location of tclConfig.sh; otherwise
dnl see if tclConfig.sh exists in same prefix lcoation as tclsh; otherwise
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: bfile.h,v 1.18 1999-12-08 15:03:11 adam Exp $
+ * $Id: bfile.h,v 1.19 2000-03-15 15:00:30 adam Exp $
*/
#ifndef BFILE_H
typedef struct BFile_struct
{
MFile mf;
+ Zebra_lock_rdwr rdwr_lock;
struct CFile_struct *cf;
} *BFile, BFile_struct;
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: mfile.h,v 1.12 1999-12-08 15:03:11 adam Exp $
+ * $Id: mfile.h,v 1.13 2000-03-15 15:00:30 adam Exp $
*/
#ifndef MFILE_H
#define MFILE_H
#include <stdio.h>
+#include <yaz/yconfig.h>
#ifndef FILENAME_MAX
#include <sys/param.h>
#define FILENAME_MAX MAXPATHLEN
#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <zebra-lock.h>
+
+YAZ_BEGIN_CDECL
#define MF_MIN_BLOCKS_CREAT 1 /* minimum free blocks in new dir */
#define MF_MAX_PARTS 28 /* max # of part-files per metafile */
typedef struct mf_dir
{
char name[FILENAME_MAX+1];
- int max_bytes; /* allocated bytes in this dir. */
- int avail_bytes; /* bytes left */
+ off_t max_bytes; /* allocated bytes in this dir. */
+ off_t avail_bytes; /* bytes left */
struct mf_dir *next;
} mf_dir;
int number;
int top;
int blocks;
- int bytes;
+ off_t bytes;
mf_dir *dir;
char *path;
int fd;
int min_bytes_creat; /* minimum bytes required to enter directory */
MFile_area ma;
int wr;
+ Zebra_mutex mutex;
struct meta_file *next;
} *MFile, meta_file;
mf_dir *dirs;
struct meta_file *mfiles;
struct MFile_area_struct *next; /* global list of active areas */
+ Zebra_mutex mutex;
} MFile_area_struct;
/*
* Unlink the file by name, rather than MFile-handle.
*/
int mf_unlink_name(MFile_area, const char *name);
-#ifdef __cplusplus
-}
-#endif
+
+YAZ_END_CDECL
#endif
--- /dev/null
+
+#ifndef ZEBRA_LOCK_H
+#define ZEBRA_LOCK_H
+
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
+#include <yaz/yconfig.h>
+
+YAZ_BEGIN_CDECL
+
+typedef struct {
+ pthread_mutex_t mutex;
+} Zebra_mutex;
+
+YAZ_EXPORT int zebra_mutex_init (Zebra_mutex *p);
+YAZ_EXPORT int zebra_mutex_destroy (Zebra_mutex *p);
+YAZ_EXPORT int zebra_mutex_lock (Zebra_mutex *p);
+YAZ_EXPORT int zebra_mutex_unlock (Zebra_mutex *p);
+
+typedef struct {
+ int readers_reading;
+ int writers_writing;
+ pthread_mutex_t mutex;
+ pthread_cond_t lock_free;
+} Zebra_lock_rdwr;
+
+YAZ_EXPORT int zebra_lock_rdwr_init (Zebra_lock_rdwr *p);
+YAZ_EXPORT int zebra_lock_rdwr_destroy (Zebra_lock_rdwr *p);
+YAZ_EXPORT int zebra_lock_rdwr_rlock (Zebra_lock_rdwr *p);
+YAZ_EXPORT int zebra_lock_rdwr_wlock (Zebra_lock_rdwr *p);
+YAZ_EXPORT int zebra_lock_rdwr_runlock (Zebra_lock_rdwr *p);
+YAZ_EXPORT int zebra_lock_rdwr_wunlock (Zebra_lock_rdwr *p);
+
+YAZ_END_CDECL
+#endif
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: attribute.c,v $
- * Revision 1.11 1999-11-30 13:48:03 adam
+ * Revision 1.12 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.11 1999/11/30 13:48:03 adam
* Improved installation. Updated for inclusion of YAZ header files.
*
* Revision 1.10 1999/02/02 14:50:49 adam
data1_att *r;
data1_attset *p;
- if (!(p = data1_attset_search_id (zi->dh, set)))
+ if (!(p = data1_attset_search_id (zi->service->dh, set)))
{
- zebraExplain_loadAttsets (zi->dh, zi->res);
- p = data1_attset_search_id (zi->dh, set);
+ zebraExplain_loadAttsets (zi->service->dh, zi->service->res);
+ p = data1_attset_search_id (zi->service->dh, set);
}
if (!p)
return -2;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: locksrv.c,v $
- * Revision 1.13 1999-05-26 07:49:13 adam
+ * Revision 1.14 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.13 1999/05/26 07:49:13 adam
* C++ compilation.
*
* Revision 1.12 1999/02/02 14:50:58 adam
#include "zserver.h"
-int zebra_server_lock_init (ZebraHandle zi)
+int zebra_server_lock_init (ZebraService zi)
{
char path_prefix[1024];
return 0;
}
-int zebra_server_lock_destroy (ZebraHandle zi)
+int zebra_server_lock_destroy (ZebraService zi)
{
xfree (zi->server_path_prefix);
zebra_lock_destroy (zi->server_lock_cmt);
return 0;
}
-int zebra_server_lock (ZebraHandle zi, int commitPhase)
+int zebra_server_lock (ZebraService zi, int commitPhase)
{
if (!zi->server_lock_cmt)
{
return 0;
}
-void zebra_server_unlock (ZebraHandle zi, int commitPhase)
+void zebra_server_unlock (ZebraService zi, int commitPhase)
{
if (zi->server_lock_org == NULL)
return;
}
}
-int zebra_server_lock_get_state (ZebraHandle zi, time_t *timep)
+int zebra_server_lock_get_state (ZebraService zi, time_t *timep)
{
char path[1024];
char buf[256];
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rank1.c,v $
- * Revision 1.5 1999-05-26 07:49:13 adam
+ * Revision 1.6 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.5 1999/05/26 07:49:13 adam
* C++ compilation.
*
* Revision 1.4 1999/02/02 14:51:01 adam
* create: Creates/Initialises this rank handler. This routine is
* called exactly once. The routine returns the class_handle.
*/
-static void *create (ZebraHandle zh)
+static void *create (ZebraService zh)
{
struct rank_class_info *ci = (struct rank_class_info *)
xmalloc (sizeof(*ci));
* when the handler is no longer needed - i.e. when the server
* dies. The class_handle was previously returned by create.
*/
-static void destroy (ZebraHandle zh, void *class_handle)
+static void destroy (ZebraService zh, void *class_handle)
{
struct rank_class_info *ci = (struct rank_class_info *) class_handle;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: retrieve.c,v $
- * Revision 1.11 1999-10-29 10:00:00 adam
+ * Revision 1.12 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.11 1999/10/29 10:00:00 adam
* Fixed minor bug where database name wasn't set in zebra_record_fetch.
*
* Revision 1.10 1999/05/26 07:49:13 adam
RecordAttr *recordAttr;
void *clientData;
- rec = rec_get (zh->records, sysno);
+ rec = rec_get (zh->service->records, sysno);
if (!rec)
{
logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno);
*basenamep = 0;
return 14;
}
- recordAttr = rec_init_attr (zh->zei, rec);
+ recordAttr = rec_init_attr (zh->service->zei, rec);
file_type = rec->info[recInfo_fileType];
fname = rec->info[recInfo_filename];
*basenamep = (char *) odr_malloc (stream, strlen(basename)+1);
strcpy (*basenamep, basename);
- if (!(rt = recType_byName (zh->recTypes, file_type, subType, &clientData)))
+ if (!(rt = recType_byName (zh->service->recTypes,
+ file_type, subType, &clientData)))
{
logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type);
return 14;
retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
retrieveCtrl.comp = comp;
retrieveCtrl.diagnostic = 0;
- retrieveCtrl.dh = zh->dh;
- retrieveCtrl.res = zh->res;
+ retrieveCtrl.dh = zh->service->dh;
+ retrieveCtrl.res = zh->service->res;
(*rt->retrieve)(clientData, &retrieveCtrl);
*output_format = retrieveCtrl.output_format;
*rec_bufp = (char *) retrieveCtrl.rec_buf;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: trunc.c,v $
- * Revision 1.16 1999-11-30 13:48:03 adam
+ * Revision 1.17 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.16 1999/11/30 13:48:03 adam
* Improved installation. Updated for inclusion of YAZ header files.
*
* Revision 1.15 1999/07/20 13:59:18 adam
rset_temp_parms parms;
parms.key_size = sizeof(struct it_key);
- parms.temp_path = res_get (zi->res, "setTmpDir");
+ parms.temp_path = res_get (zi->service->res, "setTmpDir");
parms.rset_term = rset_term_create (term, length, flags);
result = rset_create (rset_kind_temp, &parms);
result_rsfd = rset_open (result, RSETF_WRITE);
heap_close (ti);
}
#if ZMBOL
- else if (zi->isam)
+ else if (zi->service->isam)
{
ISPT *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = is_position (zi->isam, isam_p[from+i]);
+ ispt[i] = is_position (zi->service->isam, isam_p[from+i]);
if (is_readkey (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
heap_close (ti);
xfree (ispt);
}
- else if (zi->isamc)
+ else if (zi->service->isamc)
{
ISAMC_PP *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = isc_pp_open (zi->isamc, isam_p[from+i]);
+ ispt[i] = isc_pp_open (zi->service->isamc, isam_p[from+i]);
if (isc_pp_read (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
xfree (ispt);
}
#endif
- else if (zi->isams)
+ else if (zi->service->isams)
{
ISAMS_PP *ispt;
int i;
key_compare_it);
for (i = to-from; --i >= 0; )
{
- ispt[i] = isams_pp_open (zi->isams, isam_p[from+i]);
+ ispt[i] = isams_pp_open (zi->service->isams, isam_p[from+i]);
if (isams_pp_read (ispt[i], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, i);
else
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_null, &parms);
}
- if (zi->isams)
+ if (zi->service->isams)
{
if (no == 1)
{
rset_isams_parms parms;
parms.pos = *isam_p;
- parms.is = zi->isams;
+ parms.is = zi->service->isams;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isams, &parms);
}
qsort (isam_p, no, sizeof(*isam_p), isams_trunc_cmp);
}
#if ZMBOL
- else if (zi->isam)
+ else if (zi->service->isam)
{
if (no == 1)
{
rset_isam_parms parms;
parms.pos = *isam_p;
- parms.is = zi->isam;
+ parms.is = zi->service->isam;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isam, &parms);
}
qsort (isam_p, no, sizeof(*isam_p), isam_trunc_cmp);
}
- else if (zi->isamc)
+ else if (zi->service->isamc)
{
if (no == 1)
{
rset_isamc_parms parms;
parms.pos = *isam_p;
- parms.is = zi->isamc;
+ parms.is = zi->service->isamc;
parms.rset_term = rset_term_create (term, length, flags);
return rset_create (rset_kind_isamc, &parms);
}
parms.key_size = sizeof(struct it_key);
parms.cmp = key_compare_it;
- parms.isc = zi->isamc;
+ parms.isc = zi->service->isamc;
parms.isam_positions = isam_p;
parms.no_isam_positions = no;
parms.no_save_positions = 100000;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zebraapi.c,v $
- * Revision 1.27 2000-02-24 12:31:17 adam
+ * Revision 1.28 2000-03-15 15:00:30 adam
+ * First work on threaded version.
+ *
+ * Revision 1.27 2000/02/24 12:31:17 adam
* Added zebra_string_norm.
*
* Revision 1.26 1999/11/30 13:48:03 adam
#include <yaz/diagbib1.h>
#include "zserver.h"
-static void zebra_chdir (ZebraHandle zh)
+static void zebra_chdir (ZebraService zh)
{
const char *dir = res_get (zh->res, "chdir");
if (!dir)
#endif
}
-static void zebra_register_unlock (ZebraHandle zh);
+static void zebra_register_unlock (ZebraService zh);
-static int zebra_register_lock (ZebraHandle zh)
+static int zebra_register_lock (ZebraService zh)
{
time_t lastChange;
int state;
+ int errCode = 0;
- zh->errCode = 0;
- zh->errString = 0;
+ errCode = 0;
zebra_chdir (zh);
if (!(zh->records = rec_open (zh->bfs, 0, 0)))
{
logf (LOG_WARN, "rec_open");
- zh->errCode = 2;
+ errCode = 2;
}
else
{
if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 40, 0, 0)))
{
logf (LOG_WARN, "dict_open");
- zh->errCode = 2;
+ errCode = 2;
}
if (!(zh->sortIdx = sortIdx_open (zh->bfs, 0)))
{
logf (LOG_WARN, "sortIdx_open");
- zh->errCode = 2;
+ errCode = 2;
}
if (res_get_match (zh->res, "isam", "s", ISAM_DEFAULT))
{
key_isams_m(zh->res, &isams_m))))
{
logf (LOG_WARN, "isams_open");
- zh->errCode = 2;
+ errCode = 2;
}
}
#if ZMBOL
sizeof (struct it_key), zh->res)))
{
logf (LOG_WARN, "is_open");
- zh->errCode = 2;
+ errCode = 2;
}
}
else if (res_get_match (zh->res, "isam", "c", ISAM_DEFAULT))
0, key_isamc_m(zh->res, &isamc_m))))
{
logf (LOG_WARN, "isc_open");
- zh->errCode = 2;
+ errCode = 2;
}
}
#endif
- zh->zei = zebraExplain_open (zh->records, zh->dh, zh->res, 0, 0, 0);
+ zh->zei = zebraExplain_open (zh->records, zh->dh,
+ zh->res, 0, 0, 0);
if (!zh->zei)
{
logf (LOG_WARN, "Cannot obtain EXPLAIN information");
- zh->errCode = 2;
+ errCode = 2;
}
}
- if (zh->errCode)
+ if (errCode)
{
zebra_register_unlock (zh);
zh->registerState = -1;
return -1;
}
- return 0;
+ return errCode;
}
-static void zebra_register_unlock (ZebraHandle zh)
+static void zebra_register_unlock (ZebraService zh)
{
static int waitSec = -1;
zebra_server_unlock (zh, zh->registerState);
}
-ZebraHandle zebra_open (const char *configName)
+ZebraHandle zebra_open (ZebraService service)
{
ZebraHandle zh;
zh = (ZebraHandle) xmalloc (sizeof(*zh));
+
+ zh->service = service;
+ zh->sets = 0;
+
+ return zh;
+}
+
+ZebraService zebra_start (const char *configName)
+{
+ ZebraService zh = xmalloc (sizeof(*zh));
+ zh->configName = xstrdup(configName);
+ zh->sessions = 0;
+ yaz_log (LOG_LOG, "zebra_start %s", configName);
if (!(zh->res = res_open (configName)))
{
logf (LOG_WARN, "Failed to read resources `%s'", configName);
}
bf_lockDir (zh->bfs, res_get (zh->res, "lockDir"));
data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath"));
- zh->sets = NULL;
zh->registerState = -1; /* trigger open of registers! */
zh->registerChange = 0;
zh->recTypes = recTypes_init (zh->dh);
zh->records = NULL;
zh->zebra_maps = zebra_maps_open (zh->res);
zh->rank_classes = NULL;
- zh->errCode = 0;
- zh->errString = 0;
zebraRankInstall (zh, rank1_class);
return zh;
}
-void zebra_close (ZebraHandle zh)
+void zebra_stop(ZebraService zh)
{
if (!zh)
- return;
+ return ;
+ yaz_log (LOG_LOG, "zebra_stop");
+
+ /* wait for sessions to die ...... */
+
zebra_chdir (zh);
if (zh->records)
{
- resultSetDestroy (zh, -1, 0, 0);
zebraExplain_close (zh->zei, 0, 0);
dict_close (zh->dict);
sortIdx_close (zh->sortIdx);
if (zh->passwd_db)
passwd_db_close (zh->passwd_db);
res_close (zh->res);
+
+ xfree (zh->configName);
+ xfree (zh);
+}
+
+void zebra_close (ZebraHandle zh)
+{
+ if (!zh)
+ return ;
+ resultSetDestroy (zh, -1, 0, 0);
+
xfree (zh);
}
odr_malloc (stream, sizeof(*info.new_basenames) * info.new_num_max);
info.mem = stream->mem;
- res_trav (zh->res, "mapdb", &info, map_basenames_func);
+ res_trav (zh->service->res, "mapdb", &info, map_basenames_func);
for (i = 0; i<p->num_bases; i++)
if (p->basenames[i] && p->new_num_bases < p->new_num_max)
const char *setname)
{
zh->hits = 0;
- if (zebra_register_lock (zh))
+ if (zebra_register_lock (zh->service))
return;
map_basenames (zh, stream, &num_bases, &basenames);
resultSetAddRPN (zh, stream, decode, query, num_bases, basenames, setname);
- zebra_register_unlock (zh);
+ zebra_register_unlock (zh->service);
}
void zebra_records_retrieve (ZebraHandle zh, ODR stream,
ZebraPosSet poset;
int i, *pos_array;
- if (zebra_register_lock (zh))
+ if (zebra_register_lock (zh->service))
return;
pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
for (i = 0; i<num_recs; i++)
}
zebraPosSetDestroy (zh, poset, num_recs);
}
- zebra_register_unlock (zh);
+ zebra_register_unlock (zh->service);
xfree (pos_array);
}
int *position, int *num_entries, ZebraScanEntry **entries,
int *is_partial)
{
- if (zebra_register_lock (zh))
+ if (zebra_register_lock (zh->service))
{
*entries = 0;
*num_entries = 0;
rpn_scan (zh, stream, zapt, attributeset,
num_bases, basenames, position,
num_entries, entries, is_partial);
- zebra_register_unlock (zh);
+ zebra_register_unlock (zh->service);
}
void zebra_sort (ZebraHandle zh, ODR stream,
const char *output_setname, Z_SortKeySpecList *sort_sequence,
int *sort_status)
{
- if (zebra_register_lock (zh))
+ if (zebra_register_lock (zh->service))
return;
resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
output_setname, sort_sequence, sort_status);
- zebra_register_unlock (zh);
+ zebra_register_unlock (zh->service);
}
int zebra_deleleResultSet(ZebraHandle zh, int function,
int *statuses)
{
int i, status;
- if (zebra_register_lock (zh))
+ if (zebra_register_lock (zh->service))
return Z_DeleteStatus_systemProblemAtTarget;
switch (function)
{
resultSetDestroy (zh, -1, 0, statuses);
break;
}
- zebra_register_unlock (zh);
+ zebra_register_unlock (zh->service);
status = Z_DeleteStatus_success;
for (i = 0; i<num_setnames; i++)
if (statuses[i] == Z_DeleteStatus_resultSetDidNotExist)
return zh->hits;
}
-int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
+int zebra_auth (ZebraService zh, const char *user, const char *pass)
{
if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass))
return 0;
}
-void zebra_admin (ZebraHandle zh, const char *command)
+void zebra_admin_create (ZebraHandle zh, const char *database)
{
-
+
}
int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
char *output_str, int output_len)
{
WRBUF wrbuf;
- if (!zh->zebra_maps)
+ if (!zh->service->zebra_maps)
return -1;
- wrbuf = zebra_replace(zh->zebra_maps, reg_id, "",
+ wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, "",
input_str, input_len);
if (!wrbuf)
return -2;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zebraapi.h,v $
- * Revision 1.9 2000-02-24 12:31:17 adam
+ * Revision 1.10 2000-03-15 15:00:31 adam
+ * First work on threaded version.
+ *
+ * Revision 1.9 2000/02/24 12:31:17 adam
* Added zebra_string_norm.
*
* Revision 1.8 1999/11/30 13:48:03 adam
#include <yaz/oid.h>
#include <yaz/proto.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
+YAZ_BEGIN_CDECL
/* Retrieval Record Descriptor */
typedef struct {
char *term; /* scan term string */
} ZebraScanEntry;
-typedef struct zebra_info *ZebraHandle;
+typedef struct zebra_session *ZebraHandle;
+typedef struct zebra_service *ZebraService;
/* Open Zebra using file 'configName' (usually zebra.cfg) */
-YAZ_EXPORT ZebraHandle zebra_open (const char *configName);
+YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
/* Search using RPN-Query */
YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output,
YAZ_EXPORT int zebra_hits (ZebraHandle zh);
/* do authentication */
-YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
+YAZ_EXPORT int zebra_auth (ZebraService zh, const char *user, const char *pass);
/* Character normalisation on specific register .
This routine is subject to change - do not use. */
YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
const char *input_str, int input_len,
char *output_str, int output_len);
-
-#ifdef __cplusplus
-}
-#endif
+
+YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db);
+
+YAZ_EXPORT ZebraService zebra_start (const char *configName);
+YAZ_EXPORT void zebra_stop (ZebraService zs);
+
+YAZ_END_CDECL
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zrpn.c,v $
- * Revision 1.101 2000-03-02 14:35:03 adam
+ * Revision 1.102 2000-03-15 15:00:31 adam
+ * First work on threaded version.
+ *
+ * Revision 1.101 2000/03/02 14:35:03 adam
* Fixed proximity handling.
*
* Revision 1.100 1999/12/28 15:48:12 adam
static void rpn_char_map_prepare (ZebraHandle zh, int reg_type,
struct rpn_char_map_info *map_info)
{
- map_info->zm = zh->zebra_maps;
+ map_info->zm = zh->service->zebra_maps;
map_info->reg_type = reg_type;
- dict_grep_cmap (zh->dict, map_info, rpn_char_map_handler);
+ dict_grep_cmap (zh->service->dict, map_info, rpn_char_map_handler);
}
typedef struct {
{
while (*src)
{
- const char *cp = zebra_maps_output (zh->zebra_maps, reg_type, &src);
+ const char *cp = zebra_maps_output (zh->service->zebra_maps,
+ reg_type, &src);
if (!cp)
*dst++ = *src++;
else
switch (relation_value)
{
case 1:
- if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component,
+ if (!term_100 (zh->service->zebra_maps, reg_type,
+ term_sub, term_component,
space_split, term_dst))
return 0;
logf (LOG_DEBUG, "Relation <");
*term_tmp = '\0';
break;
case 2:
- if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component,
+ if (!term_100 (zh->service->zebra_maps, reg_type,
+ term_sub, term_component,
space_split, term_dst))
return 0;
logf (LOG_DEBUG, "Relation <=");
*term_tmp = '\0';
break;
case 5:
- if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component,
- space_split, term_dst))
+ if (!term_100 (zh->service->zebra_maps, reg_type,
+ term_sub, term_component, space_split, term_dst))
return 0;
logf (LOG_DEBUG, "Relation >");
*term_tmp = '\0';
break;
case 4:
- if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component,
- space_split, term_dst))
+ if (!term_100 (zh->service->zebra_maps, reg_type, term_sub,
+ term_component, space_split, term_dst))
return 0;
logf (LOG_DEBUG, "Relation >=");
case 3:
default:
logf (LOG_DEBUG, "Relation =");
- if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component,
- space_split, term_dst))
+ if (!term_100 (zh->service->zebra_maps, reg_type, term_sub,
+ term_component, space_split, term_dst))
return 0;
strcat (term_tmp, "(");
strcat (term_tmp, term_component);
}
return -1;
}
- if (zebraExplain_curDatabase (zh->zei, basenames[base_no]))
+ if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no]))
{
zh->errCode = 109; /* Database unavailable */
zh->errString = basenames[base_no];
char ord_buf[32];
int i, ord_len;
- ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal,
+ ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal,
local_attr->local);
if (ord < 0)
continue;
reg_type, space_split, term_dst))
return 0;
logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict+prefix_len);
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, &max_pos,
- 0, grep_handle);
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0,
+ grep_info, &max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r);
break;
case 1: /* right truncation */
term_dict[j++] = '(';
- if (!term_100 (zh->zebra_maps, reg_type,
+ if (!term_100 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ".*)");
- dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
break;
case 2: /* keft truncation */
term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
- if (!term_100 (zh->zebra_maps, reg_type,
+ if (!term_100 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
- dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
break;
case 3: /* left&right truncation */
term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
- if (!term_100 (zh->zebra_maps, reg_type,
+ if (!term_100 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ".*)");
- dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
break;
zh->errCode = 120;
return -1;
case 101: /* process # in term */
term_dict[j++] = '(';
- if (!term_101 (zh->zebra_maps, reg_type,
+ if (!term_101 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=#: %d", r);
break;
case 102: /* Regexp-1 */
term_dict[j++] = '(';
- if (!term_102 (zh->zebra_maps, reg_type,
+ if (!term_102 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
logf (LOG_DEBUG, "Regexp-1 tolerance=%d", r);
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d",
case 103: /* Regexp-2 */
r = 1;
term_dict[j++] = '(';
- if (!term_103 (zh->zebra_maps, reg_type,
+ if (!term_103 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, &r, space_split, term_dst))
return 0;
strcat (term_dict, ")");
logf (LOG_DEBUG, "Regexp-2 tolerance=%d", r);
- r = dict_lookup_grep (zh->dict, term_dict, r, grep_info,
+ r = dict_lookup_grep (zh->service->dict, term_dict, r, grep_info,
&max_pos, 2, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=eregular: %d",
break;
case 104: /* process # and ! in term */
term_dict[j++] = '(';
- if (!term_104 (zh->zebra_maps, reg_type,
+ if (!term_104 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=#/!: %d", r);
break;
case 105: /* process * and ! in term */
term_dict[j++] = '(';
- if (!term_105 (zh->zebra_maps, reg_type,
+ if (!term_105 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst, 1))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r);
break;
case 106: /* process * and ! in term */
term_dict[j++] = '(';
- if (!term_105 (zh->zebra_maps, reg_type,
+ if (!term_105 (zh->service->zebra_maps, reg_type,
&termp, term_dict + j, space_split, term_dst, 0))
return 0;
strcat (term_dict, ")");
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info,
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info,
&max_pos, 0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r);
while ((len = (cp_end - cp)) > 0)
{
- map = zebra_maps_input (zh->zebra_maps, reg_type, &cp, len);
+ map = zebra_maps_input (zh->service->zebra_maps, reg_type, &cp, len);
if (**map == *CHR_SPACE)
space_map = *map;
else
flags);
parms.rset_term->nn = min_nn;
parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->res, "setTmpDir");
+ parms.temp_path = res_get (zh->service->res, "setTmpDir");
result = rset_create (rset_kind_temp, &parms);
rsfd_result = rset_open (result, RSETF_WRITE);
flags);
parms.rset_term->nn = min_nn;
parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->res, "setTmpDir");
+ parms.temp_path = res_get (zh->service->res, "setTmpDir");
result = rset_create (rset_kind_temp, &parms);
rsfd_result = rset_open (result, RSETF_WRITE);
break;
}
if (ex_list)
- wrbuf = zebra_replace(zh->zebra_maps, reg_id, ex_list,
+ wrbuf = zebra_replace(zh->service->zebra_maps, reg_id, ex_list,
termz, strlen(termz));
if (!wrbuf)
return nmem_strdup(stream, termz);
logf (LOG_DEBUG, "numeric relation value=%d", relation_value);
- if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_tmp, 1,
+ if (!term_100 (zh->service->zebra_maps, reg_type, term_sub, term_tmp, 1,
term_dst))
return 0;
term_value = atoi (term_tmp);
sprintf (term_tmp, "(0*%d)", term_value);
}
logf (LOG_DEBUG, "dict_lookup_grep: %s", term_tmp);
- r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, max_pos,
+ r = dict_lookup_grep (zh->service->dict, term_dict, 0, grep_info, max_pos,
0, grep_handle);
if (r)
logf (LOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r);
zh->errCode = 121;
return -1;
}
- if (zebraExplain_curDatabase (zh->zei, basenames[base_no]))
+ if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no]))
{
zh->errCode = 109; /* Database unavailable */
zh->errString = basenames[base_no];
char ord_buf[32];
int i, ord_len;
- ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal,
+ ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal,
local_attr->local);
if (ord < 0)
continue;
parms.rset_term = rset_term_create (termz, -1, rank_type);
parms.key_size = sizeof (struct it_key);
- parms.temp_path = res_get (zh->res, "setTmpDir");
+ parms.temp_path = res_get (zh->service->res, "setTmpDir");
result = rset_create (rset_kind_temp, &parms);
rsfd = rset_open (result, RSETF_WRITE);
int sort_flag;
char termz[IT_MAX_WORD+1];
- zebra_maps_attr (zh->zebra_maps, zapt, ®_id, &search_type,
+ zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type,
&rank_type, &complete_flag, &sort_flag);
logf (LOG_DEBUG, "reg_id=%c", reg_id);
attr_init (&use, zapt, 1);
use_value = attr_find (&use, &attributeset);
- if (zebra_maps_attr (zh->zebra_maps, zapt, ®_id, &search_type,
+ if (zebra_maps_attr (zh->service->zebra_maps, zapt, ®_id, &search_type,
&rank_type, &complete_flag, &sort_flag))
{
zh->errCode = 113;
*num_entries = 0;
return;
}
- if (zebraExplain_curDatabase (zh->zei, basenames[base_no]))
+ if (zebraExplain_curDatabase (zh->service->zei, basenames[base_no]))
{
zh->errString = basenames[base_no];
zh->errCode = 109; /* Database unavailable */
{
int ord;
- ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal,
+ ord = zebraExplain_lookupSU (zh->service->zei, attp.attset_ordinal,
local_attr->local);
if (ord > 0)
ords[ord_no++] = ord;
trans_scan_term (zh, zapt, termz+prefix_len, reg_id);
- dict_scan (zh->dict, termz, &before_tmp, &after_tmp, scan_info,
- scan_handle);
+ dict_scan (zh->service->dict, termz, &before_tmp, &after_tmp,
+ scan_info, scan_handle);
}
glist = (ZebraScanEntry *)
odr_malloc (stream, (before+after)*sizeof(*glist));
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.c,v $
- * Revision 1.75 1999-11-30 13:48:04 adam
+ * Revision 1.76 2000-03-15 15:00:31 adam
+ * First work on threaded version.
+ *
+ * Revision 1.75 1999/11/30 13:48:04 adam
* Improved installation. Updated for inclusion of YAZ header files.
*
* Revision 1.74 1999/11/29 15:13:26 adam
#endif
#include <yaz/data1.h>
+#ifdef ASN_COMPILED
+#include <yaz/ill.h>
+#endif
#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);
bend_initresult *bend_init (bend_initrequest *q)
{
r->errstring = 0;
q->bend_sort = bend_sort;
q->bend_delete = bend_delete;
+ q->bend_esrequest = bend_esrequest;
q->implementation_name = "Z'mbol Information Server";
q->implementation_version = "Z'mbol 1.0";
logf (LOG_DEBUG, "bend_init");
sob = statserv_getcontrol ();
- if (!(zh = zebra_open (sob->configname)))
+ if (!(zh = zebra_open (sob->handle)))
{
logf (LOG_FATAL, "Failed to open Zebra `%s'", sob->configname);
r->errcode = 1;
xfree (openpass);
}
}
- if (zebra_auth (zh, user, passwd))
+ if (zebra_auth (zh->service, user, passwd))
{
r->errcode = 222;
r->errstring = user;
return 0;
}
-#ifndef WIN32
+static int es_admin_request (ZebraHandle zh, Z_AdminEsRequest *r)
+{
+ switch (r->toKeep->which)
+ {
+ case Z_ESAdminOriginPartToKeep_reIndex:
+ yaz_log(LOG_LOG, "adm-reindex");
+ break;
+ case Z_ESAdminOriginPartToKeep_truncate:
+ yaz_log(LOG_LOG, "adm-truncate");
+ break;
+ case Z_ESAdminOriginPartToKeep_delete:
+ yaz_log(LOG_LOG, "adm-delete");
+ break;
+ case Z_ESAdminOriginPartToKeep_create:
+ yaz_log(LOG_LOG, "adm-create");
+ zebra_admin_create (zh, r->toKeep->databaseName);
+ break;
+ case Z_ESAdminOriginPartToKeep_import:
+ yaz_log(LOG_LOG, "adm-import");
+ break;
+ case Z_ESAdminOriginPartToKeep_refresh:
+ yaz_log(LOG_LOG, "adm-refresh");
+ break;
+ case Z_ESAdminOriginPartToKeep_commit:
+ yaz_log(LOG_LOG, "adm-commit");
+ break;
+ default:
+ yaz_log(LOG_LOG, "unknown admin");
+ zh->errCode = 1001;
+ }
+ if (r->toKeep->databaseName)
+ {
+ yaz_log(LOG_LOG, "database %s", r->toKeep->databaseName);
+ }
+ return 0;
+}
+
+static int es_admin (ZebraHandle zh, Z_Admin *r)
+{
+ switch (r->which)
+ {
+ case Z_Admin_esRequest:
+ es_admin_request (zh, r->u.esRequest);
+ break;
+ case Z_Admin_taskPackage:
+ yaz_log (LOG_LOG, "adm taskpackage (unhandled)");
+ break;
+ default:
+ zh->errCode = 1001;
+ break;
+ }
+
+ return 0;
+}
+
+int bend_esrequest (void *handle, bend_esrequest_rr *rr)
+{
+ ZebraHandle zh = (ZebraHandle) handle;
+
+ yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
+ if (rr->esr->packageName)
+ yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
+ yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
+
+ if (!rr->esr->taskSpecificParameters)
+ {
+ yaz_log (LOG_WARN, "No task specific parameters");
+ }
+ else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin)
+ {
+ es_admin (zh, rr->esr->taskSpecificParameters->u.adminService);
+ rr->errcode = zh->errCode;
+ rr->errstring = zh->errString;
+ }
+ else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
+ {
+ Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder;
+ yaz_log (LOG_LOG, "Received ItemOrder");
+ switch (it->which)
+ {
+#ifdef ASN_COMPILED
+ case Z_IOItemOrder_esRequest:
+#else
+ case Z_ItemOrder_esRequest:
+#endif
+ {
+ Z_IORequest *ir = it->u.esRequest;
+ Z_IOOriginPartToKeep *k = ir->toKeep;
+ Z_IOOriginPartNotToKeep *n = ir->notToKeep;
+
+ if (k && k->contact)
+ {
+ if (k->contact->name)
+ yaz_log(LOG_LOG, "contact name %s", k->contact->name);
+ if (k->contact->phone)
+ yaz_log(LOG_LOG, "contact phone %s", k->contact->phone);
+ if (k->contact->email)
+ yaz_log(LOG_LOG, "contact email %s", k->contact->email);
+ }
+ if (k->addlBilling)
+ {
+ yaz_log(LOG_LOG, "Billing info (not shown)");
+ }
+
+ if (n->resultSetItem)
+ {
+ yaz_log(LOG_LOG, "resultsetItem");
+ yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId);
+ yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item);
+ }
+#ifdef ASN_COMPILED
+ if (n->itemRequest)
+ {
+ Z_External *r = (Z_External*) n->itemRequest;
+ ILL_ItemRequest *item_req = 0;
+ ILL_Request *ill_req = 0;
+ if (r->direct_reference)
+ {
+ oident *ent = oid_getentbyoid(r->direct_reference);
+ if (ent)
+ yaz_log(LOG_LOG, "OID %s", ent->desc);
+ if (ent && ent->value == VAL_ISO_ILL_1)
+ {
+ yaz_log (LOG_LOG, "ItemRequest");
+ if (r->which == ODR_EXTERNAL_single)
+ {
+ odr_setbuf(rr->decode,
+ r->u.single_ASN1_type->buf,
+ r->u.single_ASN1_type->len, 0);
+
+ if (!ill_ItemRequest (rr->decode, &item_req, 0, 0))
+ {
+ yaz_log (LOG_LOG,
+ "Couldn't decode ItemRequest %s near %d",
+ odr_errmsg(odr_geterror(rr->decode)),
+ odr_offset(rr->decode));
+ yaz_log(LOG_LOG, "PDU dump:");
+ odr_dumpBER(log_file(),
+ r->u.single_ASN1_type->buf,
+ r->u.single_ASN1_type->len);
+ }
+ if (rr->print)
+ {
+ ill_ItemRequest (rr->print, &item_req, 0,
+ "ItemRequest");
+ odr_reset (rr->print);
+ }
+ }
+ if (!item_req && r->which == ODR_EXTERNAL_single)
+ {
+ yaz_log (LOG_LOG, "ILLRequest");
+ odr_setbuf(rr->decode,
+ r->u.single_ASN1_type->buf,
+ r->u.single_ASN1_type->len, 0);
+
+ if (!ill_Request (rr->decode, &ill_req, 0, 0))
+ {
+ yaz_log (LOG_LOG,
+ "Couldn't decode ILLRequest %s near %d",
+ odr_errmsg(odr_geterror(rr->decode)),
+ odr_offset(rr->decode));
+ yaz_log(LOG_LOG, "PDU dump:");
+ odr_dumpBER(log_file(),
+ r->u.single_ASN1_type->buf,
+ r->u.single_ASN1_type->len);
+ }
+ if (rr->print)
+ {
+ ill_Request (rr->print, &ill_req, 0,
+ "ILLRequest");
+ odr_reset (rr->print);
+ }
+ }
+ }
+ }
+ if (item_req)
+ {
+ yaz_log (LOG_LOG, "ILL protocol version = %d",
+ *item_req->protocol_version_num);
+ }
+ }
+#endif
+ }
+ break;
+ }
+ }
+ else if (rr->esr->taskSpecificParameters->which == Z_External_update)
+ {
+ Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
+ yaz_log (LOG_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 (LOG_LOG, "action");
+ if (toKeep->action)
+ {
+ switch (*toKeep->action)
+ {
+ case Z_IUOriginPartToKeep_recordInsert:
+ yaz_log (LOG_LOG, " recordInsert");
+ break;
+ case Z_IUOriginPartToKeep_recordReplace:
+ yaz_log (LOG_LOG, " recordUpdate");
+ break;
+ case Z_IUOriginPartToKeep_recordDelete:
+ yaz_log (LOG_LOG, " recordDelete");
+ break;
+ case Z_IUOriginPartToKeep_elementUpdate:
+ yaz_log (LOG_LOG, " elementUpdate");
+ break;
+ case Z_IUOriginPartToKeep_specialUpdate:
+ yaz_log (LOG_LOG, " specialUpdate");
+ break;
+ default:
+ yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);
+ }
+ }
+ if (toKeep->databaseName)
+ {
+ yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);
+ if (!strcmp(toKeep->databaseName, "fault"))
+ {
+ rr->errcode = 109;
+ rr->errstring = toKeep->databaseName;
+ }
+ if (!strcmp(toKeep->databaseName, "accept"))
+ rr->errcode = -1;
+ }
+ if (notToKeep)
+ {
+ int i;
+ for (i = 0; i < notToKeep->num; i++)
+ {
+ Z_External *rec = notToKeep->elements[i]->record;
+
+ if (rec->direct_reference)
+ {
+ struct oident *oident;
+ oident = oid_getentbyoid(rec->direct_reference);
+ if (oident)
+ yaz_log (LOG_LOG, "record %d type %s", i,
+ oident->desc);
+ }
+ switch (rec->which)
+ {
+ case Z_External_sutrs:
+ if (rec->u.octet_aligned->len > 170)
+ yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+ rec->u.sutrs->len,
+ rec->u.sutrs->buf);
+ else
+ yaz_log (LOG_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 (LOG_LOG, "%d bytes:\n%.168s ...",
+ rec->u.octet_aligned->len,
+ rec->u.octet_aligned->buf);
+ else
+ yaz_log (LOG_LOG, "%d bytes\n%s",
+ rec->u.octet_aligned->len,
+ rec->u.octet_aligned->buf);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ yaz_log (LOG_WARN, "Unknown Extended Service(%d)",
+ rr->esr->taskSpecificParameters->which);
+
+ }
+ return 0;
+}
+
static void bend_start (struct statserv_options_block *sob)
{
+#ifdef WIN32
+
+#else
if (!sob->inetd)
{
char *pidfile = "zebrasrv.pid";
close (fd);
}
}
-}
#endif
+ if (sob->handle)
+ zebra_stop((ZebraService) sob->handle);
+ sob->handle = zebra_start(sob->configname);
+}
+
+static void bend_stop(struct statserv_options_block *sob)
+{
+ if (sob->handle)
+ zebra_stop(sob->handle);
+ sob->handle = 0;
+}
int main (int argc, char **argv)
{
sob = statserv_getcontrol ();
strcpy (sob->configname, FNAME_CONFIG);
-#ifndef WIN32
sob->bend_start = bend_start;
-#endif
+ sob->bend_stop = bend_stop;
+
+ if (sob->dynamic)
+ {
+ sob->dynamic = 0;
+ sob->threads = 1;
+ }
statserv_setcontrol (sob);
-#if ZEBRASDR
- zebraSdr_std ();
-#endif
return statserv_main (argc, argv);
}
/*
- * Copyright (C) 1994-1999, Index Data
+ * Copyright (C) 1994-2000, Index Data
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.h,v $
- * Revision 1.45 1999-11-30 13:48:04 adam
+ * Revision 1.46 2000-03-15 15:00:31 adam
+ * First work on threaded version.
+ *
+ * Revision 1.45 1999/11/30 13:48:04 adam
* Improved installation. Updated for inclusion of YAZ header files.
*
* Revision 1.44 1999/11/04 15:00:45 adam
#include <sys/times.h>
#endif
+#if HAVE_PTHREADS_H
+#include <pthreads.h>
+#endif
+
#include <yaz/backend.h>
#include <rset.h>
#include "zebraapi.h"
#include "zinfo.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+YAZ_BEGIN_CDECL
typedef struct {
int sysno;
struct zebra_rank_class *next;
} *ZebraRankClass;
-struct zebra_info {
- int registerState; /* 0 (no commit pages), 1 (use commit pages) */
- time_t registerChange;
- ZebraSet sets;
- Dict dict;
- SortIdx sortIdx;
+struct zebra_service {
+ char *configName;
+ struct zebra_session *sessions;
ISAMS isams;
#if ZMBOL
ISAM isam;
ISAMC isamc;
#endif
+ Dict dict;
+ SortIdx sortIdx;
+ int registerState; /* 0 (no commit pages), 1 (use commit pages) */
+ time_t registerChange;
+ BFiles bfs;
Records records;
- int errCode;
- int hits;
- char *errString;
ZebraExplainInfo zei;
- data1_handle dh;
- BFiles bfs;
Res res;
-
ZebraLockHandle server_lock_cmt;
ZebraLockHandle server_lock_org;
char *server_path_prefix;
struct tms tms1;
struct tms tms2;
#endif
+ data1_handle dh;
ZebraMaps zebra_maps;
ZebraRankClass rank_classes;
RecTypes recTypes;
Passwd_db passwd_db;
};
+struct zebra_session {
+#if HAVE_PTHREADS_H
+ pthread_t *pthread_session;
+#endif
+ struct zebra_session *next;
+ struct zebra_info *info;
+ struct zebra_service *service;
+
+ ZebraSet sets;
+ int errCode;
+ int hits;
+ char *errString;
+
+};
+
struct rank_control {
char *name;
- void *(*create)(ZebraHandle zh);
- void (*destroy)(ZebraHandle zh, void *class_handle);
+ void *(*create)(ZebraService zh);
+ void (*destroy)(ZebraService zh, void *class_handle);
void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
void (*end)(ZebraHandle zh, void *set_handle);
int (*calc)(void *set_handle, int sysno);
const char *output_setname, Z_SortKeySpecList *sort_sequence,
int *sort_status);
-int zebra_server_lock_init (ZebraHandle zh);
-int zebra_server_lock_destroy (ZebraHandle zh);
-int zebra_server_lock (ZebraHandle zh, int lockCommit);
-void zebra_server_unlock (ZebraHandle zh, int commitPhase);
-int zebra_server_lock_get_state (ZebraHandle zh, time_t *timep);
+int zebra_server_lock_init (ZebraService zh);
+int zebra_server_lock_destroy (ZebraService zh);
+int zebra_server_lock (ZebraService zh, int lockCommit);
+void zebra_server_unlock (ZebraService zh, int commitPhase);
+int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
typedef struct attent
{
data1_local_attribute *local_attributes;
} attent;
-void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl);
+void zebraRankInstall (ZebraService zh, struct rank_control *ctrl);
ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
-void zebraRankDestroy (ZebraHandle zh);
+void zebraRankDestroy (ZebraService zh);
int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
oid_value *output_format, char **rec_bufp,
int *rec_lenp, char **basenamep);
-#ifdef __cplusplus
-}
-#endif
+YAZ_END_CDECL
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zsets.c,v $
- * Revision 1.24 1999-11-04 15:00:45 adam
+ * Revision 1.25 2000-03-15 15:00:31 adam
+ * First work on threaded version.
+ *
+ * Revision 1.24 1999/11/04 15:00:45 adam
* Implemented delete result set(s).
*
* Revision 1.23 1999/05/26 07:49:13 adam
struct zset_sort_info *sort_info = sset->sort_info;
int i, j;
- sortIdx_sysno (zh->sortIdx, sysno);
+ sortIdx_sysno (zh->service->sortIdx, sysno);
for (i = 0; i<num_criteria; i++)
{
- sortIdx_type (zh->sortIdx, criteria[i].attrUse);
- sortIdx_read (zh->sortIdx, this_entry.buf[i]);
+ sortIdx_type (zh->service->sortIdx, criteria[i].attrUse);
+ sortIdx_read (zh->service->sortIdx, this_entry.buf[i]);
}
i = sort_info->num_entries;
while (--i >= 0)
case Z_SortKey_sortAttributes:
logf (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1);
sort_criteria[i].attrUse =
- zebra_maps_sort (zh->zebra_maps, sk->u.sortAttributes);
+ zebra_maps_sort (zh->service->zebra_maps,
+ sk->u.sortAttributes);
logf (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse);
if (sort_criteria[i].attrUse == -1)
{
zh->errCode = 116;
return;
}
- if (sortIdx_type (zh->sortIdx, sort_criteria[i].attrUse))
+ if (sortIdx_type (zh->service->sortIdx, sort_criteria[i].attrUse))
{
zh->errCode = 207;
return;
ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name)
{
- ZebraRankClass p = zh->rank_classes;
+ ZebraRankClass p = zh->service->rank_classes;
while (p && strcmp (p->control->name, name))
p = p->next;
if (p && !p->init_flag)
{
if (p->control->create)
- p->class_handle = (*p->control->create)(zh);
+ p->class_handle = (*p->control->create)(zh->service);
p->init_flag = 1;
}
return p;
}
-void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl)
+void zebraRankInstall (ZebraService zh, struct rank_control *ctrl)
{
ZebraRankClass p = (ZebraRankClass) xmalloc (sizeof(*p));
p->control = (struct rank_control *) xmalloc (sizeof(*p->control));
zh->rank_classes = p;
}
-void zebraRankDestroy (ZebraHandle zh)
+void zebraRankDestroy (ZebraService zh)
{
ZebraRankClass p = zh->rank_classes;
while (p)
# Copyright (C) 1994-1998, Index Data ApS
# All rights reserved.
# Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile.in,v 1.4 1999-11-30 13:48:04 adam Exp $
+# $Id: Makefile.in,v 1.5 2000-03-15 15:00:31 adam Exp $
SHELL=/bin/sh
TPROG=opt-test
DEFS=$(CDEFS) $(INCLUDE) -DUSE_CRYPT=0
LIB=../lib/zebrautl.a
-PO = res.o charmap.o zebramap.o passwddb.o
+PO = res.o charmap.o zebramap.o passwddb.o zebra-lock.o
all: $(LIB)
--- /dev/null
+
+#include <assert.h>
+
+#include <zebra-lock.h>
+
+int zebra_mutex_init (Zebra_mutex *p)
+{
+ pthread_mutex_init (&p->mutex, 0);
+ return 0;
+}
+
+int zebra_mutex_destroy (Zebra_mutex *p)
+{
+ pthread_mutex_destroy (&p->mutex);
+ return 0;
+}
+
+int zebra_mutex_lock (Zebra_mutex *p)
+{
+ pthread_mutex_lock (&p->mutex);
+ return 0;
+}
+
+int zebra_mutex_unlock (Zebra_mutex *p)
+{
+ pthread_mutex_unlock (&p->mutex);
+ return 0;
+}
+
+int zebra_lock_rdwr_init (Zebra_lock_rdwr *p)
+{
+ p->readers_reading = 0;
+ p->writers_writing = 0;
+ pthread_mutex_init (&p->mutex, 0);
+ pthread_cond_init (&p->lock_free, 0);
+ return 0;
+}
+
+int zebra_lock_rdwr_destroy (Zebra_lock_rdwr *p)
+{
+ assert (p->readers_reading == 0);
+ assert (p->writers_writing == 0);
+ pthread_mutex_destroy (&p->mutex);
+ pthread_cond_destroy (&p->lock_free);
+ return 0;
+}
+
+int zebra_lock_rdwr_rlock (Zebra_lock_rdwr *p)
+{
+ pthread_mutex_lock (& p->mutex);
+ while (p->writers_writing)
+ pthread_cond_wait (&p->lock_free, &p->mutex);
+ p->readers_reading++;
+ pthread_mutex_unlock(&p->mutex);
+ return 0;
+}
+
+int zebra_lock_rdwr_wlock (Zebra_lock_rdwr *p)
+{
+ pthread_mutex_lock (&p->mutex);
+ while (p->writers_writing || p->readers_reading)
+ pthread_cond_wait (&p->lock_free, &p->mutex);
+ p->writers_writing++;
+ pthread_mutex_unlock (&p->mutex);
+ return 0;
+}
+
+int zebra_lock_rdwr_runlock (Zebra_lock_rdwr *p)
+{
+ pthread_mutex_lock (&p->mutex);
+ if (p->readers_reading == 0)
+ {
+ pthread_mutex_unlock (&p->mutex);
+ return -1;
+ }
+ else
+ {
+ p->readers_reading--;
+ if (p->readers_reading == 0)
+ pthread_cond_signal (&p->lock_free);
+ pthread_mutex_unlock (&p->mutex);
+ }
+ return 0;
+}
+
+int zebra_lock_rdwr_wunlock (Zebra_lock_rdwr *p)
+{
+ pthread_mutex_lock (&p->mutex);
+ if (p->writers_writing == 0)
+ {
+ pthread_mutex_unlock (&p->mutex);
+ return -1;
+ }
+ else
+ {
+ p->writers_writing--;
+ pthread_cond_broadcast(&p->lock_free);
+ pthread_mutex_unlock(&p->mutex);
+ }
+ return 0;
+}
+