[asterisk-commits] branch oej/test-this-branch r12831 - in /team/oej/test-this-branch: configs/ ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Mar 13 12:19:40 MST 2006


Author: oej
Date: Mon Mar 13 13:19:38 2006
New Revision: 12831

URL: http://svn.digium.com/view/asterisk?rev=12831&view=rev
Log:
Update to the res_config_ldap branch

Modified:
    team/oej/test-this-branch/configs/res_ldap.conf.sample
    team/oej/test-this-branch/res/res_config_ldap.c

Modified: team/oej/test-this-branch/configs/res_ldap.conf.sample
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/configs/res_ldap.conf.sample?rev=12831&r1=12830&r2=12831&view=diff
==============================================================================
--- team/oej/test-this-branch/configs/res_ldap.conf.sample (original)
+++ team/oej/test-this-branch/configs/res_ldap.conf.sample Mon Mar 13 13:19:38 2006
@@ -6,7 +6,7 @@
 ; sip.conf => ldap,"dc=myDomain,dc=myDomainExt",config
 
 
-[general]
+[_general]
 ;dbhost=192.168.1.1,ldap.mydomain.com	; LDAP host(s)
 ;dbbasedn=MyRootDN	; Base DN
 ;dbpass=MyPassword	; Bind password
@@ -34,7 +34,7 @@
 attribute = appdata => oxyPBXExtensionApplicationData
 additionalFilter=(objectClass=oxyPBXExtension)
 
-// Sip Users Table
+; Sip Users Table
 [sip]
 attribute = name => uid
 attribute = amaflags => oxyPBXAccountAMAFlags

Modified: team/oej/test-this-branch/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/res/res_config_ldap.c?rev=12831&r1=12830&r2=12831&view=diff
==============================================================================
--- team/oej/test-this-branch/res/res_config_ldap.c (original)
+++ team/oej/test-this-branch/res/res_config_ldap.c Mon Mar 13 13:19:38 2006
@@ -7,9 +7,40 @@
  *
  * res_config_ldap.c <LDAP plugin for RealTime configuration engine>
  *
- * v0.5   - (11-16-2005) - Initial version based
- * v0.7   - (03-08-2006) - Fixes, confg file changes
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
  */
+
+/*! \file
+ *
+ * \brief ldap plugin for portable configuration engine (ARA)
+ *
+ * \author Mark Spencer <markster at digium.com>
+ * \author Manuel Guesdon
+ *
+ * \arg http://www.openldap.org
+ * \par	Version notes
+ * - v0.5   - (11-16-2005) - Initial version based
+ * - v0.7   - (03-08-2006) - Fixes, confg file changes
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <ldap.h>
+#include <stdio.h>
+
+#include "asterisk.h"
+
+STERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include <asterisk/channel.h>
 #include <asterisk/logger.h>
@@ -21,11 +52,6 @@
 #include <asterisk/utils.h>
 #include <asterisk/strings.h>
 #include <asterisk/pbx.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <ldap.h>
-#include <stdio.h>
 
 static char *res_config_ldap_desc = "LDAP RealTime Configuration Driver";
 AST_MUTEX_DEFINE_STATIC(ldap_lock);
@@ -57,24 +83,28 @@
 		cli_realtime_ldap_status_usage, NULL
 };
 
-// Log variable
+/*! \brief Log variable */
 static void ast_variable_log(const char *log_prefix, struct ast_variable *var)
 {
-	ast_log(LOG_DEBUG, "LOG Variable: %s\n", log_prefix);
+	if (option_debug > 1)
+		ast_log(LOG_DEBUG, "LOG Variable: %s\n", log_prefix);
 	while (var) {
 		ast_log(LOG_DEBUG, "%s => %s\n", var->name, var->value);
 		var = var->next;
 	};
-	ast_log(LOG_DEBUG, "END LOG Variable: %s\n", log_prefix);
-}
-
-// Log config
+	if (option_debug > 1)
+		ast_log(LOG_DEBUG, "END LOG Variable: %s\n", log_prefix);
+}
+
+/*! \brief Log config */
 static void ast_config_log(const char *log_prefix, struct ast_config *config)
 {
-	ast_log(LOG_DEBUG, "LOG Config: %s\n", log_prefix);
+	if (option_debug > 1)
+		ast_log(LOG_DEBUG, "LOG Config: %s\n", log_prefix);
 	char *category_name = NULL;
 	while ((category_name = ast_category_browse(config, category_name))) {
-		ast_log(LOG_DEBUG, "========= category: %s ==========\n",
+		if (option_debug > 1)
+			ast_log(LOG_DEBUG, "========= category: %s ==========\n",
 				category_name);
 		struct ast_variable *var = ast_variable_browse(config, category_name);
 		if (var) {
@@ -84,32 +114,32 @@
 			}
 		}
 	}
-	ast_log(LOG_DEBUG, "END LOG Config: %s\n", log_prefix);
+	if (option_debug > 1)
+		ast_log(LOG_DEBUG, "END LOG Config: %s\n", log_prefix);
 };
 
-// Table configuration
+/*! \brief Table configuration */
 struct ldap_table_config {
-	char *table_name;			// table name
-	char *additional_filter;	// additional filter       
-	struct ast_variable *attributes;	// attribute names conversion
-	struct ldap_table_config *next;	// next table
+	char *table_name;			/* table name */
+	char *additional_filter;	/* additional filter        */
+	struct ast_variable *attributes;	/* attribute names conversion */
+	struct ldap_table_config *next;	/* next table */
 };
 
-// Should be locked before using it
+/*! \brief Should be locked before using it */
 static struct ldap_table_config *table_configs = NULL;
 static struct ldap_table_config *base_table_config = NULL;
 
-// Create a new table_config
+/*! \brief Create a new table_config */
 static struct ldap_table_config *table_config_new(const char *table_name)
 {
-	struct ldap_table_config *p = malloc(sizeof(struct ldap_table_config));
-	memset(p, 0, sizeof(struct ldap_table_config));
+	struct ldap_table_config *p = ast_calloc(sizeof(*p));
 	if (table_name)
 		p->table_name = strdup(table_name);
 	return p;
 };
 
-// Find a table_config - Should be locked before using it
+/*! \brief Find a table_config - Should be locked before using it */
 static struct ldap_table_config *table_config_for_table_name(const char *table_name)
 {
 	struct ldap_table_config *c = table_configs;
@@ -122,51 +152,41 @@
 	return NULL;
 };
 
-/*
-// add attributes to table config - Should be locked before using it
+/*! \brief add attributes to table config - Should be locked before using it */
 static void ldap_table_config_add_attributes(struct ldap_table_config* table_config,const char* attributes_string)
 {
-  if (attributes_string && *attributes_string)
-    {      
-      char* string=strdup(attributes_string);
-      char* string_end=string+strlen(string);
-      char* start=string;
-      //ast_log(LOG_DEBUG, "LDAP RealTime: Add attribute: start: %s\n",start);
-      while(start<string_end)
-        {
-          char* conv_sep=NULL;
-          //ast_log(LOG_DEBUG, "LDAP RealTime: Add attribute: start: %s\n",start);
-          char* attr_sep=strchr(start,',');
-          //ast_log(LOG_DEBUG, "LDAP RealTime: Add attribute: attr_sep: %s\n",attr_sep);
-          if (!attr_sep)
-            attr_sep=string_end;
-          else
-            *attr_sep='\0';
-          conv_sep=strchr(start,'=');
-          //ast_log(LOG_DEBUG, "LDAP RealTime: Add attribute: conv_sep: %s\n",conv_sep);
-          if (conv_sep>=attr_sep)
-            conv_sep=NULL;
-
-          if (!conv_sep)
-            {
-       	 ast_log(LOG_WARNING, "LDAP RealTime: Missing '=' in attributes conversion list: %s\n",attributes_string);
-            }
-          else
-            {
-              *conv_sep='\0';
-              struct ast_variable* var=ast_variable_new(start,conv_sep+1);
-              //ast_log(LOG_DEBUG, "LDAP RealTime: Add attribute: VAR %s => %s\n",var->name,var->value);
-              if (table_config->attributes)
-       	 var->next=table_config->attributes;
-              table_config->attributes=var;
-            }
-          start=attr_sep+1;
-        };
-      free(string);
-    };
+	if (attributes_string && *attributes_string) {      
+		char* string=strdup(attributes_string);
+		char* string_end=string+strlen(string);
+		char* start=string;
+		while(start<string_end) {
+			char* conv_sep=NULL;
+    			char* attr_sep=strchr(start,',');
+			if (!attr_sep)
+				attr_sep=string_end;
+			else
+				*attr_sep='\0';
+			conv_sep=strchr(start,'=');
+			if (conv_sep>=attr_sep)
+				conv_sep=NULL;
+			if (!conv_sep) {
+				ast_log(LOG_WARNING, "LDAP RealTime: Missing '=' in attributes conversion list: %s\n",attributes_string);
+			} else {
+				struct ast_variable* var;
+				*conv_sep='\0';
+				var=ast_variable_new(start,conv_sep+1);
+				if (table_config->attributes)
+					var->next=table_config->attributes;
+				table_config->attributes=var;
+			}
+			start=attr_sep+1;
+		};
+		free(string);
+	};
 };
 */
