Back to index

openldap  2.4.31
Functions
getvalues.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/ctype.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include "ldap-int.h"

Go to the source code of this file.

Functions

char ** ldap_get_values (LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target)
struct berval ** ldap_get_values_len (LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target)
int ldap_count_values (char **vals)
int ldap_count_values_len (struct berval **vals)
void ldap_value_free (char **vals)
void ldap_value_free_len (struct berval **vals)
char ** ldap_value_dup (char *const *vals)

Function Documentation

int ldap_count_values ( char **  vals)

Definition at line 146 of file getvalues.c.

{
       int    i;

       if ( vals == NULL )
              return( 0 );

       for ( i = 0; vals[i] != NULL; i++ )
              ;      /* NULL */

       return( i );
}

Here is the caller graph for this function:

int ldap_count_values_len ( struct berval **  vals)

Definition at line 160 of file getvalues.c.

{
       return( ldap_count_values( (char **) vals ) );
}

Here is the call graph for this function:

Here is the caller graph for this function:

char** ldap_get_values ( LDAP *  ld,
LDAPMessage *  entry,
LDAP_CONST char *  target 
)

Definition at line 33 of file getvalues.c.

{
       BerElement    ber;
       char          *attr;
       int           found = 0;
       char          **vals;

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

       Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );

       ber = *entry->lm_ber;

       /* skip sequence, dn, sequence of, and snag the first attr */
       if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
              ld->ld_errno = LDAP_DECODING_ERROR;
              return( NULL );
       }

       if ( strcasecmp( target, attr ) == 0 )
              found = 1;

       /* break out on success, return out on error */
       while ( ! found ) {
              LDAP_FREE(attr);
              attr = NULL;

              if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                     ld->ld_errno = LDAP_DECODING_ERROR;
                     return( NULL );
              }

              if ( strcasecmp( target, attr ) == 0 )
                     break;

       }

       LDAP_FREE(attr);
       attr = NULL;

       /* 
        * if we get this far, we've found the attribute and are sitting
        * just before the set of values.
        */

       if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) {
              ld->ld_errno = LDAP_DECODING_ERROR;
              return( NULL );
       }

       return( vals );
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct berval** ldap_get_values_len ( LDAP *  ld,
LDAPMessage *  entry,
LDAP_CONST char *  target 
) [read]

Definition at line 90 of file getvalues.c.

{
       BerElement    ber;
       char          *attr;
       int           found = 0;
       struct berval **vals;

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

       Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );

       ber = *entry->lm_ber;

       /* skip sequence, dn, sequence of, and snag the first attr */
       if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
              ld->ld_errno = LDAP_DECODING_ERROR;
              return( NULL );
       }

       if ( strcasecmp( target, attr ) == 0 )
              found = 1;

       /* break out on success, return out on error */
       while ( ! found ) {
              LDAP_FREE( attr );
              attr = NULL;

              if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                     ld->ld_errno = LDAP_DECODING_ERROR;
                     return( NULL );
              }

              if ( strcasecmp( target, attr ) == 0 )
                     break;
       }

       LDAP_FREE( attr );
       attr = NULL;

       /* 
        * if we get this far, we've found the attribute and are sitting
        * just before the set of values.
        */

       if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) {
              ld->ld_errno = LDAP_DECODING_ERROR;
              return( NULL );
       }

       return( vals );
}

Here is the call graph for this function:

Here is the caller graph for this function:

char** ldap_value_dup ( char *const vals)

Definition at line 178 of file getvalues.c.

{
       char **new;
       int i;

       if( vals == NULL ) {
              return NULL;
       }

       for( i=0; vals[i]; i++ ) {
              ;   /* Count the number of values */
       }

       if( i == 0 ) {
              return NULL;
       }

       new = LDAP_MALLOC( (i+1)*sizeof(char *) );  /* Alloc array of pointers */
       if( new == NULL ) {
              return NULL;
       }

       for( i=0; vals[i]; i++ ) {
              new[i] = LDAP_STRDUP( vals[i] );   /* Dup each value */
              if( new[i] == NULL ) {
                     LDAP_VFREE( new );
                     return NULL;
              }
       }
       new[i] = NULL;

       return new;
}

Here is the caller graph for this function:

void ldap_value_free ( char **  vals)

Definition at line 166 of file getvalues.c.

{
       LDAP_VFREE( vals );
}

Here is the caller graph for this function:

void ldap_value_free_len ( struct berval **  vals)

Definition at line 172 of file getvalues.c.

{
       ber_bvecfree( vals );
}

Here is the call graph for this function:

Here is the caller graph for this function: