]> granicus.if.org Git - php/commitdiff
@- Added new function: ldap_compare(). (Jani)
authorfoobar <sniper@php.net>
Wed, 26 Jul 2000 11:01:44 +0000 (11:01 +0000)
committerfoobar <sniper@php.net>
Wed, 26 Jul 2000 11:01:44 +0000 (11:01 +0000)
# Documentation is coming right after this.

ext/ldap/ldap.c
ext/ldap/php_ldap.h

index 4946b6f6cd7d5c86749a96a1fb6b7340ac020cf0..78c4f12d1d5ca9386ed33a3f4f7b9da30d6467b3 100644 (file)
@@ -90,6 +90,7 @@ function_entry ldap_functions[] = {
        PHP_FE(ldap_errno,                                                              NULL)
        PHP_FE(ldap_err2str,                                                    NULL)
        PHP_FE(ldap_error,                                                              NULL)
+       PHP_FE(ldap_compare,                                                    NULL)
        {NULL, NULL, NULL}
 };
 
@@ -1367,3 +1368,47 @@ PHP_FUNCTION(ldap_error) {
        RETURN_STRING(ldap_err2string(ld_errno), 1);
 }
 /* }}} */
+
+
+/* {{{ proto int ldap_compare(int link, string dn, string attr, string value)
+       Determine if an entry has a specific value for one of its attributes. */
+PHP_FUNCTION(ldap_compare) {
+       pval **link, **dn, **attr, **value;
+       char *ldap_dn, *ldap_attr, *ldap_value;
+       LDAP *ldap;
+       int errno;
+
+       if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &link, &dn, &attr, &value) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       convert_to_string_ex(link);
+       ldap = _get_ldap_link(link);
+       if (ldap == NULL) RETURN_LONG(-1);
+
+       convert_to_string_ex(dn);
+       convert_to_string_ex(attr);
+       convert_to_string_ex(value);
+
+       ldap_dn = (*dn)->value.str.val;
+       ldap_attr = (*attr)->value.str.val;
+       ldap_value = (*value)->value.str.val;
+
+       errno = ldap_compare_s(ldap, ldap_dn, ldap_attr, ldap_value);
+
+       switch(errno) {
+               case LDAP_COMPARE_TRUE :
+                       RETURN_TRUE;
+               break;
+
+               case LDAP_COMPARE_FALSE :
+                       RETURN_FALSE;
+               break;
+       }
+       
+       php_error(E_WARNING, "LDAP: Compare operation could not be completed: %s", ldap_err2string(errno));
+       RETURN_LONG(-1);
+
+}
+/* }}} */
+  
index a2f941838c9e9eb4aac0a61b8310d8d093b31011..8ede7263ebe7110427119272f9235b5bb587591b 100644 (file)
@@ -14,6 +14,7 @@
    +----------------------------------------------------------------------+
    | Authors: Amitay Isaacs <amitay@w-o-i.com>                            |
    |          Eric Warnke   <ericw@albany.edu>                            |
+   |          Jani Taskinen <sniper@iki.fi>                               |
    +----------------------------------------------------------------------+
 */
 
@@ -76,6 +77,8 @@ PHP_FUNCTION(ldap_errno);
 PHP_FUNCTION(ldap_err2str);
 PHP_FUNCTION(ldap_error);
 
+PHP_FUNCTION(ldap_compare);
+
 ZEND_BEGIN_MODULE_GLOBALS(ldap)
        long default_link;
        long num_links, max_links;