Directory Services

ber_printf

The ber_printf function is used to encode a BER element and is similar to sprintf. One important difference is that state data is stored in the BerElement argument so that multiple calls can be made to ber_printf to append to the end of the BER element. The BerElement argument passed to this function must be a pointer to a BerElement returned by ber_alloc_t.

INT ber_printf(
  BerElement* pBerElement,
  PCHAR fmt,
   ...
);

Parameters

pBerElement
[in, out] Pointer to the encoded BerElement structure.
fmt
[in] Encoding format string. For more information, see Remarks.
...
[in] Values to be encoded as specified by the fmt argument.

Return Values

If the function succeeds, a non-negative number is returned. If the function fails, a -1 is returned.

Remarks

The format string can contain the following format characters.

Character Description
t Tag. The next argument is a ber_tag_t that specifies the tag to override the next element written to the BerElement. This works across calls.
b Boolean. The next argument is an ber_int_t, that contains either 0 for FALSE or 1 for TRUE. A Boolean element is output. If this format character is not preceded by the t format modifier, the tag 0x01U is used for the element.
e Enumerated. The next argument is a ber_int_t, that contains the enumerated value. An enumerated element is output. If this format character is not preceded by the t format modifier, the tag 0x0AU is used for the element.
i Integer. The next argument is a ber_int_t, that contains the integer value. An integer element is output. If this format character is not preceded by the t format modifier, the tag 0x02U is used for the element.
n Null. No argument is required. An ASN.1 NULL element is output. If this format character is not preceded by the t format modifier, the tag 0x05U is used for the element.
o Octet string. The next two arguments are a char*, followed by a ber_len_t with the length of the string. The string may contain NULL bytes and do not have to be zero-terminated. An octet string element is output and no character format conversions on the string data is performed. Passing a NULL pointer followed by a length of 0 is acceptable if a NULL octet string element is required. If this format character is not preceded by the t format modifier, the tag 0x04U is used for the element.
s Octet string. The next argument is a char* pointing to a zero-terminated ANSI character string. The ANSI string characters are converted to UTF-8 format and an octet string element is output, which does not include the trailing '\0' (null) byte. Passing a NULL pointer is acceptable if a NULL octet string element is required. If this format character is not preceded by the t format modifier, the tag 0x04U is used for the element.
v Several octet strings. The next argument is a char **, an array of char* pointers to zero-terminated ANSI strings. The last element in the array must be a NULL pointer. The octet strings do not include the trailing '\0' (null) byte. Be aware that a construct like {v} is used to get an actual SEQUENCE OF octet strings. The t format modifier cannot be used with this format character.
V Several octet strings. A NULL-terminated array of berval* is supplied. Be aware that a construct like {V} is used to get an actual SEQUENCE OF octet strings. The t format modifier cannot be used with this format character.
X Bitstring. The next two arguments are a char* pointer to the start of the bitstring, followed by a ber_len_t that contains the number of bits in the bitstring. A bitstring element is output. If this format character is not preceded by the t format modifier, the tag 0x03U is used for the element.
{ Begin sequence. No argument is required. If this format character is not preceded by the t format modifier, the tag 0x30U is used.
} End sequence. No argument is required. The t format modifier cannot be used with this format character.
[ Begin set. No argument is required. If this format character is not preceded by the t format modifier, the tag 0x31U is used.
] End set. No argument is required. The t format modifier cannot be used with this format character.

Each use of a { format character must be matched by a } character, either later in the format string, or in the format string of a subsequent call to ber_printf for that specific BerElement. The same applies to the [ and ] format characters.

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Winber.h.
Library: Use Wldap32.lib.

See Also

Functions, berval, BerElement, ber_scanf