⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lber-decode.3

📁 ldap服务器源码
💻 3
字号:
.TH LBER_DECODE 3 "RELEASEDATE" "OpenLDAP LDVERSION".\" $OpenLDAP: pkg/ldap/doc/man/man3/lber-decode.3,v 1.21.2.4 2007/01/02 21:43:44 kurt Exp $.\" Copyright 1998-2007 The OpenLDAP Foundation All Rights Reserved..\" Copying restrictions apply.  See COPYRIGHT/LICENSE..SH NAMEber_get_next, ber_skip_tag, ber_peek_tag, ber_scanf, ber_get_int,ber_get_enum, ber_get_stringb, ber_get_stringa, ber_get_stringal,ber_get_stringbv, ber_get_null, ber_get_boolean, ber_get_bitstring,ber_first_element, ber_next_element\- LBER simplified Basic Encoding Rules library routines for decoding.SH LIBRARYOpenLDAP LBER (liblber, -llber).SH SYNOPSIS.B #include <lber.h>.LP.BI "ber_tag_t ber_get_next(Sockbuf *" sb ", ber_len_t *" len ", BerElement *" ber ");".LP.BI "ber_tag_t ber_skip_tag(BerElement *" ber ", ber_len_t *" len ");".LP.BI "ber_tag_t ber_peek_tag(BerElement *" ber ", ber_len_t *" len ");".LP.BI "ber_tag_t ber_scanf(BerElement *" ber ", const char *" fmt ", ...);".LP.BI "ber_tag_t ber_get_int(BerElement *" ber ", ber_int_t *" num ");".LP.BI "ber_tag_t ber_get_enum(BerElement *" ber ", ber_int_t *" num ");".LP.BI "ber_tag_t ber_get_stringb(BerElement *" ber ", char *" buf ", ber_len_t *" len ");".LP.BI "ber_tag_t ber_get_stringa(BerElement *" ber ", char **" buf ");".LP.BI "ber_tag_t ber_get_stringal(BerElement *" ber ", struct berval **" bv ");".LP.BI "ber_tag_t ber_get_stringbv(BerElement *" ber ", struct berval *" bv ", int " alloc ");".LP.BI "ber_tag_t ber_get_null(BerElement *" ber ");".LP.BI "ber_tag_t ber_get_boolean(BerElement *" ber ", ber_int_t *" bool ");".LP.BI "ber_tag_t ber_get_bitstringa(BerElement *" ber ", char **" buf ", ber_len_t *" blen ");".LP.BI "ber_tag_t ber_first_element(BerElement *" ber ", ber_len_t *" len ", char **" cookie ");".LP.BI "ber_tag_t ber_next_element(BerElement *" ber ", ber_len_t *" len ", const char *" cookie ");".SH DESCRIPTION.LPThese routines provide a subroutine interface to a simplifiedimplementation of the Basic Encoding Rules of ASN.1.  The versionof BER these routines support is the one defined for the LDAPprotocol.  The encoding rules are the same as BER, except that only definite form lengths are used, and bitstrings and octet stringsare always encoded in primitive form.  This man pagedescribes the decoding routines in the lber library.  See.BR lber-encode (3)for details on the corresponding encoding routines.Consult.BR lber-types (3)for information about types, allocators, and deallocators..LPNormally, the only routines that need to be called by an applicationare.BR ber_get_next ()to get the next BER element and.BR ber_scanf ()to do the actual decoding.  In some cases,.BR ber_peek_tag ()may also need to be called in normal usage.  The other routines areprovided for those applications that need more control than.BR ber_scanf ()provides.  Ingeneral, these routines return the tag of the element decoded, orLBER_ERROR if an error occurred..LPThe.BR ber_get_next ()routine is used to read the next BER element from the given Sockbuf,\fIsb\fP.  It strips off and returns the leading tag, strips off andreturns the length of the entire element in \fIlen\fP, and sets up\fIber\fP for subsequent calls to .BR ber_scanf ()et al to decode the element. See.BR lber-sockbuf (3)for details of the Sockbuf implementation of the \fIsb\fP parameter..LPThe.BR ber_scanf ()routine is used to decode a BER element in much the same way that.BR scanf (3)works.  It reads from \fIber\fP, a pointer to a BerElementsuch as returned by.BR ber_get_next (),interprets the bytes according to the format string \fIfmt\fP, and stores theresults in its additional arguments.  The format string containsconversion specifications which are used to direct the interpretationof the BER element.  The format string can contain the followingcharacters..RS.LP.TP 3.B aOctet string.  A char ** should be supplied.  Memory is allocated,filled with the contents of the octet string, null-terminated, andreturned in the parameter.  The caller should free the returnedstring using.BR ber_memfree ()..TP.B sOctet string.  A char * buffer should be supplied, followed by a pointer to aber_len_t initialized to the size of the buffer.  Upon return, thenull-terminated octet string is put into the buffer, and theber_len_t is set to the actual size of the octet string..TP.B OOctet string.  A struct ber_val ** should be supplied, which uponreturn points to a dynamically allocated struct bervalcontaining the octet string and its length.The caller should free the returned structure using.BR ber_bvfree ()..TP.B oOctet string.  A struct ber_val * should be supplied, which uponreturn contains the dynamically allocatedoctet string and its length.  The caller should free the returned octetstring using.BR ber_memfree ()..TP.B mOctet string.  A struct ber_val * should be supplied, which upon returncontains the octet string and its length.  The string resides in memoryassigned to the BerElement, and must not be freed by the caller..TP.B bBoolean.  A pointer to a ber_int_t should be supplied..TP.B eEnumeration.  A pointer to a ber_int_t should be supplied..TP.B iInteger.  A pointer to a ber_int_t should be supplied..TP.B BBitstring.  A char ** should be supplied which will point to thedynamically allocatedbits, followed by a ber_len_t *, which will point to the length(in bits) of the bitstring returned..TP.B nNull.  No parameter is required.  The element is simply skipped ifit is recognized..TP.B vSequence of octet strings.  A char *** should be supplied, which uponreturn points to a dynamically allocated null-terminated array of char *'scontaining the octet strings.  NULL is returned if the sequence is empty.The caller should free the returned array and octet strings using.BR ber_memvfree ()..TP.B VSequence of octet strings with lengths.A struct berval *** should be supplied, which uponreturn points to a dynamically allocated null-terminated array ofstruct berval *'scontaining the octet strings and their lengths.NULL is returned if the sequence is empty.  The caller should free the returned structures using.BR ber_bvecfree ()..TP.B WSequence of octet strings with lengths.A BerVarray * should be supplied, which uponreturn points to a dynamically allocated array ofstruct berval'scontaining the octet strings and their lengths. The array is terminatedby a struct berval with a NULL bv_val string pointer.NULL is returned if the sequence is empty.  The caller should free the returned structures using.BR ber_bvarray_free ()..TP.B MSequence of octet strings with lengths.  This is a generalized formof the previous three formats.A void ** (ptr) should be supplied, followed by a ber_len_t * (len)and a ber_len_t (off).Upon return (ptr) will point to a dynamically allocated arraywhose elements are all of size (*len).  A struct berval will be filledstarting at offset (off) in each element.  The strings in each structberval reside in memory assigned to the BerElement and must not befreed by the caller.  The array is terminated by a struct bervalwith a NULL bv_val string pointer.  NULL is returned if the sequenceis empty.  The number of elements in the array is also storedin (*len) on return.  The caller should free the returned array using.BR ber_memfree ()..TP.B lLength of the next element.  A pointer to a ber_len_t should be supplied..TP.B tTag of the next element.  A pointer to a ber_tag_t should be supplied..TP.B TSkip element and return its tag.  A pointer to a ber_tag_t should be supplied..TP.B xSkip element.  The next element is skipped..TP.B {Begin sequence.  No parameter is required.  The initial sequence tagand length are skipped..TP.B }End sequence.  No parameter is required and no action is taken..TP.B [Begin set.  No parameter is required.  The initial set tagand length are skipped..TP.B ]End set.  No parameter is required and no action is taken..RE.LPThe.BR ber_get_int ()routine tries to interpret the next element as an integer,returning the result in \fInum\fP.  The tag of whatever it finds is returnedon success, LBER_ERROR (\-1) on failure..LPThe.BR ber_get_stringb ()routine is used to read an octet string into apreallocated buffer.  The \fIlen\fP parameter should be initialized tothe size of the buffer, and will contain the length of the octet stringread upon return.  The buffer should be big enough to take the octetstring value plus a terminating NULL byte..LPThe.BR ber_get_stringa ()routine is used to dynamically allocate space intowhich an octet string is read.The caller should free the returned string using.BR ber_memfree()..LPThe.BR ber_get_stringal ()routine is used to dynamically allocate spaceinto which an octet string and its length are read.  It takes astruct berval **, and returns the result in this parameter.The caller should free the returned structure using.BR ber_bvfree()..LPThe.BR ber_get_stringbv ()routine is used to read an octet string and its length into the provided struct berval *. If the \fIalloc\fP parameter is zero, the stringwill reside in memory assigned to the BerElement, and must not be freedby the caller. If the \fIalloc\fP parameter is non-zero, the string will becopied into dynamically allocated space which should be returned using.BR ber_memfree ()..LPThe.BR ber_get_null ()routine is used to read a NULL element.  It returnsthe tag of the element it skips over..LPThe.BR ber_get_boolean ()routine is used to read a boolean value.  It is called the same way that.BR ber_get_int ()is called..LPThe.BR ber_get_enum ()routine is used to read a enumeration value.  It is called the same way that.BR ber_get_int ()is called..LPThe.BR ber_get_bitstringa ()routine is used to read a bitstring value.  Ittakes a char ** which will hold the dynamically allocated bits, followed by anber_len_t *, which will point to the length (in bits) of the bitstring returned.The caller should free the returned string using.BR ber_memfree ()..LPThe.BR ber_first_element ()routine is used to return the tag and lengthof the first element in a set or sequence.  It also returns in \fIcookie\fPa magic cookie parameter that should be passed to subsequent calls tober_next_element(), which returns similar information..SH EXAMPLESAssume the variable \fIber\fP contains a lightweight BER encoding ofthe following ASN.1 object:.LP.nf      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      }.fi.LPThe element can be decoded using.BR ber_scanf ()as follows..LP.nf      ber_int_t    scope, deref, size, time, attrsonly;      char   *dn, **attrs;      ber_tag_t tag;      tag = ber_scanf( ber, "{aeeiib{v}}",          &dn, &scope, &deref,          &size, &time, &attrsonly, &attrs );      if( tag == LBER_ERROR ) {              /* error */      } else {              /* success */      }      ber_memfree( dn );      ber_memvfree( attrs );.fi.SH ERRORSIf an error occurs during decoding, generally these routines returnLBER_ERROR ((ber_tag_t)\-1)..LP.SH NOTES.LPThe return values for all of these functions are declared in the.B <lber.h>header file.  Some routines may dynamically allocate memorywhich must be freed by the caller using supplied deallocation routines..SH SEE ALSO.BR lber-encode (3),.BR lber-memory (3),.BR lber-sockbuf (3),.BR lber-types (3).SH ACKNOWLEDGEMENTS.B OpenLDAPis developed and maintained by The OpenLDAP Project (http://www.openldap.org/)..B OpenLDAPis derived from University of Michigan LDAP 3.3 Release.  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -