]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/options.c
Allow ctrls argument to be NULL.
[openldap] / libraries / libldap / options.c
index 92ebced8415964e7655ae8449c6cc2aaff6d24c3..ef19dfda61f273e2ea341c128f99b7863324a252 100644 (file)
@@ -6,7 +6,8 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/socket.h>
 #include <ac/string.h>
@@ -77,21 +78,16 @@ static const LDAPAPIFeatureInfo features[] = {
 
 int
 ldap_get_option(
-       LDAP    *ld,
+       LDAP_CONST LDAP *ld,
        int             option,
        void    *outvalue)
 {
-       struct ldapoptions *lo;
+       LDAP_CONST struct ldapoptions *lo;
 
        if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
                ldap_int_initialize();
        }
 
-       if(outvalue == NULL) {
-               /* no place to get to */
-               return LDAP_OPT_ERROR;
-       }
-
        if(ld == NULL) {
                lo = &ldap_int_global_options;
 
@@ -105,6 +101,11 @@ ldap_get_option(
                lo = &ld->ld_options;
        }
 
+       if(outvalue == NULL) {
+               /* no place to get to */
+               return LDAP_OPT_ERROR;
+       }
+
        switch(option) {
        case LDAP_OPT_API_INFO: {
                        struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
@@ -128,18 +129,18 @@ ldap_get_option(
                                info->ldapai_extensions = NULL;
                        } else {
                                int i;
-                               info->ldapai_extensions = malloc(sizeof(char *) *
+                               info->ldapai_extensions = LDAP_MALLOC(sizeof(char *) *
                                        sizeof(features)/sizeof(LDAPAPIFeatureInfo));
 
                                for(i=0; features[i].ldapaif_name != NULL; i++) {
                                        info->ldapai_extensions[i] =
-                                               strdup(features[i].ldapaif_name);
+                                               LDAP_STRDUP(features[i].ldapaif_name);
                                }
 
                                info->ldapai_extensions[i] = NULL;
                        }
 
-                       info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
+                       info->ldapai_vendor_name = LDAP_STRDUP(LDAP_VENDOR_NAME);
                        info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
 
                        return LDAP_OPT_SUCCESS;
@@ -151,7 +152,7 @@ ldap_get_option(
                        break;
                } 
 
-               * (int *) outvalue = ber_pvt_sb_get_desc( &(ld->ld_sb) );
+               * (ber_socket_t *) outvalue = ber_pvt_sb_get_desc( &(ld->ld_sb) );
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_DEREF:
@@ -167,18 +168,15 @@ ldap_get_option(
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_REFERRALS:
-               * (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS) ==
-                                     LDAP_OPT_ON);
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
                return LDAP_OPT_SUCCESS;
                
        case LDAP_OPT_RESTART:
-               * (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART) ==
-                                     LDAP_OPT_ON);
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_DNS:      /* LDAPv2 */
-               * (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_DNS) ==
-                                     LDAP_OPT_ON);
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_PROTOCOL_VERSION:
@@ -202,13 +200,7 @@ ldap_get_option(
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_HOST_NAME:
-               /*
-                * draft-ietf-ldapext-ldap-c-api-01 doesn't state
-                * whether caller has to free host names or not,
-                * we do.
-                */
-
-               * (char **) outvalue = strdup(lo->ldo_defhost);
+               * (char **) outvalue = LDAP_STRDUP(lo->ldo_defhost);
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_ERROR_NUMBER:
@@ -225,37 +217,27 @@ ldap_get_option(
                        break;
                } 
 
-               /*
-                * draft-ietf-ldapext-ldap-c-api-01 doesn't require
-                *      the client to have to free error strings, we do
-                */
-
                if( ld->ld_error == NULL ) {
                        * (char **) outvalue = NULL;
                } else {
-                       * (char **) outvalue = strdup(ld->ld_error);
+                       * (char **) outvalue = LDAP_STRDUP(ld->ld_error);
                }
 
                return LDAP_OPT_SUCCESS;
 
-        case LDAP_OPT_MATCH_STRING:
+       case LDAP_OPT_MATCHED_DN:
                if(ld == NULL) {
                        /* bad param */
                        break;
                } 
 
-               /*
-                * draft-ietf-ldapext-ldap-c-api-01 doesn't require
-                *      the client to have to free error strings, we do
-                */
-
                if( ld->ld_matched == NULL ) {
                        * (char **) outvalue = NULL;
                } else {
-                       * (char **) outvalue = strdup(ld->ld_matched);
+                       * (char **) outvalue = LDAP_STRDUP(ld->ld_matched);
                }
 
-               return 0;
+               return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_API_FEATURE_INFO: {
                        LDAPAPIFeatureInfo *info = (LDAPAPIFeatureInfo *) outvalue;
@@ -320,18 +302,18 @@ ldap_set_option(
 
        switch(option) {
        case LDAP_OPT_REFERRALS:
-               if(invalue == LDAP_OPT_ON) {
-                       LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
-               } else {
+               if(invalue == LDAP_OPT_OFF) {
                        LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
+               } else {
+                       LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
                }
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_RESTART:
-               if(invalue == LDAP_OPT_ON) {
-                       LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
-               } else {
+               if(invalue == LDAP_OPT_OFF) {
                        LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
+               } else {
+                       LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
                }
                return LDAP_OPT_SUCCESS;
        }
@@ -410,12 +392,12 @@ ldap_set_option(
                        char* host = (char *) invalue;
 
                        if(lo->ldo_defhost != NULL) {
-                               free(lo->ldo_defhost);
+                               LDAP_FREE(lo->ldo_defhost);
                                lo->ldo_defhost = NULL;
                        }
 
                        if(host != NULL) {
-                               lo->ldo_defhost = strdup(host);
+                               lo->ldo_defhost = LDAP_STRDUP(host);
                                return LDAP_OPT_SUCCESS;
                        }
 
@@ -424,14 +406,14 @@ ldap_set_option(
                                 * must want global default returned
                                 * to initial condition.
                                 */
-                               lo->ldo_defhost = strdup("localhost");
+                               lo->ldo_defhost = LDAP_STRDUP("localhost");
 
                        } else {
                                /*
                                 * must want the session default
                                 *   updated to the current global default
                                 */
-                               lo->ldo_defhost = strdup(
+                               lo->ldo_defhost = LDAP_STRDUP(
                                        ldap_int_global_options.ldo_defhost);
                        }
                } return LDAP_OPT_SUCCESS;
@@ -456,10 +438,25 @@ ldap_set_option(
                        }
 
                        if( ld->ld_error ) {
-                               free(ld->ld_error);
+                               LDAP_FREE(ld->ld_error);
+                       }
+
+                       ld->ld_error = LDAP_STRDUP(err);
+               } return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_MATCHED_DN: {
+                       char* err = (char *) invalue;
+
+                       if(ld == NULL) {
+                               /* need a struct ldap */
+                               break;
+                       }
+
+                       if( ld->ld_matched ) {
+                               LDAP_FREE(ld->ld_matched);
                        }
 
-                       ld->ld_error = strdup(err);
+                       ld->ld_matched = LDAP_STRDUP(err);
                } return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_API_FEATURE_INFO: