YAZ 5.35.1
ber_oct.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
5
14#if HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "odr-priv.h"
19#include <yaz/log.h>
20#include <assert.h>
21
22int ber_octetstring(ODR o, Odr_oct *p, int cons)
23{
24 int res, len;
25 const char *base;
26
27 switch (o->direction)
28 {
29 case ODR_DECODE:
30 if ((res = ber_declen(o->op->bp, &len, odr_max(o))) < 0)
31 {
32 odr_seterror(o, OPROTO, 14);
33 return 0;
34 }
35 o->op->bp += res;
36 if (cons) /* fetch component strings */
37 {
38 base = o->op->bp;
39 while (odp_more_chunks(o, base, len))
40 if (!odr_octetstring(o, &p, 0, 0))
41 return 0;
42 return 1;
43 }
44 /* primitive octetstring */
45 if (len < 0)
46 {
47 odr_seterror(o, OOTHER, 15);
48 return 0;
49 }
50 if (len > odr_max(o))
51 {
52 odr_seterror(o, OOTHER, 16);
53 return 0;
54 }
55 p->len = len;
56 p->buf = odr_strdupn(o, o->op->bp, len);
57 o->op->bp += len;
58 return 1;
59 case ODR_ENCODE:
60 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
61 return 0;
62 if (p->len == 0)
63 return 1;
64 if (odr_write(o, p->buf, p->len) < 0)
65 return 0;
66 return 1;
67 case ODR_PRINT:
68 return 1;
69 default:
70 odr_seterror(o, OOTHER, 17);
71 return 0;
72 }
73}
74/*
75 * Local variables:
76 * c-basic-offset: 4
77 * c-file-style: "Stroustrup"
78 * indent-tabs-mode: nil
79 * End:
80 * vim: shiftwidth=4 tabstop=8 expandtab
81 */
82
int ber_declen(const char *buf, int *len, int max)
Definition ber_len.c:93
int ber_enclen(ODR o, int len, int lenlen, int exact)
Definition ber_len.c:30
int ber_octetstring(ODR o, Odr_oct *p, int cons)
Definition ber_oct.c:22
Logging utility.
Internal ODR definitions.
#define odr_max(o)
Definition odr-priv.h:47
void odr_seterror(ODR o, int error, int id)
Definition odr.c:118
#define ODR_DECODE
Definition odr.h:95
#define ODR_PRINT
Definition odr.h:97
#define OOTHER
Definition odr.h:156
#define ODR_ENCODE
Definition odr.h:96
#define OPROTO
Definition odr.h:157
char * odr_strdupn(ODR o, const char *str, size_t n)
Definition odr_mem.c:46
int odr_write(ODR o, const char *buf, int bytes)
Definition odr_mem.c:98
int odr_octetstring(ODR o, Odr_oct **p, int opt, const char *name)
Definition odr_oct.c:19
int odp_more_chunks(ODR o, const char *base, int len)
Definition odr_util.c:29
const char * bp
Definition odr-priv.h:85
Definition odr.h:100
int len
Definition odr.h:102
char * buf
Definition odr.h:101
Definition odr.h:125
struct Odr_private * op
Definition odr.h:132
int direction
Definition odr.h:126