Add Ubuntu Vivid 15.04
[yaz-moved-to-github.git] / src / odr_tag.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file odr_tag.c
7  * \brief Implements ODR IMPLICIT tagging codec
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include "odr-priv.h"
14
15 int odr_peektag(ODR o, int *zclass, int *tag, int *cons)
16 {
17     if (o->direction != ODR_DECODE)
18     {
19         odr_seterror(o, OOTHER, 48);
20         return 0;
21     }
22     if (ODR_STACK_NOT_EMPTY(o) && !odr_constructed_more(o))
23         return 0;
24     if (ber_dectag(o->op->bp, zclass, tag, cons, odr_max(o)) <= 0)
25     {
26         odr_seterror(o, OREQUIRED, 49);
27         return 0;
28     }
29     return 1;
30 }
31
32 int odr_implicit_settag(ODR o, int zclass, int tag)
33 {
34     if (o->error)
35         return 0;
36     if (o->op->t_class < 0)
37     {
38         o->op->t_class = zclass;
39         o->op->t_tag = tag;
40     }
41     return 1;
42 }
43
44 int odr_initmember(ODR o, void *p, int size)
45 {
46     char **pp = (char **) p;
47
48     if (o->error)
49         return 0;
50     if (o->direction == ODR_DECODE)
51         *pp = (char *)odr_malloc(o, size);
52     else if (!*pp)
53     {
54         o->op->t_class = -1;
55         return 0;
56     }
57     return 1;
58 }
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * c-file-style: "Stroustrup"
63  * indent-tabs-mode: nil
64  * End:
65  * vim: shiftwidth=4 tabstop=8 expandtab
66  */
67