New Z39.50 OID utilities.
[yaz-moved-to-github.git] / zutil / z3950oid.c
1 /*
2  * Copyright (c) 1995-2001, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: z3950oid.c,v 1.1 2001-09-25 07:35:37 adam Exp $
6  */
7
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <yaz/proto.h>
13
14 Odr_oid *yaz_oidval_to_z3950oid (ODR o, int oid_class, int oid_value)
15 {
16     oident ident;
17     int oid[OID_SIZE];
18
19     ident.proto = PROTO_Z3950;
20     ident.oclass = oid_class;
21     ident.value = oid_value;
22
23     if (ident.value == VAL_NONE)
24         return 0;
25
26     return odr_oiddup(o, oid_ent_to_oid(&ident, oid));
27 }
28
29 Odr_oid *yaz_str_to_z3950oid (ODR o, int oid_class, const char *str)
30 {
31     struct oident ident;
32     int oid[OID_SIZE];
33
34     ident.proto = PROTO_Z3950;
35     ident.oclass = oid_class;
36     ident.value = oid_getvalbyname(str);
37
38     if (ident.value == VAL_NONE)
39         return 0;
40
41     return odr_oiddup(o, oid_ent_to_oid(&ident, oid));
42 }
43
44 const char *yaz_z3950oid_to_str (Odr_oid *oid, int *oid_class)
45 {
46     struct oident *ident = oid_getentbyoid(oid);
47
48     if (!ident || ident->value == VAL_NONE)
49         return 0;
50     *oid_class = ident->oclass;
51     return ident->desc;
52 }