Manual Pages for UNIX Darwin command on man ber_get_null
MyWebUniversity

Manual Pages for UNIX Darwin command on man ber_get_null

LBERDECODE(3) LBERDECODE(3)

NAME

bergetnext, berskiptag, berpeektag, berscanf, bergetint, bergetenum, bergetstringb, bergetstringa, bergetstringal, bergetstringbv, bergetnull, bergetboolean, bergetbitstring,

berfirstelement, bernextelement - LBER simplified Basic Encoding

Rules library routines for decoding LLIIBBRRAARRYY

OpenLDAP LBER (liblber, -llber)

SYNOPSIS

##iinncclluuddee <>

bbeerrttaaggtt bbeerrggeettnneexxtt((SSoocckkbbuuff **sb,, bbeerrlleenntt **len,, BBeerrEElleemmeenntt **ber));; bbeerrttaaggtt bbeerrsskkiippttaagg((BBeerrEElleemmeenntt **ber,, bbeerrlleenntt **len));; bbeerrttaaggtt bbeerrppeeeekkttaagg((BBeerrEElleemmeenntt **ber,, bbeerrlleenntt **len));; bbeerrttaaggtt bbeerrssccaannff((BBeerrEElleemmeenntt **ber,, ccoonnsstt cchhaarr **fmt,, ......));; bbeerrttaaggtt bbeerrggeettiinntt((BBeerrEElleemmeenntt **ber,, bbeerriinntttt **num));; bbeerrttaaggtt bbeerrggeetteennuumm((BBeerrEElleemmeenntt **ber,, bbeerriinntttt **num));; bbeerrttaaggtt bbeerrggeettssttrriinnggbb((BBeerrEElleemmeenntt **ber,, cchhaarr **buf,, bbeerrlleenntt **len));; bbeerrttaaggtt bbeerrggeettssttrriinnggaa((BBeerrEElleemmeenntt **ber,, cchhaarr ****buf));; bbeerrttaaggtt bbeerrggeettssttrriinnggaall((BBeerrEElleemmeenntt **ber,, ssttrruucctt bbeerrvvaall ****bv));; bbeerrttaaggtt bbeerrggeettssttrriinnggbbvv((BBeerrEElleemmeenntt **ber,, ssttrruucctt bbeerrvvaall **bv,, iinntt alloc));; bbeerrttaaggtt bbeerrggeettnnuullll((BBeerrEElleemmeenntt **ber));; bbeerrttaaggtt bbeerrggeettbboooolleeaann((BBeerrEElleemmeenntt **ber,, bbeerriinntttt **bool));; bbeerrttaaggtt bbeerrggeettbbiittssttrriinnggaa((BBeerrEElleemmeenntt **ber,, cchhaarr ****buf,, bbeerrlleenntt **blen));; bbeerrttaaggtt bbeerrffiirrsstteelleemmeenntt((BBeerrEElleemmeenntt **ber,, bbeerrlleenntt **len,, cchhaarr ****cookie));; bbeerrttaaggtt bbeerrnneexxtteelleemmeenntt((BBeerrEElleemmeenntt **ber,, bbeerrlleenntt **len,, ccoonnsstt cchhaarr **cookie));;

DESCRIPTION

These routines provide a subroutine interface to a simplified implemen-

tation of the Basic Encoding Rules of ASN.1. The version of BER these

routines support is the one defined for the LDAP protocol. The encod-

ing rules are the same as BER, except that only definite form lengths

are used, and bitstrings and octet strings are always encoded in primi-

tive form. This man page describes the decoding routines in the lber

library. See llbbeerr-eennccooddee(3) for details on the corresponding encoding

routines. Consult llbbeerr-ttyyppeess(3) for information about types, alloca-

tors, and deallocators. Normally, the only routines that need to be called by an application are bbeerrggeettnneexxtt() to get the next BER element and bbeerrssccaannff() to do the actual decoding. In some cases, bbeerrppeeeekkttaagg() may also need to be called in normal usage. The other routines are provided for those

applications that need more control than bbeerrssccaannff() provides. In gen-

