0def5ee4e2194920e864afa2af14d699a31273e2
[yaz-moved-to-github.git] / odr / odr_any.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_any.c,v 1.13 2003-03-11 11:03:31 adam Exp $
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "odr-priv.h"
13
14 /*
15  * This is a catch-all type. It stuffs a random ostring (assumed to be properly
16  * encoded) into the stream, or reads a full data element. Implicit tagging
17  * does not work, and neither does the optional flag, unless the element
18  * is the last in a sequence.
19  */
20 int odr_any(ODR o, Odr_any **p, int opt, const char *name)
21 {
22     if (o->error)
23         return 0;
24     if (o->direction == ODR_PRINT)
25     {
26         odr_prname(o, name);
27         fprintf(o->print, "ANY (len=%d)\n", (*p)->len);
28         return 1;
29     }
30     if (o->direction == ODR_DECODE)
31         *p = (Odr_oct *)odr_malloc(o, sizeof(**p));
32     if (ber_any(o, p))
33         return 1;
34     *p = 0;
35     if (!opt)
36         odr_seterror(o, OREQUIRED, 53);
37     return opt;
38 }