From ec1f815d5348cd21e393f76bc212c910c34bbc45 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 May 2003 19:55:29 +0000 Subject: [PATCH] Better ODR diagnostics for missing elements which includes additional info with name of element. New ODR function odr_missing. Removed depricated macros odr_implicit and odr_explicit. --- client/admin.h | 4 ++-- client/client.c | 17 +++++++++-------- doc/odr.xml | 13 +++++++------ include/yaz/odr.h | 17 ++++++----------- odr/Makefile.am | 4 ++-- odr/ber_tag.c | 19 +++++++++++++++++-- odr/odr-priv.h | 3 ++- odr/odr.c | 22 +++++++++++++++++++--- odr/odr_any.c | 8 +++----- odr/odr_bit.c | 6 +++--- odr/odr_bool.c | 6 +++--- odr/odr_cons.c | 4 ++-- odr/odr_enum.c | 6 +++--- odr/odr_int.c | 6 +++--- odr/odr_null.c | 6 +++--- odr/odr_oct.c | 14 +++++++------- odr/odr_oid.c | 6 +++--- odr/odr_use.c | 4 ++-- odr/odr_util.c | 15 +++++++++++++-- odr/tstodr.c | 37 ++++++++++++++++++++++++++++++++++--- util/yaz-comp | 22 +++++++++++----------- z39.50/z.tcl | 6 +++--- 22 files changed, 157 insertions(+), 88 deletions(-) diff --git a/client/admin.h b/client/admin.h index c44f70d..f692cf4 100644 --- a/client/admin.h +++ b/client/admin.h @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: admin.h,v 1.6 2003-03-11 11:07:47 adam Exp $ + * $Id: admin.h,v 1.7 2003-05-20 19:55:29 adam Exp $ */ int cmd_adm_reindex(const char* arg); @@ -15,7 +15,7 @@ int cmd_adm_commit(const char* arg); int cmd_adm_shutdown(const char* arg); int cmd_adm_startup(const char* arg); -void send_apdu(Z_APDU *a); +int send_apdu(Z_APDU *a); /* * Local variables: * tab-width: 8 diff --git a/client/client.c b/client/client.c index 5aeb19e..2b314f5 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.193 2003-05-19 20:44:33 adam Exp $ + * $Id: client.c,v 1.194 2003-05-20 19:55:29 adam Exp $ */ #include @@ -183,7 +183,7 @@ void add_otherInfos(Z_APDU *a) } } -void send_apdu(Z_APDU *a) +int send_apdu(Z_APDU *a) { char *buf; int len; @@ -199,7 +199,7 @@ void send_apdu(Z_APDU *a) { odr_perror(out, "Encoding APDU"); close_session(); - return; + return 0; } buf = odr_getbuf(out, &len, 0); if (ber_file) @@ -209,10 +209,11 @@ void send_apdu(Z_APDU *a) { fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn))); close_session(); - return; + return 0; } do_hex_dump(buf,len); odr_reset(out); /* release the APDU structure */ + return 1; } static void print_stringn(const unsigned char *buf, size_t len) @@ -297,8 +298,8 @@ static void send_initRequest(const char* type_and_host) } } - send_apdu(apdu); - printf("Sent initrequest.\n"); + if (send_apdu(apdu)) + printf("Sent initrequest.\n"); } static int process_initResponse(Z_InitResponse *res) @@ -1138,9 +1139,9 @@ static int send_searchRequest(const char *arg) printf ("Unsupported query type\n"); return 0; } - send_apdu(apdu); + if (send_apdu(apdu)) + printf("Sent searchRequest.\n"); setno = 1; - printf("Sent searchRequest.\n"); return 2; } diff --git a/doc/odr.xml b/doc/odr.xml index 820fa26..8b1cc4f 100644 --- a/doc/odr.xml +++ b/doc/odr.xml @@ -1,4 +1,4 @@ - + The ODR Module Introduction @@ -744,8 +744,8 @@ int myInt(ODR o, int **p, int optional, const char *name) The function myInt() can then be used like any of the primitive functions provided by &odr;. Note that the behavior of - odr_explicit() - and odr_implicit() macros + odr_explicit_tag() + and odr_implicit_tag() macros act exactly the same as the functions they are applied to - they respond to error conditions, etc, in the same manner - they simply have three extra parameters. The class parameter may @@ -826,7 +826,8 @@ int mySequence(ODR o, MySequence **p, int optional, const char *name) Note the 1 in the call to odr_bool(), to mark that the sequence member is optional. If either of the member types had been tagged, the macros - odr_implicit() or odr_explicit() + odr_implicit_tag() or + odr_explicit_tag() could have been used. The new function can be used exactly like the standard functions provided with &odr;. It will encode, decode or pretty-print a data value of the @@ -874,7 +875,7 @@ int odr_implicit_settag(ODR o, int class, int tag); which overrides the tag of the type immediately following it. The - macro odr_implicit() works by calling + macro odr_implicit_tag() works by calling odr_implicit_settag() immediately before calling the function pointer argument. Your type function could look like this: @@ -964,7 +965,7 @@ int mySequence(ODR o, MySequence **p, int optional, const char *name) interface) is less than the time that would be required to develop a better interface. Nevertheless, it is far from satisfying, and it's a point that will be worked on in the future. One option for you would - be to simply apply the odr_explicit() macro to + be to simply apply the odr_explicit_tag() macro to the first function, and not have to worry about odr_constructed_* yourself. Incidentally, as you might have guessed, the diff --git a/include/yaz/odr.h b/include/yaz/odr.h index bfd4d35..f4a0c26 100644 --- a/include/yaz/odr.h +++ b/include/yaz/odr.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: odr.h,v 1.10 2003-03-18 13:34:35 adam Exp $ + * $Id: odr.h,v 1.11 2003-05-20 19:55:29 adam Exp $ */ #ifndef ODR_H @@ -185,6 +185,8 @@ extern char *odr_errlist[]; YAZ_EXPORT int odr_geterror(ODR o); YAZ_EXPORT int odr_geterrorx(ODR o, int *x); YAZ_EXPORT void odr_seterror(ODR o, int errorno, int errorid); +YAZ_EXPORT void odr_setaddinfo(ODR o, const char *addinfo); +YAZ_EXPORT char *odr_getaddinfo(ODR o); YAZ_EXPORT void odr_perror(ODR o, char *message); YAZ_EXPORT void odr_setprint(ODR o, FILE *file); YAZ_EXPORT ODR odr_createmem(int direction); @@ -201,21 +203,13 @@ YAZ_EXPORT Odr_null *odr_nullval(void); #define odr_release_mem(m) nmem_destroy(m) #define ODR_MEM NMEM -#define odr_implicit(o, t, p, cl, tg, opt)\ - (odr_implicit_settag((o), cl, tg), t ((o), (p), (opt), 0) ) - #define odr_implicit_tag(o, t, p, cl, tg, opt, name)\ (odr_implicit_settag((o), cl, tg), t ((o), (p), (opt), name) ) -#define odr_explicit(o, t, p, cl, tg, opt)\ - ((int) (odr_constructed_begin((o), (p), (cl), (tg), 0) ? \ - t ((o), (p), (opt), 0) &&\ - odr_constructed_end(o) : opt)) - #define odr_explicit_tag(o, t, p, cl, tg, opt, name)\ ((int) (odr_constructed_begin((o), (p), (cl), (tg), 0) ? \ t ((o), (p), (opt), name) &&\ - odr_constructed_end(o) : opt)) + odr_constructed_end(o) : odr_missing((o), opt, name))) #define ODR_MASK_ZERO(mask)\ ((void) (memset((mask)->bits, 0, ODR_BITMASK_SIZE),\ @@ -242,7 +236,7 @@ YAZ_EXPORT Odr_null *odr_nullval(void); YAZ_EXPORT int ber_boolean(ODR o, int *val); YAZ_EXPORT int ber_tag(ODR o, void *p, int zclass, int tag, - int *constructed, int opt); + int *constructed, int opt, const char *name); YAZ_EXPORT int ber_enctag(ODR o, int zclass, int tag, int constructed); YAZ_EXPORT int ber_dectag(const unsigned char *buf, int *zclass, int *tag, int *constructed, int max); @@ -302,6 +296,7 @@ YAZ_EXPORT Odr_oid *odr_getoidbystr_nmem(NMEM o, const char *str); YAZ_EXPORT int odr_initmember(ODR o, void *p, int size); YAZ_EXPORT int odr_peektag(ODR o, int *zclass, int *tag, int *cons); YAZ_EXPORT void odr_setlenlen(ODR o, int len); +YAZ_EXPORT int odr_missing(ODR o, int opt, const char *name); typedef struct Odr_external { diff --git a/odr/Makefile.am b/odr/Makefile.am index 47d8321..eb074bc 100644 --- a/odr/Makefile.am +++ b/odr/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.8 2003-05-06 10:08:30 adam Exp $ +## $Id: Makefile.am,v 1.9 2003-05-20 19:55:29 adam Exp $ noinst_LTLIBRARIES = libodr.la @@ -14,7 +14,7 @@ tstodr_LDADD = libodr.la ../util/libutil.la tstodr_SOURCES = tstodr.c tstodrcodec.c tstodrcodec.h # Rule for generating codecs for our small ASN.1 spec -tstodrcodec.c tstodrcodec.h: $(srcdir)/tstodr.asn +tstodrcodec.c tstodrcodec.h: $(srcdir)/tstodr.asn $(top_srcdir)/util/yaz-comp cd $(srcdir); $(top_srcdir)/util/yaz-comp tstodr.asn libodr_la_SOURCES = odr_bool.c ber_bool.c ber_len.c ber_tag.c odr_util.c \ diff --git a/odr/ber_tag.c b/odr/ber_tag.c index 0df6014..8c3e186 100644 --- a/odr/ber_tag.c +++ b/odr/ber_tag.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: ber_tag.c,v 1.25 2003-03-11 11:03:31 adam Exp $ + * $Id: ber_tag.c,v 1.26 2003-05-20 19:55:29 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -22,7 +22,8 @@ * * Should perhaps be odr_tag? */ -int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) +int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt, + const char *name) { struct Odr_ber_tag *odr_ber_tag = &o->op->odr_ber_tag; int rd; @@ -44,7 +45,10 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) if (!*pp) { if (!opt) + { odr_seterror(o, OREQUIRED, 24); + odr_setaddinfo (o, name); + } return 0; } if ((rd = ber_enctag(o, zclass, tag, *constructed)) < 0) @@ -59,7 +63,10 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) if (o->op->stackp > -1 && !odr_constructed_more(o)) { if (!opt) + { odr_seterror(o, OREQUIRED, 25); + odr_setaddinfo(o, name); + } return 0; } if (odr_ber_tag->lclass < 0) @@ -70,6 +77,7 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) odr_max(o))) <= 0) { odr_seterror(o, OPROTO, 26); + odr_setaddinfo(o, name); return 0; } #ifdef ODR_DEBUG @@ -89,15 +97,22 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) else { if (!opt) + { odr_seterror(o, OREQUIRED, 27); + odr_setaddinfo(o, name); + } return 0; } case ODR_PRINT: if (!*pp && !opt) + { odr_seterror(o,OREQUIRED, 28); + odr_setaddinfo(o, name); + } return *pp != 0; default: odr_seterror(o, OOTHER, 29); + odr_setaddinfo(o, name); return 0; } } diff --git a/odr/odr-priv.h b/odr/odr-priv.h index 01b1a4f..fef7455 100644 --- a/odr/odr-priv.h +++ b/odr/odr-priv.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: odr-priv.h,v 1.4 2003-03-11 11:03:31 adam Exp $ + * $Id: odr-priv.h,v 1.5 2003-05-20 19:55:29 adam Exp $ */ #ifndef ODR_PRIV_H @@ -52,6 +52,7 @@ struct Odr_private { struct Odr_ber_tag odr_ber_tag; yaz_iconv_t iconv_handle; int error_id; + char addinfo[80]; }; /* Private macro. diff --git a/odr/odr.c b/odr/odr.c index 948043c..a29f720 100644 --- a/odr/odr.c +++ b/odr/odr.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: odr.c,v 1.42 2003-05-19 14:37:38 adam Exp $ + * $Id: odr.c,v 1.43 2003-05-20 19:55:29 adam Exp $ * */ #if HAVE_CONFIG_H @@ -36,7 +36,7 @@ char *odr_errlist[] = "Stack overflow", "Length of constructed type different from sum of members", "Overflow writing definite length of constructed type", - "HTTP Bad Request" + "Bad HTTP Request" }; char *odr_errmsg(int n) @@ -46,7 +46,8 @@ char *odr_errmsg(int n) void odr_perror(ODR o, char *message) { - fprintf(stderr, "%s: %s\n", message, odr_errlist[o->error]); + fprintf(stderr, "%s: %s: %s\n", message, odr_errlist[o->error], + odr_getaddinfo(o)); } int odr_geterror(ODR o) @@ -61,10 +62,25 @@ int odr_geterrorx(ODR o, int *x) return o->error; } +char *odr_getaddinfo(ODR o) +{ + return o->op->addinfo; +} + void odr_seterror(ODR o, int error, int id) { o->error = error; o->op->error_id = id; + o->op->addinfo[0] = '\0'; +} + +void odr_setaddinfo(ODR o, const char *addinfo) +{ + if (addinfo) + { + strncpy(o->op->addinfo, addinfo, sizeof(o->op->addinfo)-1); + o->op->addinfo[sizeof(o->op->addinfo)-1] = '\0'; + } } void odr_setprint(ODR o, FILE *file) diff --git a/odr/odr_any.c b/odr/odr_any.c index 0def5ee..e464872 100644 --- a/odr/odr_any.c +++ b/odr/odr_any.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_any.c,v 1.13 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_any.c,v 1.14 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -32,7 +32,5 @@ int odr_any(ODR o, Odr_any **p, int opt, const char *name) if (ber_any(o, p)) return 1; *p = 0; - if (!opt) - odr_seterror(o, OREQUIRED, 53); - return opt; -} + return odr_missing(o, opt, name); +} diff --git a/odr/odr_bit.c b/odr/odr_bit.c index 5cae833..07d0647 100644 --- a/odr/odr_bit.c +++ b/odr/odr_bit.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_bit.c,v 1.17 2003-04-24 12:48:47 adam Exp $ + * $Id: odr_bit.c,v 1.18 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -27,10 +27,10 @@ int odr_bitstring(ODR o, Odr_bitmask **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_BITSTRING; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); diff --git a/odr/odr_bool.c b/odr/odr_bool.c index f1cb60a..9ad56a8 100644 --- a/odr/odr_bool.c +++ b/odr/odr_bool.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_bool.c,v 1.14 2003-01-06 08:20:27 adam Exp $ + * $Id: odr_bool.c,v 1.15 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -27,10 +27,10 @@ int odr_bool(ODR o, int **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_BOOLEAN; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); diff --git a/odr/odr_cons.c b/odr/odr_cons.c index 806e38c..1521343 100644 --- a/odr/odr_cons.c +++ b/odr/odr_cons.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: odr_cons.c,v 1.25 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_cons.c,v 1.26 2003-05-20 19:55:30 adam Exp $ * */ #if HAVE_CONFIG_H @@ -31,7 +31,7 @@ int odr_constructed_begin(ODR o, void *p, int zclass, int tag, o->t_class = zclass; o->t_tag = tag; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, 1)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, 1, name)) < 0) return 0; if (!res || !cons) return 0; diff --git a/odr/odr_enum.c b/odr/odr_enum.c index 0dda8bb..22c20d8 100644 --- a/odr/odr_enum.c +++ b/odr/odr_enum.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_enum.c,v 1.8 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_enum.c,v 1.9 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -26,10 +26,10 @@ int odr_enum(ODR o, int **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_ENUM; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); diff --git a/odr/odr_int.c b/odr/odr_int.c index f5a3b33..a685761 100644 --- a/odr/odr_int.c +++ b/odr/odr_int.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_int.c,v 1.18 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_int.c,v 1.19 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -26,10 +26,10 @@ int odr_integer(ODR o, int **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_INTEGER; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); diff --git a/odr/odr_null.c b/odr/odr_null.c index 8524f8f..8e7d85d 100644 --- a/odr/odr_null.c +++ b/odr/odr_null.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_null.c,v 1.16 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_null.c,v 1.17 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -26,10 +26,10 @@ int odr_null(ODR o, Odr_null **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_NULL; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); diff --git a/odr/odr_oct.c b/odr/odr_oct.c index dee25a7..c0458dd 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.21 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_oct.c,v 1.22 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -27,10 +27,10 @@ int odr_octetstring(ODR o, Odr_oct **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_OCTETSTRING; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { int i; @@ -76,10 +76,10 @@ int odr_cstring(ODR o, char **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_OCTETSTRING; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); @@ -123,10 +123,10 @@ int odr_iconv_string(ODR o, char **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_OCTETSTRING; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (o->direction == ODR_PRINT) { odr_prname(o, name); diff --git a/odr/odr_oid.c b/odr/odr_oid.c index 6d575d1..4077f36 100644 --- a/odr/odr_oid.c +++ b/odr/odr_oid.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_oid.c,v 1.19 2003-03-11 11:03:31 adam Exp $ + * $Id: odr_oid.c,v 1.20 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -27,10 +27,10 @@ int odr_oid(ODR o, Odr_oid **p, int opt, const char *name) o->t_class = ODR_UNIVERSAL; o->t_tag = ODR_OID; } - if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0) return 0; if (!res) - return opt; + return odr_missing(o, opt, name); if (cons) { odr_seterror(o, OPROTO, 46); diff --git a/odr/odr_use.c b/odr/odr_use.c index 5ae1e9c..918d69d 100644 --- a/odr/odr_use.c +++ b/odr/odr_use.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: odr_use.c,v 1.13 2003-01-06 08:20:28 adam Exp $ + * $Id: odr_use.c,v 1.14 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -27,7 +27,7 @@ int odr_external(ODR o, Odr_external **p, int opt, const char *name) odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL); if (!odr_sequence_begin(o, p, sizeof(Odr_external), name)) - return opt; + return odr_missing(o, opt, name); pp = *p; return odr_oid(o, &pp->direct_reference, 1, "direct") && diff --git a/odr/odr_util.c b/odr/odr_util.c index 3f450ca..26a672c 100644 --- a/odr/odr_util.c +++ b/odr/odr_util.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: odr_util.c,v 1.22 2003-01-06 08:20:28 adam Exp $ + * $Id: odr_util.c,v 1.23 2003-05-20 19:55:30 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -81,4 +81,15 @@ Odr_oid *odr_getoidbystr(ODR o, const char *str) return odr_getoidbystr_nmem (o->mem, str); } - +int odr_missing(ODR o, int opt, const char *name) +{ + if (o->error) + return 0; + if (!opt) + { + printf ("odr_missing set error : %s\n", name); + odr_seterror(o, OREQUIRED, 55); + odr_setaddinfo(o, name); + } + return opt; +} diff --git a/odr/tstodr.c b/odr/tstodr.c index 1b36a5e..4d681a1 100644 --- a/odr/tstodr.c +++ b/odr/tstodr.c @@ -2,14 +2,14 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: tstodr.c,v 1.2 2003-05-06 13:09:15 adam Exp $ + * $Id: tstodr.c,v 1.3 2003-05-20 19:55:30 adam Exp $ * */ #include #include #include "tstodrcodec.h" -void tst_MySequence(ODR encode, ODR decode) +void tst_MySequence1(ODR encode, ODR decode) { char *ber_buf; int ber_len; @@ -48,12 +48,43 @@ void tst_MySequence(ODR encode, ODR decode) exit(8); } +void tst_MySequence2(ODR encode, ODR decode) +{ + char *ber_buf; + int ber_len; + Yc_MySequence *s = odr_malloc(encode, sizeof(*s)); + Yc_MySequence *t; + + s->first = 0; /* deliberately miss this .. */ + s->second = odr_malloc(encode, sizeof(*s->second)); + s->second->buf = "hello"; + s->second->len = 5; + s->second->size = 0; + s->third = odr_intdup(encode, 1); + s->fourth = odr_nullval(); + s->fifth = odr_intdup(encode, YC_MySequence_enum1); + + if (yc_MySequence(encode, &s, 0, 0)) /* should fail */ + exit(9); + if (odr_geterror(encode) != OREQUIRED) + exit(10); + if (strcmp(odr_getaddinfo(encode), "first")) + exit(11); + odr_reset(encode); + + if (odr_geterror(encode) != ONONE) + exit(12); + if (strcmp(odr_getaddinfo(encode), "")) + exit(13); +} + int main(int argc, char **argv) { ODR odr_encode = odr_createmem(ODR_ENCODE); ODR odr_decode = odr_createmem(ODR_DECODE); - tst_MySequence(odr_encode, odr_decode); + tst_MySequence1(odr_encode, odr_decode); + tst_MySequence2(odr_encode, odr_decode); odr_destroy(odr_encode); odr_destroy(odr_decode); diff --git a/util/yaz-comp b/util/yaz-comp index f7a1c06..247b607 100755 --- a/util/yaz-comp +++ b/util/yaz-comp @@ -6,7 +6,7 @@ exec tclsh "$0" "$@" # (c) Index Data 1996-2003 # See the file LICENSE for details. # -# $Id: yaz-comp,v 1.5 2003-05-06 10:06:43 adam Exp $ +# $Id: yaz-comp,v 1.6 2003-05-20 19:55:30 adam Exp $ # set yc_version 0.3 @@ -510,14 +510,14 @@ proc asnSequence {name tag implicit tagtype} { set nchoice 0 if {![string length $tag]} { lappend l "\tif (!odr_sequence_begin (o, p, sizeof(**p), name))" - lappend l "\t\treturn opt && odr_ok (o);" + lappend l "\t\treturn odr_missing(o, opt, name) && odr_ok (o);" } elseif {$implicit} { lappend l "\tif (!odr_implicit_settag (o, $tagtype, $tag) ||" lappend l "\t\t!odr_sequence_begin (o, p, sizeof(**p), name))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" } else { lappend l "\tif (!odr_constructed_begin (o, p, $tagtype, $tag, name))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" lappend l "\tif (o->direction == ODR_DECODE)" lappend l "\t\t*p = ($inf(vprefix)$name *) odr_malloc (o, sizeof(**p));" @@ -709,7 +709,7 @@ proc asnOf {name tag implicit tagtype isset} { lappend j "\tint [lindex $numName 0];" lappend l "\tif (!odr_initmember (o, p, sizeof(**p)))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" if {[string length $tag]} { if {$implicit} { lappend l "\todr_implicit_settag (o, $tagtype, $tag);" @@ -736,7 +736,7 @@ proc asnOf {name tag implicit tagtype isset} { lappend j "\}" lappend l "\t\treturn 1;" lappend l "\t*p = 0;" - lappend l "\treturn opt && odr_ok(o);" + lappend l "\treturn odr_missing(o, opt, name);" return [list [join $l \n] [join $j \n]] } @@ -832,26 +832,26 @@ proc asnChoice {name tag implicit tagtype} { lappend l "\t\};" if {![string length $tag]} { lappend l "\tif (!odr_initmember(o, p, sizeof(**p)))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" lappend l "\tif (odr_choice(o, arm, &(*p)->[lindex $uName 1], &(*p)->[lindex $uName 0], name))" } elseif {$implicit} { lappend l "\tif (!odr_initmember(o, p, sizeof(**p)))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" lappend l "\todr_implicit_settag(o, $tagtype, $tag);" lappend l "\tif (odr_choice(o, arm, &(*p)->[lindex $uName 1], &(*p)->[lindex $uName 0], name))" } else { lappend l "\tif (!*p && o->direction != ODR_DECODE)" lappend l "\t\treturn opt;" lappend l "\tif (!odr_constructed_begin(o, p, $tagtype, $tag, 0))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" lappend l "\tif (!odr_initmember(o, p, sizeof(**p)))" - lappend l "\t\treturn opt && odr_ok(o);" + lappend l "\t\treturn odr_missing(o, opt, name);" lappend l "\tif (odr_choice(o, arm, &(*p)->[lindex $uName 1], &(*p)->[lindex $uName 0], name) &&" lappend l "\t\todr_constructed_end(o))" } lappend l "\t\treturn 1;" lappend l "\t*p = 0;" - lappend l "\treturn opt && odr_ok(o);" + lappend l "\treturn odr_missing(o, opt, name);" return [list [join $l \n] [join $j \n]] } diff --git a/z39.50/z.tcl b/z39.50/z.tcl index 47bb1c3..c0855a6 100644 --- a/z39.50/z.tcl +++ b/z39.50/z.tcl @@ -1,5 +1,5 @@ # YC Sample Config File for Z39.50 -# $Id: z.tcl,v 1.10 2003-02-17 21:23:31 adam Exp $ +# $Id: z.tcl,v 1.11 2003-05-20 19:55:30 adam Exp $ # ---------------------------------------------------------- # Prefix Specifications # @@ -208,8 +208,8 @@ set filename($m) z-sutrs set body($m,c) { int z_SUTRS (ODR o, Odr_oct **p, int opt, const char *name) { - return odr_implicit(o, odr_octetstring, p, ODR_UNIVERSAL, - ODR_GENERALSTRING, opt); + return odr_implicit_tag(o, odr_octetstring, p, ODR_UNIVERSAL, + ODR_GENERALSTRING, opt, name); } } -- 1.7.10.4