YAZ  5.23.1
odr_oid.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 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 
void odr_seterror(ODR o, int error, int id)
Definition: odr.c:118
int t_class
Definition: odr-priv.h:107
#define ODR_UNIVERSAL
Definition: odr.h:65
#define ODR_PRINT
Definition: odr.h:97
int error
Definition: odr.h:128
char * name
Definition: initopt.c:18
short Odr_oid
Definition: oid_util.h:42
Header for OID basic functions.
int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt, const char *name)
Encode/decode BER tags.
Definition: ber_tag.c:34
void * odr_malloc(ODR o, size_t size)
Definition: odr_mem.c:31
void odr_prname(ODR o, const char *name)
Definition: odr_util.c:18
Internal ODR definitions.
#define ODR_OID
Definition: odr.h:78
int direction
Definition: odr.h:126
#define OPROTO
Definition: odr.h:157
int ber_oidc(ODR o, Odr_oid *p, int max_oid_size)
Definition: ber_oid.c:19
struct Odr_private * op
Definition: odr.h:132
int odr_missing(ODR o, int opt, const char *name)
Definition: odr_util.c:82
Definition: odr.h:124
#define OID_SIZE
Definition: oid_util.h:39
int opt
Definition: initopt.c:19
int odr_oid(ODR o, Odr_oid **p, int opt, const char *name)
Definition: odr_oid.c:20
void odr_printf(ODR o, const char *fmt,...)
Definition: odr.c:290
#define ODR_DECODE
Definition: odr.h:95