New function yaz_srw_sortkeys_to_sort_spec
[yaz-moved-to-github.git] / include / yaz / oid_db.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 /**
29  * \file oid_db.h
30  * \brief Header for OID database
31  */
32 #ifndef OID_DB_H
33 #define OID_DB_H
34
35 #include <yaz/yconfig.h>
36 #include <yaz/oid_util.h>
37 #include <yaz/odr.h>
38
39 YAZ_BEGIN_CDECL
40
41 /** \brief OID database */
42 typedef struct yaz_oid_db *yaz_oid_db_t;
43
44
45 typedef enum oid_class
46 {
47     CLASS_NOP=0,
48     CLASS_APPCTX,
49     CLASS_ABSYN,
50     CLASS_ATTSET,
51     CLASS_TRANSYN,
52     CLASS_DIAGSET,
53     CLASS_RECSYN,
54     CLASS_RESFORM,
55     CLASS_ACCFORM,
56     CLASS_EXTSERV,
57     CLASS_USERINFO,
58     CLASS_ELEMSPEC,
59     CLASS_VARSET,
60     CLASS_SCHEMA,
61     CLASS_TAGSET,
62     CLASS_GENERAL,
63     CLASS_NEGOT
64 } oid_class;
65     
66
67 /** \brief returns standard OID database 
68     \retval OID database handle
69 */
70 YAZ_EXPORT
71 yaz_oid_db_t yaz_oid_std(void);
72
73 /** \brief maps named OID string to raw OID by database lookup
74     \param oid_db OID database
75     \param oclass class of string (enum oid_class) 
76     \param name OID name
77     \returns raw OID or NULL if name is unknown (bad)
78
79     This function only maps known names in the database provided.
80     Use yaz_string_to_oid_nmem or yaz_string_to_oid_odr to map
81     any named OID in dot-notation (1.2.8).
82 */
83 YAZ_EXPORT
84 const Odr_oid *yaz_string_to_oid(yaz_oid_db_t oid_db,
85                                  oid_class oclass, const char *name);
86
87
88 /** \brief creates NMEM malloc'ed OID from string
89     \param oid_db OID database
90     \param oclass class of string (enum oid_class) 
91     \param name OID name
92     \param nmem memory for returned OID
93     \returns raw OID or NULL if name is unknown (bad)
94 */
95 YAZ_EXPORT
96 Odr_oid *yaz_string_to_oid_nmem(yaz_oid_db_t oid_db,
97                                 oid_class oclass, const char *name, NMEM nmem);
98
99 /** \brief creates ODR malloc'ed OID from string
100     \param oid_db OID database
101     \param oclass class of string (enum oid_class) 
102     \param name OID name
103     \param odr memory for returned OID
104     \returns raw OID or NULL if name is unknown (bad)
105 */
106 YAZ_EXPORT
107 Odr_oid *yaz_string_to_oid_odr(yaz_oid_db_t oid_db,
108                                oid_class oclass, const char *name, ODR odr);
109
110 /** \brief maps raw OID to string
111     \param oid_db OID database
112     \param oid raw OID
113     \param oclass holds OID class if found (output parameter)
114     \returns OID name or NULL if not found in database
115 */
116 YAZ_EXPORT
117 const char *yaz_oid_to_string(yaz_oid_db_t oid_db,
118                               const Odr_oid *oid, oid_class *oclass);
119
120
121 /** \brief maps any OID to string (named or dot-notation)
122     \param oid raw OID
123     \param oclass holds OID class if found (output parameter)
124     \param buf string buffer for result (must be of size OID_STR_MAX)
125     \returns OID string (named or dot notatition) 
126 */
127 YAZ_EXPORT
128 const char *yaz_oid_to_string_buf(const Odr_oid *oid,
129                                   oid_class *oclass, char *buf);
130
131
132 /** \brief maps named from standard database to dot notation
133     \param oclass class of string (enum oid_class)
134     \param name named OID
135     \param oid_buf buffer for result (must be of size OID_STR_MAX)
136     \returns OID string or NULL if name is not registered in database
137 */
138 YAZ_EXPORT
139 char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf);
140
141
142 /** \brief traverses OIDs in a database
143     \param oid_db OID database
144     \param func function to be called for each OID
145     \param client_data data to be passed to func (custom defined)
146 */
147 YAZ_EXPORT void yaz_oid_trav(yaz_oid_db_t oid_db,
148                              void (*func)(const Odr_oid *oid,
149                                           oid_class oclass, const char *name,
150                                           void *client_data),
151                              void *client_data);
152
153 /** \brief checks if OID refers to MARC transfer syntax
154     \param oid raw OID
155     \retval 1 OID is a MARC type
156     \retval 0 OID is not a MARC type
157 */
158 YAZ_EXPORT
159 int yaz_oid_is_iso2709(const Odr_oid *oid);
160
161 /** \brief adds new OID entry to database
162     \param oid_db database
163     \param oclass OID class
164     \param name name of OID
165     \param new_oid OID value (raw OID)
166     \retval 0 OID added
167     \retval -1 OID name+oclass already exists
168 */
169 YAZ_EXPORT
170 int yaz_oid_add(yaz_oid_db_t oid_db, oid_class oclass, const char *name,
171                 const Odr_oid *new_oid);
172
173
174 /** \brief creates empty OID database
175     \returns database
176 */
177 YAZ_EXPORT
178 yaz_oid_db_t yaz_oid_db_new(void);
179
180 /** \brief destroys OID database
181     \param oid_db database
182 */
183 YAZ_EXPORT
184 void yaz_oid_db_destroy(yaz_oid_db_t oid_db);
185
186 struct yaz_oid_entry {
187     enum oid_class oclass;
188     const Odr_oid *oid;
189     char *name;
190 };
191
192 YAZ_END_CDECL
193
194 #define Z3950_PREFIX 1, 2, 840, 10003
195
196 #include <yaz/oid_std.h>
197
198 #endif
199 /*
200  * Local variables:
201  * c-basic-offset: 4
202  * c-file-style: "Stroustrup"
203  * indent-tabs-mode: nil
204  * End:
205  * vim: shiftwidth=4 tabstop=8 expandtab
206  */
207