Back to index

openldap  2.4.31
Defines | Functions
vlvctrl.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/time.h>
#include "ldap-int.h"

Go to the source code of this file.

Defines

#define LDAP_VLVBYINDEX_IDENTIFIER   0xa0L
#define LDAP_VLVBYVALUE_IDENTIFIER   0x81L
#define LDAP_VLVCONTEXT_IDENTIFIER   0x04L

Functions

int ldap_create_vlv_control_value (LDAP *ld, LDAPVLVInfo *vlvinfop, struct berval *value)
int ldap_create_vlv_control (LDAP *ld, LDAPVLVInfo *vlvinfop, LDAPControl **ctrlp)
int ldap_parse_vlvresponse_control (LDAP *ld, LDAPControl *ctrl, ber_int_t *target_posp, ber_int_t *list_countp, struct berval **contextp, ber_int_t *errcodep)

Define Documentation

#define LDAP_VLVBYINDEX_IDENTIFIER   0xa0L

Definition at line 40 of file vlvctrl.c.

#define LDAP_VLVBYVALUE_IDENTIFIER   0x81L

Definition at line 41 of file vlvctrl.c.

#define LDAP_VLVCONTEXT_IDENTIFIER   0x04L

Definition at line 42 of file vlvctrl.c.


Function Documentation

int ldap_create_vlv_control ( LDAP *  ld,
LDAPVLVInfo vlvinfop,
LDAPControl **  ctrlp 
)

Definition at line 208 of file vlvctrl.c.

{
       struct berval value;

       if ( ctrlp == NULL ) {
              ld->ld_errno = LDAP_PARAM_ERROR;
              return ld->ld_errno;
       }

       ld->ld_errno = ldap_create_vlv_control_value( ld, vlvinfop, &value );
       if ( ld->ld_errno == LDAP_SUCCESS ) {

              ld->ld_errno = ldap_control_create( LDAP_CONTROL_VLVREQUEST,
                     1, &value, 0, ctrlp );
              if ( ld->ld_errno != LDAP_SUCCESS ) {
                     LDAP_FREE( value.bv_val );
              }
       }

       return ld->ld_errno;
}

Here is the call graph for this function:

int ldap_create_vlv_control_value ( LDAP *  ld,
LDAPVLVInfo vlvinfop,
struct berval value 
)

Definition at line 86 of file vlvctrl.c.

{
       ber_tag_t tag;
       BerElement *ber;

       if ( ld == NULL || vlvinfop == NULL || value == NULL ) {
              if ( ld )
                     ld->ld_errno = LDAP_PARAM_ERROR;
              return LDAP_PARAM_ERROR;
       }

       assert( LDAP_VALID( ld ) );

       value->bv_val = NULL;
       value->bv_len = 0;
       ld->ld_errno = LDAP_SUCCESS;

       ber = ldap_alloc_ber_with_options( ld );
       if ( ber == NULL ) {
              ld->ld_errno = LDAP_NO_MEMORY;
              return ld->ld_errno;
       }

       tag = ber_printf( ber, "{ii" /*}*/,
              vlvinfop->ldvlv_before_count,
              vlvinfop->ldvlv_after_count );
       if ( tag == LBER_ERROR ) {
              goto error_return;
       }

       if ( vlvinfop->ldvlv_attrvalue == NULL ) {
              tag = ber_printf( ber, "t{iiN}",
                     LDAP_VLVBYINDEX_IDENTIFIER,
                     vlvinfop->ldvlv_offset,
                     vlvinfop->ldvlv_count );
              if ( tag == LBER_ERROR ) {
                     goto error_return;
              }

       } else {
              tag = ber_printf( ber, "tO",
                     LDAP_VLVBYVALUE_IDENTIFIER,
                     vlvinfop->ldvlv_attrvalue );
              if ( tag == LBER_ERROR ) {
                     goto error_return;
              }
       }

       if ( vlvinfop->ldvlv_context ) {
              tag = ber_printf( ber, "tO",
                     LDAP_VLVCONTEXT_IDENTIFIER,
                     vlvinfop->ldvlv_context );
              if ( tag == LBER_ERROR ) {
                     goto error_return;
              }
       }

       tag = ber_printf( ber, /*{*/ "N}" ); 
       if ( tag == LBER_ERROR ) {
              goto error_return;
       }

       if ( ber_flatten2( ber, value, 1 ) == -1 ) {
              ld->ld_errno = LDAP_NO_MEMORY;
       }

       if ( 0 ) {
error_return:;
              ld->ld_errno = LDAP_ENCODING_ERROR;
       }

       if ( ber != NULL ) {
              ber_free( ber, 1 );
       }

       return ld->ld_errno;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ldap_parse_vlvresponse_control ( LDAP *  ld,
LDAPControl ctrl,
ber_int_t *  target_posp,
ber_int_t *  list_countp,
struct berval **  contextp,
ber_int_t *  errcodep 
)

Definition at line 289 of file vlvctrl.c.

{
       BerElement  *ber;
       ber_int_t pos, count, err;
       ber_tag_t tag, berTag;
       ber_len_t berLen;

       assert( ld != NULL );
       assert( LDAP_VALID( ld ) );

       if (contextp) {
              *contextp = NULL;     /* Make sure we return a NULL if error occurs. */
       }

       if (ctrl == NULL) {
              ld->ld_errno = LDAP_PARAM_ERROR;
              return(ld->ld_errno);
       }

       if (strcmp(LDAP_CONTROL_VLVRESPONSE, ctrl->ldctl_oid) != 0) {
              /* Not VLV Response control */
              ld->ld_errno = LDAP_CONTROL_NOT_FOUND;
              return(ld->ld_errno);
       }

       /* Create a BerElement from the berval returned in the control. */
       ber = ber_init(&ctrl->ldctl_value);

       if (ber == NULL) {
              ld->ld_errno = LDAP_NO_MEMORY;
              return(ld->ld_errno);
       }

       /* Extract the data returned in the control. */
       tag = ber_scanf(ber, "{iie" /*}*/, &pos, &count, &err);

       if( tag == LBER_ERROR) {
              ber_free(ber, 1);
              ld->ld_errno = LDAP_DECODING_ERROR;
              return(ld->ld_errno);
       }


       /* Since the context is the last item encoded, if caller doesn't want
          it returned, don't decode it. */
       if (contextp) {
              if (LDAP_VLVCONTEXT_IDENTIFIER == ber_peek_tag(ber, &berLen)) {
                     tag = ber_scanf(ber, "tO", &berTag, contextp);

                     if( tag == LBER_ERROR) {
                            ber_free(ber, 1);
                            ld->ld_errno = LDAP_DECODING_ERROR;
                            return(ld->ld_errno);
                     }
              }
       }

       ber_free(ber, 1);

       /* Return data to the caller for items that were requested. */
       if (target_posp) *target_posp = pos;
       if (list_countp) *list_countp = count;
       if (errcodep) *errcodep = err;

       ld->ld_errno = LDAP_SUCCESS;
       return(ld->ld_errno);
}

Here is the call graph for this function:

Here is the caller graph for this function: