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