]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/options.c
Improved ldap_int_strtok. If strtok_r does not exists, it will be worked
[openldap] / libraries / libldap / options.c
index b1c2fb66b67a01c13233cfbbd681379e89144608..1d056e5d394ed2abdd61cc294f2c35177ed4e44f 100644 (file)
@@ -1,3 +1,8 @@
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
 #include "portable.h"
 
 #include <stdio.h>
@@ -142,15 +147,22 @@ ldap_get_option(
                return 0;
 
        case LDAP_OPT_SERVER_CONTROLS:
+               * (LDAPControl ***) outvalue =
+                       ldap_controls_dup( lo->ldo_server_controls );
+
+               return 0;
+
        case LDAP_OPT_CLIENT_CONTROLS:
-               /* not yet supported */
-               break;
+               * (LDAPControl ***) outvalue =
+                       ldap_controls_dup( lo->ldo_client_controls );
+
+               return 0;
 
        case LDAP_OPT_HOST_NAME:
                /*
                 * draft-ietf-ldapext-ldap-c-api-01 doesn't state
-                * whether client to have to free host names or no,
-                * we do
+                * whether caller has to free host names or not,
+                * we do.
                 */
 
                * (char **) outvalue = ldap_strdup(lo->ldo_defhost);
@@ -165,7 +177,6 @@ ldap_get_option(
                return 0;
 
        case LDAP_OPT_ERROR_STRING:
-               /* not yet supported */
                if(ld == NULL) {
                        /* bad param */
                        break;
@@ -181,7 +192,8 @@ ldap_get_option(
                } else {
                        * (char **) outvalue = ldap_strdup(ld->ld_error);
                }
-               break;
+
+               return 0;
 
        case LDAP_OPT_API_FEATURE_INFO: {
                        LDAPAPIFeatureInfo *info = (LDAPAPIFeatureInfo *) outvalue;
@@ -202,7 +214,7 @@ ldap_get_option(
 
        case LDAP_OPT_DEBUG_LEVEL:
                * (int *) outvalue = lo->ldo_debug;
-               break;
+               return 0;
 
        default:
                /* bad param */
@@ -278,13 +290,46 @@ ldap_set_option(
                        ld->ld_version = vers;
                } return 0;
 
-       case LDAP_OPT_SERVER_CONTROLS:
-       case LDAP_OPT_CLIENT_CONTROLS:
-               /* not yet supported */
-               break;
+       case LDAP_OPT_SERVER_CONTROLS: {
+                       LDAPControl **controls = (LDAPControl **) invalue;
+
+                       ldap_controls_free( lo->ldo_server_controls );
+
+                       if( controls == NULL || *controls == NULL ) {
+                               lo->ldo_server_controls = NULL;
+                               return 0;
+                       }
+                               
+                       lo->ldo_server_controls =
+                               ldap_controls_dup( (LDAPControl **) invalue );
+
+                       if(lo->ldo_server_controls == NULL) {
+                               /* memory allocation error ? */
+                               break;
+                       }
+               } return 0;
+
+       case LDAP_OPT_CLIENT_CONTROLS: {
+                       LDAPControl **controls = (LDAPControl **) invalue;
+
+                       ldap_controls_free( lo->ldo_client_controls );
+
+                       if( controls == NULL || *controls == NULL ) {
+                               lo->ldo_client_controls = NULL;
+                               return 0;
+                       }
+                               
+                       lo->ldo_client_controls =
+                               ldap_controls_dup( (LDAPControl **) invalue );
+
+                       if(lo->ldo_client_controls == NULL) {
+                               /* memory allocation error ? */
+                               break;
+                       }
+               } return 0;
 
        case LDAP_OPT_HOST_NAME: {
-                       char* host = * (char **) invalue;
+                       char* host = (char *) invalue;
 
                        if(lo->ldo_defhost != NULL) {
                                free(lo->ldo_defhost);
@@ -325,7 +370,7 @@ ldap_set_option(
                } return 0;
 
        case LDAP_OPT_ERROR_STRING: {
-                       char* err = * (char **) invalue;
+                       char* err = (char *) invalue;
 
                        if(ld == NULL) {
                                /* need a struct ldap */
@@ -336,7 +381,7 @@ ldap_set_option(
                                free(ld->ld_error);
                        }
 
-                       ld->ld_error = strdup(err);
+                       ld->ld_error = ldap_strdup(err);
                } return 0;
 
        case LDAP_OPT_API_FEATURE_INFO: