Bug fixes, mostly.
[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.4  1995-02-10 15:55:29  quinn
8  * Bug fixes, mostly.
9  *
10  * Revision 1.3  1995/02/09  15:51:49  quinn
11  * Works better now.
12  *
13  * Revision 1.2  1995/02/07  14:13:46  quinn
14  * Bug fixes.
15  *
16  * Revision 1.1  1995/02/03  17:04:38  quinn
17  * Initial revision
18  *
19  *
20  */
21
22 #include <odr.h>
23
24 /*
25  * Top level oid en/decoder.
26  * Returns 1 on success, 0 on error.
27  */
28 int odr_oid(ODR o, Odr_oid **p, int opt)
29 {
30     int res, cons = 0;
31
32     if (o->t_class < 0)
33     {
34         o->t_class = ODR_UNIVERSAL;
35         o->t_tag = ODR_OID;
36     }
37     if (o->direction == ODR_DECODE)
38         *p =0;
39     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
40     {
41         *p = 0;
42         return 0;
43     }
44     if (!res || cons)
45     {
46         *p = 0;
47         return opt;
48     }
49     if (o->direction == ODR_PRINT)
50     {
51         int i;
52
53         fprintf(o->print, "%sOID:", odr_indent(o));
54         for (i = 0; (*p)[i] > -1; i++)
55             fprintf(o->print, " %d", (*p)[i]);
56         fprintf(o->print, "\n");
57         return 1;
58     }
59     if (o->direction == ODR_DECODE)
60         *p = nalloc(o, ODR_OID_SIZE * sizeof(**p));
61     return ber_oid(o, *p);
62 }