From 833bf58328945361db8a744c0dec2c925c97d43a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 20 Sep 2013 10:48:57 +0200 Subject: [PATCH] odr: move 5 members of struct odr to private --- include/yaz/odr.h | 11 +----- src/ber_any.c | 6 ++-- src/ber_bit.c | 12 +++---- src/ber_bool.c | 8 ++--- src/ber_int.c | 4 +-- src/ber_null.c | 2 +- src/ber_oct.c | 10 +++--- src/ber_oid.c | 8 ++--- src/ber_tag.c | 8 ++--- src/http.c | 104 ++++++++++++++++++++++++++++------------------------- src/odr-priv.h | 21 +++++++---- src/odr.c | 31 +++++++++------- src/odr_choice.c | 2 +- src/odr_cons.c | 16 ++++----- src/odr_mem.c | 29 +++++++-------- src/odr_tag.c | 2 +- src/odr_util.c | 6 ++-- src/prt-ext.c | 17 ++++----- src/zgdu.c | 15 ++++---- 19 files changed, 162 insertions(+), 150 deletions(-) diff --git a/include/yaz/odr.h b/include/yaz/odr.h index 865e4d4..20d15a4 100644 --- a/include/yaz/odr.h +++ b/include/yaz/odr.h @@ -127,14 +127,6 @@ struct odr int error; /* current error state (0==OK) */ - char *buf; /* memory handle */ - int top; /* top of buffer (max pos when encoding) */ - int size; /* current buffer size (encoding+decoding) */ - - int pos; /* current position (encoding) */ - - const char *bp; /* position in buffer (decoding) */ - NMEM mem; /* memory handle for decoding (primarily) */ struct Odr_private *op; @@ -171,6 +163,7 @@ typedef struct odr_arm extern char *odr_errlist[]; +YAZ_EXPORT int odr_offset(ODR o); 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); @@ -218,8 +211,6 @@ YAZ_EXPORT Odr_null *odr_nullval(void); ((mask)->bits[(num) >> 3] & (0X80 >> ((num) & 0X07)) ? 1 : 0) : 0) -#define odr_tell(o) ((o)->pos) -#define odr_offset(o) ((o)->bp - (o)->buf) #define odr_ok(o) (!(o)->error) #define odr_getmem(o) ((o)->mem) diff --git a/src/ber_any.c b/src/ber_any.c index be23946..f12b4ba 100644 --- a/src/ber_any.c +++ b/src/ber_any.c @@ -25,15 +25,15 @@ int ber_any(ODR o, Odr_any **p) switch (o->direction) { case ODR_DECODE: - if ((res = completeBER(o->bp, odr_max(o))) <= 0) /* FIX THIS */ + if ((res = completeBER(o->op->bp, odr_max(o))) <= 0) /* FIX THIS */ { odr_seterror(o, OPROTO, 2); return 0; } (*p)->buf = (char *)odr_malloc(o, res); - memcpy((*p)->buf, o->bp, res); + memcpy((*p)->buf, o->op->bp, res); (*p)->len = res; - o->bp += res; + o->op->bp += res; return 1; case ODR_ENCODE: if (odr_write(o, (*p)->buf, (*p)->len) < 0) diff --git a/src/ber_bit.c b/src/ber_bit.c index ac3631a..31e5500 100644 --- a/src/ber_bit.c +++ b/src/ber_bit.c @@ -25,15 +25,15 @@ int ber_bitstring(ODR o, Odr_bitmask *p, int cons) switch (o->direction) { case ODR_DECODE: - if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0) + if ((res = ber_declen(o->op->bp, &len, odr_max(o))) < 0) { odr_seterror(o, OPROTO, 4); return 0; } - o->bp += res; + o->op->bp += res; if (cons) /* fetch component strings */ { - base = o->bp; + base = o->op->bp; while (odp_more_chunks(o, base, len)) if (!odr_bitstring(o, &p, 0, 0)) return 0; @@ -57,11 +57,11 @@ int ber_bitstring(ODR o, Odr_bitmask *p, int cons) odr_seterror(o, OOTHER, 7); return 0; } - o->bp++; /* silently ignore the unused-bits field */ + o->op->bp++; /* silently ignore the unused-bits field */ len--; - memcpy(p->bits + p->top + 1, o->bp, len); + memcpy(p->bits + p->top + 1, o->op->bp, len); p->top += len; - o->bp += len; + o->op->bp += len; return 1; case ODR_ENCODE: if ((res = ber_enclen(o, p->top + 2, 5, 0)) < 0) diff --git a/src/ber_bool.c b/src/ber_bool.c index ec0a1da..de1ba3a 100644 --- a/src/ber_bool.c +++ b/src/ber_bool.c @@ -31,19 +31,19 @@ int ber_boolean(ODR o, int *val) return 0; return 1; case ODR_DECODE: - if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0) + if ((res = ber_declen(o->op->bp, &len, odr_max(o))) < 0) { odr_seterror(o, OPROTO, 9); return 0; } - o->bp+= res; + o->op->bp+= res; if (len != 1 || odr_max(o) < len) { odr_seterror(o, OPROTO, 10); return 0; } - *val = *o->bp; - o->bp++; + *val = *o->op->bp; + o->op->bp++; return 1; case ODR_PRINT: return 1; diff --git a/src/ber_int.c b/src/ber_int.c index cc02d3b..eb651e2 100644 --- a/src/ber_int.c +++ b/src/ber_int.c @@ -37,12 +37,12 @@ int ber_integer(ODR o, Odr_int *val) switch (o->direction) { case ODR_DECODE: - if ((res = ber_decinteger(o->bp, val, odr_max(o))) <= 0) + if ((res = ber_decinteger(o->op->bp, val, odr_max(o))) <= 0) { odr_seterror(o, OPROTO, 50); return 0; } - o->bp += res; + o->op->bp += res; return 1; case ODR_ENCODE: if ((res = ber_encinteger(o, *val)) < 0) diff --git a/src/ber_null.c b/src/ber_null.c index 1fee4c4..5e3cb94 100644 --- a/src/ber_null.c +++ b/src/ber_null.c @@ -33,7 +33,7 @@ int ber_null(ODR o) odr_seterror(o, OPROTO, 39); return 0; } - if (*(o->bp++) != 0X00) + if (*(o->op->bp++) != 0X00) { odr_seterror(o, OPROTO, 12); return 0; diff --git a/src/ber_oct.c b/src/ber_oct.c index 5a36482..8c60fc7 100644 --- a/src/ber_oct.c +++ b/src/ber_oct.c @@ -27,15 +27,15 @@ int ber_octetstring(ODR o, Odr_oct *p, int cons) switch (o->direction) { case ODR_DECODE: - if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0) + if ((res = ber_declen(o->op->bp, &len, odr_max(o))) < 0) { odr_seterror(o, OPROTO, 14); return 0; } - o->bp += res; + o->op->bp += res; if (cons) /* fetch component strings */ { - base = o->bp; + base = o->op->bp; while (odp_more_chunks(o, base, len)) if (!odr_octetstring(o, &p, 0, 0)) return 0; @@ -54,9 +54,9 @@ int ber_octetstring(ODR o, Odr_oct *p, int cons) } p->len = len; p->buf = odr_malloc(o, len + 1); - memcpy(p->buf, o->bp, len); + memcpy(p->buf, o->op->bp, len); p->buf[len] = '\0'; - o->bp += len; + o->op->bp += len; return 1; case ODR_ENCODE: if ((res = ber_enclen(o, p->len, 5, 0)) < 0) diff --git a/src/ber_oid.c b/src/ber_oid.c index 89b8dfa..6e2b595 100644 --- a/src/ber_oid.c +++ b/src/ber_oid.c @@ -25,7 +25,7 @@ int ber_oidc(ODR o, Odr_oid *p, int max_oid_size) switch (o->direction) { case ODR_DECODE: - if ((res = ber_declen(o->bp, &len, odr_max(o))) < 1) + if ((res = ber_declen(o->op->bp, &len, odr_max(o))) < 1) { odr_seterror(o, OPROTO, 18); return 0; @@ -35,7 +35,7 @@ int ber_oidc(ODR o, Odr_oid *p, int max_oid_size) odr_seterror(o, OPROTO, 19); return 0; } - o->bp += res; + o->op->bp += res; if (len > odr_max(o)) { odr_seterror(o, OPROTO, 20); @@ -53,10 +53,10 @@ int ber_oidc(ODR o, Odr_oid *p, int max_oid_size) return 0; } id <<= 7; - id |= *o->bp & 0X7F; + id |= *o->op->bp & 0X7F; len--; } - while (*(o->bp++) & 0X80); + while (*(o->op->bp++) & 0X80); if (id < 0) { diff --git a/src/ber_tag.c b/src/ber_tag.c index f005078..7841b8a 100644 --- a/src/ber_tag.c +++ b/src/ber_tag.c @@ -44,8 +44,8 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt, if (ODR_STACK_EMPTY(o)) { odr_seek(o, ODR_S_SET, 0); - o->top = 0; - o->bp = o->buf; + o->op->top = 0; + o->op->bp = o->op->buf; odr_ber_tag->lclass = -1; } switch (o->direction) @@ -76,7 +76,7 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt, if (odr_ber_tag->lclass < 0) { if ((odr_ber_tag->br = - ber_dectag(o->bp, &odr_ber_tag->lclass, + ber_dectag(o->op->bp, &odr_ber_tag->lclass, &odr_ber_tag->ltag, &odr_ber_tag->lcons, odr_max(o))) <= 0) { @@ -87,7 +87,7 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt, } if (zclass == odr_ber_tag->lclass && tag == odr_ber_tag->ltag) { - o->bp += odr_ber_tag->br; + o->op->bp += odr_ber_tag->br; *constructed = odr_ber_tag->lcons; odr_ber_tag->lclass = -1; return 1; diff --git a/src/http.c b/src/http.c index 683336a..397b7bd 100644 --- a/src/http.c +++ b/src/http.c @@ -10,7 +10,7 @@ #include #endif -#include +#include "odr-priv.h" #include #include #include @@ -22,41 +22,43 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, { int i = off; int chunked = 0; + const char *buf = o->op->buf; + int size = o->op->size; *headers = 0; - while (i < o->size-1 && o->buf[i] == '\n') + while (i < size-1 && buf[i] == '\n') { int po; i++; - if (o->buf[i] == '\r' && i < o->size-1 && o->buf[i+1] == '\n') + if (buf[i] == '\r' && i < size-1 && buf[i+1] == '\n') { i++; break; } - if (o->buf[i] == '\n') + if (buf[i] == '\n') break; for (po = i; ; i++) { - if (i == o->size) + if (i == size) { o->error = OHTTP; return 0; } - else if (o->buf[i] == ':') + else if (buf[i] == ':') break; } *headers = (Z_HTTP_Header *) odr_malloc(o, sizeof(**headers)); (*headers)->name = (char*) odr_malloc(o, i - po + 1); - memcpy ((*headers)->name, o->buf + po, i - po); + memcpy ((*headers)->name, buf + po, i - po); (*headers)->name[i - po] = '\0'; i++; - while (i < o->size-1 && o->buf[i] == ' ') + while (i < size-1 && buf[i] == ' ') i++; - for (po = i; i < o->size-1 && !strchr("\r\n", o->buf[i]); i++) + for (po = i; i < size-1 && !strchr("\r\n", buf[i]); i++) ; (*headers)->value = (char*) odr_malloc(o, i - po + 1); - memcpy ((*headers)->value, o->buf + po, i - po); + memcpy ((*headers)->value, buf + po, i - po); (*headers)->value[i - po] = '\0'; if (!yaz_strcasecmp((*headers)->name, "Transfer-Encoding") @@ -64,11 +66,11 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, !yaz_strcasecmp((*headers)->value, "chunked")) chunked = 1; headers = &(*headers)->next; - if (i < o->size-1 && o->buf[i] == '\r') + if (i < size-1 && buf[i] == '\r') i++; } *headers = 0; - if (o->buf[i] != '\n') + if (buf[i] != '\n') { o->error = OHTTP; return 0; @@ -80,28 +82,28 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, int off = 0; /* we know buffer will be smaller than o->size - i*/ - *content_buf = (char*) odr_malloc(o, o->size - i); + *content_buf = (char*) odr_malloc(o, size - i); while (1) { /* chunk length .. */ int chunk_len = 0; - for (; i < o->size-2; i++) - if (yaz_isdigit(o->buf[i])) + for (; i < size-2; i++) + if (yaz_isdigit(buf[i])) chunk_len = chunk_len * 16 + - (o->buf[i] - '0'); - else if (yaz_isupper(o->buf[i])) + (buf[i] - '0'); + else if (yaz_isupper(buf[i])) chunk_len = chunk_len * 16 + - (o->buf[i] - ('A'-10)); - else if (yaz_islower(o->buf[i])) + (buf[i] - ('A'-10)); + else if (yaz_islower(buf[i])) chunk_len = chunk_len * 16 + - (o->buf[i] - ('a'-10)); + (buf[i] - ('a'-10)); else break; /* chunk extension ... */ - while (o->buf[i] != '\r' && o->buf[i+1] != '\n') + while (buf[i] != '\r' && buf[i+1] != '\n') { - if (i >= o->size-2) + if (i >= size-2) { o->error = OHTTP; return 0; @@ -111,13 +113,13 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, i += 2; /* skip CRLF */ if (chunk_len == 0) break; - if (chunk_len < 0 || off + chunk_len > o->size) + if (chunk_len < 0 || off + chunk_len > size) { o->error = OHTTP; return 0; } /* copy chunk .. */ - memcpy (*content_buf + off, o->buf + i, chunk_len); + memcpy (*content_buf + off, buf + i, chunk_len); i += chunk_len + 2; /* skip chunk+CRLF */ off += chunk_len; } @@ -127,21 +129,21 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, } else { - if (i > o->size) + if (i > size) { o->error = OHTTP; return 0; } - else if (i == o->size) + else if (i == size) { *content_buf = 0; *content_len = 0; } else { - *content_len = o->size - i; + *content_len = size - i; *content_buf = (char*) odr_malloc(o, *content_len + 1); - memcpy(*content_buf, o->buf + i, *content_len); + memcpy(*content_buf, buf + i, *content_len); (*content_buf)[*content_len] = '\0'; } } @@ -477,31 +479,33 @@ int yaz_decode_http_response(ODR o, Z_HTTP_Response **hr_p) { int i, po; Z_HTTP_Response *hr = (Z_HTTP_Response *) odr_malloc(o, sizeof(*hr)); + const char *buf = o->op->buf; + int size = o->op->size; *hr_p = hr; hr->content_buf = 0; hr->content_len = 0; po = i = 5; - while (i < o->size-2 && !strchr(" \r\n", o->buf[i])) + while (i < size-2 && !strchr(" \r\n", buf[i])) i++; hr->version = (char *) odr_malloc(o, i - po + 1); if (i - po) - memcpy(hr->version, o->buf + po, i - po); + memcpy(hr->version, buf + po, i - po); hr->version[i-po] = 0; - if (o->buf[i] != ' ') + if (buf[i] != ' ') { o->error = OHTTP; return 0; } i++; hr->code = 0; - while (i < o->size-2 && o->buf[i] >= '0' && o->buf[i] <= '9') + while (i < size-2 && buf[i] >= '0' && buf[i] <= '9') { - hr->code = hr->code*10 + (o->buf[i] - '0'); + hr->code = hr->code*10 + (buf[i] - '0'); i++; } - while (i < o->size-1 && o->buf[i] != '\n') + while (i < size-1 && buf[i] != '\n') i++; return decode_headers_content(o, i, &hr->headers, &hr->content_buf, &hr->content_len); @@ -511,48 +515,50 @@ int yaz_decode_http_request(ODR o, Z_HTTP_Request **hr_p) { int i, po; Z_HTTP_Request *hr = (Z_HTTP_Request *) odr_malloc(o, sizeof(*hr)); + const char *buf = o->op->buf; + int size = o->op->size; *hr_p = hr; /* method .. */ - for (i = 0; o->buf[i] != ' '; i++) - if (i >= o->size-5 || i > 30) + for (i = 0; buf[i] != ' '; i++) + if (i >= size-5 || i > 30) { o->error = OHTTP; return 0; } hr->method = (char *) odr_malloc(o, i+1); - memcpy (hr->method, o->buf, i); + memcpy (hr->method, buf, i); hr->method[i] = '\0'; /* path */ po = i+1; - for (i = po; o->buf[i] != ' '; i++) - if (i >= o->size-5) + for (i = po; buf[i] != ' '; i++) + if (i >= size-5) { o->error = OHTTP; return 0; } hr->path = (char *) odr_malloc(o, i - po + 1); - memcpy (hr->path, o->buf+po, i - po); + memcpy (hr->path, buf+po, i - po); hr->path[i - po] = '\0'; /* HTTP version */ i++; - if (i > o->size-5 || memcmp(o->buf+i, "HTTP/", 5)) + if (i > size-5 || memcmp(buf+i, "HTTP/", 5)) { o->error = OHTTP; return 0; } i+= 5; po = i; - while (i < o->size && !strchr("\r\n", o->buf[i])) + while (i < size && !strchr("\r\n", buf[i])) i++; hr->version = (char *) odr_malloc(o, i - po + 1); - memcpy(hr->version, o->buf + po, i - po); + memcpy(hr->version, buf + po, i - po); hr->version[i - po] = '\0'; /* headers */ - if (i < o->size-1 && o->buf[i] == '\r') + if (i < size-1 && buf[i] == '\r') i++; - if (o->buf[i] != '\n') + if (buf[i] != '\n') { o->error = OHTTP; return 0; @@ -590,7 +596,7 @@ int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr) { char sbuf[80]; Z_HTTP_Header *h; - int top0 = o->top; + int top0 = o->op->top; sprintf(sbuf, "HTTP/%s %d %s\r\n", hr->version, hr->code, @@ -616,7 +622,7 @@ int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr) if (o->direction == ODR_PRINT) { odr_printf(o, "-- HTTP response:\n"); - dump_http_package(o, (const char *) o->buf + top0, o->top - top0); + dump_http_package(o, o->op->buf + top0, o->op->top - top0); odr_printf(o, "--\n"); } return 1; @@ -625,7 +631,7 @@ int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr) int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr) { Z_HTTP_Header *h; - int top0 = o->top; + int top0 = o->op->top; odr_write(o, hr->method, strlen(hr->method)); odr_write(o, " ", 1); @@ -655,7 +661,7 @@ int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr) if (o->direction == ODR_PRINT) { odr_printf(o, "-- HTTP request:\n"); - dump_http_package(o, (const char *) o->buf + top0, o->top - top0); + dump_http_package(o, o->op->buf + top0, o->op->top - top0); odr_printf(o, "--\n"); } return 1; diff --git a/src/odr-priv.h b/src/odr-priv.h index f968edd..cb021ff 100644 --- a/src/odr-priv.h +++ b/src/odr-priv.h @@ -44,8 +44,7 @@ struct Odr_ber_tag { int lcons; }; -#define odr_max(o) ((o)->size - ((o)->bp - (o)->buf)) -#define odr_offset(o) ((o)->bp - (o)->buf) +#define odr_max(o) ((o)->op->size - ((o)->op->bp - (o)->op->buf)) /** * \brief stack for BER constructed items @@ -82,6 +81,12 @@ struct odr_constack * \brief ODR private data */ struct Odr_private { + char *buf; /* memory base */ + const char *bp; /* position in buffer (decoding) */ + int pos; /* current position (encoding) */ + int top; /* top of buffer (max pos when encoding) */ + int size; /* current buffer size (encoding+decoding) */ + /* stack for constructed types (we above) */ struct odr_constack *stack_first; /** first member of allocated stack */ struct odr_constack *stack_top; /** top of stack */ @@ -113,6 +118,8 @@ struct Odr_private { #define ODR_STACK_EMPTY(x) (!(x)->op->stack_top) #define ODR_STACK_NOT_EMPTY(x) ((x)->op->stack_top) +#define odr_tell(o) ((o)->op->pos) + /* Private macro. * write a single character at the current position - grow buffer if * necessary. @@ -122,15 +129,15 @@ struct Odr_private { #define odr_putc(o, c) \ ( \ ( \ - (o)->pos < (o)->size ? \ + (o)->op->pos < (o)->op->size ? \ ( \ - (o)->buf[(o)->pos++] = (c), \ + (o)->op->buf[(o)->op->pos++] = (c), \ 0 \ ) : \ ( \ odr_grow_block((o), 1) == 0 ? \ ( \ - (o)->buf[(o)->pos++] = (c), \ + (o)->op->buf[(o)->op->pos++] = (c), \ 0 \ ) : \ ( \ @@ -140,9 +147,9 @@ struct Odr_private { ) \ ) == 0 ? \ ( \ - (o)->pos > (o)->top ? \ + (o)->op->pos > (o)->op->top ? \ ( \ - (o)->top = (o)->pos, \ + (o)->op->top = (o)->op->pos, \ 0 \ ) : \ 0 \ diff --git a/src/odr.c b/src/odr.c index e424b20..25fafb2 100644 --- a/src/odr.c +++ b/src/odr.c @@ -215,8 +215,8 @@ ODR odr_createmem(int direction) return 0; o->op = (struct Odr_private *) xmalloc(sizeof(*o->op)); o->direction = direction; - o->buf = 0; - o->size = o->pos = o->top = 0; + o->op->buf = 0; + o->op->size = o->op->pos = o->op->top = 0; o->op->can_grow = 1; o->mem = nmem_create(); o->op->enable_bias = 1; @@ -237,9 +237,9 @@ void odr_reset(ODR o) } odr_seterror(o, ONONE, 0); - o->bp = o->buf; + o->op->bp = o->op->buf; odr_seek(o, ODR_S_SET, 0); - o->top = 0; + o->op->top = 0; o->op->t_class = -1; o->op->t_tag = -1; o->op->indent = 0; @@ -258,8 +258,8 @@ void odr_reset(ODR o) void odr_destroy(ODR o) { nmem_destroy(o->mem); - if (o->buf && o->op->can_grow) - xfree(o->buf); + if (o->op->buf && o->op->can_grow) + xfree(o->op->buf); if (o->op->stream_close) o->op->stream_close(o->op->print); if (o->op->iconv_handle != 0) @@ -272,19 +272,24 @@ void odr_destroy(ODR o) void odr_setbuf(ODR o, char *buf, int len, int can_grow) { odr_seterror(o, ONONE, 0); - o->bp = buf; - o->buf = buf; + o->op->bp = buf; + o->op->buf = buf; o->op->can_grow = can_grow; - o->top = o->pos = 0; - o->size = len; + o->op->top = o->op->pos = 0; + o->op->size = len; } char *odr_getbuf(ODR o, int *len, int *size) { - *len = o->top; + *len = o->op->top; if (size) - *size = o->size; - return (char*) o->buf; + *size = o->op->size; + return o->op->buf; +} + +int odr_offset(ODR o) +{ + return o->op->bp - o->op->buf; } void odr_printf(ODR o, const char *fmt, ...) diff --git a/src/odr_choice.c b/src/odr_choice.c index c025157..a3264d9 100644 --- a/src/odr_choice.c +++ b/src/odr_choice.c @@ -56,7 +56,7 @@ int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp, { if (o->op->stack_top && !odr_constructed_more(o)) return 0; - if (ber_dectag(o->bp, &cl, &tg, &cn, odr_max(o)) <= 0) + if (ber_dectag(o->op->bp, &cl, &tg, &cn, odr_max(o)) <= 0) return 0; } else if (o->direction != ODR_DECODE) diff --git a/src/odr_cons.c b/src/odr_cons.c index 4a18372..5df0fa6 100644 --- a/src/odr_cons.c +++ b/src/odr_cons.c @@ -83,7 +83,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag, o->op->stack_top = o->op->stack_first; assert(o->op->stack_top->prev == 0); } - o->op->stack_top->lenb = o->bp; + o->op->stack_top->lenb = o->op->bp; o->op->stack_top->len_offset = odr_tell(o); o->op->stack_top->name = name ? name : "?"; if (o->direction == ODR_ENCODE) @@ -100,7 +100,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag, } else if (o->direction == ODR_DECODE) { - if ((res = ber_declen(o->bp, &o->op->stack_top->len, + if ((res = ber_declen(o->op->bp, &o->op->stack_top->len, odr_max(o))) < 0) { odr_seterror(o, OOTHER, 31); @@ -108,7 +108,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag, return 0; } o->op->stack_top->lenlen = res; - o->bp += res; + o->op->bp += res; if (o->op->stack_top->len > odr_max(o)) { odr_seterror(o, OOTHER, 32); @@ -128,7 +128,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag, ODR_STACK_POP(o); return 0; } - o->op->stack_top->base = o->bp; + o->op->stack_top->base = o->op->bp; o->op->stack_top->base_offset = odr_tell(o); return 1; } @@ -140,9 +140,9 @@ int odr_constructed_more(ODR o) if (ODR_STACK_EMPTY(o)) return 0; if (o->op->stack_top->len >= 0) - return o->bp - o->op->stack_top->base < o->op->stack_top->len; + return o->op->bp - o->op->stack_top->base < o->op->stack_top->len; else - return (!(*o->bp == 0 && *(o->bp + 1) == 0)); + return (!(*o->op->bp == 0 && *(o->op->bp + 1) == 0)); } int odr_constructed_end(ODR o) @@ -162,7 +162,7 @@ int odr_constructed_end(ODR o) case ODR_DECODE: if (o->op->stack_top->len < 0) { - if (*o->bp++ == 0 && *(o->bp++) == 0) + if (*o->op->bp++ == 0 && *(o->op->bp++) == 0) { ODR_STACK_POP(o); return 1; @@ -173,7 +173,7 @@ int odr_constructed_end(ODR o) return 0; } } - else if (o->bp - o->op->stack_top->base != + else if (o->op->bp - o->op->stack_top->base != o->op->stack_top->len) { odr_seterror(o, OCONLEN, 36); diff --git a/src/odr_mem.c b/src/odr_mem.c index 33e2bfa..28181e3 100644 --- a/src/odr_mem.c +++ b/src/odr_mem.c @@ -80,46 +80,47 @@ int odr_grow_block(ODR b, int min_bytes) if (!b->op->can_grow) return -1; - if (!b->size) + if (!b->op->size) togrow = 1024; else - togrow = b->size; + togrow = b->op->size; if (togrow < min_bytes) togrow = min_bytes; - if (b->size && !(b->buf = - (char *) xrealloc(b->buf, b->size += togrow))) + if (b->op->size && !(b->op->buf = + (char *) xrealloc(b->op->buf, b->op->size += togrow))) abort(); - else if (!b->size && !(b->buf = (char *) xmalloc(b->size = togrow))) + else if (!b->op->size && !(b->op->buf = (char *) + xmalloc(b->op->size = togrow))) abort(); return 0; } int odr_write(ODR o, const char *buf, int bytes) { - if (o->pos + bytes >= o->size && odr_grow_block(o, bytes)) + if (o->op->pos + bytes >= o->op->size && odr_grow_block(o, bytes)) { odr_seterror(o, OSPACE, 40); return -1; } - memcpy(o->buf + o->pos, buf, bytes); - o->pos += bytes; - if (o->pos > o->top) - o->top = o->pos; + memcpy(o->op->buf + o->op->pos, buf, bytes); + o->op->pos += bytes; + if (o->op->pos > o->op->top) + o->op->top = o->op->pos; return 0; } int odr_seek(ODR o, int whence, int offset) { if (whence == ODR_S_CUR) - offset += o->pos; + offset += o->op->pos; else if (whence == ODR_S_END) - offset += o->top; - if (offset > o->size && odr_grow_block(o, offset - o->size)) + offset += o->op->top; + if (offset > o->op->size && odr_grow_block(o, offset - o->op->size)) { odr_seterror(o, OSPACE, 41); return -1; } - o->pos = offset; + o->op->pos = offset; return 0; } diff --git a/src/odr_tag.c b/src/odr_tag.c index 9b94781..e696610 100644 --- a/src/odr_tag.c +++ b/src/odr_tag.c @@ -21,7 +21,7 @@ int odr_peektag(ODR o, int *zclass, int *tag, int *cons) } if (ODR_STACK_NOT_EMPTY(o) && !odr_constructed_more(o)) return 0; - if (ber_dectag(o->bp, zclass, tag, cons, odr_max(o)) <= 0) + if (ber_dectag(o->op->bp, zclass, tag, cons, odr_max(o)) <= 0) { odr_seterror(o, OREQUIRED, 49); return 0; diff --git a/src/odr_util.c b/src/odr_util.c index a5c64d6..0f6c006 100644 --- a/src/odr_util.c +++ b/src/odr_util.c @@ -32,16 +32,16 @@ int odp_more_chunks(ODR o, const char *base, int len) return 0; if (len < 0) /* indefinite length */ { - if (*o->bp == 0 && *(o->bp + 1) == 0) + if (*o->op->bp == 0 && *(o->op->bp + 1) == 0) { - o->bp += 2; + o->op->bp += 2; return 0; } else return 1; } else - return o->bp - base < len; + return o->op->bp - base < len; } Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o) diff --git a/src/prt-ext.c b/src/prt-ext.c index 2f904f1..7909e98 100644 --- a/src/prt-ext.c +++ b/src/prt-ext.c @@ -13,6 +13,7 @@ #include #include +#include "odr-priv.h" #define PRT_EXT_DEBUG 0 #if PRT_EXT_DEBUG @@ -227,13 +228,13 @@ int z_External(ODR o, Z_External **p, int opt, const char *name) return 0; /* Save our decoding ODR members */ - o_bp = o->bp; - o_buf = o->buf; - o_size = o->size; + o_bp = o->op->bp; + o_buf = o->op->buf; + o_size = o->op->size; /* Set up the OCTET STRING buffer */ - o->bp = o->buf = oct->buf; - o->size = oct->len; + o->op->bp = o->op->buf = oct->buf; + o->op->size = oct->len; /* and decode that */ r = (*type->fun)(o, &voidp, 0, 0); @@ -241,9 +242,9 @@ int z_External(ODR o, Z_External **p, int opt, const char *name) (*p)->u.single_ASN1_type = (Odr_any*) voidp; /* Restore our decoding ODR member */ - o->bp = o_bp; - o->buf = o_buf; - o->size = o_size; + o->op->bp = o_bp; + o->op->buf = o_buf; + o->op->size = o_size; return r && odr_sequence_end(o); } diff --git a/src/zgdu.c b/src/zgdu.c index ecdb9e6..8c8222e 100644 --- a/src/zgdu.c +++ b/src/zgdu.c @@ -11,24 +11,25 @@ #endif #include -#include +#include "odr-priv.h" #include int z_GDU(ODR o, Z_GDU **p, int opt, const char *name) { + const char *buf = o->op->buf; if (o->direction == ODR_DECODE) { *p = (Z_GDU *) odr_malloc(o, sizeof(**p)); - if (o->size > 10 && !memcmp(o->buf, "HTTP/", 5)) + if (o->op->size > 10 && !memcmp(buf, "HTTP/", 5)) { (*p)->which = Z_GDU_HTTP_Response; return yaz_decode_http_response(o, &(*p)->u.HTTP_Response); } - else if (o->size > 5 && - o->buf[0] >= 0x20 && o->buf[0] < 0x7f - && o->buf[1] >= 0x20 && o->buf[1] < 0x7f - && o->buf[2] >= 0x20 && o->buf[2] < 0x7f - && o->buf[3] >= 0x20 && o->buf[3] < 0x7f) + else if (o->op->size > 5 && + buf[0] >= 0x20 && buf[0] < 0x7f + && buf[1] >= 0x20 && buf[1] < 0x7f + && buf[2] >= 0x20 && buf[2] < 0x7f + && buf[3] >= 0x20 && buf[3] < 0x7f) { (*p)->which = Z_GDU_HTTP_Request; return yaz_decode_http_request(o, &(*p)->u.HTTP_Request); -- 1.7.10.4