Fix sample PQF
[yaz-moved-to-github.git] / odr / odr_oid.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_oid.c,v 1.20 2003-05-20 19:55:30 adam Exp $
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "odr-priv.h"
13 #include <yaz/oid.h>
14
15 /*
16  * Top level oid en/decoder.
17  * Returns 1 on success, 0 on error.
18  */
19 int odr_oid(ODR o, Odr_oid **p, int opt, const char *name)
20 {
21     int res, cons = 0;
22
23     if (o->error)
24         return 0;
25     if (o->t_class < 0)
26     {
27         o->t_class = ODR_UNIVERSAL;
28         o->t_tag = ODR_OID;
29     }
30     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
31         return 0;
32     if (!res)
33         return odr_missing(o, opt, name);
34     if (cons)
35     {
36         odr_seterror(o, OPROTO, 46);
37         return 0;
38     }
39     if (o->direction == ODR_PRINT)
40     {
41         int i;
42
43         odr_prname(o, name);
44         fprintf(o->print, "OID:");
45         for (i = 0; (*p)[i] > -1; i++)
46             fprintf(o->print, " %d", (*p)[i]);
47         fprintf(o->print, "\n");
48         return 1;
49     }
50     if (o->direction == ODR_DECODE)
51         *p = (int *)odr_malloc(o, OID_SIZE * sizeof(**p));
52     return ber_oidc(o, *p);
53 }