Back to index

lightning-sunbird  0.9+nobinonly
Functions
vlistctrl.c File Reference
#include "ldap-int.h"

Go to the source code of this file.

Functions

int LDAP_CALL ldap_create_virtuallist_control (LDAP *ld, LDAPVirtualList *ldvlistp, LDAPControl **ctrlp)
int LDAP_CALL ldap_parse_virtuallist_control (LDAP *ld, LDAPControl **ctrls, unsigned long *target_posp, unsigned long *list_sizep, int *errcodep)

Function Documentation

int LDAP_CALL ldap_create_virtuallist_control ( LDAP *  ld,
LDAPVirtualList ldvlistp,
LDAPControl **  ctrlp 
)

Definition at line 82 of file vlistctrl.c.

{
    BerElement *ber;
    int rc;
    
    if (!NSLDAPI_VALID_LDAP_POINTER( ld )) {
       return( LDAP_PARAM_ERROR );
    }


    if ( NULL == ctrlp || NULL == ldvlistp ) {
        LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
        return ( LDAP_PARAM_ERROR );
    }

    /* create a ber package to hold the controlValue */
    if ( LDAP_SUCCESS != nsldapi_alloc_ber_with_options( ld, &ber )  ) 
    {
        LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
        return( LDAP_NO_MEMORY );
    }

    if ( LBER_ERROR == ber_printf( ber, 
                                   "{ii", 
                                   (int)ldvlistp->ldvlist_before_count,
                                   (int)ldvlistp->ldvlist_after_count )) 
                                /* XXX lossy casts */
    {
        LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
        ber_free( ber, 1 );
        return( LDAP_ENCODING_ERROR );
    }

    if (NULL == ldvlistp->ldvlist_attrvalue)
    {
        if ( LBER_ERROR == ber_printf( ber, 
                                       "t{ii}}", 
                                   LDAP_TAG_VLV_BY_INDEX,
                                       (int)ldvlistp->ldvlist_index, 
                                       (int)ldvlistp->ldvlist_size ) ) 
                                   /* XXX lossy casts */
        {
            LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
            ber_free( ber, 1 );
            return( LDAP_ENCODING_ERROR );
        }
    } 
    else 
    {
        if ( LBER_ERROR == ber_printf( ber, 
                                      "to}", 
                                   LDAP_TAG_VLV_BY_VALUE,
                                      ldvlistp->ldvlist_attrvalue,
                                   (int)strlen( ldvlistp->ldvlist_attrvalue )) ) {
            LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
            ber_free( ber, 1 );
            return( LDAP_ENCODING_ERROR );
        }
    }


    rc = nsldapi_build_control( LDAP_CONTROL_VLVREQUEST , 
                                ber, 
                                1,
                                1, 
                                ctrlp );

    LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
    return( rc );

}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_parse_virtuallist_control ( LDAP *  ld,
LDAPControl **  ctrls,
unsigned long target_posp,
unsigned long list_sizep,
int errcodep 
)

Definition at line 187 of file vlistctrl.c.

{
    BerElement              *ber;
    int                     i, foundListControl, errcode;
    LDAPControl             *listCtrlp;
    unsigned long    target_pos, list_size;

    if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
        return( LDAP_PARAM_ERROR );
    }

    /* only ldapv3 or higher can do virtual lists. */
    if ( NSLDAPI_LDAP_VERSION( ld ) < LDAP_VERSION3 ) {
        LDAP_SET_LDERRNO( ld, LDAP_NOT_SUPPORTED, NULL, NULL );
        return( LDAP_NOT_SUPPORTED );
    }

    /* find the listControl in the list of controls if it exists */
    if ( ctrls == NULL ) {
        LDAP_SET_LDERRNO( ld, LDAP_CONTROL_NOT_FOUND, NULL, NULL );
        return ( LDAP_CONTROL_NOT_FOUND );
    } 
    
    foundListControl = 0;
    for ( i = 0; (( ctrls[i] != NULL ) && ( !foundListControl )); i++ ) {
        foundListControl = !strcmp( ctrls[i]->ldctl_oid, 
                                    LDAP_CONTROL_VLVRESPONSE );
    }
    if ( !foundListControl ) {
        LDAP_SET_LDERRNO( ld, LDAP_CONTROL_NOT_FOUND, NULL, NULL );
        return ( LDAP_CONTROL_NOT_FOUND );
    } else {
        /* let local var point to the listControl */
        listCtrlp = ctrls[i-1];                 
    }

    /*  allocate a Ber element with the contents of the list_control's struct berval */
    if ( ( ber = ber_init( &listCtrlp->ldctl_value ) ) == NULL ) {
        LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
        return( LDAP_NO_MEMORY );
    }           

    /* decode the result from the Berelement */
    if (  LBER_ERROR == ber_scanf( ber, "{iie}", &target_pos, &list_size,
           &errcode ) ) {
        LDAP_SET_LDERRNO( ld, LDAP_DECODING_ERROR, NULL, NULL );
        ber_free( ber, 1 );
        return( LDAP_DECODING_ERROR );
    }

    if ( target_posp != NULL ) {
       *target_posp = target_pos;
    }
    if ( list_sizep != NULL ) {
       *list_sizep = list_size;
    }
    if ( errcodep != NULL ) {
       *errcodep = errcode;
    }

    /* the ber encoding is no longer needed */
    ber_free(ber,1);

    return(LDAP_SUCCESS);

}

Here is the call graph for this function:

Here is the caller graph for this function: