From cabcc223cd47503763e7c42969e3be30c58276af Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Sep 2013 15:09:47 +0200 Subject: [PATCH] Get rid of size member of Odr_oct It has not served a purpose for years. --- client/admin.c | 9 ++++++--- client/client.c | 27 +++++++++++++++++++++------ doc/odr.xml | 4 +--- include/yaz/odr.h | 4 ++++ src/ber_any.c | 5 ++++- src/ber_oct.c | 17 +++++++++++++++++ src/charneg.c | 5 ++++- src/odr_mem.c | 2 ++ src/odr_oct.c | 21 ++++++++++++++++++--- src/pquery.c | 7 +++++-- src/prt-ext.c | 16 ++++++++++++---- src/seshigh.c | 5 ++++- src/sortspec.c | 2 ++ src/zoom-sru.c | 6 ++++-- test/test_odr.c | 4 ++++ util/yaz-illclient.c | 20 ++++++++++++++++---- ztest/ztest.c | 10 ++++++++-- 17 files changed, 132 insertions(+), 32 deletions(-) diff --git a/client/admin.c b/client/admin.c index 14aa281..ed9db68 100644 --- a/client/admin.c +++ b/client/admin.c @@ -237,9 +237,12 @@ int cmd_adm_import(const char *arg) Z_FragmentSyntax_notExternallyTagged; rec->u.intermediateFragment->u.notExternallyTagged = oct; - oct->len = oct->size = status.st_size; - oct->buf = (unsigned char *) odr_malloc (out, oct->size); - if (fread(oct->buf, 1, oct->size, inf) != (size_t) oct->size) + oct->len = status.st_size; +#if OCT_SIZE + oct->size = status.st_size; +#endif + oct->buf = (unsigned char *) odr_malloc (out, oct->len); + if (fread(oct->buf, 1, oct->len, inf) != (size_t) oct->len) { printf("Incomplete read of file %s\n", fname); } diff --git a/client/client.c b/client/client.c index 638d16e..7b0f926 100644 --- a/client/client.c +++ b/client/client.c @@ -322,7 +322,10 @@ static Z_ReferenceId *set_refid(ODR out) if (!refid) return 0; id = (Z_ReferenceId *) odr_malloc(out, sizeof(*id)); - id->size = id->len = strlen(refid); + id->len = strlen(refid); +#if OCT_SIZE + id->size = id->len; +#endif id->buf = (unsigned char *) odr_malloc(out, id->len); memcpy(id->buf, refid, id->len); return id; @@ -1565,7 +1568,10 @@ static int send_Z3950_searchRequest(const char *arg) /* send a very big referenceid to test transport stack etc. */ memset(big, 'A', 2100); - bigo.len = bigo.size = 2100; + bigo.len = 2100; +#if OCT_SIZE + bigo.size = bigo.len; +#endif bigo.buf = big; req->referenceId = &bigo; } @@ -1867,7 +1873,7 @@ static void print_referenceId(int iLevel, Z_ReferenceId *referenceId) int i; print_level(iLevel); - printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size); + printf("Ref Id (%d): ", referenceId->len); for (i = 0; i < referenceId->len; i++) printf("%c", referenceId->buf[i]); printf("\n"); @@ -2135,7 +2141,9 @@ static Z_External *create_external_itemRequest(void) r->u.single_ASN1_type->buf = (unsigned char *) odr_malloc(out, item_request_size); r->u.single_ASN1_type->len = item_request_size; +#if OCT_SIZE r->u.single_ASN1_type->size = item_request_size; +#endif memcpy(r->u.single_ASN1_type->buf, item_request_buf, item_request_size); @@ -2188,7 +2196,9 @@ static Z_External *create_external_ILL_APDU(void) r->u.single_ASN1_type->buf = (unsigned char *) odr_malloc(out, ill_request_size); r->u.single_ASN1_type->len = ill_request_size; +#if OCT_SIZE r->u.single_ASN1_type->size = ill_request_size; +#endif memcpy(r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size); /* printf("len = %d\n", ill_request_size); */ /* do_hex_dump(ill_request_buf,ill_request_size); */ @@ -2487,7 +2497,9 @@ static int send_Z3950_update(int version, int action_no, const char *recid, notToKeep->elements[0]->u.opaque = (Odr_oct *) odr_malloc(out, sizeof(Odr_oct)); notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid; +#if OCT_SIZE notToKeep->elements[0]->u.opaque->size = strlen(recid); +#endif notToKeep->elements[0]->u.opaque->len = strlen(recid); } else @@ -2534,7 +2546,9 @@ static int send_Z3950_update(int version, int action_no, const char *recid, notToKeep->elements[0]->u.opaque = (Odr_oct *) odr_malloc(out, sizeof(Odr_oct)); notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid; +#if OCT_SIZE notToKeep->elements[0]->u.opaque->size = strlen(recid); +#endif notToKeep->elements[0]->u.opaque->len = strlen(recid); } else @@ -3388,9 +3402,10 @@ static int send_Z3950_scanrequest(const char *set, const char *query, { req->termListAndStartPoint->term->u.general->buf = (unsigned char *) odr_strdup(out, term); - req->termListAndStartPoint->term->u.general->len = - req->termListAndStartPoint->term->u.general->size = - strlen(term); + req->termListAndStartPoint->term->u.general->len = strlen(term); +#if OCT_SIZE + req->termListAndStartPoint->term->u.general->size = strlen(term); +#endif } } req->referenceId = set_refid(out); diff --git a/doc/odr.xml b/doc/odr.xml index 770ad9c..6438e6f 100644 --- a/doc/odr.xml +++ b/doc/odr.xml @@ -670,7 +670,6 @@ typedef struct odr_oct { unsigned char *buf; int len; - int size; } Odr_oct; int odr_octetstring(ODR o, Odr_oct **p, int optional, @@ -680,8 +679,7 @@ int odr_octetstring(ODR o, Odr_oct **p, int optional, The buf field should point to the character array that holds the octetstring. The len field holds the - actual length, while the size field gives the size - of the allocated array (not of interest to you, in most cases). + actual length. The character array need not be null terminated. diff --git a/include/yaz/odr.h b/include/yaz/odr.h index 20f245b..9c7ea51 100644 --- a/include/yaz/odr.h +++ b/include/yaz/odr.h @@ -96,11 +96,15 @@ typedef nmem_bool_t Odr_bool; #define ODR_ENCODE 1 #define ODR_PRINT 2 +#define OCT_SIZE 0 + typedef struct odr_oct { unsigned char *buf; int len; +#if OCT_SIZE int size; +#endif } Odr_oct; typedef void Odr_null; diff --git a/src/ber_any.c b/src/ber_any.c index 3322a02..0002944 100644 --- a/src/ber_any.c +++ b/src/ber_any.c @@ -32,7 +32,10 @@ int ber_any(ODR o, Odr_any **p) } (*p)->buf = (unsigned char *)odr_malloc(o, res); memcpy((*p)->buf, o->bp, res); - (*p)->len = (*p)->size = res; + (*p)->len = res; +#if OCT_SIZE + (*p)->size = res; +#endif o->bp += res; return 1; case ODR_ENCODE: diff --git a/src/ber_oct.c b/src/ber_oct.c index 85242ee..2928e43 100644 --- a/src/ber_oct.c +++ b/src/ber_oct.c @@ -16,12 +16,16 @@ #endif #include "odr-priv.h" +#include +#include int ber_octetstring(ODR o, Odr_oct *p, int cons) { int res, len; const unsigned char *base; +#if OCT_SIZE unsigned char *c; +#endif switch (o->direction) { @@ -51,9 +55,14 @@ int ber_octetstring(ODR o, Odr_oct *p, int cons) odr_seterror(o, OOTHER, 16); return 0; } +#if OCT_SIZE + assert(p->size == 0); + assert(p->len == 0); + yaz_log(YLOG_LOG, "DECODE OCTET1 p->size=%d p->len=%d", p->size, p->len); if (len + 1 > p->size - p->len) { c = (unsigned char *)odr_malloc(o, p->size += len + 1); + yaz_log(YLOG_LOG, "DECODE COPY p->size=%d p->len=%d", p->size, p->len); if (p->len) memcpy(c, p->buf, p->len); p->buf = c; @@ -61,11 +70,19 @@ int ber_octetstring(ODR o, Odr_oct *p, int cons) if (len) memcpy(p->buf + p->len, o->bp, len); p->len += len; + yaz_log(YLOG_LOG, "DECODE OCTET2 p->size=%d p->len=%d", p->size, p->len); o->bp += len; /* the final null is really not part of the buffer, but */ /* it helps somes applications that assumes C strings */ if (len) p->buf[p->len] = '\0'; +#else + p->len = len; + p->buf = odr_malloc(o, len + 1); + memcpy(p->buf, o->bp, len); + p->buf[len] = '\0'; + o->bp += len; +#endif return 1; case ODR_ENCODE: if ((res = ber_enclen(o, p->len, 5, 0)) < 0) diff --git a/src/charneg.c b/src/charneg.c index 951bb37..4125d26 100644 --- a/src/charneg.c +++ b/src/charneg.c @@ -36,7 +36,10 @@ static Z_External* z_ext_record2(ODR o, const char *buf) return 0; if (!(p->u.octet_aligned->buf = (unsigned char *)odr_malloc(o, len))) return 0; - p->u.octet_aligned->len = p->u.octet_aligned->size = len; + p->u.octet_aligned->len = len; +#if OCT_SIZE + p->u.octet_aligned->size = len; +#endif memcpy(p->u.octet_aligned->buf, buf, len); return p; diff --git a/src/odr_mem.c b/src/odr_mem.c index 4309d3d..52d850b 100644 --- a/src/odr_mem.c +++ b/src/odr_mem.c @@ -67,7 +67,9 @@ Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf, int sz) Odr_oct *p = (Odr_oct *) odr_malloc(o, sizeof(Odr_oct)); p->buf = (unsigned char *) odr_malloc(o, sz); memcpy(p->buf, buf, sz); +#if OCT_SIZE p->size = sz; +#endif p->len = sz; return p; } diff --git a/src/odr_oct.c b/src/odr_oct.c index f359c4c..fc06519 100644 --- a/src/odr_oct.c +++ b/src/odr_oct.c @@ -45,7 +45,9 @@ int odr_octetstring(ODR o, Odr_oct **p, int opt, const char *name) if (o->direction == ODR_DECODE) { *p = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); +#if OCT_SIZE (*p)->size= 0; +#endif (*p)->len = 0; (*p)->buf = 0; } @@ -85,11 +87,16 @@ int odr_cstring(ODR o, char **p, int opt, const char *name) if (o->direction == ODR_ENCODE) { t->buf = (unsigned char *) *p; - t->size = t->len = strlen(*p); + t->len = strlen(*p); +#if OCT_SIZE + t->size = t->len; +#endif } else { +#if OCT_SIZE t->size= 0; +#endif t->len = 0; t->buf = 0; } @@ -159,17 +166,25 @@ int odr_iconv_string(ODR o, char **p, int opt, const char *name) odr_seterror(o, ODATA, 44); return 0; } - t->size = t->len = outbuf - (char*) t->buf; + t->len = outbuf - (char*) t->buf; +#if OCT_SIZE + t->size = t->len; +#endif } if (!t->buf) { t->buf = (unsigned char *) *p; - t->size = t->len = strlen(*p); + t->len = strlen(*p); +#if OCT_SIZE + t->size = t->len; +#endif } } else { +#if OCT_SIZE t->size= 0; +#endif t->len = 0; t->buf = 0; } diff --git a/src/pquery.c b/src/pquery.c index d4b9958..c787b58 100644 --- a/src/pquery.c +++ b/src/pquery.c @@ -313,8 +313,11 @@ Z_Term *z_Term_create(ODR o, int term_type, const char *buf, size_t len) Odr_oct *term_octet = (Odr_oct *)odr_malloc(o, sizeof(*term_octet)); term_octet->buf = (unsigned char *)odr_malloc(o, 1 + len); memcpy(term_octet->buf, buf, len); - term_octet->size = term_octet->len = len; - term_octet->buf[term_octet->size] = 0; /* null terminate */ + term_octet->len = len; +#if OCT_SIZE + term_octet->size = len; +#endif + term_octet->buf[term_octet->len] = 0; /* null terminate */ switch (term_type) { diff --git a/src/prt-ext.c b/src/prt-ext.c index 6af7c61..e489fb7 100644 --- a/src/prt-ext.c +++ b/src/prt-ext.c @@ -316,7 +316,10 @@ Z_External *z_ext_record_oid_nmem(NMEM nmem, const Odr_oid *oid, thisext->which = Z_External_sutrs; thisext->u.sutrs = sutrs; sutrs->buf = (unsigned char *)nmem_malloc(nmem, len); - sutrs->len = sutrs->size = len; + sutrs->len = len; +#if OCT_SIZE + sutrs->size = len; +#endif memcpy(sutrs->buf, buf, len); } else @@ -329,7 +332,10 @@ Z_External *z_ext_record_oid_nmem(NMEM nmem, const Odr_oid *oid, nmem_malloc(nmem, len))) return 0; memcpy(thisext->u.octet_aligned->buf, buf, len); - thisext->u.octet_aligned->len = thisext->u.octet_aligned->size = len; + thisext->u.octet_aligned->len = len; +#if OCT_SIZE + thisext->u.octet_aligned->size = len; +#endif } return thisext; } @@ -360,8 +366,10 @@ Z_External *z_ext_record_oid_any(ODR o, const Odr_oid *oid, if (!thisext->u.single_ASN1_type->buf) return 0; memcpy(thisext->u.single_ASN1_type->buf, buf, len); - thisext->u.single_ASN1_type->len = thisext->u.single_ASN1_type->size = len; - + thisext->u.single_ASN1_type->len = len; +#if OCT_SIZE + thisext->u.single_ASN1_type->size = len; +#endif return thisext; } diff --git a/src/seshigh.c b/src/seshigh.c index b36bd1f..fccb4e3 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -3128,8 +3128,11 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb) t->term->u.general = o = (Odr_oct *)odr_malloc(assoc->encode, sizeof(Odr_oct)); o->buf = (unsigned char *) - odr_malloc(assoc->encode, o->len = o->size = + odr_malloc(assoc->encode, o->len = strlen(bsrr->entries[i].term)); +#if OCT_SIZE + o->size = o->len; +#endif memcpy(o->buf, bsrr->entries[i].term, o->len); yaz_log(YLOG_DEBUG, " term #%d: '%s' (" ODR_INT_PRINTF ")", i, bsrr->entries[i].term, bsrr->entries[i].occurrences); diff --git a/src/sortspec.c b/src/sortspec.c index a016496..0cdef33 100644 --- a/src/sortspec.c +++ b/src/sortspec.c @@ -121,7 +121,9 @@ Z_SortKeySpecList *yaz_sort_spec(ODR out, const char *arg) odr_malloc(out, sizeof(Odr_oct)); i++; sks->u.missingValueData->len = strlen(sort_flags+i); +#if OCT_SIZE sks->u.missingValueData->size = sks->u.missingValueData->len; +#endif sks->u.missingValueData->buf = (unsigned char*) odr_strdup(out, sort_flags+i); i += strlen(sort_flags+i) - 1; diff --git a/src/zoom-sru.c b/src/zoom-sru.c index a5e6169..85f597b 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -334,9 +334,11 @@ static zoom_ret handle_srw_response(ZOOM_connection c, npr->u.databaseRecord->u.octet_aligned->buf = (unsigned char*) sru_rec->recordData_buf; npr->u.databaseRecord->u.octet_aligned->len = - npr->u.databaseRecord->u.octet_aligned->size = sru_rec->recordData_len; - +#if OCT_SIZE + npr->u.databaseRecord->u.octet_aligned->size = + sru_rec->recordData_len; +#endif if (sru_rec->recordSchema && !strcmp(sru_rec->recordSchema, "info:srw/schema/1/diagnostics-v1.1")) diff --git a/test/test_odr.c b/test/test_odr.c index bfc237d..6ebd750 100644 --- a/test/test_odr.c +++ b/test/test_odr.c @@ -27,7 +27,9 @@ void tst_MySequence1(ODR encode, ODR decode) s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second)); s->second->buf = (unsigned char *) "hello"; s->second->len = 5; +#if OCT_SIZE s->second->size = 0; +#endif s->third = odr_booldup(encode, 1); s->fourth = odr_nullval(); s->fifth = odr_intdup(encode, YC_MySequence_enum1); @@ -82,7 +84,9 @@ void tst_MySequence2(ODR encode, ODR decode) s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second)); s->second->buf = (unsigned char *) "hello"; s->second->len = 5; +#if OCT_SIZE s->second->size = 0; +#endif s->third = odr_booldup(encode, 1); s->fourth = odr_nullval(); s->fifth = odr_intdup(encode, YC_MySequence_enum1); diff --git a/util/yaz-illclient.c b/util/yaz-illclient.c index a8bd956..5cc39a8 100644 --- a/util/yaz-illclient.c +++ b/util/yaz-illclient.c @@ -366,7 +366,10 @@ ILL_Extension *makepromptextension(struct prog_args *args, ODR odr) { odr_malloc(odr,sizeof(*ext->u.single_ASN1_type)); ext->u.single_ASN1_type->buf= (unsigned char *) odr_malloc(odr, siz); memcpy(ext->u.single_ASN1_type->buf,buf, siz ); - ext->u.single_ASN1_type->len = ext->u.single_ASN1_type->size = siz; + ext->u.single_ASN1_type->len = siz; +#if OCT_SIZE + ext->u.single_ASN1_type->size = siz; +#endif odr_reset(odr_ext); odr_reset(odr_prt); /*!*/ @@ -382,7 +385,10 @@ ILL_Extension *makepromptextension(struct prog_args *args, ODR odr) { buf= odr_getbuf(odr_ext,&siz,0); e->item->buf= (unsigned char *) odr_malloc(odr, siz); memcpy(e->item->buf,buf, siz ); - e->item->len = e->item->size = siz; + e->item->len = siz; +#if OCT_SIZE + e->item->size = siz; +#endif odr_destroy(odr_prt); odr_destroy(odr_ext); @@ -425,7 +431,10 @@ ILL_Extension *makeoclcextension(struct prog_args *args, ODR odr) { odr_malloc(odr,sizeof(*ext->u.single_ASN1_type)); ext->u.single_ASN1_type->buf = (unsigned char *) odr_malloc(odr, siz); memcpy(ext->u.single_ASN1_type->buf,buf, siz ); - ext->u.single_ASN1_type->len = ext->u.single_ASN1_type->size = siz; + ext->u.single_ASN1_type->len = siz; +#if OCT_SIZE + ext->u.single_ASN1_type->size = siz; +#endif odr_reset(odr_ext); odr_reset(odr_prt); /*!*/ @@ -441,7 +450,10 @@ ILL_Extension *makeoclcextension(struct prog_args *args, ODR odr) { buf= odr_getbuf(odr_ext,&siz,0); e->item->buf= (unsigned char *) odr_malloc(odr, siz); memcpy(e->item->buf, buf, siz); - e->item->len = e->item->size = siz; + e->item->len = siz; +#if OCT_SIZE + e->item->size = siz; +#endif odr_destroy(odr_prt); odr_destroy(odr_ext); diff --git a/ztest/ztest.c b/ztest/ztest.c index d92d215..6707c4b 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -593,8 +593,11 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) rr->taskPackage->targetReference->buf = (unsigned char *) odr_strdup(rr->stream, "911"); rr->taskPackage->targetReference->len = - rr->taskPackage->targetReference->size = strlen((char *) (rr->taskPackage->targetReference->buf)); +#if OCT_SIZE + rr->taskPackage->targetReference->size = + strlen((char *) (rr->taskPackage->targetReference->buf)); +#endif rr->taskPackage->creationDateTime = 0; rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); rr->taskPackage->packageDiagnostics = 0; @@ -694,8 +697,11 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) rr->taskPackage->targetReference->buf = (unsigned char *) odr_strdup(rr->stream, "123"); rr->taskPackage->targetReference->len = - rr->taskPackage->targetReference->size = strlen((char *) (rr->taskPackage->targetReference->buf)); +#if OCT_SIZE + rr->taskPackage->targetReference->size = + rr->taskPackage->targetReference->len; +#endif rr->taskPackage->creationDateTime = 0; rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); rr->taskPackage->packageDiagnostics = 0; -- 1.7.10.4