ber_printf

encodes data items info a BerElement.

Library:*ldapsdk.*
NDS Version:7.xx or higher
Platform:NLM, Windows (NT, 95, 98, 2000, XP, Vista 32-bit and 64-bit ), Linux (32-bit and 64-bit), Solaris, AIX, and HP-UX

Syntax

  #include <ldap.h> or <lber.h>
  
  int ber_printf (
     BerElement  *ber,
     const char *fmt,
     ...);
  

Parameters

ber

(IN) Points to a BerElement.

fmt

(IN) Points to a format string.

...

(IN) Specifies data values for each tag in the format string.

Return Values

Returns a nonnegative number on success; otherwise, returns -1 on failure.

Remarks

The ber_printf function encodes a BerElement in a similar manner as the sprintf function. However, the ber_printf function must keep state information in the ber parameter so that this function can be called subsequently to append information to the end of a BerElement.

Similar to the sprintf function, each character in the fmt parameter refers to an argument to the ber_printf function.

The fmt parameter can have the following characters.

b

Boolean

The next parameter is a ber_int_t, which contains either 0 for False or 0xff for True.

B

Bitstring

The next two parameters are a char* pointer to the start of the bitstring, followed by a ber-len-t, which contains the number of bits in the bitstring. A bitstring element is output in primitive form. If this character is not preceded by the 't' modifier, the 0x03U tag is used for the element.

e

Enumerated

The next parameter is a ber_int_t, which contains the enumerated value in the host's byte order. An enumerated element is output. If this character is not preceded by the 't' modifier, the 0x0AU tag is used for the element.

i

Integer

The next parameter is a ber_int_t, which contains the integer in the host's byte order. An integer element is output. If this character is not preceded by the 't' modifier, the 0x02U tag is used for the element.

n

NULL

No parameter is needed. An ASN.1 NULL element is output. If this character is not preceded by the 't' modifier, the 0x05U tag is used for the element.

o

Octet string

The next two parameters are a char* pointer, followed by a ber_len_t that contains the length of the string. The string can contain NULL bytes and do not have to be zero terminated. An octet string element is output in primitive form. If this character is not preceded by the 't' modifier, the 0x04U tag is used for the element.

O

Octet string

The next parameter is a pointer to a berval structure. If this character is not preceded by the 't' modifier, the 0x04U tag is used for the element.

s

Octet string

The next parameter is a char* pointer to a zero-terminated string. An octet string is output in primitive form and does not include the trailing '\0' (NULL) byte. If this character is not preceded by the 't' modifier, the 0x04U tag is used for the element.

t

Tag

The next parameter is a ber_tag_t, which specifies the tag to override the next element to be written to the BerElement.

v

Several octet strings

The next parameter is a char**, an array of char* pointers to zero-terminated strings. The last element in the array must be a NULL pointer. The octet strings do not include the trailing '\0' (NULL) byte. A construct similar to '{v}' is used to get an actual sequence of octet strings. The 't' modifier cannot be used with this character.

V

Several octet strings

A NULL-terminated array of berval structure pointers is supplied. Note that a construct similar to '{V}' is used to get an actual sequence of octet strings. The 't' modifier cannot be used with this character.

{

Begin sequence

No parameter is needed. If this character is not preceded by the 't' modifier, the 0x30U tag is used for the element.

}

End sequence

No parameter is needed. The 't' modifier cannot be used with this character.

[

Begin set

No parameter is needed. If this character is not preceded by the 't' modifier, the 0x31U tag is used for the element.

]

End set

No parameter is needed. The 't' modifier cannot be used with this character.

Each use of a '{' character should be matched with 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 rules applies to the '[' and ']' characters.