Changed include/yaz/diagbib1.h and added include/yaz/diagsrw.h with
[yaz-moved-to-github.git] / src / odr-priv.h
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation, in whole or in part, for any purpose, is hereby granted,
6  * provided that:
7  *
8  * 1. This copyright and permission notice appear in all copies of the
9  * software and its documentation. Notices of copyright or attribution
10  * which appear at the beginning of any file must remain unchanged.
11  *
12  * 2. The name of Index Data or the individual authors may not be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22  * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  *
26  * $Id: odr-priv.h,v 1.5 2005-01-15 19:47:14 adam Exp $
27  */
28
29 /**
30  * \file odr-priv.h
31  * \brief Internal ODR definitions
32  */
33
34 #ifndef ODR_PRIV_H
35
36 #define ODR_PRIV_H
37
38 #include <yaz/odr.h>
39 #include <yaz/yaz-util.h>
40
41 struct Odr_ber_tag {      /* used to be statics in ber_tag... */
42     int lclass;
43     int ltag;
44     int br;
45     int lcons;
46 };
47
48 #define odr_max(o) ((o)->size - ((o)->bp - (o)->buf))
49 #define odr_offset(o) ((o)->bp - (o)->buf)
50
51 typedef struct odr_constack
52 {
53     const unsigned char *base;   /* starting point of data */
54     int base_offset;
55     int len;                     /* length of data, if known, else -1
56                                         (decoding only) */
57     const unsigned char *lenb;   /* where to encode length */
58     int len_offset;
59     int lenlen;                  /* length of length-field */
60 } odr_constack;
61
62 struct Odr_private {
63     /* stack for constructed types */
64 #define ODR_MAX_STACK 50
65     int stackp;          /* top of stack (-1 == initial state) */
66     odr_constack stack[ODR_MAX_STACK];
67     const char *stack_names[1 + ODR_MAX_STACK];
68
69     struct Odr_ber_tag odr_ber_tag;
70     yaz_iconv_t iconv_handle;
71     int error_id;
72     char element[80];
73     void (*stream_write)(ODR o, void *handle, int type,
74                          const char *buf, int len);
75     void (*stream_close)(void *handle);
76 };
77
78 /* Private macro.
79  * write a single character at the current position - grow buffer if
80  * necessary.
81  * (no, we're not usually this anal about our macros, but this baby is
82  *  next to unreadable without some indentation  :)
83  */
84 #define odr_putc(o, c) \
85 ( \
86     ( \
87         (o)->pos < (o)->size ? \
88         ( \
89             (o)->buf[(o)->pos++] = (c), \
90             0 \
91         ) : \
92         ( \
93             odr_grow_block((o), 1) == 0 ? \
94             ( \
95                 (o)->buf[(o)->pos++] = (c), \
96                 0 \
97             ) : \
98             ( \
99                 (o)->error = OSPACE, \
100                 -1 \
101             ) \
102         ) \
103     ) == 0 ? \
104     ( \
105         (o)->pos > (o)->top ? \
106         ( \
107             (o)->top = (o)->pos, \
108             0 \
109         ) : \
110         0 \
111     ) : \
112         -1 \
113 )
114
115 #endif