Remove member soap_handler from statserv_options_block
[yaz-moved-to-github.git] / src / ber_oct.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file ber_oct.c
8  * \brief Implements ber_octetstring
9  *
10  * This source file implements BER encoding and decoding of
11  * the OCTETSTRING type.
12  */
13
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
22 int 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_malloc(o, len + 1);
57         memcpy(p->buf, o->op->bp, len);
58         p->buf[len] = '\0';
59         o->op->bp += len;
60         return 1;
61     case ODR_ENCODE:
62         if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
63             return 0;
64         if (p->len == 0)
65             return 1;
66         if (odr_write(o, p->buf, p->len) < 0)
67             return 0;
68         return 1;
69     case ODR_PRINT:
70         return 1;
71     default:
72         odr_seterror(o, OOTHER, 17);
73         return 0;
74     }
75 }
76 /*
77  * Local variables:
78  * c-basic-offset: 4
79  * c-file-style: "Stroustrup"
80  * indent-tabs-mode: nil
81  * End:
82  * vim: shiftwidth=4 tabstop=8 expandtab
83  */
84