Bug fixes.
[yaz-moved-to-github.git] / odr / odr_oid.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_oid.c,v $
7  * Revision 1.2  1995-02-07 14:13:46  quinn
8  * Bug fixes.
9  *
10  * Revision 1.1  1995/02/03  17:04:38  quinn
11  * Initial revision
12  *
13  *
14  */
15
16 #include <odr.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)
23 {
24     int res, cons = 0;
25
26     if (o->t_class < 0)
27     {
28         o->t_class = ODR_UNIVERSAL;
29         o->t_tag = ODR_OID;
30     }
31     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
32     {
33         *p = 0;
34         return 0;
35     }
36     if (!res || cons)
37     {
38         *p = 0;
39         return opt;
40     }
41     if (o->direction == ODR_PRINT)
42     {
43         fprintf(o->print, "OID\n");
44         return 1;
45     }
46     if (o->direction == ODR_DECODE)
47         *p = nalloc(o, ODR_OID_SIZE);
48     return ber_oid(o, *p);
49 }