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