From 165b231b0f6eaa0b2b5fbf438f5ddede630b10e3 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 24 Sep 2002 08:05:41 +0000 Subject: [PATCH] Added several type casts for C++ compilation. ZOOM fixes. --- CHANGELOG | 6 ++ client/admin.c | 3 +- client/client.c | 35 +++++---- client/tabcomplete.c | 4 +- configure.in | 18 ++++- odr/odr.c | 4 +- odr/odr_oct.c | 10 +-- retrieval/d1_map.c | 4 +- util/siconv.c | 26 +++---- ztest/read-marc.c | 4 +- zutil/charneg.c | 6 +- zutil/pquery.c | 9 +-- zutil/zoom-c.c | 195 +++++++++++++++++++++++++++----------------------- zutil/zoom-opt.c | 6 +- 14 files changed, 189 insertions(+), 141 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index eb9b576..1294bcc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,12 @@ Possible compatibility problems with earlier versions marked with '*'. --- 1.9.1 2002/MM/DD +SGML reader parses comments and makes them part of the data1 tree. + +Added several type casts so that YAZ compiles as C++ code. + +ZOOM didn't handle PDU encoding failures properly. + Added more Bib-1 diagnostics (approved extensions). Better check for iconv. diff --git a/client/admin.c b/client/admin.c index 9db314e..b94e968 100644 --- a/client/admin.c +++ b/client/admin.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: admin.c,v 1.13 2002-09-17 11:07:30 adam Exp $ + * $Id: admin.c,v 1.14 2002-09-24 08:05:41 adam Exp $ */ #include @@ -26,6 +26,7 @@ #include +#include "admin.h" /* Helper functions to get to various statics in the client */ ODR getODROutputStream(); diff --git a/client/client.c b/client/client.c index 78e7f8a..0e3687f 100644 --- a/client/client.c +++ b/client/client.c @@ -2,12 +2,13 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.170 2002-09-17 21:19:38 adam Exp $ + * $Id: client.c,v 1.171 2002-09-24 08:05:41 adam Exp $ */ #include #include #include +#include #include @@ -106,7 +107,7 @@ int rl_attempted_completion_over = 0; #define maxOtherInfosSupported 10 struct { int oidval; - char* value; + char* value; } extraOtherInfos[maxOtherInfosSupported]; @@ -1568,7 +1569,7 @@ static int cmd_update(char *arg) if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r"))) { size_t len = status.st_size; - char *buf = xmalloc (len); + char *buf = (char *) xmalloc (len); fread (buf, 1, len, inf); @@ -1632,8 +1633,9 @@ static int cmd_update(char *arg) notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque; if (*recid) { - notToKeep->elements[0]->u.opaque = odr_malloc (out, sizeof(Odr_oct)); - notToKeep->elements[0]->u.opaque->buf = recid; + notToKeep->elements[0]->u.opaque = (Odr_oct *) + odr_malloc (out, sizeof(Odr_oct)); + notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid; notToKeep->elements[0]->u.opaque->size = strlen(recid); notToKeep->elements[0]->u.opaque->len = strlen(recid); } @@ -2538,7 +2540,7 @@ int cmd_register_oid(char* args) { {"schema",CLASS_SCHEMA}, {"tagset",CLASS_TAGSET}, {"general",CLASS_GENERAL}, - {0,0} + {0,(enum oid_class) 0} }; char oname_str[101], oclass_str[101], oid_str[101]; char* name; @@ -2860,12 +2862,22 @@ int cmd_list_otherinfo(char* args) } if(extraOtherInfos[i].oidval != -1) - printf(" otherinfo %d %s %s\n",i,yaz_z3950_oid_value_to_str(extraOtherInfos[i].oidval,CLASS_RECSYN), extraOtherInfos[i].value); + printf(" otherinfo %d %s %s\n", + i, + yaz_z3950_oid_value_to_str( + (enum oid_value) extraOtherInfos[i].oidval, + CLASS_RECSYN), + extraOtherInfos[i].value); } else { for(i=0; i @@ -80,7 +80,7 @@ void oid_loader(struct oident* oid, void* data_) char** build_list_for_oclass(oid_class oclass) { oid_callback_t data; - data.values = calloc(10,sizeof(char*)); + data.values = (char **) calloc(10,sizeof(char*)); data.index = 0; data.max = 9; data.oclass = oclass; diff --git a/configure.in b/configure.in index 55076ad..c971eff 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2002 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.91 2002-09-20 22:23:13 adam Exp $ +dnl $Id: configure.in,v 1.92 2002-09-24 08:05:41 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.9.1) dnl @@ -184,12 +184,24 @@ AC_CACHE_VAL(ac_cv_check_socklen_t,[ac_cv_check_socklen_t='' AC_TRY_COMPILE([ #include #include - extern accept(int, struct sockaddr *, socklen_t *); + #ifdef __cplusplus + extern "C" { + #endif + extern int accept(int, struct sockaddr *, socklen_t *); + #ifdef __cplusplus + } + #endif ],,[ac_cv_check_socklen_t=socklen_t],[ AC_TRY_COMPILE([ #include #include - extern accept(int, struct sockaddr *, size_t t *); + #ifdef __cplusplus + extern "C" { + #endif + extern int accept(int, struct sockaddr *, size_t t *); + #ifdef __cplusplus + } + #endif ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int]) ]) ]) diff --git a/odr/odr.c b/odr/odr.c index 6a73b62..a0f34e1 100644 --- a/odr/odr.c +++ b/odr/odr.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: odr.c,v 1.37 2002-08-28 08:12:49 adam Exp $ + * $Id: odr.c,v 1.38 2002-09-24 08:05:41 adam Exp $ * */ #if HAVE_CONFIG_H @@ -84,7 +84,7 @@ ODR odr_createmem(int direction) r->can_grow = 1; r->mem = nmem_create(); r->enable_bias = 1; - r->op = xmalloc (sizeof(*r->op)); + r->op = (struct Odr_private *) xmalloc (sizeof(*r->op)); r->op->odr_ber_tag.lclass = -1; r->op->iconv_handle = 0; odr_reset(r); diff --git a/odr/odr_oct.c b/odr/odr_oct.c index 204648c..b1c400d 100644 --- a/odr/odr_oct.c +++ b/odr/odr_oct.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_oct.c,v 1.18 2002-08-28 07:53:51 adam Exp $ + * $Id: odr_oct.c,v 1.19 2002-09-24 08:05:41 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -143,10 +143,10 @@ int odr_iconv_string(ODR o, char **p, int opt, const char *name) size_t inleft = strlen(*p); char *inbuf = *p; size_t outleft = 4 * inleft + 2; - char *outbuf = odr_malloc (o, outleft); + char *outbuf = (char *) odr_malloc (o, outleft); size_t ret; - t->buf = outbuf; + t->buf = (unsigned char *) outbuf; ret = yaz_iconv (o->op->iconv_handle, &inbuf, &inleft, &outbuf, &outleft); @@ -178,9 +178,9 @@ int odr_iconv_string(ODR o, char **p, int opt, const char *name) if (o->op->iconv_handle != 0) { size_t inleft = t->len; - char *inbuf = t->buf; + char *inbuf = (char *) t->buf; size_t outleft = 4 * inleft + 2; - char *outbuf = odr_malloc (o, outleft); + char *outbuf = (char *) odr_malloc (o, outleft); size_t ret; *p = outbuf; diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index d648e6e..d3c79e5 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_map.c,v 1.24 2002-07-29 20:04:08 adam Exp $ + * $Id: d1_map.c,v 1.25 2002-09-24 08:05:41 adam Exp $ */ #include @@ -225,7 +225,7 @@ static data1_node *dup_child (data1_handle dh, data1_node *n, for (; n; n = n->next) { - *last = *m = nmem_malloc (mem, sizeof(**m)); + *last = *m = (data1_node *) nmem_malloc (mem, sizeof(**m)); memcpy (*m, n, sizeof(**m)); (*m)->parent = parent; diff --git a/util/siconv.c b/util/siconv.c index 3b70ba6..8bbc4ed 100644 --- a/util/siconv.c +++ b/util/siconv.c @@ -2,7 +2,7 @@ * Copyright (c) 1997-2002, Index Data * See the file LICENSE for details. * - * $Id: siconv.c,v 1.4 2002-08-30 11:27:44 adam Exp $ + * $Id: siconv.c,v 1.5 2002-09-24 08:05:41 adam Exp $ */ /* mini iconv and wrapper for system iconv library (if present) */ @@ -188,7 +188,7 @@ static unsigned long yaz_read_UCS4LE (yaz_iconv_t cd, unsigned char *inp, static size_t yaz_write_UTF8 (yaz_iconv_t cd, unsigned long x, char **outbuf, size_t *outbytesleft) { - unsigned char *outp = *outbuf; + unsigned char *outp = (unsigned char *) *outbuf; if (x <= 0x7f && *outbytesleft >= 1) { *outp++ = (unsigned char) x; @@ -239,14 +239,14 @@ static size_t yaz_write_UTF8 (yaz_iconv_t cd, unsigned long x, cd->my_errno = YAZ_ICONV_E2BIG; /* not room for output */ return (size_t)(-1); } - *outbuf = outp; + *outbuf = (char *) outp; return 0; } static size_t yaz_write_ISO8859_1 (yaz_iconv_t cd, unsigned long x, char **outbuf, size_t *outbytesleft) { - unsigned char *outp = *outbuf; + unsigned char *outp = (unsigned char *) *outbuf; if (x > 255 || x < 1) { cd->my_errno = YAZ_ICONV_EILSEQ; @@ -262,7 +262,7 @@ static size_t yaz_write_ISO8859_1 (yaz_iconv_t cd, unsigned long x, cd->my_errno = YAZ_ICONV_E2BIG; return (size_t)(-1); } - *outbuf = outp; + *outbuf = (char *) outp; return 0; } @@ -270,7 +270,7 @@ static size_t yaz_write_ISO8859_1 (yaz_iconv_t cd, unsigned long x, static size_t yaz_write_UCS4 (yaz_iconv_t cd, unsigned long x, char **outbuf, size_t *outbytesleft) { - unsigned char *outp = *outbuf; + unsigned char *outp = (unsigned char *) *outbuf; if (*outbytesleft >= 4) { *outp++ = (unsigned char) (x<<24); @@ -284,14 +284,14 @@ static size_t yaz_write_UCS4 (yaz_iconv_t cd, unsigned long x, cd->my_errno = YAZ_ICONV_E2BIG; return (size_t)(-1); } - *outbuf = outp; + *outbuf = (char *) outp; return 0; } static size_t yaz_write_UCS4LE (yaz_iconv_t cd, unsigned long x, char **outbuf, size_t *outbytesleft) { - unsigned char *outp = *outbuf; + unsigned char *outp = (unsigned char *) *outbuf; if (*outbytesleft >= 4) { *outp++ = (unsigned char) x; @@ -305,13 +305,13 @@ static size_t yaz_write_UCS4LE (yaz_iconv_t cd, unsigned long x, cd->my_errno = YAZ_ICONV_E2BIG; return (size_t)(-1); } - *outbuf = outp; + *outbuf = (char *) outp; return 0; } yaz_iconv_t yaz_iconv_open (const char *tocode, const char *fromcode) { - yaz_iconv_t cd = xmalloc (sizeof(*cd)); + yaz_iconv_t cd = (yaz_iconv_t) xmalloc (sizeof(*cd)); cd->write_handle = 0; cd->read_handle = 0; @@ -404,7 +404,8 @@ size_t yaz_iconv (yaz_iconv_t cd, char **inbuf, size_t *inbytesleft, if (cd->init_handle) { size_t no_read; - size_t r = (cd->init_handle)(cd, *inbuf, *inbytesleft, &no_read); + size_t r = (cd->init_handle)(cd, (unsigned char *) *inbuf, + *inbytesleft, &no_read); if (r) { if (cd->my_errno == YAZ_ICONV_EINVAL) @@ -428,7 +429,8 @@ size_t yaz_iconv (yaz_iconv_t cd, char **inbuf, size_t *inbytesleft, break; } - x = (cd->read_handle)(cd, *inbuf, *inbytesleft, &no_read); + x = (cd->read_handle)(cd, (unsigned char *) *inbuf, *inbytesleft, + &no_read); if (no_read == 0) { r = (size_t)(-1); diff --git a/ztest/read-marc.c b/ztest/read-marc.c index 9f90f82..6333a40 100644 --- a/ztest/read-marc.c +++ b/ztest/read-marc.c @@ -2,7 +2,7 @@ * Copyright (c) 2002, Index Data. * See the file LICENSE for details. * - * $Id: read-marc.c,v 1.2 2002-03-19 13:48:27 adam Exp $ + * $Id: read-marc.c,v 1.3 2002-09-24 08:05:41 adam Exp $ */ /* @@ -1610,7 +1610,7 @@ char *dummy_xml_record (int num, ODR odr) if (len > 1) { len = wrbuf_len(wr); - rec = odr_malloc (odr, len+1); + rec = (char *) odr_malloc (odr, len+1); memcpy (rec, wrbuf_buf(wr), len+1); rec[len] = 0; } diff --git a/zutil/charneg.c b/zutil/charneg.c index f8a5fd0..d4a9383 100644 --- a/zutil/charneg.c +++ b/zutil/charneg.c @@ -1,5 +1,5 @@ /* - $ $Id: charneg.c,v 1.4 2002-07-25 12:50:17 adam Exp $ + $ $Id: charneg.c,v 1.5 2002-09-24 08:05:42 adam Exp $ * Helper functions for Character Set and Language Negotiation - 3 */ @@ -20,8 +20,8 @@ static Z_External* z_ext_record2(ODR o, int oid_class, int oid_value, p->indirect_reference = 0; oid.proto = PROTO_Z3950; - oid.oclass = oid_class; - oid.value = oid_value; + oid.oclass = (enum oid_class) oid_class; + oid.value = (enum oid_value) oid_value; p->direct_reference = odr_oiddup(o, oid_getoidbyent(&oid)); p->which = Z_External_octet; diff --git a/zutil/pquery.c b/zutil/pquery.c index 2ced379..3d938ce 100644 --- a/zutil/pquery.c +++ b/zutil/pquery.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * - * $Id: pquery.c,v 1.17 2002-09-02 13:59:07 adam Exp $ + * $Id: pquery.c,v 1.18 2002-09-24 08:05:42 adam Exp $ */ #include @@ -324,11 +324,12 @@ static Z_AttributesPlusTerm *rpn_term (struct yaz_pqf_parser *li, ODR o, break; case Z_Term_characterString: term->which = Z_Term_characterString; - term->u.characterString = term_octet->buf; /* null terminated above */ + term->u.characterString = (char*) term_octet->buf; + /* null terminated above */ break; case Z_Term_numeric: term->which = Z_Term_numeric; - term->u.numeric = odr_intdup (o, atoi(term_octet->buf)); + term->u.numeric = odr_intdup (o, atoi((char*) (term_octet->buf))); break; case Z_Term_null: term->which = Z_Term_null; @@ -743,7 +744,7 @@ int p_query_attset (const char *arg) YAZ_PQF_Parser yaz_pqf_create (void) { - YAZ_PQF_Parser p = xmalloc (sizeof(*p)); + YAZ_PQF_Parser p = (YAZ_PQF_Parser) xmalloc (sizeof(*p)); p->error = 0; p->left_sep = "{\""; diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 58a51bf..b220b01 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.1 2002-09-16 18:45:14 adam Exp $ + * $Id: zoom-c.c,v 1.2 2002-09-24 08:05:42 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -18,8 +18,14 @@ #include #endif -static int ZOOM_connection_send_init (ZOOM_connection c); -static int do_write_ex (ZOOM_connection c, char *buf_out, int len_out); +typedef enum { + zoom_pending, + zoom_complete +} zoom_ret; + + +static zoom_ret ZOOM_connection_send_init (ZOOM_connection c); +static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out); static ZOOM_Event ZOOM_Event_create (int kind) { @@ -376,7 +382,7 @@ ZOOM_query_sortby(ZOOM_query s, const char *criteria) return 0; } -static int do_write(ZOOM_connection c); +static zoom_ret do_write(ZOOM_connection c); ZOOM_API(void) ZOOM_connection_destroy(ZOOM_connection c) @@ -408,12 +414,17 @@ ZOOM_connection_destroy(ZOOM_connection c) void ZOOM_resultset_addref (ZOOM_resultset r) { if (r) + { (r->refcount)++; + yaz_log (LOG_DEBUG, "ZOOM_resultset_addref r=%p count=%d", + r, r->refcount); + } } ZOOM_resultset ZOOM_resultset_create () { ZOOM_resultset r = (ZOOM_resultset) xmalloc (sizeof(*r)); + yaz_log (LOG_DEBUG, "ZOOM_resultset_create r = %p", r); r->refcount = 1; r->size = 0; r->odr = odr_createmem (ODR_ENCODE); @@ -488,7 +499,8 @@ ZOOM_resultset_destroy(ZOOM_resultset r) if (!r) return; (r->refcount)--; - yaz_log (LOG_DEBUG, "destroy r = %p count=%d", r, r->refcount); + yaz_log (LOG_DEBUG, "ZOOM_resultset_destroy r = %p count=%d", + r, r->refcount); if (r->refcount == 0) { ZOOM_record_cache rc; @@ -576,7 +588,7 @@ ZOOM_resultset_records (ZOOM_resultset r, ZOOM_record *recs, } } -static int do_connect (ZOOM_connection c) +static zoom_ret do_connect (ZOOM_connection c) { void *add; const char *effective_host; @@ -600,7 +612,7 @@ static int do_connect (ZOOM_connection c) ZOOM_connection_put_event(c, event); ZOOM_connection_send_init(c); c->state = STATE_ESTABLISHED; - return 1; + return zoom_pending; } else if (ret > 0) { @@ -610,12 +622,12 @@ static int do_connect (ZOOM_connection c) c->mask += ZOOM_SELECT_WRITE; if (c->cs->io_pending & CS_WANT_READ) c->mask += ZOOM_SELECT_READ; - return 1; + return zoom_pending; } } c->state = STATE_IDLE; c->error = ZOOM_ERROR_CONNECT; - return 0; + return zoom_complete; } int z3950_connection_socket(ZOOM_connection c) @@ -692,29 +704,33 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) z_APDU(odr_pr, &a, 0, 0); odr_destroy(odr_pr); } + yaz_log (LOG_DEBUG, "encoding failed"); c->error = ZOOM_ERROR_ENCODE; - do_close (c); + odr_reset(out); return -1; } return 0; } -static int send_APDU (ZOOM_connection c, Z_APDU *a) +static zoom_ret send_APDU (ZOOM_connection c, Z_APDU *a) { ZOOM_Event event; assert (a); if (encode_APDU(c, a, c->odr_out)) - return -1; + return zoom_complete; c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0); event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU); ZOOM_connection_put_event (c, event); odr_reset(c->odr_out); - do_write (c); - return 0; + return do_write (c); } -static int ZOOM_connection_send_init (ZOOM_connection c) +/* returns 1 if PDU was sent OK (still pending ) + 0 if PDU was not sent OK (nothing to wait for) +*/ + +static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) { const char *impname; Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_initRequest); @@ -818,12 +834,10 @@ static int ZOOM_connection_send_init (ZOOM_connection c) } } assert (apdu); - send_APDU (c, apdu); - - return 0; + return send_APDU (c, apdu); } -static int ZOOM_connection_send_search (ZOOM_connection c) +static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) { ZOOM_resultset r; int lslb, ssub, mspn; @@ -934,7 +948,7 @@ static int ZOOM_connection_send_search (ZOOM_connection c) break; } r->setname = xstrdup (setname); - yaz_log (LOG_DEBUG, "allocating %s", r->setname); + yaz_log (LOG_DEBUG, "allocating set %s", r->setname); } else r->setname = xstrdup ("default"); @@ -942,8 +956,7 @@ static int ZOOM_connection_send_search (ZOOM_connection c) } search_req->resultSetName = odr_strdup(c->odr_out, r->setname); /* send search request */ - send_APDU (c, apdu); - return 1; + return send_APDU (c, apdu); } static void response_diag (ZOOM_connection c, Z_DiagRec *p) @@ -1372,19 +1385,19 @@ static int scan_response (ZOOM_connection c, Z_ScanResponse *res) return 1; } -static int send_sort (ZOOM_connection c) +static zoom_ret send_sort (ZOOM_connection c) { ZOOM_resultset resultset; if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH) - return 0; + return zoom_complete; resultset = c->tasks->u.search.resultset; if (c->error) { resultset->r_sort_spec = 0; - return 0; + return zoom_complete; } if (resultset->r_sort_spec) { @@ -1399,13 +1412,12 @@ static int send_sort (ZOOM_connection c) req->sortedResultSetName = odr_strdup (c->odr_out, resultset->setname); req->sortSequence = resultset->r_sort_spec; resultset->r_sort_spec = 0; - send_APDU (c, apdu); - return 1; + return send_APDU (c, apdu); } - return 0; + return zoom_complete; } -static int send_present (ZOOM_connection c) +static zoom_ret send_present (ZOOM_connection c) { Z_APDU *apdu = 0; Z_PresentRequest *req = 0; @@ -1416,7 +1428,7 @@ static int send_present (ZOOM_connection c) ZOOM_resultset resultset; if (!c->tasks) - return 0; + return zoom_complete; switch (c->tasks->which) { @@ -1429,12 +1441,12 @@ static int send_present (ZOOM_connection c) resultset->count = c->tasks->u.retrieve.count; if (resultset->start >= resultset->size) - return 0; + return zoom_complete; if (resultset->start + resultset->count > resultset->size) resultset->count = resultset->size - resultset->start; break; default: - return 0; + return zoom_complete; } syntax = ZOOM_resultset_option_get (resultset, "preferredRecordSyntax"); @@ -1442,9 +1454,9 @@ static int send_present (ZOOM_connection c) schema = ZOOM_resultset_option_get (resultset, "schema"); if (c->error) /* don't continue on error */ - return 0; + return zoom_complete; if (resultset->start < 0) - return 0; + return zoom_complete; for (i = 0; icount; i++) { ZOOM_record rec = @@ -1453,7 +1465,7 @@ static int send_present (ZOOM_connection c) break; } if (i == resultset->count) - return 0; + return zoom_complete; apdu = zget_APDU(c->odr_out, Z_APDU_presentRequest); req = apdu->u.presentRequest; @@ -1524,8 +1536,7 @@ static int send_present (ZOOM_connection c) req->recordComposition = compo; } req->resultSetId = odr_strdup(c->odr_out, resultset->setname); - send_APDU (c, apdu); - return 1; + return send_APDU (c, apdu); } ZOOM_API(ZOOM_scanset) @@ -1571,28 +1582,27 @@ ZOOM_scanset_destroy (ZOOM_scanset scan) } } -static int send_package (ZOOM_connection c) +static zoom_ret send_package (ZOOM_connection c) { ZOOM_Event event; if (!c->tasks) - return 0; + return zoom_complete; assert (c->tasks->which == ZOOM_TASK_PACKAGE); - + event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU); ZOOM_connection_put_event (c, event); - - do_write_ex (c, c->tasks->u.package->buf_out, - c->tasks->u.package->len_out); - return 1; + + return do_write_ex (c, c->tasks->u.package->buf_out, + c->tasks->u.package->len_out); } -static int send_scan (ZOOM_connection c) +static zoom_ret send_scan (ZOOM_connection c) { ZOOM_scanset scan; Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_scanRequest); Z_ScanRequest *req = apdu->u.scanRequest; if (!c->tasks) - return 0; + return zoom_complete; assert (c->tasks->which == ZOOM_TASK_SCAN); scan = c->tasks->u.scan.scan; @@ -1613,9 +1623,7 @@ static int send_scan (ZOOM_connection c) req->databaseNames = set_DatabaseNames (c, scan->options, &req->num_databaseNames); - send_APDU (c, apdu); - - return 1; + return send_APDU (c, apdu); } ZOOM_API(size_t) @@ -1665,8 +1673,6 @@ ZOOM_scanset_option_set (ZOOM_scanset scan, const char *key, ZOOM_options_set (scan->options, key, val); } - - static Z_APDU *create_es_package (ZOOM_package p, int type) { const char *str; @@ -1744,7 +1750,8 @@ static Z_External *encode_ill_request (ZOOM_package p) r->u.single_ASN1_type = (Odr_oct *) odr_malloc (out, sizeof(*r->u.single_ASN1_type)); - r->u.single_ASN1_type->buf = odr_malloc (out, illRequest_size); + r->u.single_ASN1_type->buf = (unsigned char*) + odr_malloc (out, illRequest_size); r->u.single_ASN1_type->len = illRequest_size; r->u.single_ASN1_type->size = illRequest_size; memcpy (r->u.single_ASN1_type->buf, illRequest_buf, illRequest_size); @@ -1754,7 +1761,7 @@ static Z_External *encode_ill_request (ZOOM_package p) static Z_ItemOrder *encode_item_order(ZOOM_package p) { - Z_ItemOrder *req = odr_malloc (p->odr_out, sizeof(*req)); + Z_ItemOrder *req = (Z_ItemOrder *) odr_malloc (p->odr_out, sizeof(*req)); const char *str; req->which=Z_IOItemOrder_esRequest; @@ -1765,7 +1772,7 @@ static Z_ItemOrder *encode_item_order(ZOOM_package p) req->u.esRequest->toKeep = (Z_IOOriginPartToKeep *) odr_malloc(p->odr_out,sizeof(Z_IOOriginPartToKeep)); req->u.esRequest->toKeep->supplDescription = 0; - req->u.esRequest->toKeep->contact = + req->u.esRequest->toKeep->contact = (Z_IOContact *) odr_malloc (p->odr_out, sizeof(*req->u.esRequest->toKeep->contact)); str = ZOOM_options_get(p->options, "contact-name"); @@ -1823,7 +1830,7 @@ ZOOM_API(void) apdu = create_es_package (p, VAL_ITEMORDER); if (apdu) { - r = odr_malloc (p->odr_out, sizeof(*r)); + r = (Z_External *) odr_malloc (p->odr_out, sizeof(*r)); r->direct_reference = yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV, @@ -1845,7 +1852,7 @@ ZOOM_API(void) ZOOM_task task = ZOOM_connection_add_task (c, ZOOM_TASK_PACKAGE); task->u.package = p; buf = odr_getbuf(p->odr_out, &p->len_out, 0); - p->buf_out = xmalloc (p->len_out); + p->buf_out = (char *) xmalloc (p->len_out); memcpy (p->buf_out, buf, p->len_out); (p->refcount)++; @@ -1904,52 +1911,60 @@ ZOOM_package_option_set (ZOOM_package p, const char *key, static int ZOOM_connection_exec_task (ZOOM_connection c) { ZOOM_task task = c->tasks; + zoom_ret ret = zoom_complete; - yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task"); if (!task) - return 0; - if (c->error != ZOOM_ERROR_NONE || - (!c->cs && task->which != ZOOM_TASK_CONNECT)) { - ZOOM_connection_remove_tasks (c); + yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task task="); return 0; } yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task type=%d run=%d", task->which, task->running); + if (c->error != ZOOM_ERROR_NONE || + (!c->cs && task->which != ZOOM_TASK_CONNECT)) + { + yaz_log (LOG_DEBUG, "remove tasks because of error = %d", c->error); + ZOOM_connection_remove_tasks (c); + return 0; + } if (task->running) + { + yaz_log (LOG_DEBUG, "task already running"); return 0; + } task->running = 1; switch (task->which) { case ZOOM_TASK_SEARCH: - /* see if search hasn't been sent yet. */ - if (ZOOM_connection_send_search (c)) - return 1; + ret = ZOOM_connection_send_search (c); break; case ZOOM_TASK_RETRIEVE: - if (send_present (c)) - return 1; + ret = send_present (c); break; case ZOOM_TASK_CONNECT: - if (do_connect(c)) - return 1; + ret = do_connect(c); break; case ZOOM_TASK_SCAN: - if (send_scan(c)) - return 1; + ret = send_scan(c); break; case ZOOM_TASK_PACKAGE: - if (send_package(c)) - return 1; + ret = send_package(c); + break; } - ZOOM_connection_remove_task (c); - return 0; + if (ret == zoom_complete) + { + yaz_log (LOG_DEBUG, "task removed (complete)"); + ZOOM_connection_remove_task (c); + return 0; + } + yaz_log (LOG_DEBUG, "task pending"); + return 1; } -static int send_sort_present (ZOOM_connection c) +static zoom_ret send_sort_present (ZOOM_connection c) { - int r = send_sort (c); - if (!r) + zoom_ret r = send_sort (c); + if (r == zoom_complete) r = send_present (c); return r; } @@ -1969,7 +1984,7 @@ static int es_response (ZOOM_connection c, if (id) ZOOM_options_setl (c->tasks->u.package->options, - "targetReference", id->buf, id->len); + "targetReference", (char*) id->buf, id->len); } return 1; } @@ -1980,7 +1995,7 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) Z_InitResponse *initrs; c->mask = 0; - yaz_log (LOG_DEBUG, "hande_apdu type=%d", apdu->which); + yaz_log (LOG_DEBUG, "handle_apdu type=%d", apdu->which); switch(apdu->which) { case Z_APDU_initResponse: @@ -2017,12 +2032,12 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) if (p) { char *charset=NULL, *lang=NULL; - int selected; + int sel; - yaz_get_response_charneg(tmpmem, p, &charset, &lang, &selected); + yaz_get_response_charneg(tmpmem, p, &charset, &lang, &sel); yaz_log(LOG_DEBUG, "Target accepted: charset - %s," "language - %s, select - %d", - charset, lang, selected); + charset, lang, sel); nmem_destroy(tmpmem); } @@ -2030,17 +2045,17 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) break; case Z_APDU_searchResponse: handle_search_response (c, apdu->u.searchResponse); - if (!send_sort_present (c)) + if (send_sort_present (c) == zoom_complete) ZOOM_connection_remove_task (c); break; case Z_APDU_presentResponse: handle_present_response (c, apdu->u.presentResponse); - if (!send_present (c)) + if (send_present (c) == zoom_complete) ZOOM_connection_remove_task (c); break; case Z_APDU_sortResponse: sort_response (c, apdu->u.sortResponse); - if (!send_present (c)) + if (send_present (c) == zoom_complete) ZOOM_connection_remove_task (c); break; case Z_APDU_scanResponse: @@ -2119,7 +2134,7 @@ static int do_read (ZOOM_connection c) return 1; } -static int do_write_ex (ZOOM_connection c, char *buf_out, int len_out) +static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out) { int r; ZOOM_Event event; @@ -2137,14 +2152,14 @@ static int do_write_ex (ZOOM_connection c, char *buf_out, int len_out) yaz_log (LOG_DEBUG, "reconnect write"); c->tasks->running = 0; ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT); - return 0; + return zoom_complete; } if (c->state == STATE_CONNECTING) c->error = ZOOM_ERROR_CONNECT; else c->error = ZOOM_ERROR_CONNECTION_LOST; do_close (c); - return 1; + return zoom_complete; } else if (r == 1) { @@ -2161,10 +2176,10 @@ static int do_write_ex (ZOOM_connection c, char *buf_out, int len_out) c->mask = ZOOM_SELECT_READ|ZOOM_SELECT_EXCEPT; yaz_log (LOG_DEBUG, "do_write_ex 2 mask=%d", c->mask); } - return 0; + return zoom_pending; } -static int do_write(ZOOM_connection c) +static zoom_ret do_write(ZOOM_connection c) { return do_write_ex (c, c->buf_out, c->len_out); } diff --git a/zutil/zoom-opt.c b/zutil/zoom-opt.c index be0edd3..9e789b6 100644 --- a/zutil/zoom-opt.c +++ b/zutil/zoom-opt.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-opt.c,v 1.1 2002-09-16 18:45:14 adam Exp $ + * $Id: zoom-opt.c,v 1.2 2002-09-24 08:05:42 adam Exp $ * * ZOOM layer for C, options handling */ @@ -101,7 +101,7 @@ ZOOM_options_setl (ZOOM_options opt, const char *name, const char *value, (*e)->value = 0; if (value) { - (*e)->value = xmalloc (len+1); + (*e)->value = (char *) xmalloc (len+1); memcpy ((*e)->value, value, len); (*e)->value[len] = '\0'; } @@ -114,7 +114,7 @@ ZOOM_options_setl (ZOOM_options opt, const char *name, const char *value, (*e)->value = 0; if (value) { - (*e)->value = xmalloc (len+1); + (*e)->value = (char *) xmalloc (len+1); memcpy ((*e)->value, value, len); (*e)->value[len] = '\0'; } -- 1.7.10.4