[svn-commits] gtjoseph: trunk r425482 - in /trunk: ./ include/asterisk/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Oct 14 13:13:36 CDT 2014


Author: gtjoseph
Date: Tue Oct 14 13:13:33 2014
New Revision: 425482

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=425482
Log:
res_phoneprov: Create accessor for ast_phoneprov_std_variable_lookup

Based on feedback from Richard, I created an accessor for
res_phoneprov/ast_phoneprov_std_variable_lookup and added
load priority to AST_MODULE_INFO.

Tested-by: George Joseph
Tested-by: Richard Mudgett

Review: https://reviewboard.asterisk.org/r/4076/
........

Merged revisions 425480 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 425481 from http://svn.asterisk.org/svn/asterisk/branches/13

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/phoneprov.h
    trunk/res/res_phoneprov.c
    trunk/res/res_pjsip_phoneprov_provider.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/include/asterisk/phoneprov.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/phoneprov.h?view=diff&rev=425482&r1=425481&r2=425482
==============================================================================
--- trunk/include/asterisk/phoneprov.h (original)
+++ trunk/include/asterisk/phoneprov.h Tue Oct 14 13:13:33 2014
@@ -53,8 +53,13 @@
 	AST_PHONEPROV_STD_VAR_LIST_LENGTH,	/* This entry must always be the last in the list */
 };
 
-/*! \brief Lookup table for the standard phoneprov variable names */
-extern const char *ast_phoneprov_std_variable_lookup[];
+/*!
+ * \brief Returns the string respresentation of a phoneprov standard variable.
+ * \param var One of enum ast_phoneprov_std_variables
+ *
+ * \return The string representation or NULL if not found.
+ */
+const char *ast_phoneprov_std_variable_lookup(enum ast_phoneprov_std_variables var);
 
 /*!
  * \brief Causes the provider to load its users.

Modified: trunk/res/res_phoneprov.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_phoneprov.c?view=diff&rev=425482&r1=425481&r2=425482
==============================================================================
--- trunk/res/res_phoneprov.c (original)
+++ trunk/res/res_phoneprov.c Tue Oct 14 13:13:33 2014
@@ -180,7 +180,7 @@
 	return CMP_MATCH; \
 }
 
-const char *ast_phoneprov_std_variable_lookup[] = {
+static const char *variable_lookup[] = {
 	[AST_PHONEPROV_STD_MAC] = "MAC",
 	[AST_PHONEPROV_STD_PROFILE] = "PROFILE",
 	[AST_PHONEPROV_STD_USERNAME] = "USERNAME",
@@ -207,7 +207,7 @@
 };
 
 /* Translate the standard variables to their users.conf equivalents. */
-const char *pp_user_lookup[] = {
+static const char *pp_user_lookup[] = {
 	[AST_PHONEPROV_STD_MAC] = "macaddress",
 	[AST_PHONEPROV_STD_PROFILE] = "profile",
 	[AST_PHONEPROV_STD_USERNAME] = "username",
@@ -234,7 +234,7 @@
 };
 
 /* Translate the standard variables to their phoneprov.conf [general] equivalents. */
-const char *pp_general_lookup[] = {
+static const char *pp_general_lookup[] = {
 	[AST_PHONEPROV_STD_MAC] = NULL,
 	[AST_PHONEPROV_STD_PROFILE] = "default_profile",
 	[AST_PHONEPROV_STD_USERNAME] = NULL,
@@ -699,22 +699,22 @@
 		return NULL;
 	}
 
-	tmp = ast_var_find(exten->headp, ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_LINENUMBER]);
+	tmp = ast_var_find(exten->headp, variable_lookup[AST_PHONEPROV_STD_LINENUMBER]);
 	if (!tmp) {
 		AST_VAR_LIST_INSERT_TAIL(exten->headp,
-			ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_LINENUMBER], "1"));
+			ast_var_assign(variable_lookup[AST_PHONEPROV_STD_LINENUMBER], "1"));
 		exten->index = 1;
 	} else {
 		sscanf(tmp, "%d", &exten->index);
 	}
 
-	if (!ast_var_find(exten->headp, ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_LINEKEYS])) {
+	if (!ast_var_find(exten->headp, variable_lookup[AST_PHONEPROV_STD_LINEKEYS])) {
 		AST_VAR_LIST_INSERT_TAIL(exten->headp,
-			ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_LINEKEYS], "1"));
+			ast_var_assign(variable_lookup[AST_PHONEPROV_STD_LINEKEYS], "1"));
 	}
 
 	set_timezone_variables(exten->headp,
-		ast_var_find(vars, ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_TIMEZONE]));
+		ast_var_find(vars, variable_lookup[AST_PHONEPROV_STD_TIMEZONE]));
 
 	return exten;
 }
