[asterisk-commits] russell: branch group/res_config_ldap r63963 - in /team/group/res_config_ldap...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri May 11 12:18:25 MST 2007


Author: russell
Date: Fri May 11 14:18:25 2007
New Revision: 63963

URL: http://svn.digium.com/view/asterisk?view=rev&rev=63963
Log:
Significantly simplify the configuration of attribute mappings

Modified:
    team/group/res_config_ldap/configs/res_ldap.conf.sample
    team/group/res_config_ldap/res/res_config_ldap.c

Modified: team/group/res_config_ldap/configs/res_ldap.conf.sample
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/configs/res_ldap.conf.sample?view=diff&rev=63963&r1=63962&r2=63963
==============================================================================
--- team/group/res_config_ldap/configs/res_ldap.conf.sample (original)
+++ team/group/res_config_ldap/configs/res_ldap.conf.sample Fri May 11 14:18:25 2007
@@ -1,9 +1,9 @@
 ; Sample Asterisk config file for res_config_ldap
 ; in extconfig.conf you can use it like this:
-; sipusers => ldap,"dc=myDomain,dc=myDomainExt",sip
-; sippeers => ldap,"dc=myDomain,dc=myDomainExt",sip
-; extensions => ldap,"dc=myDomain,dc=myDomainExt",extensions
-; sip.conf => ldap,"dc=myDomain,dc=myDomainExt",config
+; sipusers = ldap,"dc=myDomain,dc=myDomainExt",sip
+; sippeers = ldap,"dc=myDomain,dc=myDomainExt",sip
+; extensions = ldap,"dc=myDomain,dc=myDomainExt",extensions
+; sip.conf = ldap,"dc=myDomain,dc=myDomainExt",config
 
 
 [_general]
@@ -15,121 +15,121 @@
 
 ; Configuration Table
 [config]
-; Attributes mapping (asterisk variable name => ldap attribute name)
-attribute = filename => oxyPBXConfigFilename
-attribute = category => oxyPBXConfigCategory
-attribute = variable_name => oxyPBXConfigVariableName
-attribute = variable_value => oxyPBXConfigVariableValue
-attribute = cat_metric => oxyPBXConfigCategoryMetric
-attribute = commented => oxyPBXConfigCommented
+; Attributes mapping (asterisk variable name = ldap attribute name)
+filename = PBXConfigFilename
+category = PBXConfigCategory
+variable_name = PBXConfigVariableName
+variable_value = PBXConfigVariableValue
+cat_metric = PBXConfigCategoryMetric
+commented = PBXConfigCommented
 
 ; addtional filter
-additionalFilter=(objectClass=oxyPBXConfig)
+additionalFilter=(objectClass=PBXConfig)
 
 ; Extensions Table
 [extensions]
-attribute = context  =>  oxyPBXExtensionContext
-attribute = exten  =>  oxyPBXExtensionExten
-attribute = priority => oxyPBXExtensionPriority
-attribute = app => oxyPBXExtensionApplication
-attribute = appdata => oxyPBXExtensionApplicationData
-additionalFilter=(objectClass=oxyPBXExtension)
+context  =  PBXExtensionContext
+exten  =  PBXExtensionExten
+priority = PBXExtensionPriority
+app = PBXExtensionApplication
+appdata = PBXExtensionApplicationData
+additionalFilter=(objectClass=PBXExtension)
 
 ; Sip Users Table
 [sip]
-attribute = name => uid
-attribute = amaflags => oxyPBXAccountAMAFlags
-attribute = callgroup => oxyPBXAccountCallGroup
-attribute = callerid => oxyPBXAccountCallerID
-attribute = canreinvite => oxyPBXAccountCanReinvite
-attribute = context => oxyPBXAccountContext
-attribute = dtmfmode => oxyPBXAccountDTMFMode
-attribute = fromuser => oxyPBXAccountFromUser
-attribute = fromdomain => oxyPBXAccountFromDomain
-attribute = fullcontact => oxyPBXAccountFullContact
-attribute = fullcontact => gecos
-attribute = host => oxyPBXAccountHost
-attribute = insecure => oxyPBXAccountInsecure
-attribute = mailbox => oxyPBXAccountMailbox
-attribute = md5secret => realmedPassword
-attribute = nat => oxyPBXAccountNAT
-attribute = deny => oxyPBXAccountDeny
-attribute = permit => oxyPBXAccountPermit
-attribute = pickupgroup => oxyPBXAccountPickupGroup
-attribute = port => oxyPBXAccountPort
-attribute = qualify => oxyPBXAccountQualify
-attribute = restrictcid => oxyPBXAccountRestrictCID
-attribute = rtptimeout => oxyPBXAccountRTPTimeout
-attribute = rtpholdtimeout => oxyPBXAccountRTPHoldTimeout
-attribute = type => oxyPBXAccountType
-attribute = disallow => oxyPBXAccountDisallowedCodec
-attribute = allow => oxyPBXAccountAllowedCodec
-attribute = MusicOnHold => oxyPBXAccountMusicOnHold
-attribute = regseconds => oxyPBXAccountExpirationTimestamp
-attribute = regcontext => oxyPBXAccountRegistrationContext
-attribute = regexten => oxyPBXAccountRegistrationExten
-attribute = CanCallForward => oxyPBXAccountCanCallForward
-additionalFilter=(objectClass=oxyPBXAccountSIP)
+name = uid
+amaflags = PBXAccountAMAFlags
+callgroup = PBXAccountCallGroup
+callerid = PBXAccountCallerID
+canreinvite = PBXAccountCanReinvite
+context = PBXAccountContext
+dtmfmode = PBXAccountDTMFMode
+fromuser = PBXAccountFromUser
+fromdomain = PBXAccountFromDomain
+fullcontact = PBXAccountFullContact
+fullcontact = gecos
+host = PBXAccountHost
+insecure = PBXAccountInsecure
+mailbox = PBXAccountMailbox
+md5secret = realmedPassword
+nat = PBXAccountNAT
+deny = PBXAccountDeny
+permit = PBXAccountPermit
+pickupgroup = PBXAccountPickupGroup
+port = PBXAccountPort
+qualify = PBXAccountQualify
+restrictcid = PBXAccountRestrictCID
+rtptimeout = PBXAccountRTPTimeout
+rtpholdtimeout = PBXAccountRTPHoldTimeout
+type = PBXAccountType
+disallow = PBXAccountDisallowedCodec
+allow = PBXAccountAllowedCodec
+MusicOnHold = PBXAccountMusicOnHold
+regseconds = PBXAccountExpirationTimestamp
+regcontext = PBXAccountRegistrationContext
+regexten = PBXAccountRegistrationExten
+CanCallForward = PBXAccountCanCallForward
+additionalFilter=(objectClass=PBXAccountSIP)
 
 ; IAX Users Table
 [iax]
-attribute = amaflags => oxyPBXAccountAMAFlags
-attribute = callerid => oxyPBXAccountCallerID
-attribute = context => oxyPBXAccountContext
-attribute = fullcontact => oxyPBXAccountFullContact
-attribute = fullcontact => gecos
-attribute = host => oxyPBXAccountHost
-attribute = mailbox => oxyPBXAccountMailbox
-attribute = md5secret => realmedPassword
-attribute = deny => oxyPBXAccountDeny
-attribute = permit => oxyPBXAccountPermit
-attribute = port => oxyPBXAccountPort
-attribute = qualify => oxyPBXAccountQualify
-attribute = type => oxyPBXAccountType
-attribute = disallow => oxyPBXAccountDisallowedCodec
-attribute = allow => oxyPBXAccountAllowedCodec
-attribute = regseconds => oxyPBXAccountExpirationTimestamp
-attribute = regcontext => oxyPBXAccountRegistrationContext
-attribute = regexten => oxyPBXAccountRegistrationExten
-attribute = notransfer => oxyPBXAccountNoTransfer
-additionalFilter=(objectClass=oxyPBXAccountIAX)
+amaflags = PBXAccountAMAFlags
+callerid = PBXAccountCallerID
+context = PBXAccountContext
+fullcontact = PBXAccountFullContact
+fullcontact = gecos
+host = PBXAccountHost
+mailbox = PBXAccountMailbox
+md5secret = realmedPassword
+deny = PBXAccountDeny
+permit = PBXAccountPermit
+port = PBXAccountPort
+qualify = PBXAccountQualify
+type = PBXAccountType
+disallow = PBXAccountDisallowedCodec
+allow = PBXAccountAllowedCodec
+regseconds = PBXAccountExpirationTimestamp
+regcontext = PBXAccountRegistrationContext
+regexten = PBXAccountRegistrationExten
+notransfer = PBXAccountNoTransfer
+additionalFilter=(objectClass=PBXAccountIAX)
 
 ; A Test Family
 [testfamily]
-attribute = MyUSERID => uid
+MyUSERID = uid
 additionalFilter=(objectClass=*)
 
 [accounts]
-attribute = amaflags => oxyPBXAccountAMAFlags
-attribute = callgroup => oxyPBXAccountCallGroup
-attribute = callerid => oxyPBXAccountCallerID
-attribute = canreinvite => oxyPBXAccountCanReinvite
-attribute = context => oxyPBXAccountContext
-attribute = dtmfmode => oxyPBXAccountDTMFMode
-attribute = fromuser => oxyPBXAccountFromUser
-attribute = fromdomain => oxyPBXAccountFromDomain
-attribute = fullcontact => oxyPBXAccountFullContact
-attribute = fullcontact => gecos
-attribute = host => oxyPBXAccountHost
-attribute = insecure => oxyPBXAccountInsecure
-attribute = mailbox => oxyPBXAccountMailbox
-attribute = md5secret => realmedPassword
-attribute = nat => oxyPBXAccountNAT
-attribute = deny => oxyPBXAccountDeny
-attribute = permit => oxyPBXAccountPermit
-attribute = pickupgroup => oxyPBXAccountPickupGroup
-attribute = port => oxyPBXAccountPort
-attribute = qualify => oxyPBXAccountQualify
-attribute = restrictcid => oxyPBXAccountRestrictCID
-attribute = rtptimeout => oxyPBXAccountRTPTimeout
-attribute = rtpholdtimeout => oxyPBXAccountRTPHoldTimeout
-attribute = type => oxyPBXAccountType
-attribute = disallow => oxyPBXAccountDisallowedCodec
-attribute = allow => oxyPBXAccountAllowedCodec
-attribute = MusicOnHold => oxyPBXAccountMusicOnHold
-attribute = regseconds => oxyPBXAccountExpirationTimestamp
-attribute = regcontext => oxyPBXAccountRegistrationContext
-attribute = regexten => oxyPBXAccountRegistrationExten
-attribute = CanCallForward => oxyPBXAccountCanCallForward
-additionalFilter=(objectClass=oxyPBXAccount)
+amaflags = PBXAccountAMAFlags
+callgroup = PBXAccountCallGroup
+callerid = PBXAccountCallerID
+canreinvite = PBXAccountCanReinvite
+context = PBXAccountContext
+dtmfmode = PBXAccountDTMFMode
+fromuser = PBXAccountFromUser
+fromdomain = PBXAccountFromDomain
+fullcontact = PBXAccountFullContact
+fullcontact = gecos
+host = PBXAccountHost
+insecure = PBXAccountInsecure
+mailbox = PBXAccountMailbox
+md5secret = realmedPassword
+nat = PBXAccountNAT
+deny = PBXAccountDeny
+permit = PBXAccountPermit
+pickupgroup = PBXAccountPickupGroup
+port = PBXAccountPort
+qualify = PBXAccountQualify
+restrictcid = PBXAccountRestrictCID
+rtptimeout = PBXAccountRTPTimeout
+rtpholdtimeout = PBXAccountRTPHoldTimeout
+type = PBXAccountType
+disallow = PBXAccountDisallowedCodec
+allow = PBXAccountAllowedCodec
+MusicOnHold = PBXAccountMusicOnHold
+regseconds = PBXAccountExpirationTimestamp
+regcontext = PBXAccountRegistrationContext
+regexten = PBXAccountRegistrationExten
+CanCallForward = PBXAccountCanCallForward
+additionalFilter=(objectClass=PBXAccount)
 

