940ca9dc6ed95de5f5c0ab29a344e3d78ab07f53
[yaz-moved-to-github.git] / src / odr_null.c
1 /*
2  * Copyright (c) 1995-2004, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: odr_null.c,v 1.2 2004-03-09 20:49:04 adam Exp $
6  */
7 #if HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include "odr-priv.h"
12
13 /*
14  * Top level null en/decoder.
15  * Returns 1 on success, 0 on error.
16  */
17 int odr_null(ODR o, Odr_null **p, int opt, const char *name)
18 {
19     int res, cons = 0;
20
21     if (o->error)
22         return 0;
23     if (o->t_class < 0)
24     {
25         o->t_class = ODR_UNIVERSAL;
26         o->t_tag = ODR_NULL;
27     }
28     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
29         return 0;
30     if (!res)
31         return odr_missing(o, opt, name);
32     if (o->direction == ODR_PRINT)
33     {
34         odr_prname(o, name);
35         fprintf(o->print, "NULL\n");
36         return 1;
37     }
38     if (cons)
39     {
40 #ifdef ODR_STRICT_NULL
41         odr_seterror(OPROTO, 42);
42         return 0;
43 #else
44         /* Warning: Bad NULL */
45 #endif
46     }
47     if (o->direction == ODR_DECODE)
48         *p = odr_nullval();
49     return ber_null(o);
50 }