@@ -935,7 +935,7 @@
 		 * the IP address we are listening on that the phone contacted for this config file */
 
 		server = ast_var_find(AST_LIST_FIRST(&route->user->extensions)->headp,
-			ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_SERVER]);
+			variable_lookup[AST_PHONEPROV_STD_SERVER]);
 
 		if (!server) {
 			union {
@@ -953,7 +953,7 @@
 
 				AST_LIST_TRAVERSE(&route->user->extensions, exten_iter, entry) {
 					AST_VAR_LIST_INSERT_TAIL(exten_iter->headp,
-						ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_SERVER], newserver));
+						ast_var_assign(variable_lookup[AST_PHONEPROV_STD_SERVER], newserver));
 				}
 			}
 		}
@@ -1221,7 +1221,7 @@
 		}
 	}
 	if (value) {
-		var = ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_SERVER], value);
+		var = ast_var_assign(variable_lookup[AST_PHONEPROV_STD_SERVER], value);
 		AST_VAR_LIST_INSERT_TAIL(defaults, var);
 	} else {
 		ast_log(LOG_WARNING, "Unable to find a valid server address or name.\n");
@@ -1234,7 +1234,7 @@
 			ast_config_destroy(cfg);
 		}
 	}
-	var = ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_SERVER_PORT], S_OR(value, "5060"));
+	var = ast_var_assign(variable_lookup[AST_PHONEPROV_STD_SERVER_PORT], S_OR(value, "5060"));
 	AST_VAR_LIST_INSERT_TAIL(defaults, var);
 
 	value = ast_variable_retrieve(phoneprov_cfg, "general", pp_general_lookup[AST_PHONEPROV_STD_PROFILE]);
@@ -1244,7 +1244,7 @@
 		ast_var_list_destroy(defaults);
 		return NULL;
 	}
-	var = ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_PROFILE], value);
+	var = ast_var_assign(variable_lookup[AST_PHONEPROV_STD_PROFILE], value);
 	AST_VAR_LIST_INSERT_TAIL(defaults, var);
 	ast_config_destroy(phoneprov_cfg);
 
@@ -1257,11 +1257,11 @@
 	/* Go ahead and load global variables from users.conf so we can append to profiles */
 	for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
 		if (!strcasecmp(v->name, pp_user_lookup[AST_PHONEPROV_STD_VOICEMAIL_EXTEN])) {
-			var = ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_VOICEMAIL_EXTEN], v->value);
+			var = ast_var_assign(variable_lookup[AST_PHONEPROV_STD_VOICEMAIL_EXTEN], v->value);
 			AST_VAR_LIST_INSERT_TAIL(defaults, var);
 		}
 		if (!strcasecmp(v->name, pp_user_lookup[AST_PHONEPROV_STD_EXTENSION_LENGTH])) {
-			var = ast_var_assign(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_EXTENSION_LENGTH], v->value);
+			var = ast_var_assign(variable_lookup[AST_PHONEPROV_STD_EXTENSION_LENGTH], v->value);
 			AST_VAR_LIST_INSERT_TAIL(defaults, var);
 		}
 	}
@@ -1309,14 +1309,14 @@
 				if (pp_user_lookup[i]) {
 					value = ast_variable_retrieve(cfg, cat, pp_user_lookup[i]);
 					if (value) {
-						varx = ast_var_assign(ast_phoneprov_std_variable_lookup[i],
+						varx = ast_var_assign(variable_lookup[i],
 							value);
 						AST_VAR_LIST_INSERT_TAIL(variables, varx);
 					}
 				}
 			}
 
-			if (!ast_var_find(variables, ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_MAC])) {
+			if (!ast_var_find(variables, variable_lookup[AST_PHONEPROV_STD_MAC])) {
 				ast_log(LOG_WARNING, "autoprov set for %s, but no mac address - skipping.\n", cat);
 				ast_var_list_destroy(variables);
 				continue;
@@ -1486,14 +1486,24 @@
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT | AST_MODFLAG_GLOBAL_SYMBOLS, "HTTP Phone Provisioning",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",
 		.support_level = AST_MODULE_SUPPORT_EXTENDED,
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,
+		.load_pri = AST_MODPRI_CHANNEL_DEPEND,
 	);
 
 /****  Public API for register/unregister, set defaults, and add extension. ****/
+
+const char *ast_phoneprov_std_variable_lookup(enum ast_phoneprov_std_variables var)
+{
+	if (var >= AST_PHONEPROV_STD_VAR_LIST_LENGTH) {
+		return NULL;
+	}
+
+	return variable_lookup[var];
+}
 
 int ast_phoneprov_provider_register(char *provider_name,
 	ast_phoneprov_load_users_cb load_users)
@@ -1608,13 +1618,13 @@
 		return -1;
 	}
 
