]> granicus.if.org Git - php/commitdiff
- Add support for LDAP_X_OPT_CONNECT_TIMEOUT (Netscape LDAP SDK equivalent for LDAP_O...
authorJani Taskinen <jani@php.net>
Sat, 6 Oct 2007 02:13:31 +0000 (02:13 +0000)
committerJani Taskinen <jani@php.net>
Sat, 6 Oct 2007 02:13:31 +0000 (02:13 +0000)
ext/ldap/ldap.c

index 8440000be6549901e0a6a57d9adc81c6de1602cd..420ddcfc2118c14029d00255ab741d16e6185141 100644 (file)
@@ -260,6 +260,8 @@ PHP_MINIT_FUNCTION(ldap)
        REGISTER_LONG_CONSTANT("LDAP_OPT_TIMELIMIT", LDAP_OPT_TIMELIMIT, CONST_PERSISTENT | CONST_CS);
 #ifdef LDAP_OPT_NETWORK_TIMEOUT
        REGISTER_LONG_CONSTANT("LDAP_OPT_NETWORK_TIMEOUT", LDAP_OPT_NETWORK_TIMEOUT, CONST_PERSISTENT | CONST_CS);
+#elif defined (LDAP_X_OPT_CONNECT_TIMEOUT)
+       REGISTER_LONG_CONSTANT("LDAP_OPT_NETWORK_TIMEOUT", LDAP_X_OPT_CONNECT_TIMEOUT, CONST_PERSISTENT | CONST_CS);
 #endif
        REGISTER_LONG_CONSTANT("LDAP_OPT_PROTOCOL_VERSION", LDAP_OPT_PROTOCOL_VERSION, CONST_PERSISTENT | CONST_CS);
        REGISTER_LONG_CONSTANT("LDAP_OPT_ERROR_NUMBER", LDAP_OPT_ERROR_NUMBER, CONST_PERSISTENT | CONST_CS);
@@ -1724,20 +1726,30 @@ PHP_FUNCTION(ldap_get_option)
                        zval_dtor(*retval);
                        ZVAL_LONG(*retval, val);
                } break;
-#ifdef LDAP_OPT_NETWORK_TIMEOUT
+#if defined(LDAP_OPT_NETWORK_TIMEOUT) || defined(LDAP_X_OPT_CONNECT_TIMEOUT)
        case LDAP_OPT_NETWORK_TIMEOUT:
                {
+# ifdef LDAP_OPT_NETWORK_TIMEOUT
                        struct timeval *timeout;
-                       
-                       if (ldap_get_option(ld->link, opt, (void *) &timeout)) {
+
+                       if (ldap_get_option(ld->link, LDAP_OPT_NETWORK_TIMEOUT, (void *) &timeout)) {
                                if (timeout) {
                                        ldap_memfree(timeout);
                                }
                                RETURN_FALSE;
-                       }                       
+                       }                      
                        zval_dtor(*retval);
                        ZVAL_LONG(*retval, timeout->tv_sec);
                        ldap_memfree(timeout);
+# elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
+                       int timeout;
+
+                       if (ldap_get_option(ld->link, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) {
+                               RETURN_FALSE;
+                       }                       
+                       zval_dtor(*retval);
+                       ZVAL_LONG(*retval, (timeout / 1000));
+# endif
                } break;
 #endif
        /* options with string value */
@@ -1822,17 +1834,27 @@ PHP_FUNCTION(ldap_set_option)
                                RETURN_FALSE;
                        }
                } break;
-#ifdef LDAP_OPT_NETWORK_TIMEOUT
+#if defined(LDAP_OPT_NETWORK_TIMEOUT) || defined(LDAP_X_OPT_CONNECT_TIMEOUT)
        case LDAP_OPT_NETWORK_TIMEOUT:
                {
+# ifdef LDAP_OPT_NETWORK_TIMEOUT
                        struct timeval timeout;
-                       
+
                        convert_to_long_ex(newval);
                        timeout.tv_sec = Z_LVAL_PP(newval);
                        timeout.tv_usec = 0;
-                       if (ldap_set_option(ldap, opt, (void *) &timeout)) {
+                       if (ldap_set_option(ldap, LDAP_OPT_NETWORK_TIMEOUT, (void *) &timeout)) {
                                RETURN_FALSE;
                        }                       
+# elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
+                       int timeout;
+
+                       convert_to_long_ex(newval);
+                       timeou = 1000 * Z_LVAL_PP(newval); /* Convert to milliseconds */
+                       if (ldap_set_option(ldap, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) {
+                               RETURN_FALSE;
+                       }                       
+# endif
                } break;
 #endif
                /* options with string value */