00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033 #ifndef ODR_H
00034 #define ODR_H
00035
00036 #include <stdio.h>
00037 #include <string.h>
00038
00039 #include <yaz/yconfig.h>
00040 #include <yaz/nmem.h>
00041
00042
00043 #include <yaz/oid_util.h>
00044
00045 YAZ_BEGIN_CDECL
00046
00047 #ifndef bool_t
00048 #define bool_t int
00049 #endif
00050
00051
00052
00053
00054 #define ODR_NONE -1
00055 #define ODR_IMPLICIT 0
00056 #define ODR_EXPLICIT 1
00057
00058
00059
00060
00061 #define ODR_UNIVERSAL 0
00062 #define ODR_APPLICATION 1
00063 #define ODR_CONTEXT 2
00064 #define ODR_PRIVATE 3
00065
00066
00067
00068
00069 #define ODR_BOOLEAN 1
00070 #define ODR_INTEGER 2
00071 #define ODR_BITSTRING 3
00072 #define ODR_OCTETSTRING 4
00073 #define ODR_NULL 5
00074 #define ODR_OID 6
00075 #define ODR_ODESC 7
00076 #define ODR_EXTERNAL 8
00077 #define ODR_REAL 9
00078 #define ODR_ENUM 10
00079 #define ODR_SEQUENCE 16
00080 #define ODR_SET 17
00081 #define ODR_NUMERICSTRING 18
00082 #define ODR_PRINTABLESTRING 19
00083 #define ODR_GENERALIZEDTIME 24
00084 #define ODR_GRAPHICSTRING 25
00085 #define ODR_VISIBLESTRING 26
00086 #define ODR_GENERALSTRING 27
00087
00088
00089
00090
00091 #define ODR_DECODE 0
00092 #define ODR_ENCODE 1
00093 #define ODR_PRINT 2
00094
00095 typedef struct odr_oct
00096 {
00097 unsigned char *buf;
00098 int len;
00099 int size;
00100 } Odr_oct;
00101
00102 typedef void Odr_null;
00103 extern Odr_null *ODR_NULLVAL;
00104
00105 typedef Odr_oct Odr_any;
00106
00107 typedef struct odr_bitmask
00108 {
00109 #define ODR_BITMASK_SIZE 256
00110 unsigned char bits[ODR_BITMASK_SIZE];
00111 int top;
00112 } Odr_bitmask;
00113
00114 #define ODR_S_SET 0
00115 #define ODR_S_CUR 1
00116 #define ODR_S_END 2
00117
00118 typedef struct odr *ODR;
00119
00121 struct odr
00122 {
00123 int direction;
00124
00125 int error;
00126
00127 unsigned char *buf;
00128 int top;
00129 int size;
00130
00131 int pos;
00132
00133 const unsigned char *bp;
00134
00135 NMEM mem;
00136
00137 struct Odr_private *op;
00138 };
00139
00140 typedef int (*Odr_fun)(ODR, char **, int, const char *);
00141
00142 typedef struct odr_arm
00143 {
00144 int tagmode;
00145 int zclass;
00146 int tag;
00147 int which;
00148 Odr_fun fun;
00149 char *name;
00150 } Odr_arm;
00151
00152
00153
00154
00155 #define ONONE 0
00156 #define OMEMORY 1
00157 #define OSYSERR 2
00158 #define OSPACE 3
00159 #define OREQUIRED 4
00160 #define OUNEXPECTED 5
00161 #define OOTHER 6
00162 #define OPROTO 7
00163 #define ODATA 8
00164 #define OSTACK 9
00165 #define OCONLEN 10
00166 #define OLENOV 11
00167 #define OHTTP 12
00168
00169 extern char *odr_errlist[];
00170
00171 YAZ_EXPORT int odr_geterror(ODR o);
00172 YAZ_EXPORT int odr_geterrorx(ODR o, int *x);
00173 YAZ_EXPORT void odr_seterror(ODR o, int errorno, int errorid);
00174 YAZ_EXPORT void odr_setelement(ODR o, const char *addinfo);
00175 YAZ_EXPORT const char *odr_getelement(ODR o);
00176 YAZ_EXPORT void odr_perror(ODR o, const char *message);
00177 YAZ_EXPORT void odr_setprint(ODR o, FILE *file);
00178 YAZ_EXPORT ODR odr_createmem(int direction);
00179 YAZ_EXPORT void odr_reset(ODR o);
00180 YAZ_EXPORT void odr_destroy(ODR o);
00181 YAZ_EXPORT void odr_setbuf(ODR o, char *buf, int len, int can_grow);
00182 YAZ_EXPORT char *odr_getbuf(ODR o, int *len, int *size);
00183 YAZ_EXPORT void *odr_malloc(ODR o, int size);
00184 YAZ_EXPORT char *odr_strdup(ODR o, const char *str);
00185 YAZ_EXPORT char *odr_strdupn(ODR o, const char *str, size_t n);
00186 YAZ_EXPORT char *odr_strdup_null(ODR o, const char *str);
00187 YAZ_EXPORT int *odr_intdup(ODR o, int v);
00188 YAZ_EXPORT Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf,
00189 int sz);
00190 YAZ_EXPORT NMEM odr_extract_mem(ODR o);
00191 YAZ_EXPORT Odr_null *odr_nullval(void);
00192 #define odr_release_mem(m) nmem_destroy(m)
00193 #define ODR_MEM NMEM
00194
00195 #define odr_implicit_tag(o, t, p, cl, tg, opt, name)\
00196 (odr_implicit_settag((o), cl, tg), t ((o), (p), (opt), name) )
00197
00198 #define odr_explicit_tag(o, t, p, cl, tg, opt, name)\
00199 ((int) (odr_constructed_begin((o), (p), (cl), (tg), 0) ? \
00200 t ((o), (p), (opt), name) &&\
00201 odr_constructed_end(o) : odr_missing((o), opt, name)))
00202
00203 #define ODR_MASK_ZERO(mask)\
00204 ((void) (memset((mask)->bits, 0, ODR_BITMASK_SIZE),\
00205 (mask)->top = -1))
00206
00207 #define ODR_MASK_SET(mask, num)\
00208 (((mask)->bits[(num) >> 3] |= 0X80 >> ((num) & 0X07)),\
00209 (mask)->top < (num) >> 3 ? ((mask)->top = (num) >> 3) : 0)
00210
00211 #define ODR_MASK_CLEAR(mask, num)\
00212 ((mask)->bits[(num) >> 3] &= ~(0X80 >> ((num) & 0X07)))
00213
00214 #define ODR_MASK_GET(mask, num) ( ((num) >> 3 <= (mask)->top) ? \
00215 ((mask)->bits[(num) >> 3] & (0X80 >> ((num) & 0X07)) ? 1 : 0) : 0)
00216
00217
00218 #define odr_tell(o) ((o)->pos)
00219 #define odr_offset(o) ((o)->bp - (o)->buf)
00220 #define odr_ok(o) (!(o)->error)
00221 #define odr_getmem(o) ((o)->mem)
00222
00223 #define ODR_MAXNAME 256
00224
00225 YAZ_EXPORT int ber_boolean(ODR o, int *val);
00226 YAZ_EXPORT int ber_tag(ODR o, void *p, int zclass, int tag,
00227 int *constructed, int opt, const char *name);
00228 YAZ_EXPORT int ber_enctag(ODR o, int zclass, int tag, int constructed);
00229 YAZ_EXPORT int ber_dectag(const unsigned char *buf, int *zclass,
00230 int *tag, int *constructed, int max);
00231 YAZ_EXPORT int odr_bool(ODR o, int **p, int opt, const char *name);
00232 YAZ_EXPORT int odr_integer(ODR o, int **p, int opt, const char *name);
00233 YAZ_EXPORT int odr_enum(ODR o, int **p, int opt, const char *name);
00234 YAZ_EXPORT int odr_implicit_settag(ODR o, int zclass, int tag);
00235 YAZ_EXPORT int ber_enclen(ODR o, int len, int lenlen, int exact);
00236 YAZ_EXPORT int ber_declen(const unsigned char *buf, int *len, int max);
00237 YAZ_EXPORT void odr_prname(ODR o, const char *name);
00238 YAZ_EXPORT int ber_null(ODR o);
00239 YAZ_EXPORT int odr_null(ODR o, Odr_null **p, int opt, const char *name);
00240 YAZ_EXPORT int ber_integer(ODR o, int *val);
00241 YAZ_EXPORT int odr_constructed_begin(ODR o, void *p, int zclass, int tag,
00242 const char *name);
00243 YAZ_EXPORT int odr_constructed_end(ODR o);
00244 YAZ_EXPORT int odr_sequence_begin(ODR o, void *p, int size, const char *name);
00245 YAZ_EXPORT int odr_set_begin(ODR o, void *p, int size, const char *name);
00246 YAZ_EXPORT int odr_sequence_end(ODR o);
00247 YAZ_EXPORT int odr_set_end(ODR o);
00248 YAZ_EXPORT int ber_octetstring(ODR o, Odr_oct *p, int cons);
00249 YAZ_EXPORT int odr_octetstring(ODR o, Odr_oct **p, int opt, const char *name);
00250 YAZ_EXPORT int odp_more_chunks(ODR o, const unsigned char *base, int len);
00251 YAZ_EXPORT int odr_constructed_more(ODR o);
00252 YAZ_EXPORT int odr_bitstring(ODR o, Odr_bitmask **p, int opt,
00253 const char *name);
00254 YAZ_EXPORT int ber_bitstring(ODR o, Odr_bitmask *p, int cons);
00255 YAZ_EXPORT int odr_generalstring(ODR o, char **p, int opt, const char *name);
00256 YAZ_EXPORT int ber_oidc(ODR o, Odr_oid *p, int max_oid_size);
00257 YAZ_EXPORT int odr_oid(ODR o, Odr_oid **p, int opt, const char *name);
00258 YAZ_EXPORT int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp,
00259 const char *name);
00260 YAZ_EXPORT int odr_cstring(ODR o, char **p, int opt, const char *name);
00261 YAZ_EXPORT int odr_iconv_string(ODR o, char **p, int opt, const char *name);
00262 YAZ_EXPORT int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num,
00263 const char *name);
00264 YAZ_EXPORT int odr_set_of(ODR o, Odr_fun type, void *p, int *num,
00265 const char *name);
00266 YAZ_EXPORT int odr_any(ODR o, Odr_any **p, int opt, const char *name);
00267
00268 YAZ_EXPORT int ber_any(ODR o, Odr_any **p);
00275 YAZ_EXPORT int completeBER(const unsigned char *buf, int len);
00276
00277 YAZ_EXPORT void odr_begin(ODR o);
00278 YAZ_EXPORT void odr_end(ODR o);
00279 YAZ_EXPORT Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o);
00280 YAZ_EXPORT Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o);
00281 YAZ_EXPORT int odr_grow_block(ODR b, int min_bytes);
00282 YAZ_EXPORT int odr_write(ODR o, unsigned char *buf, int bytes);
00283 YAZ_EXPORT int odr_seek(ODR o, int whence, int offset);
00284 YAZ_EXPORT int odr_dumpBER(FILE *f, const char *buf, int len);
00285 YAZ_EXPORT void odr_choice_bias(ODR o, int what);
00286 YAZ_EXPORT void odr_choice_enable_bias(ODR o, int mode);
00287 YAZ_EXPORT int odr_total(ODR o);
00288 YAZ_EXPORT char *odr_errmsg(int n);
00289 YAZ_EXPORT Odr_oid *odr_getoidbystr(ODR o, const char *str);
00290 YAZ_EXPORT Odr_oid *odr_getoidbystr_nmem(NMEM o, const char *str);
00291
00292 YAZ_EXPORT int odr_initmember(ODR o, void *p, int size);
00293 YAZ_EXPORT int odr_peektag(ODR o, int *zclass, int *tag, int *cons);
00294 YAZ_EXPORT void odr_setlenlen(ODR o, int len);
00295 YAZ_EXPORT int odr_missing(ODR o, int opt, const char *name);
00296 YAZ_EXPORT char *odr_prepend(ODR o, const char *prefix, const char *old);
00297
00298 typedef struct Odr_external
00299 {
00300 Odr_oid *direct_reference;
00301 int *indirect_reference;
00302 char *descriptor;
00303 int which;
00304 #define ODR_EXTERNAL_single 0
00305 #define ODR_EXTERNAL_octet 1
00306 #define ODR_EXTERNAL_arbitrary 2
00307 union
00308 {
00309 Odr_any *single_ASN1_type;
00310 Odr_oct *octet_aligned;
00311 Odr_bitmask *arbitrary;
00312 } u;
00313 } Odr_external;
00314
00315 YAZ_EXPORT int odr_external(ODR o, Odr_external **p, int opt,
00316 const char *name);
00317 YAZ_EXPORT int odr_visiblestring(ODR o, char **p, int opt,
00318 const char *name);
00319 YAZ_EXPORT int odr_graphicstring(ODR o, char **p, int opt,
00320 const char *name);
00321 YAZ_EXPORT int odr_generalizedtime(ODR o, char **p, int opt,
00322 const char *name);
00323
00324 YAZ_EXPORT int odr_set_charset(ODR o, const char *to, const char *from);
00325
00326 YAZ_EXPORT void odr_set_stream(ODR o, void *handle,
00327 void (*stream_write)(ODR o,
00328 void *handle,
00329 int type,
00330 const char *buf,
00331 int len),
00332 void (*stream_close)(void *handle));
00333
00334 YAZ_EXPORT void odr_printf(ODR o, const char *fmt, ...);
00335
00336 YAZ_EXPORT const char **odr_get_element_path(ODR o);
00337
00338 YAZ_END_CDECL
00339
00340 #include <yaz/xmalloc.h>
00341
00342 #endif
00343
00344
00345
00346
00347
00348
00349
00350