-	username = ast_var_find(vars, ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_USERNAME]);
+	username = ast_var_find(vars, variable_lookup[AST_PHONEPROV_STD_USERNAME]);
 	if (!username) {
 		ast_log(LOG_ERROR, "Extension name can't be empty.\n");
 		return -1;
 	}
 
-	mac = ast_var_find(vars, ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_MAC]);
+	mac = ast_var_find(vars, variable_lookup[AST_PHONEPROV_STD_MAC]);
 	if (!mac) {
 		ast_log(LOG_ERROR, "MAC Address can't be empty.\n");
 		return -1;
@@ -1627,7 +1637,7 @@
 	}
 
 	profile_name = ast_var_find(vars,
-		ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_PROFILE]);
+		variable_lookup[AST_PHONEPROV_STD_PROFILE]);
 	if (!profile_name) {
 		ast_log(LOG_ERROR, "No profile could be found for user '%s' - skipping.\n", username);
 		return -1;

Modified: trunk/res/res_pjsip_phoneprov_provider.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_phoneprov_provider.c?view=diff&rev=425482&r1=425481&r2=425482
==============================================================================
--- trunk/res/res_pjsip_phoneprov_provider.c (original)
+++ trunk/res/res_pjsip_phoneprov_provider.c Tue Oct 14 13:13:33 2014
@@ -240,13 +240,13 @@
 	assign_and_insert("TRANSPORT_ID", endpoint->transport, vars);
 
 	if (endpoint->id.self.number.valid && !ast_strlen_zero(endpoint->id.self.number.str)) {
-		assign_and_insert(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_CALLERID],
+		assign_and_insert(ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_CALLERID),
 			endpoint->id.self.number.str, vars);
 	}
 
 	if (endpoint->id.self.name.valid && !ast_strlen_zero(endpoint->id.self.name.str)) {
 		assign_and_insert(
-			ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_DISPLAY_NAME],
+			ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_DISPLAY_NAME),
 			endpoint->id.self.name.str, vars);
 	}
 
@@ -271,9 +271,9 @@
 	}
 
 	assign_and_insert("AUTH_ID", auth_name, vars);
-	assign_and_insert(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_USERNAME],
+	assign_and_insert(ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_USERNAME),
 		auth->auth_user, vars);
-	assign_and_insert(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_SECRET],
+	assign_and_insert(ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_SECRET),
 		auth->auth_pass, vars);
 	ao2_ref(auth, -1);
 
@@ -313,25 +313,25 @@
 		}
 
 		if (!ast_var_find(pp->vars,
-			ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_USERNAME])) {
+			ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_USERNAME))) {
 			assign_and_insert(
-				ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_USERNAME], id,
+				ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_USERNAME), id,
 				pp->vars);
 		}
 
 		if (!ast_var_find(pp->vars,
-			ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_LABEL])) {
-			assign_and_insert(ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_LABEL],
+			ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_LABEL))) {
+			assign_and_insert(ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_LABEL),
 				id, pp->vars);
 		}
 
 		if (!ast_var_find(pp->vars,
-			ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_SERVER_PORT])) {
+			ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_SERVER_PORT))) {
 			assign_and_insert("SERVER_PORT", S_OR(port_string, "5060"), pp->vars);
 		}
 
 		if (!ast_var_find(pp->vars,
-			ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_PROFILE])) {
+			ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_PROFILE))) {
 			ast_log(LOG_ERROR, "phoneprov %s didn't contain a PROFILE entry.\n", id);
 		} else if (!ast_phoneprov_add_extension(AST_MODULE, pp->vars)) {
 			user_count++;
@@ -354,13 +354,13 @@
 	const char *id = ast_sorcery_object_get_id(pp);
 
 	if (!ast_var_find(pp->vars,
-		ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_MAC])) {
+		ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_MAC))) {
 		ast_log(LOG_ERROR, "phoneprov %s must contain a MAC entry.\n", id);
 		return -1;
 	}
 
 	if (!ast_var_find(pp->vars,
-		ast_phoneprov_std_variable_lookup[AST_PHONEPROV_STD_PROFILE])) {
+		ast_phoneprov_std_variable_lookup(AST_PHONEPROV_STD_PROFILE))) {
 		ast_log(LOG_ERROR, "phoneprov %s must contain a PROFILE entry.\n", id);
 		return -1;
 	}




More information about the svn-commits mailing list