New OID database - with public definitions in oid_db.h. Removed old OID
[yaz-moved-to-github.git] / src / odr_oid.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: odr_oid.c,v 1.10 2007-04-12 13:52:57 adam Exp $
6  */
7 /**
8  * \file odr_oid.c
9  * \brief Implements ODR OID codec
10  */
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include <yaz/oid_util.h>
16 #include "odr-priv.h"
17
18 /*
19  * Top level oid en/decoder.
20  * Returns 1 on success, 0 on error.
21  */
22 int odr_oid(ODR o, Odr_oid **p, int opt, const char *name)
23 {
24     int res, cons = 0;
25
26     if (o->error)
27         return 0;
28     if (o->op->t_class < 0)
29     {
30         o->op->t_class = ODR_UNIVERSAL;
31         o->op->t_tag = ODR_OID;
32     }
33     res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
34     if (res < 0)
35         return 0;
36     if (!res)
37         return odr_missing(o, opt, name);
38     if (cons)
39     {
40         odr_seterror(o, OPROTO, 46);
41         return 0;
42     }
43     if (o->direction == ODR_PRINT)
44     {
45         int i;
46
47         odr_prname(o, name);
48         odr_printf(o, "OID:");
49         for (i = 0; (*p)[i] > -1; i++)
50             odr_printf(o, " %d", (*p)[i]);
51         odr_printf(o, "\n");
52         return 1;
53     }
54     if (o->direction == ODR_DECODE)
55         *p = (int *)odr_malloc(o, OID_SIZE * sizeof(**p));
56     return ber_oidc(o, *p, OID_SIZE);
57 }
58 /*
59  * Local variables:
60  * c-basic-offset: 4
61  * indent-tabs-mode: nil
62  * End:
63  * vim: shiftwidth=4 tabstop=8 expandtab
64  */
65