95d44477c3ac7b70f80bb1f4932fcd90b0d2ecc8
[yaz-moved-to-github.git] / src / odr_oid.c
1 /*
2  * Copyright (c) 1995-2004, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: odr_oid.c,v 1.3 2004-08-13 07:30:06 adam Exp $
6  */
7 #if HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include "odr-priv.h"
12 #include <yaz/oid.h>
13
14 /*
15  * Top level oid en/decoder.
16  * Returns 1 on success, 0 on error.
17  */
18 int odr_oid(ODR o, Odr_oid **p, int opt, const char *name)
19 {
20     int res, cons = 0;
21
22     if (o->error)
23         return 0;
24     if (o->t_class < 0)
25     {
26         o->t_class = ODR_UNIVERSAL;
27         o->t_tag = ODR_OID;
28     }
29     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
30         return 0;
31     if (!res)
32         return odr_missing(o, opt, name);
33     if (cons)
34     {
35         odr_seterror(o, OPROTO, 46);
36         return 0;
37     }
38     if (o->direction == ODR_PRINT)
39     {
40         int i;
41
42         odr_prname(o, name);
43         odr_printf(o, "OID:");
44         for (i = 0; (*p)[i] > -1; i++)
45             odr_printf(o, " %d", (*p)[i]);
46         odr_printf(o, "\n");
47         return 1;
48     }
49     if (o->direction == ODR_DECODE)
50         *p = (int *)odr_malloc(o, OID_SIZE * sizeof(**p));
51     return ber_oidc(o, *p);
52 }