e3a8ab854534dec3075605a197a1f20564e4e3e9
[yaz-moved-to-github.git] / src / odr_null.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: odr_null.c,v 1.8 2007-03-19 21:08:13 adam Exp $
6  */
7 /**
8  * \file odr_null.c
9  * \brief Implements ODR NULL codec
10  */
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include "odr-priv.h"
16
17 /*
18  * Top level null en/decoder.
19  * Returns 1 on success, 0 on error.
20  */
21 int odr_null(ODR o, Odr_null **p, int opt, const char *name)
22 {
23     int res, cons = 0;
24
25     if (o->error)
26         return 0;
27     if (o->op->t_class < 0)
28     {
29         o->op->t_class = ODR_UNIVERSAL;
30         o->op->t_tag = ODR_NULL;
31     }
32     res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
33     if (res < 0)
34         return 0;
35     if (!res)
36         return odr_missing(o, opt, name);
37     if (o->direction == ODR_PRINT)
38     {
39         odr_prname(o, name);
40         odr_printf(o, "NULL\n");
41         return 1;
42     }
43     if (cons)
44     {
45 #ifdef ODR_STRICT_NULL
46         odr_seterror(OPROTO, 42);
47         return 0;
48 #else
49         /* Warning: Bad NULL */
50 #endif
51     }
52     if (o->direction == ODR_DECODE)
53         *p = odr_nullval();
54     return ber_null(o);
55 }
56 /*
57  * Local variables:
58  * c-basic-offset: 4
59  * indent-tabs-mode: nil
60  * End:
61  * vim: shiftwidth=4 tabstop=8 expandtab
62  */
63