]> git.sur5r.net Git - openldap/commitdiff
Updated new entry parsing routines from HEAD
authorHoward Chu <hyc@openldap.org>
Fri, 6 Sep 2002 05:16:37 +0000 (05:16 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 6 Sep 2002 05:16:37 +0000 (05:16 +0000)
clients/tools/ldapsearch.c
include/ldap.h
libraries/libldap/getattr.c
libraries/libldap/getvalues.c

index 5c17c8e0a592c1e65bd32d8dfa6afce760b53c66..639d8c818da47f53743835d45230af063b7c981e 100644 (file)
@@ -1326,24 +1326,26 @@ print_entry(
                ber_free( ber, 0 );
        }
 }
-#else /* This is the proposed new way of doing things. */
+#else
+/* This is the proposed new way of doing things.
+ * It is more * efficient, but the API is non-standard.
+ */
 static void
 print_entry(
        LDAP    *ld,
        LDAPMessage     *entry,
        int             attrsonly)
 {
-       char            *ufn;
+       char            *ufn = NULL;
        char    tmpfname[ 256 ];
        char    url[ 256 ];
        int                     i, rc;
        BerElement              *ber = NULL;
-       struct berval   *bvals, bv;
+       struct berval           bv, *bvals, **bvp = &bvals;
        LDAPControl **ctrls = NULL;
        FILE            *tmpfp;
 
        rc = ldap_get_dn_ber( ld, entry, &ber, &bv );
-       ufn = NULL;
 
        if ( ldif < 2 ) {
                ufn = ldap_dn2ufn( bv.bv_val );
@@ -1373,17 +1375,17 @@ print_entry(
 
        if( ufn != NULL ) ldap_memfree( ufn );
 
-       for ( rc = ldap_get_attribute_ber( ld, entry, ber, &bv ); rc == LDAP_SUCCESS;
-               rc = ldap_get_attribute_ber( ld, entry, ber, &bv ) )
+       if ( attrsonly ) bvp = NULL;
+
+       for ( rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp ); rc == LDAP_SUCCESS;
+               rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp ) )
        {
                if (bv.bv_val == NULL) break;
 
                if ( attrsonly ) {
                        write_ldif( LDIF_PUT_NOVALUE, bv.bv_val, NULL, 0 );
-                       /* skip values */
-                       ber_scanf( ber, "x}" );
 
-               } else if (( rc = ldap_get_values_ber( ld, entry, ber, &bvals )) == LDAP_SUCCESS ) {
+               } else {
                        for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
                                if ( vals2tmp > 1 || ( vals2tmp
                                        && ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len ) ))
index 710f17e49eb4d3afb15edad518c9cdae61acc23d..c1b76ef42c2c0aa53b6327a851abdb8d3ef6d169 100644 (file)
@@ -1254,11 +1254,8 @@ ldap_get_dn_ber LDAP_P((
 
 LDAP_F( int )
 ldap_get_attribute_ber LDAP_P((
-       LDAP *ld, LDAPMessage *e, BerElement *ber, struct berval *attr ));
-
-LDAP_F( int )
-ldap_get_values_ber LDAP_P((
-       LDAP *ld, LDAPMessage *e, BerElement *ber, struct berval **bv ));
+       LDAP *ld, LDAPMessage *e, BerElement *ber, struct berval *attr,
+       struct berval **vals ));
 
 /*
  * in getattr.c
index db690d13b1c7facc64539cbbecc188a04c3951a9..34ee28da563a40a9706cf1aca713aaea49f2dd3d 100644 (file)
  *  Copyright (c) 1990 Regents of the University of Michigan.
  *  All rights reserved.
  *
- *  getattr.c
+ *  getvalues.c
  */
 
 #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"
 
-char *
-ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout )
+char **
+ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 {
-       int rc;
-       ber_tag_t tag;
-       ber_len_t len = 0;
-       char *attr;
-       BerElement *ber;
-
-#ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, ENTRY, "ldap_first_attribute\n", 0, 0, 0 );
-#else
-       Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
-#endif
+       BerElement      ber;
+       char            *attr;
+       int             found = 0;
+       char            **vals;
 
        assert( ld != NULL );
        assert( LDAP_VALID( ld ) );
        assert( entry != NULL );
-       assert( berout != NULL );
+       assert( target != NULL );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values\n", 0, 0, 0 );
+#else
+       Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
+#endif
 
-       *berout = NULL;
+       ber = *entry->lm_ber;
 
-       ber = ldap_alloc_ber_with_options( ld );
-       if( ber == NULL ) {
-               return NULL;
+       /* 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 );
        }
 
-       *ber = *entry->lm_ber;
+       if ( strcasecmp( target, attr ) == 0 )
+               found = 1;
 
-       /* 
-        * Skip past the sequence, dn, sequence of sequence leaving
-        * us at the first attribute.
-        */
+       /* break out on success, return out on error */
+       while ( ! found ) {
+               LDAP_FREE(attr);
+               attr = NULL;
 
-       tag = ber_scanf( ber, "{xl{" /*}}*/, &len );
-       if( tag == LBER_ERROR ) {
-               ld->ld_errno = LDAP_DECODING_ERROR;
-               ber_free( ber, 0 );
-               return NULL;
-       }
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
+                       ld->ld_errno = LDAP_DECODING_ERROR;
+                       return( NULL );
+               }
 
-       /* set the length to avoid overrun */
-       rc = ber_set_option( ber, LBER_OPT_REMAINING_BYTES, &len );
-       if( rc != LBER_OPT_SUCCESS ) {
-               ld->ld_errno = LDAP_LOCAL_ERROR;
-               ber_free( ber, 0 );
-               return NULL;
-       }
+               if ( strcasecmp( target, attr ) == 0 )
+                       break;
 
-       if ( ber_pvt_ber_remaining( ber ) == 0 ) {
-               assert( len == 0 );
-               ber_free( ber, 0 );
-               return NULL;
        }
-       assert( len != 0 );
 
-       /* snatch the first attribute */
-       tag = ber_scanf( ber, "{ax}", &attr );
-       if( tag == LBER_ERROR ) {
+       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;
-               ber_free( ber, 0 );
-               return NULL;
+               return( NULL );
        }
 
-       *berout = ber;
-       return attr;
+       return( vals );
 }
 
-/* ARGSUSED */
-char *
-ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
+struct berval **
+ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 {
-       ber_tag_t tag;
-       char *attr;
+       BerElement      ber;
+       char            *attr;
+       int             found = 0;
+       struct berval   **vals;
+
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, ENTRY, "ldap_next_attribute\n", 0, 0, 0 );
+       LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values_len\n", 0, 0, 0 );
 #else
-       Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
 #endif
 
-       assert( ld != NULL );
-       assert( LDAP_VALID( ld ) );
-       assert( entry != NULL );
-       assert( ber != NULL );
+       ber = *entry->lm_ber;
 
-       if ( ber_pvt_ber_remaining( ber ) == 0 ) {
-               return NULL;
+       /* 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;
        }
 
-       /* skip sequence, snarf attribute type, skip values */
-       tag = ber_scanf( ber, "{ax}", &attr ); 
-       if( tag == LBER_ERROR ) {
+       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( NULL );
        }
 
-       return attr;
+       return( vals );
 }
 
-/* ARGSUSED */
 int
-ldap_get_attribute_ber( LDAP *ld, LDAPMessage *entry, BerElement *ber,
-       BerValue *attr )
+ldap_count_values( char **vals )
 {
-       ber_tag_t tag;
-       int rc = LDAP_SUCCESS;
+       int     i;
 
-#ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, ENTRY, "ldap_get_attribute_ber\n", 0, 0, 0 );
-#else
-       Debug( LDAP_DEBUG_TRACE, "ldap_get_attribute_ber\n", 0, 0, 0 );
-#endif
+       if ( vals == NULL )
+               return( 0 );
 
-       assert( ld != NULL );
-       assert( LDAP_VALID( ld ) );
-       assert( entry != NULL );
-       assert( ber != NULL );
-       assert( attr != NULL );
+       for ( i = 0; vals[i] != NULL; i++ )
+               ;       /* NULL */
 
-       attr->bv_val = NULL;
-       attr->bv_len = 0;
+       return( i );
+}
 
-       if ( ber_pvt_ber_remaining( ber ) ) {
-               /* skip sequence, snarf attribute type */
-               tag = ber_scanf( ber, "{m", attr ); 
-               if( tag == LBER_ERROR ) {
-                       rc = ld->ld_errno = LDAP_DECODING_ERROR;
-               }
-       }
+int
+ldap_count_values_len( struct berval **vals )
+{
+       return( ldap_count_values( (char **) vals ) );
+}
+
+void
+ldap_value_free( char **vals )
+{
+       LDAP_VFREE( vals );
+}
 
-       return rc;
+void
+ldap_value_free_len( struct berval **vals )
+{
+       ber_bvecfree( vals );
 }
index ee2962b7c34f725797605e021ea1e11e1d5b4304..34ee28da563a40a9706cf1aca713aaea49f2dd3d 100644 (file)
@@ -144,30 +144,6 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
        return( vals );
 }
 
-int
-ldap_get_values_ber( LDAP *ld, LDAPMessage *entry, BerElement *ber, BerVarray *bv )
-{
-       int             rc = LDAP_SUCCESS;
-
-       assert( ld != NULL );
-       assert( LDAP_VALID( ld ) );
-       assert( entry != NULL );
-       assert( ber != NULL );
-       assert( bv != NULL );
-
-#ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values_ber\n", 0, 0, 0 );
-#else
-       Debug( LDAP_DEBUG_TRACE, "ldap_get_values_ber\n", 0, 0, 0 );
-#endif
-
-       /* get the array of vals */
-       if ( ber_scanf( ber, "W}" /* }}} */, bv ) == LBER_ERROR ) {
-               rc = ld->ld_errno = LDAP_DECODING_ERROR;
-       }
-
-       return( rc );
-}
 int
 ldap_count_values( char **vals )
 {