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;
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);
((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)
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)
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;
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)
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;
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)
odr_seterror(o, OPROTO, 39);
return 0;
}
- if (*(o->bp++) != 0X00)
+ if (*(o->op->bp++) != 0X00)
{
odr_seterror(o, OPROTO, 12);
return 0;
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;
}
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)
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;
odr_seterror(o, OPROTO, 19);
return 0;
}
- o->bp += res;
+ o->op->bp += res;
if (len > odr_max(o))
{
odr_seterror(o, OPROTO, 20);
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)
{
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)
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)
{
}
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;
#include <config.h>
#endif
-#include <yaz/odr.h>
+#include "odr-priv.h"
#include <yaz/yaz-version.h>
#include <yaz/yaz-iconv.h>
#include <yaz/matchstr.h>
{
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")
!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;
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;
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;
}
}
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';
}
}
{
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);
{
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;
{
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,
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;
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);
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;
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
* \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 */
#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.
#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 \
) : \
( \
) \
) == 0 ? \
( \
- (o)->pos > (o)->top ? \
+ (o)->op->pos > (o)->op->top ? \
( \
- (o)->top = (o)->pos, \
+ (o)->op->top = (o)->op->pos, \
0 \
) : \
0 \
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;
}
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;
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)
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, ...)
{
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)
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)
}
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);
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);
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;
}
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)
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;
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);
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;
}
}
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;
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)
#include <yaz/proto.h>
#include <yaz/oid_db.h>
+#include "odr-priv.h"
#define PRT_EXT_DEBUG 0
#if PRT_EXT_DEBUG
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);
(*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);
}
#endif
#include <string.h>
-#include <yaz/odr.h>
+#include "odr-priv.h"
#include <yaz/zgdu.h>
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);