Add odr_prepend()
[yaz-moved-to-github.git] / src / z3950oid.c
1 /*
2  * Copyright (c) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: z3950oid.c,v 1.1 2003-10-27 12:21:36 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 = (enum oid_class) oid_class;
21     ident.value = (enum oid_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 = (enum oid_class) 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 }
53
54
55 const char* yaz_z3950_oid_value_to_str(oid_value ov, oid_class oc)
56 {
57     struct oident tmpentry;
58     int tmp_oid[OID_SIZE];
59      
60     tmpentry.proto = PROTO_Z3950;
61     tmpentry.oclass = oc;
62     tmpentry.value = ov; 
63     
64     if( oid_ent_to_oid(&tmpentry,tmp_oid) ) 
65     {
66         return tmpentry.desc;
67     } 
68     else 
69     {
70         return "";
71     }
72 }
73
74
75 /*
76  * Local variables:
77  * tab-width: 8
78  * c-basic-offset: 4
79  * End:
80  * vim600: sw=4 ts=8 fdm=marker
81  * vim<600: sw=4 ts=8
82  */