Update source headers for 2008. Omit CVS ID keyword subst.
[yaz-moved-to-github.git] / include / yaz / oid_db.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 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 /* $Id: oid_db.h,v 1.10 2007-11-30 11:42:04 adam Exp $ */
28
29 /**
30  * \file oid_db.h
31  * \brief Header for OID database
32  */
33 #ifndef OID_DB_H
34 #define OID_DB_H
35
36 #include <yaz/yconfig.h>
37 #include <yaz/oid_util.h>
38 #include <yaz/odr.h>
39
40 YAZ_BEGIN_CDECL
41
42 /** \brief OID database */
43 typedef struct yaz_oid_db *yaz_oid_db_t;
44
45
46 typedef enum oid_class
47 {
48     CLASS_NOP=0,
49     CLASS_APPCTX,
50     CLASS_ABSYN,
51     CLASS_ATTSET,
52     CLASS_TRANSYN,
53     CLASS_DIAGSET,
54     CLASS_RECSYN,
55     CLASS_RESFORM,
56     CLASS_ACCFORM,
57     CLASS_EXTSERV,
58     CLASS_USERINFO,
59     CLASS_ELEMSPEC,
60     CLASS_VARSET,
61     CLASS_SCHEMA,
62     CLASS_TAGSET,
63     CLASS_GENERAL,
64     CLASS_NEGOT
65 } oid_class;
66     
67
68 /** \brief returns standard OID database 
69     \retval OID database handle
70 */
71 YAZ_EXPORT
72 yaz_oid_db_t yaz_oid_std(void);
73
74 /** \brief maps named OID string to raw OID by database lookup
75     \param oid_db OID database
76     \param oclass class of string (enum oid_class) 
77     \param name OID name
78     \returns raw OID or NULL if name is unknown (bad)
79
80     This function only maps known names in the database provided.
81     Use yaz_string_to_oid_nmem or yaz_string_to_oid_odr to map
82     any named OID in dot-notation (1.2.8).
83 */
84 YAZ_EXPORT
85 const Odr_oid *yaz_string_to_oid(yaz_oid_db_t oid_db,
86                                  oid_class oclass, const char *name);
87
88
89 /** \brief creates NMEM malloc'ed OID from string
90     \param oid_db OID database
91     \param oclass class of string (enum oid_class) 
92     \param name OID name
93     \param nmem memory for returned OID
94     \returns raw OID or NULL if name is unknown (bad)
95 */
96 YAZ_EXPORT
97 Odr_oid *yaz_string_to_oid_nmem(yaz_oid_db_t oid_db,
98                                 oid_class oclass, const char *name, NMEM nmem);
99
100 /** \brief creates ODR malloc'ed OID from string
101     \param oid_db OID database
102     \param oclass class of string (enum oid_class) 
103     \param name OID name
104     \param odr memory for returned OID
105     \returns raw OID or NULL if name is unknown (bad)
106 */
107 YAZ_EXPORT
108 Odr_oid *yaz_string_to_oid_odr(yaz_oid_db_t oid_db,
109                                oid_class oclass, const char *name, ODR odr);
110
111 /** \brief maps raw OID to string
112     \param oid_db OID database
113     \param oid raw OID
114     \param oclass holds OID class if found (output parameter)
115     \returns OID name or NULL if not found in database
116 */
117 YAZ_EXPORT
118 const char *yaz_oid_to_string(yaz_oid_db_t oid_db,
119                               const Odr_oid *oid, oid_class *oclass);
120
121
122 /** \brief maps any OID to string (named or dot-notation)
123     \param oid raw OID
124     \param oclass holds OID class if found (output parameter)
125     \param buf string buffer for result (must be of size OID_STR_MAX)
126     \returns OID string (named or dot notatition) 
127 */
128 YAZ_EXPORT
129 const char *yaz_oid_to_string_buf(const Odr_oid *oid,
130                                   oid_class *oclass, char *buf);
131
132
133 /** \brief maps named from standard database to dot notation
134     \param oclass class of string (enum oid_class)
135     \param name named OID
136     \param oid_buf buffer for result (must be of size OID_STR_MAX)
137     \returns OID string or NULL if name is not registered in database
138 */
139 YAZ_EXPORT
140 char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf);
141
142
143 /** \brief traverses OIDs in a database
144     \param oid_db OID database
145     \param func function to be called for each OID
146     \param client_data data to be passed to func (custom defined)
147 */
148 YAZ_EXPORT void yaz_oid_trav(yaz_oid_db_t oid_db,
149                              void (*func)(const Odr_oid *oid,
150                                           oid_class oclass, const char *name,
151                                           void *client_data),
152                              void *client_data);
153
154 /** \brief checks if OID refers to MARC transfer syntax
155     \param oid raw OID
156     \retval 1 OID is a MARC type
157     \retval 0 OID is not a MARC type
158 */
159 YAZ_EXPORT
160 int yaz_oid_is_iso2709(const Odr_oid *oid);
161
162 /** \brief adds new OID entry to database
163     \param oid_db database
164     \param oclass OID class
165     \param name name of OID
166     \param new_oid OID value (raw OID)
167     \retval 0 OID added
168     \retval -1 OID name+oclass already exists
169 */
170 YAZ_EXPORT
171 int yaz_oid_add(yaz_oid_db_t oid_db, oid_class oclass, const char *name,
172                 const Odr_oid *new_oid);
173
174
175 /** \brief creates empty OID database
176     \returns database
177 */
178 YAZ_EXPORT
179 yaz_oid_db_t yaz_oid_db_new(void);
180
181 /** \brief destroys OID database
182     \param oid_db database
183 */
184 YAZ_EXPORT
185 void yaz_oid_db_destroy(yaz_oid_db_t oid_db);
186
187 struct yaz_oid_entry {
188     enum oid_class oclass;
189     const Odr_oid *oid;
190     char *name;
191 };
192
193 YAZ_END_CDECL
194
195 #define Z3950_PREFIX 1, 2, 840, 10003
196
197 #include <yaz/oid_std.h>
198
199 #endif
200 /*
201  * Local variables:
202  * c-basic-offset: 4
203  * indent-tabs-mode: nil
204  * End:
205  * vim: shiftwidth=4 tabstop=8 expandtab
206  */
207