1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * \brief Internal ODR definitions
37 #include <yaz/yaz-util.h>
39 /** \brief Utility structure used by ber_tag */
47 #define odr_max(o) ((o)->op->size - ((o)->op->bp - (o)->op->buf))
50 * \brief stack for BER constructed items
52 * data structure for con stack.. a little peculiar. Since we can't
53 * deallocate memory we reuse stack items (popped items gets reused)
56 * +---+ +---+ +---+ +---+
57 * NULL -|p n|-----|p n|-----|p n|-----|p n|-- NULL
58 * +---+ +---+ +---+ +---+
60 * stack_first stack_top reused item
65 const char *base; /** starting point of data */
67 int len; /** length of data, if known, else -1
69 const char *lenb; /** where to encode length */
71 int lenlen; /** length of length-field */
72 const char *name; /** name of stack entry */
74 struct odr_constack *prev; /** pointer back in stack */
75 struct odr_constack *next; /** pointer forward */
78 #define ODR_MAX_STACK 2000
81 * \brief ODR private data
84 char *buf; /* memory base */
85 const char *bp; /* position in buffer (decoding) */
86 int pos; /* current position (encoding) */
87 int top; /* top of buffer (max pos when encoding) */
88 int size; /* current buffer size (encoding+decoding) */
90 /* stack for constructed types (we above) */
91 struct odr_constack *stack_first; /** first member of allocated stack */
92 struct odr_constack *stack_top; /** top of stack */
94 const char **tmp_names_buf; /** array returned by odr_get_element_path */
95 int tmp_names_sz; /** size of tmp_names_buf */
97 struct Odr_ber_tag odr_ber_tag; /** used by ber_tag */
99 yaz_iconv_t iconv_handle;
102 void (*stream_write)(ODR o, void *handle, int type,
103 const char *buf, int len);
104 void (*stream_close)(void *handle);
106 int can_grow; /* are we allowed to reallocate */
107 int t_class; /* implicit tagging (-1==default tag) */
110 int enable_bias; /* force choice enable flag */
111 int choice_bias; /* force choice */
112 int lenlen; /* force length-of-lenght (odr_setlen()) */
113 FILE *print; /* output file handler for direction print */
114 int indent; /* current indent level for printing */
117 #define ODR_STACK_POP(x) (x)->op->stack_top = (x)->op->stack_top->prev
118 #define ODR_STACK_EMPTY(x) (!(x)->op->stack_top)
119 #define ODR_STACK_NOT_EMPTY(x) ((x)->op->stack_top)
121 #define odr_tell(o) ((o)->op->pos)
124 * write a single character at the current position - grow buffer if
126 * (no, we're not usually this anal about our macros, but this baby is
127 * next to unreadable without some indentation :)
129 #define odr_putc(o, c) \
132 (o)->op->pos < (o)->op->size ? \
134 (o)->op->buf[(o)->op->pos++] = (c), \
138 odr_grow_block((o), 1) == 0 ? \
140 (o)->op->buf[(o)->op->pos++] = (c), \
144 (o)->error = OSPACE, \
150 (o)->op->pos > (o)->op->top ? \
152 (o)->op->top = (o)->op->pos, \
164 * c-file-style: "Stroustrup"
165 * indent-tabs-mode: nil
167 * vim: shiftwidth=4 tabstop=8 expandtab