YAZ  5.23.1
odr-priv.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
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.
15  *
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.
26  */
32 #ifndef ODR_PRIV_H
33 
34 #define ODR_PRIV_H
35 
36 #include <yaz/odr.h>
37 #include <yaz/yaz-util.h>
38 
40 struct Odr_ber_tag {
41  int lclass;
42  int ltag;
43  int br;
44  int lcons;
45 };
46 
47 #define odr_max(o) ((o)->op->size - ((o)->op->bp - (o)->op->buf))
48 
64 {
65  const char *base;
67  int len;
69  const char *lenb;
71  int lenlen;
72  const char *name;
74  struct odr_constack *prev;
75  struct odr_constack *next;
76 };
77 
78 #define ODR_MAX_STACK 2000
79 
83 struct Odr_private {
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) */
89 
90  /* stack for constructed types (we above) */
94  const char **tmp_names_buf;
97  struct Odr_ber_tag odr_ber_tag;
100  int error_id;
101  char element[80];
102  void (*stream_write)(ODR o, void *handle, int type,
103  const char *buf, int len);
104  void (*stream_close)(void *handle);
105 
106  int can_grow; /* are we allowed to reallocate */
107  int t_class; /* implicit tagging (-1==default tag) */
108  int t_tag;
109 
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 */
115 };
116 
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)
120 
121 #define odr_tell(o) ((o)->op->pos)
122 
123 /* Private macro.
124  * write a single character at the current position - grow buffer if
125  * necessary.
126  * (no, we're not usually this anal about our macros, but this baby is
127  * next to unreadable without some indentation :)
128  */
129 #define odr_putc(o, c) \
130 ( \
131  ( \
132  (o)->op->pos < (o)->op->size ? \
133  ( \
134  (o)->op->buf[(o)->op->pos++] = (c), \
135  0 \
136  ) : \
137  ( \
138  odr_grow_block((o), 1) == 0 ? \
139  ( \
140  (o)->op->buf[(o)->op->pos++] = (c), \
141  0 \
142  ) : \
143  ( \
144  (o)->error = OSPACE, \
145  -1 \
146  ) \
147  ) \
148  ) == 0 ? \
149  ( \
150  (o)->op->pos > (o)->op->top ? \
151  ( \
152  (o)->op->top = (o)->op->pos, \
153  0 \
154  ) : \
155  0 \
156  ) : \
157  -1 \
158 )
159 
160 #endif
161 /*
162  * Local variables:
163  * c-basic-offset: 4
164  * c-file-style: "Stroustrup"
165  * indent-tabs-mode: nil
166  * End:
167  * vim: shiftwidth=4 tabstop=8 expandtab
168  */
169 
Header for ODR (Open Data Representation)
int t_class
Definition: odr-priv.h:107
struct odr_constack * stack_top
Definition: odr-priv.h:92
int lcons
Definition: odr-priv.h:44
int choice_bias
Definition: odr-priv.h:111
stack for BER constructed items
Definition: odr-priv.h:63
FILE * print
Definition: odr-priv.h:113
struct odr_constack * next
Definition: odr-priv.h:75
int can_grow
Definition: odr-priv.h:106
Header for common YAZ utilities.
int ltag
Definition: odr-priv.h:42
const char * lenb
Definition: odr-priv.h:69
const char ** tmp_names_buf
Definition: odr-priv.h:94
int error_id
Definition: odr-priv.h:100
const char * base
Definition: odr-priv.h:65
enum l_file_type type
Definition: log.c:45
int indent
Definition: odr-priv.h:114
Utility structure used by ber_tag.
Definition: odr-priv.h:40
int lenlen
Definition: odr-priv.h:71
int size
Definition: odr-priv.h:88
yaz_iconv_t iconv_handle
Definition: odr-priv.h:99
const char * bp
Definition: odr-priv.h:85
struct odr_constack * prev
Definition: odr-priv.h:74
Definition: odr.h:124
const char * name
Definition: odr-priv.h:72
int lclass
Definition: odr-priv.h:41
char * buf
Definition: odr-priv.h:84
int lenlen
Definition: odr-priv.h:112
struct odr_constack * stack_first
Definition: odr-priv.h:91
int enable_bias
Definition: odr-priv.h:110
ODR private data.
Definition: odr-priv.h:83
int base_offset
Definition: odr-priv.h:66
int tmp_names_sz
Definition: odr-priv.h:95
int len_offset
Definition: odr-priv.h:70