#if OCT_SIZE
oct->size = status.st_size;
#endif
- oct->buf = (unsigned char *) odr_malloc (out, oct->len);
+ oct->buf = (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);
#if OCT_SIZE
id->size = id->len;
#endif
- id->buf = (unsigned char *) odr_malloc(out, id->len);
+ id->buf = (char *) odr_malloc(out, id->len);
memcpy(id->buf, refid, id->len);
return id;
}
req->referenceId = set_refid(out);
if (!strcmp(arg, "@big")) /* strictly for troublemaking */
{
- static unsigned char big[2100];
+ static char big[2100];
static Odr_oct bigo;
/* send a very big referenceid to test transport stack etc. */
case QueryType_CCL:
query.which = Z_Query_type_2;
query.u.type_2 = &ccl_query;
- ccl_query.buf = (unsigned char*) arg;
+ ccl_query.buf = (char *) arg;
ccl_query.len = strlen(arg);
break;
case QueryType_CCL2RPN:
r->u.single_ASN1_type = (Odr_oct *)
odr_malloc(out, sizeof(*r->u.single_ASN1_type));
- r->u.single_ASN1_type->buf = (unsigned char *)
- odr_malloc(out, item_request_size);
+ r->u.single_ASN1_type->buf = (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;
r->u.single_ASN1_type = (Odr_oct *)
odr_malloc(out, sizeof(*r->u.single_ASN1_type));
- r->u.single_ASN1_type->buf = (unsigned char *)
- odr_malloc(out, ill_request_size);
+ r->u.single_ASN1_type->buf = (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;
{
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->buf = (char *) recid;
#if OCT_SIZE
notToKeep->elements[0]->u.opaque->size = strlen(recid);
#endif
{
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->buf = (char *) recid;
#if OCT_SIZE
notToKeep->elements[0]->u.opaque->size = strlen(recid);
#endif
&ext->u.single_ASN1_type->len) == 0)
return 0;
- ext->u.single_ASN1_type->buf = (unsigned char *) asn_buf;
+ ext->u.single_ASN1_type->buf = asn_buf;
oid = yaz_string_to_oid_odr(yaz_oid_std(),
CLASS_EXTSERV, oid_str, out);
req->termListAndStartPoint->term->u.general)
{
req->termListAndStartPoint->term->u.general->buf =
- (unsigned char *) odr_strdup(out, term);
+ odr_strdup(out, term);
req->termListAndStartPoint->term->u.general->len = strlen(term);
#if OCT_SIZE
req->termListAndStartPoint->term->u.general->size = strlen(term);
typedef struct odr_oct
{
- unsigned char *buf;
+ char *buf;
int len;
#if OCT_SIZE
int size;
typedef struct odr_bitmask
{
#define ODR_BITMASK_SIZE 256
- unsigned char bits[ODR_BITMASK_SIZE];
+ char bits[ODR_BITMASK_SIZE];
int top;
} Odr_bitmask;
int error; /* current error state (0==OK) */
- unsigned char *buf; /* memory handle */
+ 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 unsigned char *bp; /* position in buffer (decoding) */
+ const char *bp; /* position in buffer (decoding) */
NMEM mem; /* memory handle for decoding (primarily) */
YAZ_EXPORT char *odr_strdup_null(ODR o, const char *str);
YAZ_EXPORT Odr_int *odr_intdup(ODR o, Odr_int v);
YAZ_EXPORT Odr_bool *odr_booldup(ODR o, Odr_bool v);
-YAZ_EXPORT Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf,
- int sz);
+YAZ_EXPORT Odr_oct *odr_create_Odr_oct(ODR o, const char *buf, int sz);
YAZ_EXPORT NMEM odr_extract_mem(ODR o);
YAZ_EXPORT Odr_null *odr_nullval(void);
#define odr_release_mem(m) nmem_destroy(m)
YAZ_EXPORT int ber_tag(ODR o, void *p, int zclass, int tag,
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,
+YAZ_EXPORT int ber_dectag(const char *buf, int *zclass,
int *tag, int *constructed, int max);
YAZ_EXPORT int odr_bool(ODR o, Odr_bool **p, int opt, const char *name);
YAZ_EXPORT int odr_integer(ODR o, Odr_int **p, int opt, const char *name);
YAZ_EXPORT int odr_enum(ODR o, Odr_int **p, int opt, const char *name);
YAZ_EXPORT int odr_implicit_settag(ODR o, int zclass, int tag);
YAZ_EXPORT int ber_enclen(ODR o, int len, int lenlen, int exact);
-YAZ_EXPORT int ber_declen(const unsigned char *buf, int *len, int max);
+YAZ_EXPORT int ber_declen(const char *buf, int *len, int max);
YAZ_EXPORT void odr_prname(ODR o, const char *name);
YAZ_EXPORT int ber_null(ODR o);
YAZ_EXPORT int odr_null(ODR o, Odr_null **p, int opt, const char *name);
YAZ_EXPORT int odr_set_end(ODR o);
YAZ_EXPORT int ber_octetstring(ODR o, Odr_oct *p, int cons);
YAZ_EXPORT int odr_octetstring(ODR o, Odr_oct **p, int opt, const char *name);
-YAZ_EXPORT int odp_more_chunks(ODR o, const unsigned char *base, int len);
+YAZ_EXPORT int odp_more_chunks(ODR o, const char *base, int len);
YAZ_EXPORT int odr_constructed_more(ODR o);
YAZ_EXPORT int odr_bitstring(ODR o, Odr_bitmask **p, int opt,
const char *name);
\retval 0 package is incomplete
\retval >0 package is complete and length is return value
*/
-YAZ_EXPORT int completeBER(const unsigned char *buf, int len);
+YAZ_EXPORT int completeBER(const char *buf, int len);
YAZ_EXPORT void odr_begin(ODR o);
YAZ_EXPORT void odr_end(ODR o);
YAZ_EXPORT Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o);
YAZ_EXPORT Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o);
YAZ_EXPORT int odr_grow_block(ODR b, int min_bytes);
-YAZ_EXPORT int odr_write(ODR o, unsigned char *buf, int bytes);
YAZ_EXPORT int odr_write2(ODR o, const char *buf, int bytes);
YAZ_EXPORT int odr_seek(ODR o, int whence, int offset);
YAZ_EXPORT int odr_dumpBER(FILE *f, const char *buf, int len);
odr_seterror(o, OPROTO, 2);
return 0;
}
- (*p)->buf = (unsigned char *)odr_malloc(o, res);
+ (*p)->buf = (char *)odr_malloc(o, res);
memcpy((*p)->buf, o->bp, res);
(*p)->len = res;
#if OCT_SIZE
o->bp += res;
return 1;
case ODR_ENCODE:
- if (odr_write(o, (*p)->buf, (*p)->len) < 0)
+ if (odr_write2(o, (*p)->buf, (*p)->len) < 0)
return 0;
return 1;
default: odr_seterror(o, OOTHER, 3); return 0;
#define BER_ANY_DEBUG 0
-int completeBER_n(const unsigned char *buf, int len, int level)
+int completeBER_n(const char *buf, int len, int level)
{
int res, ll, zclass, tag, cons;
- const unsigned char *b = buf;
+ const char *b = buf;
if (level > 1000)
{
return (b - buf) + 2;
}
-int completeBER(const unsigned char *buf, int len)
+int completeBER(const char *buf, int len)
{
int res = completeBER_n(buf, len, 0);
#if BER_ANY_DEBUG
int ber_bitstring(ODR o, Odr_bitmask *p, int cons)
{
int res, len;
- const unsigned char *base;
+ const char *base;
switch (o->direction)
{
return 0;
if (p->top < 0)
return 1;
- if (odr_write(o, p->bits, p->top + 1) < 0)
+ if (odr_write2(o, p->bits, p->top + 1) < 0)
return 0;
return 1;
case ODR_PRINT:
#include "odr-priv.h"
static int ber_encinteger(ODR o, Odr_int val);
-static int ber_decinteger(const unsigned char *buf, Odr_int *val, int max);
+static int ber_decinteger(const char *buf, Odr_int *val, int max);
int ber_integer(ODR o, Odr_int *val)
{
len = sizeof(uval) - i;
if (ber_enclen(o, len, 1, 1) != 1)
return -1;
- if (odr_write(o, (unsigned char*) tmp + i, len) < 0)
+ if (odr_write2(o, (const char *) tmp + i, len) < 0)
return -1;
return 0;
}
/*
* Returns: Number of bytes read or 0 if no match, -1 if error.
*/
-int ber_decinteger(const unsigned char *buf, Odr_int *val, int max)
+int ber_decinteger(const char *buf, Odr_int *val, int max)
{
unsigned long long uval = 0;
int i, len;
int res;
- const unsigned char *b = buf;
+ const unsigned char *b = (const unsigned char *) buf;
- if ((res = ber_declen(b, &len, max)) < 0)
+ if ((res = ber_declen((const char *) b, &len, max)) < 0)
return -1;
if (len+res > max || len < 0) /* out of bounds or indefinite encoding */
return -1;
uval = (uval << 8) + b[i];
*val = uval;
b += len;
- return b - buf;
+ return (const char *) b - buf;
}
/*
* Local variables:
* len = -1 indefinite length.
* len >= 0 definite length
*/
-int ber_declen(const unsigned char *buf, int *len, int max)
+int ber_declen(const char *buf, int *len, int max)
{
- const unsigned char *b = buf;
+ const unsigned char *b = (const unsigned char *) buf;
int n;
if (max < 1)
}
if (*len < 0)
return -2;
- return (b - buf);
+ return ((const char *) b - buf);
}
/*
* Local variables:
int ber_octetstring(ODR o, Odr_oct *p, int cons)
{
int res, len;
- const unsigned char *base;
+ const char *base;
#if OCT_SIZE
unsigned char *c;
#endif
return 0;
if (p->len == 0)
return 1;
- if (odr_write(o, p->buf, p->len) < 0)
+ if (odr_write2(o, p->buf, p->len) < 0)
return 0;
return 1;
case ODR_PRINT:
*
* Returns number of bytes read or -1 for error.
*/
-int ber_dectag(const unsigned char *b, int *zclass, int *tag,
+int ber_dectag(const char *cp, int *zclass, int *tag,
int *constructed, int max)
{
+ const unsigned char *b = (const unsigned char *) cp;
int l = 1;
if (l > max)
p->which = Z_External_octet;
if (!(p->u.octet_aligned = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct))))
return 0;
- if (!(p->u.octet_aligned->buf = (unsigned char *)odr_malloc(o, len)))
+ if (!(p->u.octet_aligned->buf = (char *)odr_malloc(o, len)))
return 0;
p->u.octet_aligned->len = len;
#if OCT_SIZE
int r = cs_complete_http(buf, len, head_only);
return r;
}
- return completeBER((const unsigned char *) buf, len);
+ return completeBER(buf, len);
}
return 0;
if (!buf[0] && !buf[1])
return 0;
- if ((res = ber_dectag((unsigned char*)b, &zclass, &tag, &cons, len)) <= 0)
+ if ((res = ber_dectag(b, &zclass, &tag, &cons, len)) <= 0)
return 0;
if (res > len)
{
b += res;
taglen = res;
len -= res;
- if ((res = ber_declen((unsigned char*)b, &ll, len)) <= 0)
+ if ((res = ber_declen(b, &ll, len)) <= 0)
{
fprintf(f, "\n%sBad length\n", level_str);
return 0;
odr_write2(o, "\r\n", 2);
}
}
- odr_write(o, (unsigned char *) "\r\n", 2);
+ odr_write2(o, "\r\n", 2);
if (hr->content_buf)
odr_write2(o, hr->content_buf, hr->content_len);
if (o->direction == ODR_PRINT)
*/
struct odr_constack
{
- const unsigned char *base; /** starting point of data */
+ const char *base; /** starting point of data */
int base_offset;
int len; /** length of data, if known, else -1
(decoding only) */
- const unsigned char *lenb; /** where to encode length */
+ const char *lenb; /** where to encode length */
int len_offset;
int lenlen; /** length of length-field */
const char *name; /** name of stack entry */
void odr_setbuf(ODR o, char *buf, int len, int can_grow)
{
odr_seterror(o, ONONE, 0);
- o->bp = (unsigned char *) buf;
- o->buf = (unsigned char *) buf;
+ o->bp = buf;
+ o->buf = buf;
o->op->can_grow = can_grow;
o->top = o->pos = 0;
o->size = len;
o->op->stack_top->name = name ? name : "?";
if (o->direction == ODR_ENCODE)
{
- static unsigned char dummy[sizeof(int)+1];
+ static char dummy[sizeof(int)+1];
o->op->stack_top->lenlen = lenlen;
- if (odr_write(o, dummy, lenlen) < 0) /* dummy */
+ if (odr_write2(o, dummy, lenlen) < 0) /* dummy */
{
ODR_STACK_POP(o);
return 0;
return nmem_total(o->mem);
}
-Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf, int sz)
+Odr_oct *odr_create_Odr_oct(ODR o, const char *buf, int sz)
{
Odr_oct *p = (Odr_oct *) odr_malloc(o, sizeof(Odr_oct));
- p->buf = (unsigned char *) odr_malloc(o, sz);
+ p->buf = (char *) odr_malloc(o, sz);
memcpy(p->buf, buf, sz);
#if OCT_SIZE
p->size = sz;
if (togrow < min_bytes)
togrow = min_bytes;
if (b->size && !(b->buf =
- (unsigned char *) xrealloc(b->buf, b->size += togrow)))
+ (char *) xrealloc(b->buf, b->size += togrow)))
abort();
- else if (!b->size && !(b->buf = (unsigned char *)
- xmalloc(b->size = togrow)))
+ else if (!b->size && !(b->buf = (char *) xmalloc(b->size = togrow)))
abort();
return 0;
}
return 0;
}
-int odr_write(ODR o, unsigned char *buf, int bytes)
-{
- return odr_write2(o, (char *) buf, bytes);
-}
-
int odr_seek(ODR o, int whence, int offset)
{
if (whence == ODR_S_CUR)
t = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); /* wrapper for octstring */
if (o->direction == ODR_ENCODE)
{
- t->buf = (unsigned char *) *p;
+ t->buf = *p;
t->len = strlen(*p);
#if OCT_SIZE
t->size = t->len;
char *outbuf = (char *) odr_malloc (o, outleft);
size_t ret;
- t->buf = (unsigned char *) outbuf;
+ t->buf = outbuf;
ret = yaz_iconv(o->op->iconv_handle, &inbuf, &inleft,
&outbuf, &outleft);
}
if (!t->buf)
{
- t->buf = (unsigned char *) *p;
+ t->buf = *p;
t->len = strlen(*p);
#if OCT_SIZE
t->size = t->len;
odr_printf(o, "%s ", name);
}
-int odp_more_chunks(ODR o, const unsigned char *base, int len)
+int odp_more_chunks(ODR o, const char *base, int len)
{
if (!len)
return 0;
{
Z_Term *term = (Z_Term *)odr_malloc(o, sizeof(*term));
Odr_oct *term_octet = (Odr_oct *)odr_malloc(o, sizeof(*term_octet));
- term_octet->buf = (unsigned char *)odr_malloc(o, 1 + len);
+ term_octet->buf = (char *)odr_malloc(o, 1 + len);
memcpy(term_octet->buf, buf, len);
term_octet->len = len;
#if OCT_SIZE
if (zclass == ODR_CONTEXT && tag == 1 && cons == 0)
{
/* we have an OCTET STRING. decode BER contents from it */
- const unsigned char *o_bp;
- unsigned char *o_buf;
+ const char *o_bp;
+ char *o_buf;
int o_size;
char *voidp = 0;
Odr_oct *oct;
thisext->which = Z_External_sutrs;
thisext->u.sutrs = sutrs;
- sutrs->buf = (unsigned char *)nmem_malloc(nmem, len);
+ sutrs->buf = (char *)nmem_malloc(nmem, len);
sutrs->len = len;
#if OCT_SIZE
sutrs->size = len;
if (!(thisext->u.octet_aligned = (Odr_oct *)
nmem_malloc(nmem, sizeof(Odr_oct))))
return 0;
- if (!(thisext->u.octet_aligned->buf = (unsigned char *)
+ if (!(thisext->u.octet_aligned->buf = (char *)
nmem_malloc(nmem, len)))
return 0;
memcpy(thisext->u.octet_aligned->buf, buf, len);
thisext->u.single_ASN1_type = (Odr_any *) odr_malloc(o, sizeof(Odr_any));
if (!thisext->u.single_ASN1_type)
return 0;
- thisext->u.single_ASN1_type->buf = (unsigned char *) odr_malloc(o, len);
+ thisext->u.single_ASN1_type->buf = (char *) odr_malloc(o, len);
if (!thisext->u.single_ASN1_type->buf)
return 0;
memcpy(thisext->u.single_ASN1_type->buf, buf, len);
t->term->which = Z_Term_general;
t->term->u.general = o =
(Odr_oct *)odr_malloc(assoc->encode, sizeof(Odr_oct));
- o->buf = (unsigned char *)
+ o->buf = (char *)
odr_malloc(assoc->encode, o->len =
strlen(bsrr->entries[i].term));
#if OCT_SIZE
#if OCT_SIZE
sks->u.missingValueData->size = sks->u.missingValueData->len;
#endif
- sks->u.missingValueData->buf = (unsigned char*)
- odr_strdup(out, sort_flags+i);
+ sks->u.missingValueData->buf = odr_strdup(out, sort_flags+i);
i += strlen(sort_flags+i) - 1;
break;
}
{
(*term)->which = Z_Term_general;
(*term)->u.general =
- odr_create_Odr_oct(odr, (unsigned char *)cdata, strlen(cdata));
+ odr_create_Odr_oct(odr, cdata, strlen(cdata));
}
else if (!xmlStrcmp(type, BAD_CAST "numeric"))
{
x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1);
x->which = Z_External_octet;
x->u.octet_aligned = (Odr_oct *) odr_malloc(odr, sizeof(Odr_oct));
- x->u.octet_aligned->buf = (unsigned char *) odr_malloc(odr, octet_len);
+ x->u.octet_aligned->buf = (char *) odr_malloc(odr, octet_len);
memcpy(x->u.octet_aligned->buf, octet_buf, octet_len);
x->u.octet_aligned->len = octet_len;
npr->u.databaseRecord->u.octet_aligned = (Odr_oct *)
odr_malloc(c->odr_in, sizeof(Odr_oct));
- npr->u.databaseRecord->u.octet_aligned->buf = (unsigned char*)
+ npr->u.databaseRecord->u.octet_aligned->buf =
sru_rec->recordData_buf;
npr->u.databaseRecord->u.octet_aligned->len =
sru_rec->recordData_len;
r->which = Z_External_single;
r->u.single_ASN1_type =
- odr_create_Odr_oct(out,
- (unsigned char *)illRequest_buf,
- illRequest_size);
+ odr_create_Odr_oct(out, illRequest_buf, illRequest_size);
}
return r;
}
ext->indirect_reference = 0;
ext->which = Z_External_octet;
- ext->u.single_ASN1_type =
- odr_create_Odr_oct(p->odr_out, (const unsigned char *) doc, len);
+ ext->u.single_ASN1_type = odr_create_Odr_oct(p->odr_out, doc, len);
return apdu;
}
if (recordIdOpaque)
{
notToKeep->elements[0]->u.opaque =
- odr_create_Odr_oct(p->odr_out,
- (const unsigned char *) recordIdOpaque,
+ odr_create_Odr_oct(p->odr_out, recordIdOpaque,
recordIdOpaque_len);
}
else if (recordIdNumber)
YAZ_CHECK(s);
s->first = odr_intdup(encode, 12345);
s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second));
- s->second->buf = (unsigned char *) "hello";
+ s->second->buf = (char *) "hello";
s->second->len = 5;
#if OCT_SIZE
s->second->size = 0;
YAZ_CHECK(s);
s->first = 0; /* deliberately miss this .. */
s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second));
- s->second->buf = (unsigned char *) "hello";
+ s->second->buf = (char *) "hello";
s->second->len = 5;
#if OCT_SIZE
s->second->size = 0;
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <yaz/wrbuf.h>
#include <yaz/test.h>
buf= odr_getbuf(odr_ext,&siz,0);
ext->u.single_ASN1_type=(Odr_any *)
odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
- ext->u.single_ASN1_type->buf= (unsigned char *) odr_malloc(odr, siz);
+ ext->u.single_ASN1_type->buf= (char *) odr_malloc(odr, siz);
memcpy(ext->u.single_ASN1_type->buf,buf, siz );
ext->u.single_ASN1_type->len = siz;
#if OCT_SIZE
printf("External: \n");
z_External(odr_prt, &ext,0,0); /*!*/
buf= odr_getbuf(odr_ext,&siz,0);
- e->item->buf= (unsigned char *) odr_malloc(odr, siz);
+ e->item->buf= (char *) odr_malloc(odr, siz);
memcpy(e->item->buf,buf, siz );
e->item->len = siz;
#if OCT_SIZE
buf= odr_getbuf(odr_ext,&siz,0);
ext->u.single_ASN1_type = (Odr_any*)
odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
- ext->u.single_ASN1_type->buf = (unsigned char *) odr_malloc(odr, siz);
+ ext->u.single_ASN1_type->buf = (char *) odr_malloc(odr, siz);
memcpy(ext->u.single_ASN1_type->buf,buf, siz );
ext->u.single_ASN1_type->len = siz;
#if OCT_SIZE
printf("External: \n");
z_External(odr_prt, &ext,0,0); /*!*/
buf= odr_getbuf(odr_ext,&siz,0);
- e->item->buf= (unsigned char *) odr_malloc(odr, siz);
+ e->item->buf= (char *) odr_malloc(odr, siz);
memcpy(e->item->buf, buf, siz);
e->item->len = siz;
#if OCT_SIZE
rr->taskPackage->targetReference = (Odr_oct *)
odr_malloc(rr->stream, sizeof(Odr_oct));
rr->taskPackage->targetReference->buf =
- (unsigned char *) odr_strdup(rr->stream, "911");
+ odr_strdup(rr->stream, "911");
rr->taskPackage->targetReference->len =
strlen((char *) (rr->taskPackage->targetReference->buf));
#if OCT_SIZE
rr->taskPackage->targetReference = (Odr_oct *)
odr_malloc(rr->stream, sizeof(Odr_oct));
rr->taskPackage->targetReference->buf =
- (unsigned char *) odr_strdup(rr->stream, "123");
+ odr_strdup(rr->stream, "123");
rr->taskPackage->targetReference->len =
strlen((char *) (rr->taskPackage->targetReference->buf));
#if OCT_SIZE