1 .TH LBER_ENCODE 3 "2008/07/16" "OpenLDAP 2.4.11"
2 .\" $OpenLDAP: pkg/ldap/doc/man/man3/lber-encode.3,v 1.21.2.4 2008/02/11 23:26:39 kurt Exp $
3 .\" Copyright 1998-2008 The OpenLDAP Foundation All Rights Reserved.
4 .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
6 ber_alloc_t, ber_flush, ber_flush2, ber_printf, ber_put_int, ber_put_enum, ber_put_ostring, ber_put_string, ber_put_null, ber_put_boolean, ber_put_bitstring, ber_start_seq, ber_start_set, ber_put_seq, ber_put_set \- OpenLDAP LBER simplified Basic Encoding Rules library routines for encoding
8 OpenLDAP LBER (liblber, -llber)
12 .BI "BerElement *ber_alloc_t(int " options ");"
14 .BI "int ber_flush(Sockbuf *" sb ", BerElement *" ber ", int " freeit ");"
16 .BI "int ber_flush2(Sockbuf *" sb ", BerElement *" ber ", int " freeit ");"
18 .BI "int ber_printf(BerElement *" ber ", const char *" fmt ", ...);"
20 .BI "int ber_put_int(BerElement *" ber ", ber_int_t " num ", ber_tag_t " tag ");"
22 .BI "int ber_put_enum(BerElement *" ber ", ber_int_t " num ", ber_tag_t " tag ");"
24 .BI "int ber_put_ostring(BerElement *" ber ", const char *" str ", ber_len_t " len ", ber_tag_t " tag ");"
26 .BI "int ber_put_string(BerElement *" ber ", const char *" str ", ber_tag_t " tag ");"
28 .BI "int ber_put_null(BerElement *" ber ", ber_tag_t " tag ");"
30 .BI "int ber_put_boolean(BerElement *" ber ", ber_int_t " bool ", ber_tag_t " tag ");"
32 .BI "int ber_put_bitstring(BerElement *" ber ", const char *" str ", ber_len_t " blen ", ber_tag_t " tag ");"
34 .BI "int ber_start_seq(BerElement *" ber ", ber_tag_t " tag ");"
36 .BI "int ber_start_set(BerElement *" ber ", ber_tag_t " tag ");"
38 .BI "int ber_put_seq(BerElement *" ber ");"
40 .BI "int ber_put_set(BerElement *" ber ");"
43 These routines provide a subroutine interface to a simplified
44 implementation of the Basic Encoding Rules of ASN.1. The version
45 of BER these routines support is the one defined for the LDAP
46 protocol. The encoding rules are the same as BER, except that
47 only definite form lengths are used, and bitstrings and octet strings
48 are always encoded in primitive form. This
49 man page describes the encoding routines in the lber library. See
51 for details on the corresponding decoding routines. Consult
53 for information about types, allocators, and deallocators.
55 Normally, the only routines that need to be called by an application
58 to allocate a BER element for encoding,
60 to do the actual encoding, and
62 to actually write the element. The other routines are provided for those
63 applications that need more control than
66 general, these routines return the length of the element encoded, or
67 -1 if an error occurred.
71 routine is used to allocate a new BER element. It
72 should be called with an argument of LBER_USE_DER.
76 routine is used to actually write the element to a socket
77 (or file) descriptor, once it has been fully encoded (using
81 for more details on the Sockbuf implementation of the \fIsb\fP parameter.
82 If the \fIfreeit\fP parameter is non-zero, the supplied \fIber\fP will
84 If \fILBER_FLUSH_FREE_ON_SUCCESS\fP is used, the \fIber\fP is only freed
85 when successfully flushed, otherwise it is left intact;
86 if \fILBER_FLUSH_FREE_ON_ERROR\fP is used, the \fIber\fP is only freed
87 when an error occurs, otherwise it is left intact;
88 if \fILBER_FLUSH_FREE_ALWAYS\fP is used, the \fIber\fP is freed anyway.
89 This function differs from the original
91 function, whose behavior corresponds to that indicated
92 for \fILBER_FLUSH_FREE_ON_SUCCESS\fP.
93 Note that in the future, the behavior of
95 with \fIfreeit\fP non-zero might change into that of
97 with \fIfreeit\fP set to \fILBER_FLUSH_FREE_ALWAYS\fP.
101 routine is used to encode a BER element in much the same way that
103 works. One important difference, though, is
104 that some state information is kept with the \fIber\fP parameter so
105 that multiple calls can be made to
107 to append things to the end of the BER element.
109 writes to \fIber\fP, a pointer to a BerElement such as returned by
112 formats its arguments according to the format string \fIfmt\fP.
113 The format string can contain the following characters:
118 Boolean. An ber_int_t parameter should be supplied. A boolean element
122 Enumeration. An ber_int_t parameter should be supplied. An
123 enumeration element is output.
126 Integer. An ber_int_t parameter should be supplied. An integer element
130 Bitstring. A char * pointer to the start of the bitstring is supplied,
131 followed by the number of bits in the bitstring. A bitstring element
135 Null. No parameter is required. A null element is output.
138 Octet string. A char * is supplied, followed by the length of the
139 string pointed to. An octet string element is output.
142 Octet string. A struct berval * is supplied.
143 An octet string element is output.
146 Octet string. A null-terminated string is supplied. An octet string
147 element is output, not including the trailing NULL octet.
150 Tag. A ber_tag_t specifying the tag to give the next element
151 is provided. This works across calls.
154 Several octet strings. A null-terminated array of char *'s is
155 supplied. Note that a construct like '{v}' is required to get
156 an actual SEQUENCE OF octet strings.
159 Several octet strings. A null-terminated array of struct berval *'s
160 is supplied. Note that a construct like '{V}' is required to get
161 an actual SEQUENCE OF octet strings.
164 Several octet strings. An array of struct berval's is supplied. The
165 array is terminated by a struct berval with a NULL bv_val.
166 Note that a construct like '{W}' is required to get
167 an actual SEQUENCE OF octet strings.
170 Begin sequence. No parameter is required.
173 End sequence. No parameter is required.
176 Begin set. No parameter is required.
179 End set. No parameter is required.
184 routine writes the integer element \fInum\fP to the BER element \fIber\fP.
188 routine writes the enumeration element \fInum\fP to the BER element \fIber\fP.
191 .BR ber_put_boolean ()
192 routine writes the boolean value given by \fIbool\fP to the BER element.
195 .BR ber_put_bitstring ()
196 routine writes \fIblen\fP bits starting
197 at \fIstr\fP as a bitstring value to the given BER element. Note
198 that \fIblen\fP is the length \fIin bits\fP of the bitstring.
201 .BR ber_put_ostring ()
202 routine writes \fIlen\fP bytes starting at
203 \fIstr\fP to the BER element as an octet string.
206 .BR ber_put_string ()
207 routine writes the null-terminated string (minus
208 the terminating '\0') to the BER element as an octet string.
212 routine writes a NULL element to the BER element.
216 routine is used to start a sequence in the BER element. The
218 routine works similarly.
219 The end of the sequence or set is marked by the nearest matching call to
225 Assuming the following variable declarations, and that the variables
226 have been assigned appropriately, an lber encoding of
227 the following ASN.1 object:
230 AlmostASearchRequest := SEQUENCE {
231 baseObject DistinguishedName,
237 derefAliases ENUMERATED {
238 neverDerefaliases (0),
239 derefInSearching (1),
240 derefFindingBaseObj (2),
241 alwaysDerefAliases (3)
243 sizelimit INTEGER (0 .. 65535),
244 timelimit INTEGER (0 .. 65535),
246 attributes SEQUENCE OF AttributeType
250 can be achieved like so:
254 ber_int_t scope, ali, size, time, attrsonly;
258 /* ... fill in values ... */
260 ber = ber_alloc_t( LBER_USE_DER );
266 rc = ber_printf( ber, "{siiiib{v}}", dn, scope, ali,
267 size, time, attrsonly, attrs );
276 If an error occurs during encoding, generally these routines return -1.
280 The return values for all of these functions are declared in the
281 <lber.h> header file.
285 .BR lber-sockbuf (3),
288 .\" Shared Project Acknowledgement Text
289 .B "OpenLDAP Software"
290 is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>.
291 .B "OpenLDAP Software"
292 is derived from University of Michigan LDAP 3.3 Release.