]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/compare.c
Happy New Year
[openldap] / libraries / libldap / compare.c
index e7f7ee170e27bea7913f9df61251961cbf3f54e1..2ce7a787be0abc7c7176207119ebe45bb1b5cf1e 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2015 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  *     }
  */
 
+BerElement *
+ldap_build_compare_req(
+       LDAP *ld,
+       LDAP_CONST char *dn,
+       LDAP_CONST char *attr,
+       struct berval *bvalue,
+       LDAPControl **sctrls,
+       LDAPControl **cctrls,
+       int     *msgidp )
+{
+       BerElement      *ber;
+       int rc;
+
+       /* create a message to send */
+       if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
+               return( NULL );
+       }
+
+       LDAP_NEXT_MSGID(ld, *msgidp);
+       rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
+               *msgidp,
+               LDAP_REQ_COMPARE, dn, attr, bvalue );
+       if ( rc == -1 )
+       {
+               ld->ld_errno = LDAP_ENCODING_ERROR;
+               ber_free( ber, 1 );
+               return( NULL );
+       }
+
+       /* Put Server Controls */
+       if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
+               ber_free( ber, 1 );
+               return( NULL );
+       }
+
+       if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
+               ld->ld_errno = LDAP_ENCODING_ERROR;
+               ber_free( ber, 1 );
+               return( NULL );
+       }
+
+       return( ber );
+}
+
 /*
  * ldap_compare_ext - perform an ldap extended compare operation.  The dn
  * of the entry to compare to and the attribute and value to compare (in
@@ -74,34 +118,10 @@ ldap_compare_ext(
        rc = ldap_int_client_controls( ld, cctrls );
        if( rc != LDAP_SUCCESS ) return rc;
 
-       /* create a message to send */
-       if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
-               return( LDAP_NO_MEMORY );
-       }
-
-       LDAP_NEXT_MSGID(ld, id);
-       rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
-               id,
-               LDAP_REQ_COMPARE, dn, attr, bvalue );
-       if ( rc == -1 )
-       {
-               ld->ld_errno = LDAP_ENCODING_ERROR;
-               ber_free( ber, 1 );
-               return( ld->ld_errno );
-       }
-
-       /* Put Server Controls */
-       if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
-               ber_free( ber, 1 );
+       ber = ldap_build_compare_req(
+               ld, dn, attr, bvalue, sctrls, cctrls, &id );
+       if( !ber )
                return ld->ld_errno;
-       }
-
-       if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
-               ld->ld_errno = LDAP_ENCODING_ERROR;
-               ber_free( ber, 1 );
-               return( ld->ld_errno );
-       }
-
 
        /* send the message */
        *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber, id );