Fixed bug regarding inetd mode.
[yaz-moved-to-github.git] / odr / odr_enum.c
1 /*
2  * Copyright (c) 1995-2000, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_enum.c,v $
7  * Revision 1.5  2000-02-29 13:44:55  adam
8  * Check for config.h (currently not generated).
9  *
10  * Revision 1.4  1999/11/30 13:47:11  adam
11  * Improved installation. Moved header files to include/yaz.
12  *
13  * Revision 1.3  1999/04/20 09:56:48  adam
14  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
15  * Modified all encoders/decoders to reflect this change.
16  *
17  * Revision 1.2  1999/01/08 11:23:27  adam
18  * Added const modifier to some of the BER/ODR encoding routines.
19  *
20  * Revision 1.1  1998/03/20 14:45:01  adam
21  * Implemented odr_enum and odr_set_of.
22  *
23  */
24 #if HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <yaz/odr.h>
29
30 /*
31  * Top level enum en/decoder.
32  * Returns 1 on success, 0 on error.
33  */
34 int odr_enum(ODR o, int **p, int opt, const char *name)
35 {
36     int res, cons = 0;
37
38     if (o->error)
39         return 0;
40     if (o->t_class < 0)
41     {
42         o->t_class = ODR_UNIVERSAL;
43         o->t_tag = ODR_ENUM;
44     }
45     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
46         return 0;
47     if (!res)
48         return opt;
49     if (o->direction == ODR_PRINT)
50     {
51         odr_prname(o, name);
52         fprintf(o->print, "%d\n", **p);
53         return 1;
54     }
55     if (cons)
56     {
57         o->error = OPROTO;
58         return 0;
59     }
60     if (o->direction == ODR_DECODE)
61         *p = (int *)odr_malloc(o, sizeof(int));
62     return ber_integer(o, *p);
63 }