YAZ  4.2.60
odr_oid.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <yaz/oid_util.h>
14 #include "odr-priv.h"
15 
16 /*
17  * Top level oid en/decoder.
18  * Returns 1 on success, 0 on error.
19  */
20 int odr_oid(ODR o, Odr_oid **p, int opt, const char *name)
21 {
22  int res, cons = 0;
23 
24  if (o->error)
25  return 0;
26  if (o->op->t_class < 0)
27  {
28  o->op->t_class = ODR_UNIVERSAL;
29  o->op->t_tag = ODR_OID;
30  }
31  res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
32  if (res < 0)
33  return 0;
34  if (!res)
35  return odr_missing(o, opt, name);
36  if (cons)
37  {
38  odr_seterror(o, OPROTO, 46);
39  return 0;
40  }
41  if (o->direction == ODR_PRINT)
42  {
43  int i;
44 
45  odr_prname(o, name);
46  odr_printf(o, "OID:");
47  for (i = 0; (*p)[i] > -1; i++)
48  odr_printf(o, " %d", (*p)[i]);
49  odr_printf(o, "\n");
50  return 1;
51  }
52  if (o->direction == ODR_DECODE)
53  *p = (Odr_oid *)odr_malloc(o, OID_SIZE * sizeof(**p));
54  return ber_oidc(o, *p, OID_SIZE);
55 }
56 /*
57  * Local variables:
58  * c-basic-offset: 4
59  * c-file-style: "Stroustrup"
60  * indent-tabs-mode: nil
61  * End:
62  * vim: shiftwidth=4 tabstop=8 expandtab
63  */
64