Modified: team/group/res_config_ldap/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/res/res_config_ldap.c?view=diff&rev=63963&r1=63962&r2=63963
==============================================================================
--- team/group/res_config_ldap/res/res_config_ldap.c (original)
+++ team/group/res_config_ldap/res/res_config_ldap.c Fri May 11 14:18:25 2007
@@ -238,59 +238,17 @@
 
 /*! \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)
-{
-	if (attribute_string && *attribute_string) {
-		char *string = strdup(attribute_string);
-		char *start = string;
-		char *p = strstr(start, "=>");
-
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Add attribute: start: %s\n", start);
-
-		if (!p) {
-			ast_log(LOG_WARNING,
-					"Missing '=>' in attribute: %s in %s\n",
-					attribute_string, table_config->table_name);
-		} else {
-			char *value = p + 2;	//skip =>      
-			/* trim ! */
-			while (isspace(*start))
-				start++;
-			p--;
-			while (p >= start && isspace(*p)) {
-				*p = '\0';
-				p--;
-			}
-			while (isspace(*value))
-				value++;
-			p = value + strlen(value) - 1;
-			while (p >= value && isspace(*p)) {
-				*p = '\0';
-				p--;
-			}
-			if (ast_strlen_zero(start)) {
-				ast_log(LOG_WARNING,
-						"Empty variable name in attribute: %s in %s\n",
-						attribute_string, table_config->table_name);
-			} else if (ast_strlen_zero(value)) {
-				ast_log(LOG_WARNING,
-						"Empty ldap attribute name in attribute: %s in %s\n",
-						attribute_string, table_config->table_name);
-			} else {
-				struct ast_variable *var = ast_variable_new(start, value);
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "Add attribute: VAR %s => %s\n",var->name,var->value);
-				if (table_config->attributes)
-					var->next = table_config->attributes;
-				table_config->attributes = var;
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "Added attribute in %s: %s -> %s\n",
-						table_config->table_name, start, value);
-			}
-		}
-		free(string);
-	}
+	const char *attribute_name, const char *attribute_value)
+{
+	if (ast_strlen_zero(attribute_name) || ast_strlen_zero(attribute_value))
+ 		return;
+
+	if (!(var = ast_variable_new(attribute_name, attribute_value)))
+ 		return;
+
+	if (table_config->attributes)
+		var->next = table_config->attributes;
+	table_config->attributes = var;
 }
 
 /*! \brief Free table_config 
@@ -1656,12 +1614,12 @@
 					static_table_config = table_config;
 			}
 			for (; var; var = var->next) {
-				if (!strcasecmp(var->name, "attribute"))
-					ldap_table_config_add_attribute(table_config, var->value);
-				else if (!strcasecmp(var->name, "escape"))
+				if (!strcasecmp(var->name, "escape"))
 					ldap_table_config_add_escape(table_config, var->value);
 				else if (!strcasecmp(var->name, "additionalFilter"))
 					table_config->additional_filter = strdup(var->value);
+				else
+					ldap_table_config_add_attribute(table_config, var->name, var->value);
 			}
 		}
 	}



More information about the asterisk-commits mailing list