-// add attribute to table config - Should be locked before using it
+
+/*! \brief add attribute to table config - Should be locked before using it */
 static void ldap_table_config_add_attribute(struct ldap_table_config *table_config,
 					    const char *attribute_string)
 {
@@ -182,7 +202,7 @@
 					attribute_string, table_config->table_name);
 		} else {
 			char *value = p + 2;	//skip =>      
-			// trim !
+			/* trim ! */
 			while (isspace(*start))
 				start++;
 			p--;
@@ -220,7 +240,7 @@
 	};
 };
 
-// Free table_config
+/*! \brief Free table_config */
 static void table_configs_free(void)
 {
 	struct ldap_table_config *c = table_configs;
@@ -240,7 +260,7 @@
 	base_table_config = NULL;
 }
 
-// Convert variable name to ldap attribute name - Should be locked before using it
+/*! \brief Convert variable name to ldap attribute name - Should be locked before using it */
 static const char *convert_attribute_name_to_ldap(struct ldap_table_config *table_config,
 						  const char *attribute_name)
 {
@@ -263,7 +283,7 @@
 	return attribute_name;
 };
 
-// Convert ldap attribute name to variable name - Should be locked before using it
+/*! \brief Convert ldap attribute name to variable name - Should be locked before using it */
 static const char *convert_attribute_name_from_ldap(struct ldap_table_config *table_config,
 						    const char *attribute_name)
 {
@@ -286,7 +306,7 @@
 	return attribute_name;
 };
 
-// Find variable by name
+/*! \brief Find variable by name */
 static struct ast_variable *variable_named(struct ast_variable *var,
 					   const char *name)
 {
@@ -299,7 +319,7 @@
 	return NULL;
 }
 
-// Get variables from ldap entry attributes - Should be locked before using it
+/*! \brief Get variables from ldap entry attributes - Should be locked before using it */
 static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config *table_config,
 						       LDAPMessage *ldap_entry)
 {
@@ -307,8 +327,7 @@
 	struct ast_variable *var = NULL;
 	struct ast_variable *prev = NULL;
 
-	char *ldap_attribute_name =
-		ldap_first_attribute(ldapConn, ldap_entry, &ber);
+	char *ldap_attribute_name = ldap_first_attribute(ldapConn, ldap_entry, &ber);
 
 	while (ldap_attribute_name) {
 		const char *attribute_name =
@@ -318,13 +337,13 @@
 		char **values = NULL;
 
 		values = ldap_get_values(ldapConn, ldap_entry, ldap_attribute_name);
-		if (!values) {
-		} else {
+		if (values) {
 			char **v = values;
 
 			while (*v) {
 				char *value = *v;
-				ast_log(LOG_DEBUG,
+				if (option_debug > 1)
+					ast_log(LOG_DEBUG,
 						"LDAP RealTime (%d): attribute_name: %s value: %s\n",
 						__LINE__, attribute_name, value);
 				if (is_realmed_password_attribute) {
@@ -332,7 +351,8 @@
 						value += 5;
 					else
 						value = NULL;
-					ast_log(LOG_DEBUG, "LDAP RealTime (%d): md5: %s\n",
+					if (option_debug > 1)
+						ast_log(LOG_DEBUG, "LDAP RealTime (%d): md5: %s\n",
 							__LINE__, value);
 				};
 				if (value) {
@@ -362,7 +382,7 @@
 			|| err == LDAP_TIMEOUT || err == LDAP_CONNECT_ERROR);
 }
 
-// LGet LDAP entry by dn and return attributes as variables  - Should be locked before using it
+/*! \brief LGet LDAP entry by dn and return attributes as variables  - Should be locked before using it */
 static struct ast_variable *ldap_loadentry(struct ldap_table_config *table_config,
 					   const char *dn)
 {
@@ -433,7 +453,7 @@
 	}
 }
 
-// caller should free returned pointer
+/*! \brief caller should free returned pointer */
 static char *substituted(struct ast_channel *channel, const char *string)
 {
 #define MAXRESULT	2048
@@ -452,7 +472,7 @@
 	return ret_string;
 }
 
-// caller should free returned pointer
+/*! \brief caller should free returned pointer */
 static char *cleaned_basedn(struct ast_channel *channel, const char *basedn)
 {
 	char *cbasedn = NULL;
@@ -480,7 +500,7 @@
 	return cbasedn;
 }
 
-// Append a string to a filter string. The filter string can grow
+/*! \brief Append a string to a filter string. The filter string can grow */
 static void append_string_to_filter(char **filter_ptr, int *filter_size_ptr,
 				    const char *filter)
 {
@@ -507,7 +527,7 @@
 		free(r_filter);
 }
 
-// Replace search by by in string. No check is done on string allocated size !
+/*! \brief Replace search by by in string. No check is done on string allocated size ! */
 static int replace_string_in_string(char *string, const char *search,const char *by)
 {
 	int search_len = strlen(search);
@@ -530,8 +550,8 @@
 	return replaced;
 };
 
-// Append a name=value filter string. The filter string can grow.
-// convert name and value if "LIKE' is used (see http://bugs.digium.com/view.php?id=5765)
+/*! \brief Append a name=value filter string. The filter string can grow. */
+/*! \brief convert name and value if "LIKE' is used (see http://bugs.digium.com/view.php?id=5765) */
 static void append_var_and_value_to_filter(char **filter_ptr,
 					   int *filter_size_ptr,
 					   struct ldap_table_config
@@ -562,7 +582,7 @@
 		free(new_value);
 }
 
-/* LDAP base function
+/*! \brief LDAP base function */
  return a null terminated array of ast_variable (one per entry) or NULL if no entry is found or if an error occured
  caller should free the returned array and ast_variables
  entries_count_ptr is a pointer to found entries count (can be NULL)
@@ -586,7 +606,7 @@
 		const char *newparam = NULL;
 		const char *newval = NULL;
 
-		// Get the first parameter and first value in our list of passed paramater/value pairs 
+		/* Get the first parameter and first value in our list of passed paramater/value pairs  */
 		newparam = va_arg(ap, const char *);
 		newval = va_arg(ap, const char *);
 		if (!newparam || !newval) {
@@ -595,7 +615,7 @@
 		} else {
 			ast_mutex_lock(&ldap_lock);
 
-			// We now have our complete statement; Lets connect to the server and execute it. 
+			/* We now have our complete statement; Lets connect to the server and execute it.  */
 			if (!ldap_reconnect()) {
 			} else {
 				struct ldap_table_config *table_config = NULL;
@@ -626,8 +646,8 @@
 									base_table_config->additional_filter);
 					};
 
-					// Create the first part of the query using the first parameter/value pairs we just extracted
-					//   If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat
+					/* Create the first part of the query using the first parameter/value pairs we just extracted */
+					/*   If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
 
 					append_var_and_value_to_filter(&filter, &filter_size,
 								       table_config, newparam, newval);
@@ -783,7 +803,7 @@
 	return vars;
 }
 
-// same as realtime_ldap_base_ but take variable arguments count list
+/*! \brief same as realtime_ldap_base_ but take variable arguments count list */
 static struct ast_variable **realtime_ldap_base_(unsigned int
 						 *entries_count_ptr,
 						 const char *basedn,
@@ -797,7 +817,7 @@
 	return vars;
 }
 
-// See Asterisk doc
+/*! \brief See Asterisk doc */
 static struct ast_variable *realtime_ldap(const char *basedn,
 					  const char *table_name, va_list ap)
 {
@@ -827,7 +847,7 @@
 	return var;
 }
 
-// See Asterisk doc
+/*! \brief See Asterisk doc */
 static struct ast_config *realtime_multi_ldap(const char *basedn,
 					      const char *table_name,
 					      va_list ap)
@@ -886,7 +906,7 @@
 		return strcmp(as->name, bs->name);
 }
 
-// See Asterisk doc
+/*! \brief See Asterisk doc */
 static struct ast_config *config_ldap(const char *basedn,
 				      const char *table_name,
 				      const char *file,
@@ -910,7 +930,7 @@
 			char *last_category = NULL;
 			int last_category_metric = 0;
 
-			// sort on metric and category
+			/* sort on metric and category */
 			struct category_and_metric *categories =
 				malloc(sizeof(struct category_and_metric) * vars_count);
 			struct ast_variable **p = vars;



More information about the asterisk-commits mailing list