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