1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>2. Object Identifiers</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="tools.html" title="Chapter 9. Supporting Tools"><link rel="prev" href="tools.html" title="Chapter 9. Supporting Tools"><link rel="next" href="tools.nmem.html" title="3. Nibble Memory"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2. Object Identifiers</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tools.html">Prev</a> </td><th width="60%" align="center">Chapter 9. Supporting Tools</th><td width="20%" align="right"> <a accesskey="n" href="tools.nmem.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tools.oid"></a>2. Object Identifiers</h2></div></div></div><p>
2 The basic YAZ representation of an OID is an array of integers,
3 terminated with the value -1. This integer is of type
4 <code class="literal">Odr_oid</code>.
6 Fundamental OID operations and the type <code class="literal">Odr_oid</code>
7 are defined in <code class="filename">yaz/oid_util.h</code>.
9 An OID can either be declared as a automatic variable or it can
10 allocated using the memory utilities or ODR/NMEM. It's
11 guaranteed that an OID can fit in <code class="literal">OID_SIZE</code> integers.
12 </p><div class="example"><a name="tools.oid.bib1.1"></a><p class="title"><b>Example 9.13. Create OID on stack</b></p><div class="example-contents"><p>
13 We can create an OID for the Bib-1 attribute set with:
14 </p><pre class="screen">
15 Odr_oid bib1[OID_SIZE];
24 </p></div></div><br class="example-break"><p>
25 And OID may also be filled from a string-based representation using
26 dots (.). This is achieved by function
27 </p><pre class="screen">
28 int oid_dotstring_to_oid(const char *name, Odr_oid *oid);
30 This functions returns 0 if name could be converted; -1 otherwise.
31 </p><div class="example"><a name="tools.oid.bib1.2"></a><p class="title"><b>Example 9.14. Using oid_oiddotstring_to_oid</b></p><div class="example-contents"><p>
32 We can fill the Bib-1 attribute set OID easier with:
33 </p><pre class="screen">
34 Odr_oid bib1[OID_SIZE];
35 oid_oiddotstring_to_oid("1.2.840.10003.3.1", bib1);
37 </p></div></div><br class="example-break"><p>
38 We can also allocate an OID dynamically on a ODR stream with:
39 </p><pre class="screen">
40 Odr_oid *odr_getoidbystr(ODR o, const char *str);
42 This creates an OID from string-based representation using dots.
43 This function take an <acronym class="acronym">ODR</acronym> stream as parameter. This stream is used to
44 allocate memory for the data elements, which is released on a
45 subsequent call to <code class="function">odr_reset()</code> on that stream.
46 </p><div class="example"><a name="tools.oid.bib1.3"></a><p class="title"><b>Example 9.15. Using odr_getoidbystr</b></p><div class="example-contents"><p>
47 We can create a OID for the Bib-1 attribute set with:
48 </p><pre class="screen">
49 Odr_oid *bib1 = odr_getoidbystr(odr, "1.2.840.10003.3.1");
51 </p></div></div><br class="example-break"><p>
53 </p><pre class="screen">
54 char *oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
56 does the reverse of <code class="function">oid_oiddotstring_to_oid</code>. It
57 converts an OID to the string-based representation using dots.
58 The supplied char buffer <code class="literal">oidbuf</code> holds the resulting
59 string and must be at least <code class="literal">OID_STR_MAX</code> in size.
61 OIDs can be copied with <code class="function">oid_oidcpy</code> which takes
62 two OID lists as arguments. Alternativly, an OID copy can be allocated
64 </p><pre class="screen">
65 Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o);
68 OIDs can be compared with <code class="function">oid_oidcmp</code> which returns
69 zero if the two OIDs provided are identical; non-zero otherwise.
70 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="tools.oid.database"></a>2.1. OID database</h3></div></div></div><p>
71 From YAZ version 3 and later, the oident system has been replaced
72 by an OID database. OID database is a misnomer .. the old odient
73 system was also a database.
75 The OID database is really just a map between named Object Identifiers
76 (string) and their OID raw equivalents. Most operations either
77 convert from string to OID or other way around.
79 Unfortunately, whenever we supply a string we must also specify the
80 <span class="emphasis"><em>OID class</em></span>. The class is necessary because some
81 strings correspond to multiple OIDs. An example of such a string is
82 <code class="literal">Bib-1</code> which may either be an attribute-set
85 Applications using the YAZ database should include
86 <code class="filename">yaz/oid_db.h</code>.
88 A YAZ database handle is of type <code class="literal">yaz_oid_db_t</code>.
89 Actually that's a pointer. You need not think deal with that.
90 YAZ has a built-in database which can be considered "constant" for
92 We can get hold that by using function <code class="function">yaz_oid_std</code>.
94 All functions with prefix <code class="function">yaz_string_to_oid</code>
95 converts from class + string to OID. We have variants of this
96 operation due to different memory allocation strategies.
98 All functions with prefix
99 <code class="function">yaz_oid_to_string</code> converts from OID to string
101 </p><div class="example"><a name="tools.oid.bib1.4"></a><p class="title"><b>Example 9.16. Create OID with YAZ DB</b></p><div class="example-contents"><p>
102 We can create an OID for the Bib-1 attribute set on the ODR stream
104 </p><pre class="screen">
106 yaz_string_to_oid_odr(yaz_oid_std(), CLASS_ATTSET, "Bib-1", odr);
108 This is more complex than using <code class="function">odr_getoidbystr</code>.
109 You would only use <code class="function">yaz_string_to_oid_odr</code> when the
110 string (here Bib-1) is supplied by a user or configuration.
111 </p></div></div><br class="example-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="tools.oid.std"></a>2.2. Standard OIDs</h3></div></div></div><p>
112 All the object identifers in the standard OID database as returned
113 by <code class="function">yaz_oid_std</code> can referenced directly in a
114 program as a constant OID.
115 Each constant OID is prefixed with <code class="literal">yaz_oid_</code> -
116 followed by OID class (lowercase) - then by OID name (normalized and
119 See <a class="xref" href="list-oids.html" title="Appendix A. List of Object Identifiers">Appendix A, <i>List of Object Identifiers</i></a> for list of all object identifiers
121 These are declared in <code class="filename">yaz/oid_std.h</code> but are
122 included by <code class="filename">yaz/oid_db.h</code> as well.
123 </p><div class="example"><a name="tools.oid.bib1.5"></a><p class="title"><b>Example 9.17. Use a built-in OID</b></p><div class="example-contents"><p>
124 We can allocate our own OID filled with the constant OID for
126 </p><pre class="screen">
127 Odr_oid *bib1 = odr_oiddup(o, yaz_oid_attset_bib1);
129 </p></div></div><br class="example-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="tools.oid.oident"></a>2.3. OID oident</h3></div></div></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
130 The oident utility has been removed from YAZ version 3. This
131 sub section only applies to YAZ version 2.
133 The OID module provides a higher-level representation of the
134 family of object identifiers which describe the Z39.50 protocol and its
135 related objects. The definition of the module interface is given in
136 the <code class="filename">oid.h</code> file.
138 The interface is mainly based on the <code class="literal">oident</code> structure.
139 The definition of this structure looks like this:
140 </p><pre class="screen">
141 typedef struct oident
146 int oidsuffix[OID_SIZE];
150 The proto field takes one of the values
151 </p><pre class="screen">
155 Use <code class="literal">PROTO_Z3950</code> for Z39.50 Object Identifers,
156 <code class="literal">PROTO_GENERAL</code> for other types (such as
157 those associated with ILL).
160 The oclass field takes one of the values
161 </p><pre class="screen">
178 corresponding to the OID classes defined by the Z39.50 standard.
180 Finally, the value field takes one of the values
181 </p><pre class="screen">
234 again, corresponding to the specific OIDs defined by the standard.
236 <a class="ulink" href="http://www.loc.gov/z3950/agency/defns/oids.html" target="_top">
237 Registry of Z39.50 Object Identifiers</a> for the
240 The desc field contains a brief, mnemonic name for the OID in question.
243 </p><pre class="screen">
244 struct oident *oid_getentbyoid(int *o);
246 takes as argument an OID, and returns a pointer to a static area
247 containing an <code class="literal">oident</code> structure. You typically use
248 this function when you receive a PDU containing an OID, and you wish
249 to branch out depending on the specific OID value.
252 </p><pre class="screen">
253 int *oid_ent_to_oid(struct oident *ent, int *dst);
255 Takes as argument an <code class="literal">oident</code> structure - in which
256 the <code class="literal">proto</code>, <code class="literal">oclass</code>/, and
257 <code class="literal">value</code> fields are assumed to be set correctly -
258 and returns a pointer to a the buffer as given by <code class="literal">dst</code>
260 representation of the corresponding OID. The function returns
261 NULL and the array dst is unchanged if a mapping couldn't place.
262 The array <code class="literal">dst</code> should be at least of size
263 <code class="literal">OID_SIZE</code>.
266 The <code class="function">oid_ent_to_oid()</code> function can be used whenever
267 you need to prepare a PDU containing one or more OIDs. The separation of
268 the <code class="literal">protocol</code> element from the remainder of the
269 OID-description makes it simple to write applications that can
270 communicate with either Z39.50 or OSI SR-based applications.
273 </p><pre class="screen">
274 oid_value oid_getvalbyname(const char *name);
276 takes as argument a mnemonic OID name, and returns the
277 <code class="literal">/value</code> field of the first entry in the database that
278 contains the given name in its <code class="literal">desc</code> field.
280 Three utility functions are provided for translating OIDs'
281 symbolic names (e.g. <code class="literal">Usmarc</code> into OID structures
282 (int arrays) and strings containing the OID in dotted notation
283 (e.g. <code class="literal">1.2.840.10003.9.5.1</code>). They are:
284 </p><pre class="screen">
285 int *oid_name_to_oid(oid_class oclass, const char *name, int *oid);
286 char *oid_to_dotstring(const int *oid, char *oidbuf);
287 char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oidbuf);
289 <code class="literal">oid_name_to_oid()</code>
290 translates the specified symbolic <code class="literal">name</code>,
291 interpreted as being of class <code class="literal">oclass</code>. (The
292 class must be specified as many symbolic names exist within
293 multiple classes - for example, <code class="literal">Zthes</code> is the
294 symbolic name of an attribute set, a schema and a tag-set.) The
295 sequence of integers representing the OID is written into the
296 area <code class="literal">oid</code> provided by the caller; it is the
297 caller's responsibility to ensure that this area is large enough
298 to contain the translated OID. As a convenience, the address of
299 the buffer (i.e. the value of <code class="literal">oid</code>) is
302 <code class="literal">oid_to_dotstring()</code>
303 Translates the int-array <code class="literal">oid</code> into a dotted
304 string which is written into the area <code class="literal">oidbuf</code>
305 supplied by the caller; it is the caller's responsibility to
306 ensure that this area is large enough. The address of the buffer
309 <code class="literal">oid_name_to_dotstring()</code>
310 combines the previous two functions to derive a dotted string
311 representing the OID specified by <code class="literal">oclass</code> and
312 <code class="literal">name</code>, writing it into the buffer passed as
313 <code class="literal">oidbuf</code> and returning its address.
314 </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
315 The OID module has been criticized - and perhaps rightly so
316 - for needlessly abstracting the
317 representation of OIDs. Other toolkits use a simple
318 string-representation of OIDs with good results. In practice, we have
319 found the interface comfortable and quick to work with, and it is a
320 simple matter (for what it's worth) to create applications compatible
321 with both ISO SR and Z39.50. Finally, the use of the
322 <code class="literal">/oident</code> database is by no means mandatory.
323 You can easily create your own system for representing OIDs, as long
324 as it is compatible with the low-level integer-array representation
326 </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tools.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tools.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tools.nmem.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 9. Supporting Tools </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 3. Nibble Memory</td></tr></table></div></body></html>