1034a7b7335d983c56f6d8af883001287e60d8d0
[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.8 2007-01-03 08:42:15 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 "odr-priv.h"
16 #include <yaz/oid.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->t_class < 0)
29     {
30         o->t_class = ODR_UNIVERSAL;
31         o->t_tag = ODR_OID;
32     }
33     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
34         return 0;
35     if (!res)
36         return odr_missing(o, opt, name);
37     if (cons)
38     {
39         odr_seterror(o, OPROTO, 46);
40         return 0;
41     }
42     if (o->direction == ODR_PRINT)
43     {
44         int i;
45
46         odr_prname(o, name);
47         odr_printf(o, "OID:");
48         for (i = 0; (*p)[i] > -1; i++)
49             odr_printf(o, " %d", (*p)[i]);
50         odr_printf(o, "\n");
51         return 1;
52     }
53     if (o->direction == ODR_DECODE)
54         *p = (int *)odr_malloc(o, OID_SIZE * sizeof(**p));
55     return ber_oidc(o, *p, OID_SIZE);
56 }
57 /*
58  * Local variables:
59  * c-basic-offset: 4
60  * indent-tabs-mode: nil
61  * End:
62  * vim: shiftwidth=4 tabstop=8 expandtab
63  */
64