Index: res/res_config_ldap.c
===================================================================
--- res/res_config_ldap.c	(revision 379211)
+++ res/res_config_ldap.c	(working copy)
@@ -135,6 +135,7 @@
 /*! \brief Find a table_config
  *
  * Should be locked before using it 
+ *
  *  \note This function assumes ldap_lock to be locked.
  */
 static struct ldap_table_config *table_config_for_table_name(const char *table_name)
@@ -219,7 +220,8 @@
 	table_config->attributes = var;
 }
 
-/*! \brief Free table_config 
+/*! \brief Free table_config
+ *
  * \note assumes ldap_lock to be locked
  */
 static void table_configs_free(void)
@@ -245,7 +247,7 @@
 
 /*! \brief Convert variable name to ldap attribute name
  *
- * Should be locked before using it
+ * \note Should be locked before using it
  */
 static const char *convert_attribute_name_to_ldap(struct ldap_table_config *table_config,
 	const char *attribute_name)
@@ -272,6 +274,7 @@
 }
 
 /*! \brief Convert ldap attribute name to variable name 
+ *
  * \note Should be locked before using it
  */
 static const char *convert_attribute_name_from_ldap(struct ldap_table_config *table_config,
@@ -400,7 +403,8 @@
 	int delim_tot_count = 0;
 	int delim_count = 0;
 
-	/* First find the total count */
+	/* \breif First find the total count
+	 */
 	ldap_entry = ldap_first_entry(ldapConn, ldap_result_msg);
 
 	for (tot_count = 0; ldap_entry; tot_count++) { 
@@ -414,7 +418,7 @@
 		*entries_count_ptr = tot_count;
 	}
 
-	/* Now that we have the total count we allocate space and create the variables
+	/*! \note Now that we have the total count we allocate space and create the variables
 	 * Remember that each element in vars is a linked list that points to realtime variable.
 	 * If the we are dealing with a static realtime variable we create a new element in the \a vars array for each delimited
 	 * value in \a variable_value; otherwise, we keep \a vars static and increase the length of the linked list of variables in the array element.
@@ -426,7 +430,8 @@
 
 	i = 0;
 
-	/* For each static realtime variable we may create several entries in the \a vars array if it's delimited */
+	/* \brief For each static realtime variable we may create several entries in the \a vars array if it's delimited
+	 */
 	for (entry_index = 0; ldap_entry; ) {
 		int pos = 0;
 		delim_value = NULL;
@@ -959,7 +964,7 @@
 
 /*! \brief See Asterisk doc
  *
- * For Realtime Dynamic(i.e., switch, queues, and directory) -- I think
+ * For Realtime Dynamic(i.e., switch, queues, and directory)
  */
 static struct ast_variable *realtime_ldap(const char *basedn,
 					  const char *table_name, va_list ap)
@@ -1082,9 +1087,9 @@
 	return 0;
 }
 
-/*! \brief See Asterisk doc
+/*! \brief See Asterisk Realtime Documentation
  *
- * This is for Static Realtime (again: I think...)
+ * This is for Static Realtime
  *	
  * load the configuration stuff for the .conf files
  * called on a reload
@@ -1274,15 +1279,16 @@
 	}
 
 	mods_size = 2; /* one for the first param/value pair and one for the the terminating NULL */
-	ldap_mods = ast_calloc(sizeof(LDAPMod *), mods_size);
-	ldap_mods[0] = ast_calloc(1, sizeof(LDAPMod));
+	ldap_mods = ldap_memcalloc(sizeof(LDAPMod *), mods_size);
+	ldap_mods[0] = ldap_memcalloc(1, sizeof(LDAPMod));
+ 
+ 	ldap_mods[0]->mod_op = LDAP_MOD_REPLACE;
+	ldap_mods[0]->mod_type = ldap_memcalloc(sizeof(char), strlen(newparam) + 1);
+ 	strcpy(ldap_mods[0]->mod_type, newparam);
+ 
+	ldap_mods[0]->mod_values = ldap_memcalloc(sizeof(char), 2);
+	ldap_mods[0]->mod_values[0] = ldap_memcalloc(sizeof(char), strlen(newval) + 1);
 
-	ldap_mods[0]->mod_op = LDAP_MOD_REPLACE;
-	ldap_mods[0]->mod_type = ast_strdup(newparam);
-
-	ldap_mods[0]->mod_values = ast_calloc(sizeof(char *), 2);
-	ldap_mods[0]->mod_values[0] = ast_strdup(newval);
-
 	while ((newparam = va_arg(ap, const char *))) {
 		newparam = convert_attribute_name_to_ldap(table_config, newparam);
 		newval = va_arg(ap, const char *);
@@ -1596,25 +1602,25 @@
 static int load_module(void)
 {
 	if (parse_config() < 0) {
-		ast_log(LOG_ERROR, "Cannot load LDAP RealTime driver.\n");
-		return 0;
+		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	ast_mutex_lock(&ldap_lock);
 
 	if (!ldap_reconnect())  {
-		ast_log(LOG_WARNING, "Couldn't establish connection to LDAP directory. Check debug.\n");
+                return AST_MODULE_LOAD_DECLINE;
 	}
 
 	ast_config_engine_register(&ldap_engine);
-	ast_verb(1, "LDAP RealTime driver loaded.\n");
 	ast_cli_register_multiple(ldap_cli, ARRAY_LEN(ldap_cli));
-
 	ast_mutex_unlock(&ldap_lock);
 
-	return 0;
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
+/*! \brief Unload Module
+ *
+ */
 static int unload_module(void)
 {
 	/* Aquire control before doing anything to the module itself. */
@@ -1636,6 +1642,8 @@
 	return 0;
 }
 
+/*! \breif Relod Module
+ */
 static int reload(void)
 {
 	/* Aquire control before doing anything to the module itself. */
@@ -1664,7 +1672,8 @@
 	return 0;
 }
 
-/*! \brief parse the configuration file */
+/*! \brief parse the configuration file
+ */
 static int parse_config(void)
 {
 	struct ast_config *config;
@@ -1686,7 +1695,7 @@
 		return -1;
 	}
 
-	if (!(s = ast_variable_retrieve(config, "_general", "user"))) {
+	if (!(s = ast_variable_retrieve(config, "general", "user"))) {
 		ast_log(LOG_NOTICE, "No directory user found, anonymous binding as default.\n");
 		user[0] = '\0';
 	} else {
@@ -1694,7 +1703,7 @@
 	}
 
 	if (!ast_strlen_zero(user)) {
-		if (!(s = ast_variable_retrieve(config, "_general", "pass"))) {
+		if (!(s = ast_variable_retrieve(config, "general", "pass"))) {
 			ast_log(LOG_WARNING, "No directory password found, using 'asterisk' as default.\n");
 			ast_copy_string(pass, "asterisk", sizeof(pass));
 		} else {
@@ -1703,10 +1712,10 @@
 	}
 
 	/* URL is preferred, use host and port if not found */
-	if ((s = ast_variable_retrieve(config, "_general", "url"))) {
+	if ((s = ast_variable_retrieve(config, "general", "url"))) {
 		ast_copy_string(url, s, sizeof(url));
-	} else if ((host = ast_variable_retrieve(config, "_general", "host"))) {
-		if (!(s = ast_variable_retrieve(config, "_general", "port")) || sscanf(s, "%5d", &port) != 1 || port > 65535) {
+	} else if ((host = ast_variable_retrieve(config, "general", "host"))) {
+		if (!(s = ast_variable_retrieve(config, "general", "port")) || sscanf(s, "%5d", &port) != 1 || port > 65535) {
 			ast_log(LOG_NOTICE, "No directory port found, using 389 as default.\n");
 			port = 389;
 		}
@@ -1718,13 +1727,13 @@
 		return -1;
 	}
 
-	if (!(s = ast_variable_retrieve(config, "_general", "basedn"))) {
+	if (!(s = ast_variable_retrieve(config, "general", "basedn"))) {
 		ast_log(LOG_ERROR, "No LDAP base dn found, using '%s' as default.\n", RES_CONFIG_LDAP_DEFAULT_BASEDN);
 		ast_copy_string(base_distinguished_name, RES_CONFIG_LDAP_DEFAULT_BASEDN, sizeof(base_distinguished_name));
 	} else 
 		ast_copy_string(base_distinguished_name, s, sizeof(base_distinguished_name));
 
-	if (!(s = ast_variable_retrieve(config, "_general", "version")) && !(s = ast_variable_retrieve(config, "_general", "protocol"))) {
+	if (!(s = ast_variable_retrieve(config, "general", "version")) && !(s = ast_variable_retrieve(config, "general", "protocol"))) {
 		ast_log(LOG_NOTICE, "No explicit LDAP version found, using 3 as default.\n");
 	} else if (sscanf(s, "%30d", &version) != 1 || version < 1 || version > 6) {
 		ast_log(LOG_WARNING, "Invalid LDAP version '%s', using 3 as default.\n", s);
@@ -1734,7 +1743,7 @@
 	table_configs_free();
 
 	while ((category_name = ast_category_browse(config, category_name))) {
-		int is_general = (strcasecmp(category_name, "_general") == 0);
+		int is_general = (strcasecmp(category_name, "general") == 0);
 		int is_config = (strcasecmp(category_name, "config") == 0); /*!< using the [config] context for Static RealTime */
 		struct ast_variable *var = ast_variable_browse(config, category_name);
 		
@@ -1764,7 +1773,10 @@
 	return 1;
 }
 
-/*! \note ldap_lock should have been locked before calling this function. */
+/*! \brief Reconnect to LDAP connection 
+ *
+ * \note ldap_lock should have been locked before calling this function.
+ */
 static int ldap_reconnect(void)
 {
 	int bind_result = 0;
@@ -1812,6 +1824,9 @@
 	}
 }
 
+/*! \brief Realtime Status
+ *
+ */
 static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char status[256], credentials[100] = "";
@@ -1860,6 +1875,9 @@
 	return CLI_SUCCESS;
 }
 
+/*! \brief Module Information
+ *
+ */
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "LDAP realtime interface",
 	.load = load_module,
 	.unload = unload_module,
