res_phoneprov: Create accessor for ast_phoneprov_std_variable_lookup
authorGeorge Joseph <george.joseph@fairview5.com>
Tue, 14 Oct 2014 18:13:33 +0000 (18:13 +0000)
committerGeorge Joseph <george.joseph@fairview5.com>
Tue, 14 Oct 2014 18:13:33 +0000 (18:13 +0000)
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

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425482 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/phoneprov.h
res/res_phoneprov.c
res/res_pjsip_phoneprov_provider.c

index 364a574..24e8cc9 100644 (file)
@@ -53,8 +53,13 @@ enum ast_phoneprov_std_variables {
        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.
index e463bbd..78511cc 100644 (file)
@@ -180,7 +180,7 @@ static int fname(void *obj, void *arg, int flags) \
        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 @@ const char *ast_phoneprov_std_variable_lookup[] = {
 };
 
 /* 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 @@ const char *pp_user_lookup[] = {
 };
 
 /* 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 @@ static struct extension *build_extension(const char *name, struct varshead *vars
                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 @@ static int phoneprov_callback(struct ast_tcptls_session_instance *ser, const str
                 * 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 @@ static int phoneprov_callback(struct ast_tcptls_session_instance *ser, const str
 
                                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 @@ static struct varshead *get_defaults(void)
                }
        }
        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 @@ static struct varshead *get_defaults(void)
                        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 @@ static struct varshead *get_defaults(void)
                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 @@ static struct varshead *get_defaults(void)
        /* 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 @@ static int load_users(void)
                                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,15 +1486,25 @@ static int reload(void)
        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 @@ int ast_phoneprov_add_extension(char *provider_name, struct varshead *vars)
                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 @@ int ast_phoneprov_add_extension(char *provider_name, struct varshead *vars)
        }
 
        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;
index 509880a..6c2c777 100644 (file)
@@ -240,13 +240,13 @@ static int load_endpoint(const char *id, const char *endpoint_name, struct varsh
        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 @@ static int load_endpoint(const char *id, const char *endpoint_name, struct varsh
        }
 
        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 @@ static int load_users(void)
                }
 
                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 @@ static int users_apply_handler(const struct ast_sorcery *sorcery, void *obj)
        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;
        }