eral, these routines return the tag of the element decoded, or

LBERERROR if an error occurred.

The bbeerrggeettnneexxtt() routine is used to read the next BER element from the given Sockbuf, sb. It strips off and returns the leading tag, strips off and returns the length of the entire element in len, and sets up ber for subsequent calls to bbeerrssccaannff() et al to decode the

element. See llbbeerr-ssoocckkbbuuff(3) for details of the Sockbuf implementation

of the sb parameter. The bbeerrssccaannff() routine is used to decode a BER element in much the same way that ssccaannff(3) works. It reads from ber, a pointer to a BerElement such as returned by bbeerrggeettnneexxtt(), interprets the bytes

according to the format string fmt, and stores the results in its addi-

tional arguments. The format string contains conversion specifications which are used to direct the interpretation of the BER element. The format string can contain the following characters.

aa Octet string. A char ** should be supplied. Memory is allo-

cated, filled with the contents of the octet string, null-

terminated, and returned in the parameter. The caller should free the returned string using bbeerrmmeemmffrreeee(). ss Octet string. A char * buffer should be supplied, followed by a pointer to a berlent initialized to the size of the

buffer. Upon return, the null-terminated octet string is put

into the buffer, and the berlent is set to the actual size of the octet string. OO Octet string. A struct berval ** should be supplied, which upon return points to a dynamically allocated struct berval containing the octet string and its length. The caller should free the returned structure using bbeerrbbvvffrreeee(). oo Octet string. A struct berval * should be supplied, which upon return contains the dynamically allocated octet string and its length. The caller should free the returned octet string using bbeerrmmeemmffrreeee(). mm Octet string. A struct berval * should be supplied, which upon return contains the octet string and its length. The string resides in memory assigned to the BerElement, and must not be freed by the caller. bb Boolean. A pointer to a berintt should be supplied. ee Enumeration. A pointer to a berintt should be supplied. ii Integer. A pointer to a berintt should be supplied. BB Bitstring. A char ** should be supplied which will point to the dynamically allocated bits, followed by a berlent *, which will point to the length (in bits) of the bitstring returned. nn Null. No parameter is required. The element is simply skipped if it is recognized. vv Sequence of octet strings. A char *** should be supplied,

which upon return points to a dynamically allocated null-ter-

minated array of char *'s containing the octet strings. NULL is returned if the sequence is empty. The caller should free the returned array and octet strings using bbeerrmmeemmvvffrreeee(). VV Sequence of octet strings with lengths. A struct berval *** should be supplied, which upon return points to a dynamically

allocated null-terminated array of struct berval *'s contain-

ing the octet strings and their lengths. NULL is returned if the sequence is empty. The caller should free the returned structures using bbeerrbbvveeccffrreeee(). WW Sequence of octet strings with lengths. A BerVarray * should

be supplied, which upon return points to a dynamically allo-

cated array of struct berval's containing the octet strings and their lengths. The array is terminated by a struct berval with a NULL bvval string pointer. NULL is returned if the sequence is empty. The caller should free the returned structures using bbeerrbbvvaarrrraayyffrreeee().

MM Sequence of octet strings with lengths. This is a general-

ized form of the previous three formats. A void ** (ptr) should be supplied, followed by a berlent * (len) and a

berlent (off). Upon return (ptr) will point to a dynami-

cally allocated array whose elements are all of size (*len). A struct berval will be filled starting at offset (off) in each element. The strings in each struct berval reside in memory assigned to the BerElement and must not be freed by the caller. The array is terminated by a struct berval with a NULL bvval string pointer. NULL is returned if the sequence is empty. The number of elements in the array is also stored in (*len) on return. The caller should free the returned array using bbeerrmmeemmffrreeee(). ll Length of the next element. A pointer to a berlent should be supplied. tt Tag of the next element. A pointer to a bertagt should be supplied. TT Skip element and return its tag. A pointer to a bertagt should be supplied. xx Skip element. The next element is skipped. {{ Begin sequence. No parameter is required. The initial sequence tag and length are skipped. }} End sequence. No parameter is required and no action is taken. [[ Begin set. No parameter is required. The initial set tag and length are skipped. ]] End set. No parameter is required and no action is taken. The bbeerrggeettiinntt() routine tries to interpret the next element as an integer, returning the result in num. The tag of whatever it finds is

