00001
00002
00003
00004
00005
00014 #if HAVE_CONFIG_H
00015 #include <config.h>
00016 #endif
00017
00018 #include "odr-priv.h"
00019
00020 int ber_octetstring(ODR o, Odr_oct *p, int cons)
00021 {
00022 int res, len;
00023 const unsigned char *base;
00024 unsigned char *c;
00025
00026 switch (o->direction)
00027 {
00028 case ODR_DECODE:
00029 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
00030 {
00031 odr_seterror(o, OPROTO, 14);
00032 return 0;
00033 }
00034 o->bp += res;
00035 if (cons)
00036 {
00037 base = o->bp;
00038 while (odp_more_chunks(o, base, len))
00039 if (!odr_octetstring(o, &p, 0, 0))
00040 return 0;
00041 return 1;
00042 }
00043
00044 if (len < 0)
00045 {
00046 odr_seterror(o, OOTHER, 15);
00047 return 0;
00048 }
00049 if (len > odr_max(o))
00050 {
00051 odr_seterror(o, OOTHER, 16);
00052 return 0;
00053 }
00054 if (len + 1 > p->size - p->len)
00055 {
00056 c = (unsigned char *)odr_malloc(o, p->size += len + 1);
00057 if (p->len)
00058 memcpy(c, p->buf, p->len);
00059 p->buf = c;
00060 }
00061 if (len)
00062 memcpy(p->buf + p->len, o->bp, len);
00063 p->len += len;
00064 o->bp += len;
00065
00066
00067 if (len)
00068 p->buf[p->len] = '\0';
00069 return 1;
00070 case ODR_ENCODE:
00071 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
00072 return 0;
00073 if (p->len == 0)
00074 return 1;
00075 if (odr_write(o, p->buf, p->len) < 0)
00076 return 0;
00077 return 1;
00078 case ODR_PRINT:
00079 return 1;
00080 default:
00081 odr_seterror(o, OOTHER, 17);
00082 return 0;
00083 }
00084 }
00085
00086
00087
00088
00089
00090
00091
00092