]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/init.c
rename ldap_pvt_init_utils() to ldap_int_utils_init() and provide
[openldap] / libraries / libldap / init.c
index 056b5920eefc20d24e5fda542bd7dbd591b9d8e7..8c22855fd85f97472ec2463001687bb3ad8f8dbc 100644 (file)
@@ -15,7 +15,7 @@
 #include "ldap-int.h"
 #include "ldapconfig.h"
 
-struct ldapoptions openldap_ldap_global_options; 
+struct ldapoptions openldap_ldap_global_options = { LDAP_DEBUG_NONE };  
 
 #undef gopts
 #define gopts openldap_ldap_global_options
@@ -29,11 +29,11 @@ int openldap_ldap_initialized = 0;
 #define ATTR_STRING    4
 
 struct ol_keyvalue {
-       char*           key;
+       const char *            key;
        int                     value;
 };
 
-static struct ol_keyvalue deref_kv[] = {
+static const struct ol_keyvalue deref_kv[] = {
        {"never", LDAP_DEREF_NEVER},
        {"searching", LDAP_DEREF_SEARCHING},
        {"finding", LDAP_DEREF_FINDING},
@@ -41,10 +41,10 @@ static struct ol_keyvalue deref_kv[] = {
        {NULL, 0}
 };
 
-static struct ol_attribute {
+static const struct ol_attribute {
        int                     type;
-       char*           name;
-       void*           data;
+       const char *    name;
+       const void *    data;
        size_t          offset;
 } attrs[] = {
        {ATTR_KV,               "DEREF",        deref_kv, /* or &deref_kv[0] */
@@ -59,9 +59,9 @@ static struct ol_attribute {
                offsetof(struct ldapoptions, ldo_defhost)},
        {ATTR_INT,              "PORT",                 NULL,
                offsetof(struct ldapoptions, ldo_defport)},
-       {ATTR_BOOL,             "REFERRALS",    (void *) LDAP_BOOL_REFERRALS, 0},
-       {ATTR_BOOL,             "RESTART",              (void *) LDAP_BOOL_RESTART, 0},
-       {ATTR_BOOL,             "DNS",                  (void *) LDAP_BOOL_DNS, 0},
+       {ATTR_BOOL,             "REFERRALS",    NULL,   LDAP_BOOL_REFERRALS},
+       {ATTR_BOOL,             "RESTART",      NULL,   LDAP_BOOL_RESTART},
+       {ATTR_BOOL,             "DNS",          NULL,   LDAP_BOOL_DNS},
        {ATTR_NONE,             NULL,           NULL,   0}
 };
 
@@ -92,14 +92,15 @@ static void openldap_ldap_init_w_conf(const char *file)
                if(*start == '#') continue;
 
                /* trim leading white space */
-               while((*start != '\0') && isspace(*start)) start++;
+               while((*start != '\0') && isspace((unsigned char) *start))
+                       start++;
 
                /* anything left? */
                if(*start == '\0') continue;
 
                /* trim trailing white space */
                end = &start[strlen(start)-1];
-               while(isspace(*end)) end--;
+               while(isspace((unsigned char)*end)) end--;
                end[1] = '\0';
 
                /* anything left? */
@@ -108,7 +109,7 @@ static void openldap_ldap_init_w_conf(const char *file)
 
                /* parse the command */
                cmd=start;
-               while((*start != '\0') && !isspace(*start)) {
+               while((*start != '\0') && !isspace((unsigned char)*start)) {
                        start++;
                }
                if(*start == '\0') {
@@ -119,7 +120,7 @@ static void openldap_ldap_init_w_conf(const char *file)
                *start++ = '\0';
 
                /* we must have some non-whitespace to skip */
-               while(isspace(*start)) start++;
+               while(isspace((unsigned char)*start)) start++;
                opt = start;
 
                for(i=0; attrs[i].type != ATTR_NONE; i++) {
@@ -129,34 +130,34 @@ static void openldap_ldap_init_w_conf(const char *file)
                                continue;
                        }
 
-                       p = &((char *) &gopts)[attrs[i].offset];
-
                        switch(attrs[i].type) {
                        case ATTR_BOOL:
                                if((strcasecmp(opt, "on") == 0) 
                                        || (strcasecmp(opt, "yes") == 0)
                                        || (strcasecmp(opt, "true") == 0))
                                {
-                                       LDAP_BOOL_SET(&gopts, (int) attrs[i].data);
+                                       LDAP_BOOL_SET(&gopts, attrs[i].offset);
 
                                } else {
-                                       LDAP_BOOL_CLR(&gopts, (int) attrs[i].data);
+                                       LDAP_BOOL_CLR(&gopts, attrs[i].offset);
                                }
 
                                break;
 
                        case ATTR_INT:
+                               p = &((char *) &gopts)[attrs[i].offset];
                                * (int*) p = atoi(opt);
                                break;
 
                        case ATTR_KV: {
-                                       struct ol_keyvalue *kv;
+                                       const struct ol_keyvalue *kv;
 
-                                       for(kv = (struct ol_keyvalue *) attrs[i].data;
+                                       for(kv = attrs[i].data;
                                                kv->key != NULL;
                                                kv++) {
 
                                                if(strcasecmp(opt, kv->key) == 0) {
+                                                       p = &((char *) &gopts)[attrs[i].offset];
                                                        * (int*) p = kv->value;
                                                        break;
                                                }
@@ -164,12 +165,15 @@ static void openldap_ldap_init_w_conf(const char *file)
                                } break;
 
                        case ATTR_STRING:
+                               p = &((char *) &gopts)[attrs[i].offset];
                                if (* (char**) p != NULL) free(* (char**) p);
                                * (char**) p = strdup(opt);
                                break;
                        }
                }
        }
+
+       fclose(fp);
 }
 
 static void openldap_ldap_init_w_userconf(const char *file)
@@ -234,33 +238,33 @@ static void openldap_ldap_init_w_env(const char *prefix)
                        continue;
                }
 
-               p = &((char *) &gopts)[attrs[i].offset];
-
                switch(attrs[i].type) {
                case ATTR_BOOL:
                        if((strcasecmp(value, "on") == 0) 
                                || (strcasecmp(value, "yes") == 0)
                                || (strcasecmp(value, "true") == 0))
                        {
-                               LDAP_BOOL_SET(&gopts, (int) attrs[i].data);
+                               LDAP_BOOL_SET(&gopts, attrs[i].offset);
 
                        } else {
-                               LDAP_BOOL_CLR(&gopts, (int) attrs[i].data);
+                               LDAP_BOOL_CLR(&gopts, attrs[i].offset);
                        }
                        break;
 
                case ATTR_INT:
+                       p = &((char *) &gopts)[attrs[i].offset];
                        * (int*) p = atoi(value);
                        break;
 
                case ATTR_KV: {
-                               struct ol_keyvalue *kv;
+                               const struct ol_keyvalue *kv;
 
-                               for(kv = (struct ol_keyvalue *) attrs[i].data;
+                               for(kv = attrs[i].data;
                                        kv->key != NULL;
                                        kv++) {
 
                                        if(strcasecmp(value, kv->key) == 0) {
+                                               p = &((char *) &gopts)[attrs[i].offset];
                                                * (int*) p = kv->value;
                                                break;
                                        }
@@ -268,6 +272,7 @@ static void openldap_ldap_init_w_env(const char *prefix)
                        } break;
 
                case ATTR_STRING:
+                       p = &((char *) &gopts)[attrs[i].offset];
                        if (* (char**) p != NULL) free(* (char**) p);
                        if (*value == '\0') {
                                * (char**) p = NULL;
@@ -284,9 +289,9 @@ void openldap_ldap_initialize( void )
        if ( openldap_ldap_initialized ) {
                return;
        }
-       
-       ldap_pvt_init_utils();
-       
+
+       ldap_int_utils_init();
+
        gopts.ldo_version =     LDAP_VERSION2;
        gopts.ldo_deref =       LDAP_DEREF_NEVER;
        gopts.ldo_timelimit = LDAP_NO_LIMIT;
@@ -301,10 +306,7 @@ void openldap_ldap_initialize( void )
 
        LDAP_BOOL_ZERO(&gopts);
 
-#if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || \
-       LDAP_VERSION_MAX > LDAP_VERSION2
        LDAP_BOOL_SET(&gopts, LDAP_BOOL_REFERRALS);
-#endif
 
        openldap_ldap_initialized = 1;