Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
PJSIP Configuration Wizard. More...
#include "asterisk.h"
#include <regex.h>
#include <pjsip.h>
#include "asterisk/astobj2.h"
#include "asterisk/cli.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sorcery.h"
#include "asterisk/vector.h"
Go to the source code of this file.
Data Structures | |
struct | object_type_wizard |
Keeps track of the sorcery wizard and last config for each object type. More... | |
struct | string_vector |
A generic char * vector definition. More... | |
Macros | |
#define | BASE_REGISTRAR "res_pjsip_config_wizard" |
#define | MAX_ID_SUFFIX 20 |
Defines the maximum number of characters that can be added to a wizard id. More... | |
#define | NOT_EQUALS(a, b) (a != b) |
#define | OTW_DELETE_CB(otw) |
#define | variable_list_append_return(existing, name, value) |
Appends a variable to the end of an existing list. On failure, cause the calling function to return -1. More... | |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | add_extension (struct ast_context *context, const char *exten, int priority, const char *application) |
static int | add_hints (const char *context, const char *exten, const char *application, const char *id) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static | AST_VECTOR_RW (object_type_wizards, struct object_type_wizard *) |
static void * | create_object (const struct ast_sorcery *sorcery, const char *id, const char *type, struct ast_variable *vars) |
Creates a sorcery object and applies a variable list. More... | |
static int | delete_existing_cb (void *obj, void *arg, int flags) |
static int | delete_extens (const char *context, const char *exten) |
static struct object_type_wizard * | find_wizard (const char *object_type) |
Finds the otw for the object type. More... | |
static struct ast_variable * | get_object_variables (struct ast_variable *vars, char *prefix) |
We need to strip off the prefix from the name of each variable so they're suitable for objectset_apply. I.E. will transform outbound_auth/username to username. More... | |
static int | handle_aor (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz, struct string_vector *remote_hosts_vector) |
static int | handle_auth (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz, char *direction) |
static int | handle_auths (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz) |
static int | handle_endpoint (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz) |
static char * | handle_export_primitives (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | handle_identify (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz, struct string_vector *remote_hosts_vector) |
static int | handle_phoneprov (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz) |
static int | handle_registrations (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz, struct string_vector *remote_hosts_vector) |
static void | instance_created_observer (const char *name, struct ast_sorcery *sorcery) |
When the res_pjsip instance is created, add an observer to it and initialize the wizard vector. Also, bump the module's ref count so it can't be unloaded before the sorcery instance is destroyed. More... | |
static void | instance_destroying_observer (const char *name, struct ast_sorcery *sorcery) |
When the res_pjsip instance is destroyed, remove the observer and unref the module. This should then allow this module to unload cleanly. More... | |
static int | is_one_of (const char *needle, const char *haystack[]) |
static int | is_variable_true (struct ast_variable *vars, const char *name) |
Finds the last variable in a list and tests it. More... | |
static int | load_module (void) |
static void | object_type_loaded_observer (const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded) |
Called after an object type is loaded/reloaded. More... | |
static void | object_type_registered_observer (const char *name, struct ast_sorcery *sorcery, const char *object_type) |
When each object type is registered, map a memory wizard to it. More... | |
static int | reload_module (void) |
static int | unload_module (void) |
static int | variable_list_append (struct ast_variable **existing, const char *name, const char *value) |
Appends a variable to the end of an existing list. More... | |
static int | wizard_apply_handler (const struct ast_sorcery *sorcery, struct object_type_wizard *otw, struct ast_category *wiz) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Config Wizard" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .reload = reload_module, .unload = unload_module, .load_pri = AST_MODPRI_REALTIME_DRIVER, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | config_wizard_cli [] |
static const struct ast_sorcery_global_observer | global_observer |
struct ast_sorcery_instance_observer | observer |
PJSIP Configuration Wizard.
Definition in file res_pjsip_config_wizard.c.
#define BASE_REGISTRAR "res_pjsip_config_wizard" |
Definition at line 276 of file res_pjsip_config_wizard.c.
#define MAX_ID_SUFFIX 20 |
Defines the maximum number of characters that can be added to a wizard id.
Definition at line 274 of file res_pjsip_config_wizard.c.
#define OTW_DELETE_CB | ( | otw | ) |
Appends a variable to the end of an existing list. On failure, cause the calling function to return -1.
Definition at line 373 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1364 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1364 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 420 of file res_pjsip_config_wizard.c.
References app, ast_add_extension2_nolock(), ast_context_remove_extension2(), ast_free, ast_free_ptr(), ast_get_context_name(), ast_get_extension_app(), ast_get_extension_app_data(), ast_strdup, ast_strdupa, ast_strlen_zero(), BASE_REGISTRAR, voicemailpwcheck::context, context_name, ast_exten::data, E_MATCH, ast_exten::exten, NULL, paren, pbx_find_extension(), priority, and pbx_find_info::stacklen.
Referenced by add_hints().
|
static |
Definition at line 482 of file res_pjsip_config_wizard.c.
References add_extension(), ast_alloca, ast_assert, ast_context_find_or_create(), ast_context_remove_extension2(), ast_log, ast_strlen_zero(), ast_unlock_context(), ast_unlock_contexts(), ast_wrlock_context(), ast_wrlock_contexts(), BASE_REGISTRAR, voicemailpwcheck::context, LOG_ERROR, NULL, and PRIORITY_HINT.
Referenced by handle_endpoint().
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1364 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 289 of file res_pjsip_config_wizard.c.
References NULL.
|
static |
Creates a sorcery object and applies a variable list.
Definition at line 331 of file res_pjsip_config_wizard.c.
References ao2_ref, ast_log, ast_sorcery_alloc(), ast_sorcery_objectset_apply(), LOG_ERROR, NULL, sorcery, and type.
Referenced by handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
|
static |
Definition at line 825 of file res_pjsip_config_wizard.c.
References ast_sorcery_object_get_extended(), ast_strlen_zero(), CMP_MATCH, voicemailpwcheck::context, ast_sorcery_wizard::delete, delete_extens(), object_type_wizard::object_type, object_type_wizard::sorcery, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by handle_registrations(), and object_type_loaded_observer().
|
static |
Definition at line 405 of file res_pjsip_config_wizard.c.
References ast_context_remove_extension(), BASE_REGISTRAR, voicemailpwcheck::context, E_MATCH, NULL, pbx_find_extension(), PRIORITY_HINT, and pbx_find_info::stacklen.
Referenced by delete_existing_cb(), and handle_endpoint().
|
static |
Finds the otw for the object type.
Definition at line 313 of file res_pjsip_config_wizard.c.
References AST_VECTOR_GET, AST_VECTOR_RW_RDLOCK, AST_VECTOR_RW_UNLOCK, AST_VECTOR_SIZE, NULL, and object_type_wizard::object_type.
Referenced by object_type_loaded_observer().
|
static |
We need to strip off the prefix from the name of each variable so they're suitable for objectset_apply. I.E. will transform outbound_auth/username to username.
Definition at line 386 of file res_pjsip_config_wizard.c.
References ast_begins_with(), ast_variables_destroy(), ast_variable::name, ast_variable::next, NULL, prefix, ast_variable::value, and variable_list_append().
Referenced by handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
|
static |
Definition at line 601 of file res_pjsip_config_wizard.c.
References ao2_ref, ast_category_first(), ast_category_get_name(), ast_free, ast_str_buffer(), ast_str_create, ast_str_substitute_variables_varshead(), ast_strlen_zero(), ast_var_assign, ast_var_list_create(), ast_var_list_destroy(), AST_VAR_LIST_INSERT_TAIL(), ast_variable_find_last_in_list(), ast_variables_destroy(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sorcery_wizard::create, create_object(), get_object_variables(), NULL, RAII_VAR, sorcery, ast_sorcery_wizard::update, var, variable_list_append(), variable_list_append_return, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
Definition at line 531 of file res_pjsip_config_wizard.c.
References ao2_ref, ast_category_first(), ast_category_get_name(), ast_log, ast_variable_find_last_in_list(), ast_variables_destroy(), ast_sorcery_wizard::create, create_object(), ast_sorcery_wizard::delete, get_object_variables(), is_variable_true(), LOG_ERROR, MAX_ID_SUFFIX, NULL, prefix, RAII_VAR, ast_sorcery_wizard::retrieve_id, sorcery, ast_sorcery_wizard::update, variable_list_append_return, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by handle_auths().
|
static |
Definition at line 589 of file res_pjsip_config_wizard.c.
References handle_auth(), and sorcery.
Referenced by wizard_apply_handler().
|
static |
Definition at line 659 of file res_pjsip_config_wizard.c.
References add_hints(), ao2_ref, ast_category_first(), ast_category_get_name(), ast_strlen_zero(), ast_variable_find_last_in_list(), ast_variables_destroy(), ast_sorcery_wizard::create, create_object(), delete_extens(), get_object_variables(), is_variable_true(), MAX_ID_SUFFIX, NULL, RAII_VAR, sorcery, ast_sorcery_wizard::update, variable_list_append_return, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
Definition at line 1208 of file res_pjsip_config_wizard.c.
References a, ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), ast_copy_string(), ast_log, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_object_get_id(), ast_sorcery_objectset_create, ast_sorcery_retrieve_by_fields(), ast_strlen_zero(), ast_variable_find_in_list(), ast_variables_destroy(), AST_VECTOR_GET, AST_VECTOR_RW_RDLOCK, AST_VECTOR_RW_UNLOCK, AST_VECTOR_SIZE, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, container, errno, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, object_type_wizard::object_type, sorcery, ast_cli_entry::usage, and ast_variable::value.
|
static |
Definition at line 729 of file res_pjsip_config_wizard.c.
References ao2_ref, ast_category_first(), ast_category_get_name(), ast_log, ast_variable_find_last_in_list(), ast_variables_destroy(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sorcery_wizard::create, create_object(), ast_sorcery_wizard::delete, get_object_variables(), is_variable_true(), LOG_ERROR, MAX_ID_SUFFIX, NULL, RAII_VAR, ast_sorcery_wizard::retrieve_id, sorcery, ast_sorcery_wizard::update, variable_list_append_return, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
Definition at line 783 of file res_pjsip_config_wizard.c.
References ao2_ref, ast_category_first(), ast_category_get_name(), ast_log, ast_variable_find_last_in_list(), ast_variables_destroy(), ast_sorcery_wizard::create, create_object(), ast_sorcery_wizard::delete, get_object_variables(), is_variable_true(), LOG_ERROR, MAX_ID_SUFFIX, NULL, RAII_VAR, ast_sorcery_wizard::retrieve_id, sorcery, ast_sorcery_wizard::update, variable_list_append_return, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
Definition at line 842 of file res_pjsip_config_wizard.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_callback, ao2_cleanup, ao2_container_alloc_list, ao2_container_count(), ao2_ref, ast_category_first(), ast_category_get_name(), ast_free, ast_log, ast_sorcery_object_id_compare(), ast_str_buffer(), ast_str_create, ast_str_reset(), ast_str_substitute_variables_varshead(), ast_strlen_zero(), ast_var_assign, ast_var_list_create(), ast_var_list_destroy(), AST_VAR_LIST_INSERT_TAIL(), ast_variable_find_last_in_list(), ast_variable_new, ast_variables_destroy(), ast_variables_dup(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sorcery_wizard::create, create_object(), delete_existing_cb(), get_object_variables(), id, is_variable_true(), LOG_ERROR, MAX_ID_SUFFIX, NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_SEARCH_KEY, OBJ_UNLINK, RAII_VAR, ast_sorcery_wizard::retrieve_multiple, rh, sorcery, ast_sorcery_wizard::update, variable_list_append_return, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
When the res_pjsip instance is created, add an observer to it and initialize the wizard vector. Also, bump the module's ref count so it can't be unloaded before the sorcery instance is destroyed.
Definition at line 1186 of file res_pjsip_config_wizard.c.
References ast_module_ref, ast_sorcery_instance_observer_add(), name, observer, ast_module_info::self, and sorcery.
|
static |
When the res_pjsip instance is destroyed, remove the observer and unref the module. This should then allow this module to unload cleanly.
Definition at line 1198 of file res_pjsip_config_wizard.c.
References ast_module_unref, ast_sorcery_instance_observer_remove(), name, observer, ast_module_info::self, and sorcery.
|
static |
Definition at line 300 of file res_pjsip_config_wizard.c.
Referenced by object_type_registered_observer().
|
static |
Finds the last variable in a list and tests it.
Definition at line 351 of file res_pjsip_config_wizard.c.
References ast_true(), ast_variable_find_last_in_list(), and name.
Referenced by handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
|
static |
Definition at line 1311 of file res_pjsip_config_wizard.c.
References ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_SUCCESS, ast_module_ref, ast_sip_get_sorcery(), ast_sorcery_get_object_type(), ast_sorcery_global_observer_add(), ast_sorcery_instance_observer_add(), ast_sorcery_reload(), AST_VECTOR_RW_INIT, config_wizard_cli, global_observer, object_type_registered_observer(), observer, and ast_module_info::self.
|
static |
Called after an object type is loaded/reloaded.
Definition at line 1047 of file res_pjsip_config_wizard.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_callback, ao2_cleanup, ao2_container_alloc_list, ao2_container_count(), ast_category_browse_filtered(), ast_category_delete(), ast_category_first(), ast_category_get(), ast_category_get_name(), ast_config_destroy(), ast_config_load2(), ast_debug, ast_log, ast_variable_lists_match(), ast_variable_new, ast_variables_destroy(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, delete_existing_cb(), find_wizard(), ast_flags::flags, object_type_wizard::last_config, LOG_ERROR, NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, RAII_VAR, ast_sorcery_wizard::retrieve_multiple, sorcery, object_type_wizard::wizard, wizard_apply_handler(), and object_type_wizard::wizard_data.
|
static |
When each object type is registered, map a memory wizard to it.
Definition at line 1146 of file res_pjsip_config_wizard.c.
References ast_debug, ast_free, ast_log, ast_malloc, AST_SORCERY_APPLY_SUCCESS, ast_sorcery_object_type_apply_wizard, AST_SORCERY_WIZARD_APPLY_ALLOW_DUPLICATE, AST_SORCERY_WIZARD_APPLY_READONLY, AST_VECTOR_APPEND, AST_VECTOR_RW_UNLOCK, AST_VECTOR_RW_WRLOCK, is_one_of(), object_type_wizard::last_config, LOG_ERROR, NULL, object_type_wizard::object_type, object_type_wizard::sorcery, sorcery, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by load_module().
|
static |
Definition at line 1305 of file res_pjsip_config_wizard.c.
References ast_sip_get_sorcery(), and ast_sorcery_reload().
|
static |
Definition at line 1348 of file res_pjsip_config_wizard.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_sorcery_global_observer_remove(), AST_VECTOR_REMOVE_ALL_CMP_UNORDERED, AST_VECTOR_RW_FREE, config_wizard_cli, global_observer, NOT_EQUALS, NULL, and OTW_DELETE_CB.
|
static |
Appends a variable to the end of an existing list.
Definition at line 357 of file res_pjsip_config_wizard.c.
References ast_log, ast_variable_list_append, ast_variable_new, LOG_ERROR, name, and value.
Referenced by get_object_variables(), and handle_aor().
|
static |
Definition at line 979 of file res_pjsip_config_wizard.c.
References ast_category_first(), ast_debug, ast_free, ast_strdup, ast_strdupa, ast_strlen_zero(), ast_strsep(), AST_STRSEP_TRIM, ast_variable_find_last_in_list(), AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_INIT, AST_VECTOR_REMOVE_ALL_CMP_UNORDERED, handle_aor(), handle_auths(), handle_endpoint(), handle_identify(), handle_phoneprov(), handle_registrations(), NOT_EQUALS, NULL, object_type_wizard::object_type, and sorcery.
Referenced by object_type_loaded_observer().
|
static |
Definition at line 1364 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1364 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1301 of file res_pjsip_config_wizard.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 1036 of file res_pjsip_config_wizard.c.
Referenced by load_module(), and unload_module().
struct ast_sorcery_instance_observer observer |
Definition at line 1041 of file res_pjsip_config_wizard.c.
Referenced by ast_mwi_add_observer(), ast_mwi_remove_observer(), ast_sorcery_observer_add(), instance_created_observer(), instance_destroying_observer(), load_module(), sorcery_generic_observer_remove(), sorcery_observer_notify_create(), sorcery_observer_notify_delete(), sorcery_observer_notify_loaded(), sorcery_observer_notify_update(), sorcery_observer_remove(), stasis_state_add_observer(), and stasis_state_remove_observer().