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

📄 lber-encode.3

📁 开放源码的ldap系统
💻 3
字号:
.TH LBER_ENCODE 3 "12 May 2000" "OpenLDAP LDVERSION".\" $OpenLDAP: pkg/ldap/doc/man/man3/lber-encode.3,v 1.3.8.2 2000/07/29 01:53:04 kurt Exp $.\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved..\" Copying restrictions apply.  See COPYRIGHT/LICENSE..SH NAMEber_alloc_t, ber_flush, 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 \- LBER simplified Basic Encoding Rules library routines for encoding.SH SYNOPSIS.nf.ft B#include <lber.h>.ft.fi.LP.nf.ft BBerElement *ber_alloc_t( int options );.ft.fi.LP.nf.ft Bint ber_flush(	Sockbuf *sb,	BerElement *ber,	int freeit);.ft.fi.LP.nf.ft Bint ber_printf(	BerElement *ber,	const char \(**fmt, ...);.ft.fi.LP.nf.ft Bint ber_put_int(	BerElement *ber,	ber_int_t num,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_put_enum(	BerElement *ber,	ber_int_t num,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_put_ostring(	BerElement *ber,	const char \(**str,	ber_len_t long len,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_put_string(	BerElement *ber,	const char \(**str,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_put_null(	BerElement *ber;	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_put_boolean(	BerElement *ber;	ber_int_t bool;	ber_tag_t tag;.ft.fi.LP.nf.ft Bint ber_put_bitstring(	BerElement *ber,	const char *str,	ber_len_t blen,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_start_seq(	BerElement *ber,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_start_set(	BerElement *ber,	ber_tag_t tag);.ft.fi.LP.nf.ft Bint ber_put_seq(	BerElement *ber);.ft.fi.LP.nf.ft Bint ber_put_set(	BerElement *ber);.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.  In addition, these lightweightBER routines restrict tags and class to fit in a single octet (thismeans the actual tag must be less than 31).  When a "tag" is specifiedin the descriptions below, it refers to the tag, class, and primitiveor constructed bit in the first octet of the encoding.  Thisman page describes the encoding routines in the lber library.  Seelber-decode(3) for details on the corresponding decoding routines.Consult lber-types(3) for information about types, allocators, and deallocators..LPNormally, the only routines that need be called by an applicationare ber_alloc_t() to allocate a BER element for encoding, ber_printf()to do the actual encoding, and ber_flush() to actually write theelement.  The other routines are provided for thoseapplications that need more control than ber_printf() provides.  Ingeneral, these routines return the length of the element encoded, or-1 if an error occurred..LPThe ber_alloc_t() routine is used to allocate a new BER element.  Itshould be called with an argument of LBER_USE_DER.  Theber_flush() routine is used to actually write the element to a socket(or file) descriptor, once it has been fully encoded (using ber_printf()and friends).  The \fIsb\fP structure contains the descriptor and aBerElement used for input buffering.  Only the \fIsb_sd\fP field is relevantto the ber_flush() routine..LPThe ber_printf() routine is used to encode a BER element in much thesame way that sprintf(3) works.  One important difference, though, isthat some state information is kept with the \fIber\fP parameter sothat multiple calls can be made to ber_printf() to append things tothe end of the BER element.  Ber_printf() writes to \fIber\fP, a pointer to aBerElement such as returned by ber_alloc().  It interprets andformats its arguments according to the format string \fIfmt\fP.The format string can contain the following characters:.RS.LP.TP 3.SM bBoolean.  An ber_int_t parameter should be supplied.  A boolean elementis output..TP.SM eEnumeration.  An ber_int_t parameter should be supplied.  Anenumeration element is output..TP.SM iInteger.  An ber_int_t parameter should be supplied.  An integer elementis output..TP.SM BBitstring.  A char * pointer to the start of the bitstring is supplied,followed by the number of bits in the bitstring.  A bitstring elementis output..TP.SM nNull.  No parameter is required.  A null element is output..TP.SM oOctet string.  A char * is supplied, followed by the length of thestring pointed to.  An octet string element is output..TP.SM OOctet string.  A struct berval * is supplied.An octet string element is output..TP.SM sOctet string.  A null-terminated string is supplied.  An octet stringelement is output, not including the trailing NULL octet..TP.SM tTag.  A ber_tag_t specifying the tag to give the next elementis provided.  This works across calls..TP.SM vSeveral octet strings.  A null-terminated array of char *'s issupplied.  Note that a construct like '{v}' is required to getan actual SEQUENCE OF octet strings..TP.SM VSeveral octet strings.  A null-terminated array of struct berval *'sis supplied.  Note that a construct like '{V}' is required to getan actual SEQUENCE OF octet strings..TP.SM {Begin sequence.  No parameter is required..TP.SM }End sequence.  No parameter is required..TP.SM [Begin set.  No parameter is required..TP.SM ]End set.  No parameter is required..RE.LPThe ber_put_int() routine writes the integer element \fInum\fP tothe BER element \fIber\fP..LPThe ber_put_enum() routine writes the enumberation element\fInum\fP to the BER element \fIber\fP..LPThe ber_put_boolean() routine writes the boolean value given by\fIbool\fP to the BER element..LPThe ber_put_bitstring() routine writes \fIblen\fP bits startingat \fIstr\fP as a bitstring value to the given BER element.  Notethat \fIblen\fP is the length \fIin bits\fP of the bitstring..LPThe ber_put_ostring() routine writes \fIlen\fP bytes starting at\fIstr\fP to the BER element as an octet string..LPThe ber_put_string() routine writes the null-terminated string (minusthe terminating '\0') to the BER element as an octet string..LPThe ber_put_null() routine writes a NULL element to the BER element..LPThe ber_start_seq() routine is used to start a sequence in the BERelement.  The ber_start_set() routine works similarly.The end of the sequence or set is marked by the nearest matchingcall to ber_put_seq() or ber_put_set(), respectively..LPThe 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 EXAMPLESAssuming the following variable declarations, and that the variableshave been assigned appropriately, an lber 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.LPcan be achieved like so:.LP.nf      int rc;      ber_int_t    scope, ali, size, time, attrsonly;      char   *dn, **attrs;      BerElement *ber;      /* ... fill in values ... */      ber = ber_alloc_t( LBER_USE_DER );      if ( ber == NULL ) {		/* error */      }      rc = ber_printf( ber, "{siiiib{v}}", dn, scope, ali,          size, time, attrsonly, attrs );      if( rc == -1 ) {              /* error */      } else {              /* success */      }.fi.SH ERRORSIf an error occurs during encoding, generally these routines return -1..LP.SH NOTES.LPThe return values for all of these functions are declared in the<lber.h> header file..SH SEE ALSO.BR lber-decode (3).BR lber-memory (3).BR lber-types (3).BR ldap-async (3).BR ldap-sync (3).BR ldap-parse (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 + -