Towards 2.1.40.
[yaz-moved-to-github.git] / src / z3950oid.c
1 /*
2  * Copyright (C) 1995-2006, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: z3950oid.c,v 1.5 2006-04-20 20:50:51 adam Exp $
6  */
7
8 /** \file z3950oid.c
9     \brief Z3950 OID conversion utilities
10 */
11
12 #if HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15
16 #include <yaz/proto.h>
17
18 Odr_oid *yaz_oidval_to_z3950oid (ODR o, int oid_class, int oid_value)
19 {
20     oident ident;
21     int oid[OID_SIZE];
22
23     ident.proto = PROTO_Z3950;
24     ident.oclass = (enum oid_class) oid_class;
25     ident.value = (enum oid_value) oid_value;
26
27     if (ident.value == VAL_NONE)
28         return 0;
29
30     return odr_oiddup(o, oid_ent_to_oid(&ident, oid));
31 }
32
33 Odr_oid *yaz_str_to_z3950oid (ODR o, int oid_class, const char *str)
34 {
35     struct oident ident;
36     int oid[OID_SIZE];
37
38     ident.proto = PROTO_Z3950;
39     ident.oclass = (enum oid_class) oid_class;
40     ident.value = oid_getvalbyname(str);
41
42     if (ident.value == VAL_NONE)
43         return 0;
44
45     return odr_oiddup(o, oid_ent_to_oid(&ident, oid));
46 }
47
48 const char *yaz_z3950oid_to_str (Odr_oid *oid, int *oid_class)
49 {
50     struct oident *ident = oid_getentbyoid(oid);
51
52     if (!ident || ident->value == VAL_NONE)
53         return 0;
54     *oid_class = ident->oclass;
55     return ident->desc;
56 }
57
58
59 const char* yaz_z3950_oid_value_to_str(oid_value ov, oid_class oc)
60 {
61     struct oident tmpentry;
62     int tmp_oid[OID_SIZE];
63      
64     tmpentry.proto = PROTO_Z3950;
65     tmpentry.oclass = oc;
66     tmpentry.value = ov; 
67     
68     if( oid_ent_to_oid(&tmpentry,tmp_oid) ) 
69     {
70         return tmpentry.desc;
71     } 
72     else 
73     {
74         return "";
75     }
76 }
77 /*
78  * Local variables:
79  * c-basic-offset: 4
80  * indent-tabs-mode: nil
81  * End:
82  * vim: shiftwidth=4 tabstop=8 expandtab
83  */
84