X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=doc%2Fodr.xml;h=38d300e61ff3daa77662abe574ab8dfe882ec48a;hb=69d044abe3d3a3560267a16dc4db13386974d5e1;hp=3ae89c5e68ffc85310ac303cb1389167df768a1f;hpb=cbd3dfed0ab7919bf1deb0e8af5fed4ffb8bdf5d;p=yaz-moved-to-github.git diff --git a/doc/odr.xml b/doc/odr.xml index 3ae89c5..38d300e 100644 --- a/doc/odr.xml +++ b/doc/odr.xml @@ -1,4 +1,4 @@ - + The ODR Module Introduction @@ -17,15 +17,15 @@ (). Only if you need to implement ASN.1 beyond that which has been provided, should you worry about the second half of the documentation - (section Programming with ODR). + (). If you use one of the higher-level interfaces, you can skip this section entirely. This is important, so we'll repeat it for emphasis: You do - not need to read section Programming with - ODR to implement Z39.50 with &yaz;. + not need to read + to implement Z39.50 with &yaz;. @@ -39,7 +39,7 @@ Using ODR - ODR Streams + ODR Streams Conceptually, the ODR stream is the source of encoded data in the @@ -74,7 +74,7 @@ - Memory Management + Memory Management Two forms of memory management take place in the &odr; system. The first @@ -169,7 +169,7 @@ - Encoding and Decoding Data + Encoding and Decoding Data When encoding data, the ODR stream will write the encoded octet string @@ -260,7 +260,8 @@ z_APDU()). - Encoding and decoding functions + + Encoding and decoding functions int odr_integer(ODR o, int **p, int optional, const char *name); @@ -298,7 +299,8 @@ last call to odr_reset() will be released. - Encoding and decoding of an integer + + Encoding and decoding of an integer The use of the double indirection can be a little confusing at first (its purpose will become clear later on, hopefully), @@ -355,7 +357,58 @@ void do_nothing_useful(int value) - Diagnostics + Printing + + When an ODR stream is created of type ODR_PRINT + the ODR module will print the contents of a PDU in a readable format. + By default output is written to the stderr stream. + This behavior can be changed, however, by calling the function + + odr_setprint(ODR o, FILE *file); + + before encoders or decoders are being invoked. + It is also possible to direct the output to a buffer (of indeed + another file), by using the more generic mechanism: + + void odr_set_stream(ODR o, void *handle, + void (*stream_write)(ODR o, void *handle, int type, + const char *buf, int len), + void (*stream_close)(void *handle)); + + Here the user provides an opaque handle and two handlers, + stream_write for writing, + and stream_close which is supposed + to close/free resources associated with handle. + The stream_close handler is optional and + if NULL for the function is provided, it will not be invoked. + The stream_write takes the ODR handle + as parameter, the user defined handle, a type + ODR_OCTETSTRING, ODR_VISIBLESTRING + which indicates the type of contents is being written. + + + Another utility useful for diagnostics (error handling) or as + part of the printing facilities is: + + const char **odr_get_element_path(ODR o); + + which returns a list of current elements that ODR deals with at the + moment. For the returned array, say ar, + ar[0] is the top level element, + ar[n] is the last. The last element has the + property that ar[n+1] == NULL. + + + Element Path for record + + For a database record part of a PresentResponse the + array returned by odr_get_element + is presentResponse, databaseOrSurDiagnostics, ?, record, ?, databaseRecord . The question mark appears due to + unnamed constructions. + + + + Diagnostics The encoding/decoding functions all return 0 when an error occurs. @@ -389,7 +442,8 @@ void do_nothing_useful(int value) one of these constants: - ODR Error codes +
+ ODR Error codes @@ -447,7 +501,8 @@ void do_nothing_useful(int value) - Summary and Synopsis + + Summary and Synopsis #include <odr.h> @@ -478,7 +533,7 @@ void do_nothing_useful(int value) - Programming with ODR + Programming with ODR The API of &odr; is designed to reflect the structure of ASN.1, rather @@ -489,9 +544,9 @@ void do_nothing_useful(int value) There is an ASN.1 tutorial available at - this site. + this site. This site also has standards for ASN.1 (X.680) and BER (X.690) - online. + online. @@ -517,14 +572,15 @@ void do_nothing_useful(int value) SEQUENCE members which don't exist in XDR. - The Primitive ASN.1 Types + + The Primitive ASN.1 Types ASN.1 defines a number of primitive types (many of which correspond roughly to primitive types in structured programming languages, such as C). - INTEGER + INTEGER The &odr; function for encoding or decoding (or printing) the ASN.1 @@ -582,21 +638,21 @@ void do_nothing_useful(int value) similar manners: - BOOLEAN + BOOLEAN int odr_bool(ODR o, bool_t **p, int optional, const char *name); - REAL + REAL Not defined. - NULL + NULL int odr_null(ODR o, bool_t **p, int optional, const char *name); @@ -609,7 +665,7 @@ int odr_null(ODR o, bool_t **p, int optional, const char *name); - OCTET STRING + OCTET STRING typedef struct odr_oct @@ -656,7 +712,7 @@ int odr_visiblestring(ODR o, char **p, int optional, - BIT STRING + BIT STRING int odr_bitstring(ODR o, Odr_bitmask **p, int optional, @@ -694,7 +750,7 @@ int ODR_MASK_GET(Odr_bitmask *b, int bitno); - OBJECT IDENTIFIER + OBJECT IDENTIFIER int odr_oid(ODR o, Odr_oid **p, int optional, const char *name); @@ -704,14 +760,14 @@ int odr_oid(ODR o, Odr_oid **p, int optional, const char *name); The C OID representation is simply an array of integers, terminated by the value -1 (the Odr_oid type is synonymous with the int type). - We suggest that you use the OID database module (see section - Object Identifiers) to handle object identifiers + We suggest that you use the OID database module (see + ) to handle object identifiers in your application. - Tagging Primitive Types + Tagging Primitive Types The simplest way of tagging a type is to use the @@ -762,7 +818,7 @@ int myInt(ODR o, int **p, int optional, const char *name) - Constructed Types + Constructed Types Constructed types are created by combining primitive types. The @@ -849,17 +905,18 @@ int mySequence(ODR o, MySequence **p, int optional, const char *name) - Tagging Constructed Types + + Tagging Constructed Types - See section Tagging Primitive types - for information on how to tag the primitive types, as well as types - that are already defined. + See for information on how to tag + the primitive types, as well as types that are already defined. - Implicit Tagging + + Implicit Tagging Assume the type above had been defined as @@ -907,7 +964,7 @@ int mySequence(ODR o, MySequence **p, int optional, const char *name) - Explicit Tagging + Explicit Tagging Explicit tagging of constructed types is a little more complicated, @@ -982,7 +1039,7 @@ int mySequence(ODR o, MySequence **p, int optional, const char *name) - SEQUENCE OF + SEQUENCE OF To handle sequences (arrays) of a specific type, the function @@ -1038,7 +1095,7 @@ int myArray(ODR o, MyArray **p, int optional, const char *name) - CHOICE Types + CHOICE Types The choice type is used fairly often in some ASN.1 definitions, so