From 43801085d371c69455730182f72c4e53d8c8218f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 29 Nov 2000 14:22:47 +0000 Subject: [PATCH] Implemented XML/SGML attributes for data1 so that d1_read reads them and d1_write generates proper attributes for XML/SGML records. Added register locking for threaded version. --- CHANGELOG | 3 ++ configure | 4 +- configure.in | 6 +-- include/yaz/data1.h | 21 +++++++- retrieval/d1_map.c | 15 +++--- retrieval/d1_read.c | 134 ++++++++++++++++++++++++++++++++++++++++++-------- retrieval/d1_write.c | 27 ++++++++-- server/statserv.c | 9 ++-- yaz.m4 | 8 +-- 9 files changed, 184 insertions(+), 43 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 15733f3..69972de 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ Possible compatibility problems with earlier versions marked with '*'. +Added extended attributes for retrieval module (data1), so that data1 +records carry d1_readXML/SGML attributes. + On UNIX when POSIX threads are available, a separate library libyazthread is created. Programmers should link with that library and the yaz library when using threads. The reason for the split was that some applications diff --git a/configure b/configure index 943c337..35cb1b6 100755 --- a/configure +++ b/configure @@ -2453,12 +2453,12 @@ echo "configure:2452: checking for working POSIX Threads" >&5 #line 2454 "configure" #include "confdefs.h" #include - int func(void *p) { return 0; } + void *func(void *p) { return 0; } int main() { pthread_t pthread_id; - int r = pthread_create (&pthread_id, 0, func, 0); + pthread_create (&pthread_id, 0, func, 0); ; return 0; } EOF if { (eval echo configure:2465: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then diff --git a/configure.in b/configure.in index 706e187..173ab9f 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2000 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.38 2000-11-23 10:58:32 adam Exp $ +dnl $Id: configure.in,v 1.39 2000-11-29 14:22:47 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.7) dnl @@ -120,10 +120,10 @@ if test "$enable_threads" = "yes"; then AC_CHECK_LIB(pthread,main) AC_MSG_CHECKING(for working POSIX Threads) AC_TRY_LINK([#include - int func(void *p) { return 0; } + void *func(void *p) { return 0; } ],[ pthread_t pthread_id; - int r = pthread_create (&pthread_id, 0, func, 0);], + pthread_create (&pthread_id, 0, func, 0);], thread_ok=yes,thread_ok=no) if test "$thread_ok" = "yes"; then LIBTHREAD=-lpthread diff --git a/include/yaz/data1.h b/include/yaz/data1.h index 38a65f1..23dce1f 100644 --- a/include/yaz/data1.h +++ b/include/yaz/data1.h @@ -24,7 +24,12 @@ * OF THIS SOFTWARE. * * $Log: data1.h,v $ - * Revision 1.4 2000-02-28 11:20:06 adam + * Revision 1.5 2000-11-29 14:22:47 adam + * Implemented XML/SGML attributes for data1 so that d1_read reads them + * and d1_write generates proper attributes for XML/SGML records. Added + * register locking for threaded version. + * + * Revision 1.4 2000/02/28 11:20:06 adam * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. * * Revision 1.3 2000/01/04 17:46:17 ian @@ -244,6 +249,8 @@ #define d1_isspace(c) strchr(" \r\n\t\f", c) #define d1_isdigit(c) ((c) <= '9' && (c) >= '0') +#define DATA1_USING_XATTR 1 + YAZ_BEGIN_CDECL #define data1_matchstr(s1, s2) yaz_matchstr(s1, s2) @@ -393,6 +400,14 @@ typedef struct data1_sub_elements { data1_element *elements; } data1_sub_elements; +#if DATA1_USING_XATTR +typedef struct data1_xattr { + char *name; + char *value; + struct data1_xattr *next; +} data1_xattr; +#endif + typedef struct data1_absyn { char *name; @@ -439,6 +454,9 @@ typedef struct data1_node int get_bytes; unsigned node_selected : 1; unsigned make_variantlist : 1; +#if DATA1_USING_XATTR + data1_xattr *attributes; +#endif } tag; struct @@ -528,6 +546,7 @@ YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh, data1_absyn *absyn, const char *name); YAZ_EXPORT data1_node *data1_mk_node(data1_handle dh, NMEM m); +YAZ_EXPORT data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type); YAZ_EXPORT data1_absyn *data1_get_absyn(data1_handle dh, const char *name); YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name); YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file); diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index 9dc5e99..15d14cb 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -1,10 +1,15 @@ /* - * Copyright (c) 1995-1999, Index Data. + * Copyright (c) 1995-2000, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_map.c,v $ - * Revision 1.17 1999-11-30 13:47:12 adam + * Revision 1.18 2000-11-29 14:22:47 adam + * Implemented XML/SGML attributes for data1 so that d1_read reads them + * and d1_write generates proper attributes for XML/SGML records. Added + * register locking for threaded version. + * + * Revision 1.17 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.16 1999/10/21 12:06:29 adam @@ -303,11 +308,9 @@ static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, { if (!cur || mt->new_field || !tagmatch(cur, mt)) { - cur = data1_mk_node (dh, mem); - cur->which = DATA1N_tag; - cur->u.tag.element = 0; + cur = data1_mk_node_type (dh, mem, DATA1N_tag); cur->u.tag.tag = mt->value.string; - cur->u.tag.node_selected = 0; + cur->parent = pn; cur->root = pn->root; if (!pn->child) diff --git a/retrieval/d1_read.c b/retrieval/d1_read.c index 6ff7445..a275341 100644 --- a/retrieval/d1_read.c +++ b/retrieval/d1_read.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_read.c,v $ - * Revision 1.32 2000-01-06 11:25:59 adam + * Revision 1.33 2000-11-29 14:22:47 adam + * Implemented XML/SGML attributes for data1 so that d1_read reads them + * and d1_write generates proper attributes for XML/SGML records. Added + * register locking for threaded version. + * + * Revision 1.32 2000/01/06 11:25:59 adam * Added case to prevent warning. * * Revision 1.31 1999/12/21 14:16:20 ian @@ -192,6 +197,41 @@ data1_node *data1_mk_node (data1_handle dh, NMEM m) return r; } +data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type) +{ + data1_node *r; + + r = data1_mk_node(dh, m); + r->which = type; + switch(type) + { + case DATA1N_tag: + r->u.tag.tag = 0; + r->u.tag.element = 0; + r->u.tag.no_data_requested = 0; + r->u.tag.node_selected = 0; + r->u.tag.make_variantlist = 0; + r->u.tag.get_bytes = -1; +#if DATA1_USING_XATTR + r->u.tag.attributes = 0; +#endif + break; + case DATA1N_root: + r->u.root.type = 0; + r->u.root.absyn = 0; + break; + case DATA1N_data: + r->u.data.data = 0; + r->u.data.len = 0; + r->u.data.what = 0; + r->u.data.formatted_text = 0; + break; + default: + logf (LOG_WARN, "data_mk_node_type. bad type = %d\n", type); + } + return r; +} + void data1_free_tree (data1_handle dh, data1_node *t) { data1_node *p = t->child, *pn; @@ -226,16 +266,11 @@ data1_node *data1_add_insert_taggeddata(data1_handle dh, data1_node *root, int first_flag, int local_allowed) { data1_node *partag = get_parent_tag (dh, at); - data1_node *tagn = data1_mk_node (dh, m); + data1_node *tagn = data1_mk_node_type (dh, m, DATA1N_tag); data1_element *e = NULL; data1_node *datn; - tagn->which = DATA1N_tag; tagn->u.tag.tag = data1_insert_string (dh, tagn, m, tagname); - tagn->u.tag.node_selected = 0; - tagn->u.tag.make_variantlist = 0; - tagn->u.tag.no_data_requested = 0; - tagn->u.tag.get_bytes = -1; if (partag) e = partag->u.tag.element; @@ -243,11 +278,10 @@ data1_node *data1_add_insert_taggeddata(data1_handle dh, data1_node *root, data1_getelementbytagname (dh, root->u.root.absyn, e, tagname); if (!local_allowed && !tagn->u.tag.element) return NULL; - tagn->last_child = tagn->child = datn = data1_mk_node (dh, m); + tagn->last_child = tagn->child = datn = data1_mk_node_type (dh, m, DATA1N_data); tagn->root = root; datn->parent = tagn; datn->root = root; - datn->which = DATA1N_data; datn->u.data.formatted_text = 0; tagn->parent = at; @@ -292,6 +326,61 @@ data1_node *data1_insert_taggeddata(data1_handle dh, data1_node *root, return data1_add_insert_taggeddata (dh, root, at, tagname, m, 1, 0); } +#if DATA1_USING_XATTR +data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, + int (*get_byte)(void *fh), void *fh, + WRBUF wrbuf, int *ch) +{ + data1_xattr *p_first = 0; + data1_xattr **pp = &p_first; + int c = *ch; + for (;;) + { + data1_xattr *p; + int len; + while (c && d1_isspace(c)) + c = (*get_byte)(fh); + if (!c || c == '>' || c == '/') + break; + *pp = p = nmem_malloc (m, sizeof(*p)); + p->next = 0; + pp = &p->next; + p->value = 0; + + wrbuf_rewind(wrbuf); + while (c && c != '=' && c != '>' && c != '/' && !d1_isspace(c)) + { + wrbuf_putc (wrbuf, c); + c = (*get_byte)(fh); + } + wrbuf_putc (wrbuf, '\0'); + len = wrbuf_len(wrbuf); + p->name = nmem_malloc (m, len); + strcpy (p->name, wrbuf_buf(wrbuf)); + if (c == '=') + { + c = (*get_byte)(fh); + if (c == '"') + c = (*get_byte)(fh); + wrbuf_rewind(wrbuf); + while (c && c != '"' && c != '>' && c != '/') + { + wrbuf_putc (wrbuf, c); + c = (*get_byte)(fh); + } + wrbuf_putc (wrbuf, '\0'); + len = wrbuf_len(wrbuf); + p->value = nmem_malloc (m, len); + strcpy (p->value, wrbuf_buf(wrbuf)); + if (c == '"') + c = (*get_byte)(fh); + } + } + *ch = c; + return p_first; +} +#endif + /* * Ugh. Sometimes functions just grow and grow on you. This one reads a * 'node' and its children. @@ -322,20 +411,27 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, if (c == '<') /* beginning of tag */ { +#if DATA1_USING_XATTR + data1_xattr *xattr; +#endif char tag[64]; char args[256]; size_t i; - for (i = 0; (c=(*get_byte)(fh)) && c != '>' && !d1_isspace(c);) if (i < (sizeof(tag)-1)) tag[i++] = c; tag[i] = '\0'; +#if DATA1_USING_XATTR + xattr = data1_read_xattr (dh, m, get_byte, fh, wrbuf, &c); + args[0] = '\0'; +#else while (d1_isspace(c)) c = (*get_byte)(fh); for (i = 0; c && c != '>'; c = (*get_byte)(fh)) if (i < (sizeof(args)-1)) args[i++] = c; args[i] = '\0'; +#endif if (c != '>') { yaz_log(LOG_WARN, "d1: %d: Malformed tag", line); @@ -382,8 +478,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, yaz_log(LOG_WARN, "Unable to acquire abstract syntax " "for '%s'", tag); /* It's now OK for a record not to have an absyn */ } - res = data1_mk_node (dh, m); - res->which = DATA1N_root; + res = data1_mk_node_type (dh, m, DATA1N_root); res->u.root.type = data1_insert_string (dh, res, m, tag); res->u.root.absyn = absyn; res->root = res; @@ -448,14 +543,12 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, localtag = 1; /* our parent is a local tag */ elem = data1_getelementbytagname(dh, absyn, e, tag); - res = data1_mk_node (dh, m); - res->which = DATA1N_tag; + res = data1_mk_node_type (dh, m, DATA1N_tag); res->u.tag.tag = data1_insert_string (dh, res, m, tag); res->u.tag.element = elem; - res->u.tag.node_selected = 0; - res->u.tag.make_variantlist = 0; - res->u.tag.no_data_requested = 0; - res->u.tag.get_bytes = -1; +#if DATA1_USING_XATTR + res->u.tag.attributes = xattr; +#endif } if (parent) { @@ -481,9 +574,8 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, c = (*get_byte)(fh); continue; } - res = data1_mk_node(dh, m); + res = data1_mk_node_type (dh, m, DATA1N_data); res->parent = parent; - res->which = DATA1N_data; res->u.data.what = DATA1I_text; res->u.data.formatted_text = 0; res->root = parent->root; @@ -496,7 +588,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, wrbuf_rewind(wrbuf); - while (c != '<') + while (c && c != '<') { wrbuf_putc (wrbuf, c); c = (*get_byte)(fh); diff --git a/retrieval/d1_write.c b/retrieval/d1_write.c index 4d4b7b3..eb64130 100644 --- a/retrieval/d1_write.c +++ b/retrieval/d1_write.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_write.c,v $ - * Revision 1.8 1999-11-30 13:47:12 adam + * Revision 1.9 2000-11-29 14:22:47 adam + * Implemented XML/SGML attributes for data1 so that d1_read reads them + * and d1_write generates proper attributes for XML/SGML records. Added + * register locking for threaded version. + * + * Revision 1.8 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.7 1999/10/21 12:06:29 adam @@ -73,8 +78,24 @@ static int nodetoidsgml(data1_node *n, int select, WRBUF b, int col) } else { - sprintf(line, "%*s<%s>\n", col, "", tag); - wrbuf_write(b, line, strlen(line)); +#if DATA1_USING_XATTR + data1_xattr *p; +#endif + sprintf (line, "%*s<", col, ""); + wrbuf_puts (b, line); + wrbuf_puts (b, tag); +#if DATA1_USING_XATTR + for (p = c->u.tag.attributes; p; p = p->next) + { + wrbuf_putc (b, ' '); + wrbuf_puts (b, p->name); + wrbuf_putc (b, '='); + wrbuf_putc (b, '"'); + wrbuf_puts (b, p->value); + wrbuf_putc (b, '"'); + } +#endif + wrbuf_puts(b, ">\n"); if (nodetoidsgml(c, select, b, (col > 40) ? 40 : col+2) < 0) return -1; sprintf (line, "%*s\n", col, "", tag); diff --git a/server/statserv.c b/server/statserv.c index 458f664..5a2823ae0 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -7,7 +7,12 @@ * Chas Woodfield, Fretwell Downing Informatics. * * $Log: statserv.c,v $ - * Revision 1.67 2000-11-23 10:58:32 adam + * Revision 1.68 2000-11-29 14:22:47 adam + * Implemented XML/SGML attributes for data1 so that d1_read reads them + * and d1_write generates proper attributes for XML/SGML records. Added + * register locking for threaded version. + * + * Revision 1.67 2000/11/23 10:58:32 adam * SSL comstack support. Separate POSIX thread support library. * * Revision 1.66 2000/10/06 12:00:28 adam @@ -714,13 +719,11 @@ static void *new_session (void *vp) if (mask) { - yaz_log (LOG_LOG, "new_session , accept incomplete"); cs_accept_mask = mask; /* accept didn't complete */ cs_get_mask = 0; } else { - yaz_log (LOG_LOG, "new_session , accept complete"); cs_accept_mask = 0; /* accept completed. */ cs_get_mask = mask = EVENT_INPUT; } diff --git a/yaz.m4 b/yaz.m4 index bd6cf14..acad24a 100644 --- a/yaz.m4 +++ b/yaz.m4 @@ -1,4 +1,4 @@ -## $Id: yaz.m4,v 1.1 2000-10-11 10:40:56 adam Exp $ +## $Id: yaz.m4,v 1.2 2000-11-29 14:22:47 adam Exp $ ## # Use this m4 funciton for autoconf if you use YAZ in your own # configure script. @@ -29,14 +29,14 @@ AC_DEFUN([YAZ_INIT], fi AC_MSG_CHECKING(for YAZ) if $yazconfig --version >/dev/null 2>&1; then - YAZLIB=`$yazconfig --libs` + YAZLIB=`$yazconfig --libs $1` # if this is empty, it's a simple version YAZ 1.6 script # so we have to source it instead... if test "X$YAZLIB" = "X"; then . $yazconfig else - YAZLALIB=`$yazconfig --lalibs` - YAZINC=`$yazconfig --cflags` + YAZLALIB=`$yazconfig --lalibs $1` + YAZINC=`$yazconfig --cflags $1` YAZVERSION=`$yazconfig --version` fi AC_MSG_RESULT($yazconfig) -- 1.7.10.4