Asterisk - The Open Source Telephony Project
18.5.0
|
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... | |
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) |
AST_VECTOR (string_vector, char *) | |
A generic char * vector definition. More... | |
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 | 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) |
static void | wizard_mapped_observer (const char *name, struct ast_sorcery *sorcery, const char *object_type, struct ast_sorcery_wizard *wizard, const char *wizard_args, void *wizard_data) |
When each wizard is mapped, save it off to the vector. More... | |
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_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 278 of file res_pjsip_config_wizard.c.
Referenced by add_extension(), add_hints(), and delete_extens().
#define MAX_ID_SUFFIX 20 |
Defines the maximum number of characters that can be added to a wizard id.
Definition at line 276 of file res_pjsip_config_wizard.c.
Referenced by handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
Referenced by unload_module(), and wizard_apply_handler().
#define OTW_DELETE_CB | ( | otw | ) |
Referenced by unload_module().
Appends a variable to the end of an existing list. On failure, cause the calling function to return -1.
Definition at line 375 of file res_pjsip_config_wizard.c.
Referenced by handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
|
static |
Definition at line 1351 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1351 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 422 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, context_name, ast_exten::data, E_MATCH, NULL, paren, pbx_find_extension(), and pbx_find_info::stacklen.
Referenced by add_hints().
|
static |
Definition at line 484 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, LOG_ERROR, NULL, and PRIORITY_HINT.
Referenced by handle_endpoint().
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1351 of file res_pjsip_config_wizard.c.
AST_VECTOR | ( | string_vector | , |
char * | |||
) |
A generic char * vector definition.
|
static |
Definition at line 291 of file res_pjsip_config_wizard.c.
References NULL.
|
static |
Creates a sorcery object and applies a variable list.
Definition at line 333 of file res_pjsip_config_wizard.c.
References ao2_ref, ast_log, ast_sorcery_alloc(), ast_sorcery_objectset_apply(), LOG_ERROR, and NULL.
Referenced by handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
|
static |
Definition at line 837 of file res_pjsip_config_wizard.c.
References ast_sorcery_object_get_extended(), ast_strlen_zero, CMP_MATCH, context, ast_sorcery_wizard::delete, delete_extens(), exten, 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 407 of file res_pjsip_config_wizard.c.
References ast_context_remove_extension(), BASE_REGISTRAR, 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 315 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 388 of file res_pjsip_config_wizard.c.
References ast_begins_with(), ast_variables_destroy(), ast_variable::name, ast_variable::next, NULL, 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 603 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, 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 533 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, 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 591 of file res_pjsip_config_wizard.c.
References handle_auth().
Referenced by wizard_apply_handler().
|
static |
Definition at line 661 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, 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 1230 of file res_pjsip_config_wizard.c.
References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_args::argc, ast_cli_args::argv, 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, ast_cli_args::fd, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, object_type_wizard::object_type, object_type_wizard::sorcery, ast_cli_entry::usage, and ast_variable::value.
|
static |
Definition at line 731 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(), host, is_variable_true(), LOG_ERROR, MAX_ID_SUFFIX, NULL, RAII_VAR, ast_sorcery_wizard::retrieve_id, 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 795 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, 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 854 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, 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 1208 of file res_pjsip_config_wizard.c.
References ast_module_ref, ast_sorcery_instance_observer_add(), and ast_module_info::self.
Referenced by wizard_apply_handler().
|
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 1220 of file res_pjsip_config_wizard.c.
References ast_module_unref, ast_sorcery_instance_observer_remove(), and ast_module_info::self.
Referenced by wizard_apply_handler().
|
static |
Definition at line 302 of file res_pjsip_config_wizard.c.
Referenced by object_type_registered_observer(), and wizard_mapped_observer().
|
static |
Finds the last variable in a list and tests it.
Definition at line 353 of file res_pjsip_config_wizard.c.
References ast_true(), and ast_variable_find_last_in_list().
Referenced by handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), and handle_registrations().
|
static |
Definition at line 1327 of file res_pjsip_config_wizard.c.
References ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_SUCCESS, ast_sorcery_global_observer_add(), and AST_VECTOR_RW_INIT.
Referenced by unload_module().
|
static |
Called after an object type is loaded/reloaded.
Definition at line 1063 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, object_type_wizard::wizard, wizard_apply_handler(), and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
When each object type is registered, map a memory wizard to it.
Definition at line 1196 of file res_pjsip_config_wizard.c.
References ast_sorcery_apply_wizard_mapping, and is_one_of().
Referenced by wizard_apply_handler().
|
static |
Definition at line 1336 of file res_pjsip_config_wizard.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_REALTIME_DRIVER, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_sorcery_global_observer_remove(), AST_VECTOR_REMOVE_ALL_CMP_UNORDERED, AST_VECTOR_RW_FREE, ASTERISK_GPL_KEY, load_module(), NOT_EQUALS, NULL, and OTW_DELETE_CB.
|
static |
Appends a variable to the end of an existing list.
Definition at line 359 of file res_pjsip_config_wizard.c.
References ast_log, ast_variable_list_append, ast_variable_new, and LOG_ERROR.
Referenced by get_object_variables(), and handle_aor().
|
static |
Definition at line 991 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(), host, instance_created_observer(), instance_destroying_observer(), name, NOT_EQUALS, NULL, object_type_wizard::object_type, object_type_loaded_observer(), object_type_registered_observer(), object_type_wizard::sorcery, object_type_wizard::wizard, object_type_wizard::wizard_data, and wizard_mapped_observer().
Referenced by object_type_loaded_observer().
|
static |
When each wizard is mapped, save it off to the vector.
Definition at line 1162 of file res_pjsip_config_wizard.c.
References ast_debug, ast_free, ast_malloc, AST_VECTOR_APPEND, AST_VECTOR_RW_UNLOCK, AST_VECTOR_RW_WRLOCK, is_one_of(), object_type_wizard::last_config, NULL, object_type_wizard::object_type, object_type_wizard::sorcery, object_type_wizard::wizard, and object_type_wizard::wizard_data.
Referenced by wizard_apply_handler().
|
static |
Definition at line 1351 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1351 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1323 of file res_pjsip_config_wizard.c.
|
static |
Definition at line 1051 of file res_pjsip_config_wizard.c.
struct ast_sorcery_instance_observer observer |
Definition at line 1056 of file res_pjsip_config_wizard.c.
Referenced by ast_sorcery_observer_add(), sorcery_generic_observer_remove(), sorcery_observer_notify_create(), sorcery_observer_notify_delete(), sorcery_observer_notify_loaded(), sorcery_observer_notify_update(), and sorcery_observer_remove().