returned on success, LBERERROR (-1) on failure.

The bbeerrggeettssttrriinnggbb() routine is used to read an octet string into a preallocated buffer. The len parameter should be initialized to the size of the buffer, and will contain the length of the octet string read upon return. The buffer should be big enough to take the octet string value plus a terminating NULL byte. The bbeerrggeettssttrriinnggaa() routine is used to dynamically allocate space into which an octet string is read. The caller should free the returned string using bbeerrmmeemmffrreeee(()).. The bbeerrggeettssttrriinnggaall() routine is used to dynamically allocate space into which an octet string and its length are read. It takes a struct berval **, and returns the result in this parameter. The caller should free the returned structure using bbeerrbbvvffrreeee(()).. The bbeerrggeettssttrriinnggbbvv() routine is used to read an octet string and its length into the provided struct berval *. If the alloc parameter is zero, the string will reside in memory assigned to the BerElement, and

must not be freed by the caller. If the alloc parameter is non-zero,

the string will be copied into dynamically allocated space which should be returned using bbeerrmmeemmffrreeee(). The bbeerrggeettnnuullll() routine is used to read a NULL element. It returns the tag of the element it skips over. The bbeerrggeettbboooolleeaann() routine is used to read a boolean value. It is called the same way that bbeerrggeettiinntt() is called. The bbeerrggeetteennuumm() routine is used to read a enumeration value. It is called the same way that bbeerrggeettiinntt() is called. The bbeerrggeettbbiittssttrriinnggaa() routine is used to read a bitstring value. It

takes a char ** which will hold the dynamically allocated bits, fol-

lowed by an berlent *, which will point to the length (in bits) of the bitstring returned. The caller should free the returned string using bbeerrmmeemmffrreeee(). The bbeerrffiirrsstteelleemmeenntt() routine is used to return the tag and length of the first element in a set or sequence. It also returns in cookie a magic cookie parameter that should be passed to subsequent calls to bernextelement(), which returns similar information. EEXXAAMMPPLLEESS

Assume the variable ber contains a lightweight BER encoding of the fol-

lowing ASN.1 object: AlmostASearchRequest := SEQUENCE { baseObject DistinguishedName, scope ENUMERATED { baseObject (0), singleLevel (1), wholeSubtree (2) }, derefAliases ENUMERATED { neverDerefaliases (0), derefInSearching (1), derefFindingBaseObj (2), alwaysDerefAliases (3) }, sizelimit INTEGER (0 .. 65535), timelimit INTEGER (0 .. 65535), attrsOnly BOOLEAN, attributes SEQUENCE OF AttributeType } The element can be decoded using bbeerrssccaannff() as follows. berintt scope, deref, size, time, attrsonly; char *dn, **attrs; bertagt tag; tag = berscanf( ber, "{aeeiib{v}}", &dn, &scope, &deref, &size, &time, &attrsonly, &attrs );

if( tag == LBERERROR ) {

/* error */ } else { /* success */ } bermemfree( dn ); bermemvfree( attrs ); EERRRROORRSS If an error occurs during decoding, generally these routines return

LBERERROR ((bertagt)-1).

NNOOTTEESS The return values for all of these functions are declared in the <> header file. Some routines may dynamically allocate memory which must be freed by the caller using supplied deallocation routines.

SEE ALSO

llbbeerr-eennccooddee(3), llbbeerr-mmeemmoorryy(3), llbbeerr-ssoocckkbbuuff(3), llbbeerr-ttyyppeess(3)

AACCKKNNOOWWLLEEDDGGEEMMEENNTTSS OOppeennLLDDAAPP is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). OOppeennLLDDAAPP is derived from University of Michigan LDAP 3.3 Release. OpenLDAP 2.2.19 2004/11/26 LBERDECODE(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™