a8f31f2257b4d9145329a4576d84b6c5c8f3445a
[yaz-moved-to-github.git] / src / odr_tag.c
1 /*
2  * Copyright (c) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: odr_tag.c,v 1.1 2003-10-27 12:21:34 adam Exp $
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "odr-priv.h"
13
14 int odr_peektag(ODR o, int *zclass, int *tag, int *cons)
15 {
16     if (o->direction != ODR_DECODE)
17     {
18         odr_seterror(o, OOTHER, 48);
19         return 0;
20     }
21     if (o->op->stackp > -1 && !odr_constructed_more(o))
22         return 0;
23     if (ber_dectag(o->bp, zclass, tag, cons, odr_max(o)) <= 0)
24     {
25         odr_seterror(o, OREQUIRED, 49);
26         return 0;
27     }
28     return 1;
29 }
30
31 int odr_implicit_settag(ODR o, int zclass, int tag)
32 {
33     if (o->error)
34         return 0;
35     if (o->t_class < 0)
36     {
37         o->t_class = zclass;
38         o->t_tag = tag;
39     }
40     return 1;
41 }
42
43 int odr_initmember(ODR o, void *p, int size)
44 {
45     char **pp = (char **) p;
46
47     if (o->error)
48         return 0;
49     if (o->direction == ODR_DECODE)
50         *pp = (char *)odr_malloc(o, size);
51     else if (!*pp)
52     {
53         o->t_class = -1;
54         return 0;
55     }
56     return 1;
57 }