Asterisk - The Open Source Telephony Project
18.5.0
|
Phone provisioning application for the asterisk internal http server. More...
#include "asterisk.h"
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/paths.h"
#include "asterisk/pbx.h"
#include "asterisk/cli.h"
#include "asterisk/module.h"
#include "asterisk/http.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/strings.h"
#include "asterisk/stringfields.h"
#include "asterisk/options.h"
#include "asterisk/config.h"
#include "asterisk/acl.h"
#include "asterisk/astobj2.h"
#include "asterisk/ast_version.h"
#include "asterisk/phoneprov.h"
Go to the source code of this file.
Data Structures | |
struct | extension |
structure to hold extensions More... | |
struct | http_route |
structure to hold http routes (valid URIs, and the files they link to) More... | |
struct | phone_profile |
structure to hold phone profiles read from phoneprov.conf More... | |
struct | phoneprov_file |
structure to hold file data More... | |
struct | phoneprov_provider |
structure to hold config providers More... | |
struct | user |
structure to hold users read from users.conf More... | |
Macros | |
#define | AST_API_MODULE |
#define | MAX_PROFILE_BUCKETS 17 |
#define | MAX_PROVIDER_BUCKETS 17 |
#define | MAX_ROUTE_BUCKETS 563 |
#define | MAX_USER_BUCKETS 563 |
#define | SIMPLE_CMP_FN(fname, stype, field) |
Creates a compare function for a structure string field. More... | |
#define | SIMPLE_HASH_FN(fname, stype, field) |
Creates a hash function for a structure string field. More... | |
#define | VAR_BUF_SIZE 4096 |
Functions | |
static int | add_user_extension (struct user *user, struct extension *exten) |
Add an extension to a user ordered by index/linenumber. More... | |
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,.requires="http",) | |
int | ast_phoneprov_add_extension (char *provider_name, struct varshead *vars) |
Adds an extension. More... | |
void | ast_phoneprov_delete_extension (char *provider_name, char *macaddress) |
Deletes an extension. More... | |
void | ast_phoneprov_delete_extensions (char *provider_name) |
Deletes all extensions for this provider. More... | |
int | ast_phoneprov_provider_register (char *provider_name, ast_phoneprov_load_users_cb load_users) |
Registers a config provider to phoneprov. More... | |
void | ast_phoneprov_provider_unregister (char *provider_name) |
Unegisters a config provider from phoneprov and frees its resources. More... | |
const char * | ast_phoneprov_std_variable_lookup (enum ast_phoneprov_std_variables var) |
Returns the string respresentation of a phoneprov standard variable. More... | |
static struct extension * | build_extension (const char *name, struct varshead *vars) |
static void | build_profile (const char *name, struct ast_variable *v) |
Build a phone profile and add it to the list of phone profiles. More... | |
static void | build_route (struct phoneprov_file *pp_file, struct phone_profile *profile, struct user *user, char *uri) |
Build a route structure and add it to the list of available http routes. More... | |
static struct user * | build_user (const char *mac, struct phone_profile *profile, char *provider_name) |
Build and return a user structure based on gathered config data. More... | |
static int | build_user_routes (struct user *user) |
Add an http route for dynamic files attached to the profile of the user. More... | |
static struct extension * | delete_extension (struct extension *exten) |
static void | delete_file (struct phoneprov_file *file) |
static void | delete_profiles (void) |
Delete all phone profiles, freeing their memory. More... | |
static void | delete_providers (void) |
Delete all providers. More... | |
static void | delete_routes (void) |
Delete all http routes, freeing their memory. More... | |
static void | delete_users (void) |
Delete all users. More... | |
static int | extension_delete_cb (void *obj, void *arg, void *data, int flags) |
static int | extensions_delete_cb (void *obj, void *arg, int flags) |
static struct phone_profile * | find_profile (const char *name) |
Return a phone profile looked up by name. More... | |
static struct phoneprov_provider * | find_provider (char *name) |
static struct user * | find_user (const char *macaddress) |
Return a user looked up by name. More... | |
static struct varshead * | get_defaults (void) |
static char * | handle_show_routes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
CLI command to list static and dynamic routes. More... | |
static int | http_route_cmp_fn (void *obj, void *arg, int flags) |
static int | http_route_hash_fn (const void *obj, const int flags) |
static int | load_common (void) |
static int | load_file (const char *filename, char **ret) |
Read a TEXT file into a string and return the length. More... | |
static int | load_module (void) |
Load the module. More... | |
static int | load_users (void) |
static int | lookup_iface (const char *iface, struct in_addr *address) |
static int | phone_profile_cmp_fn (void *obj, void *arg, int flags) |
static int | phone_profile_hash_fn (const void *obj, const int flags) |
static int | phoneprov_callback (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers) |
Callback that is executed everytime an http request is received by this module. More... | |
static int | pp_each_extension_helper (struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **bufstr, int len) |
A dialplan function that can be used to output a template for each extension attached to a user. More... | |
static int | pp_each_extension_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | pp_each_extension_read2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
static int | pp_each_user_helper (struct ast_channel *chan, char *data, char *buf, struct ast_str **bufstr, int len) |
A dialplan function that can be used to print a string for each phoneprov user. More... | |
static int | pp_each_user_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | pp_each_user_read2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
static void | profile_destructor (void *obj) |
static void | provider_destructor (void *obj) |
static int | reload (void) |
static void | route_destructor (void *obj) |
static int | route_list_cb (void *obj, void *arg, void *data, int flags) |
static int | routes_delete_cb (void *obj, void *arg, int flags) |
static void | set_timezone_variables (struct varshead *headp, const char *zone) |
Set all timezone-related variables based on a zone (i.e. America/New_York) More... | |
static int | unload_module (void) |
static struct phone_profile * | unref_profile (struct phone_profile *prof) |
static struct http_route * | unref_route (struct http_route *route) |
static struct user * | unref_user (struct user *user) |
static int | user_cmp_fn (void *obj, void *arg, int flags) |
static void | user_destructor (void *obj) |
Free all memory associated with a user. More... | |
static int | user_hash_fn (const void *obj, const int flags) |
Variables | |
static struct in_addr | __ourip = { .s_addr = 0x00000000, } |
for use in lookup_iface More... | |
struct ao2_container * | http_routes |
static struct ast_http_uri | phoneprovuri |
static struct ast_cli_entry | pp_cli [] |
static struct ast_custom_function | pp_each_extension_function |
static struct ast_custom_function | pp_each_user_function |
static const char * | pp_general_lookup [] |
static const char * | pp_user_lookup [] |
struct ao2_container * | profiles |
struct ao2_container * | providers |
struct ao2_container * | users |
static const char * | variable_lookup [] |
Phone provisioning application for the asterisk internal http server.
Definition in file res_phoneprov.c.
#define AST_API_MODULE |
Definition at line 45 of file res_phoneprov.c.
#define MAX_PROFILE_BUCKETS 17 |
Definition at line 81 of file res_phoneprov.c.
Referenced by load_module().
#define MAX_PROVIDER_BUCKETS 17 |
Definition at line 80 of file res_phoneprov.c.
Referenced by load_module().
#define MAX_ROUTE_BUCKETS 563 |
Definition at line 82 of file res_phoneprov.c.
Referenced by load_module().
#define MAX_USER_BUCKETS 563 |
Definition at line 83 of file res_phoneprov.c.
Referenced by load_module().
#define SIMPLE_CMP_FN | ( | fname, | |
stype, | |||
field | |||
) |
Creates a compare function for a structure string field.
fname | The name to use for the function |
stype | The structure type |
field | The field in the structure to compare |
SIMPLE_CMP_FN(mystruct, myfield) will produce a function named mystruct_cmp_fn which compares mystruct->myfield.
Definition at line 157 of file res_phoneprov.c.
#define SIMPLE_HASH_FN | ( | fname, | |
stype, | |||
field | |||
) |
Creates a hash function for a structure string field.
fname | The name to use for the function |
stype | The structure type |
field | The field in the structure to hash |
SIMPLE_HASH_FN(mystruct, myfield) will produce a function named mystruct_hash_fn which hashes mystruct->myfield.
Definition at line 128 of file res_phoneprov.c.
#define VAR_BUF_SIZE 4096 |
Definition at line 86 of file res_phoneprov.c.
Add an extension to a user ordered by index/linenumber.
Definition at line 798 of file res_phoneprov.c.
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 , |
||
. | requires = "http" |
||
) |
Referenced by ast_beep_stop(), ast_cel_backend_register(), ast_manager_event_blob_create(), ast_sounds_get_index_for_file(), chan_misdn_log(), do_reload(), find_member_by_queuename_and_interface(), handle_cli_realtime_mysql_status(), handle_cli_realtime_pgsql_status(), load_module(), load_values_config(), ooh323_convert_hangupcause_h323ToAsterisk(), realtime_ldap_status(), reload(), reload_module(), unload_module(), and vm_msg_play().
int ast_phoneprov_add_extension | ( | char * | provider_name, |
struct varshead * | vars | ||
) |
Adds an extension.
provider_name | The name of the provider |
defaults | An ast_vat_t linked list of the extension's variables. The list is automatically cloned and it must contain at least MACADDRESS and USERNAME entries. |
0 | if successful |
non-zero | if failure |
Definition at line 1614 of file res_phoneprov.c.
Referenced by users_apply_handler().
void ast_phoneprov_delete_extension | ( | char * | provider_name, |
char * | macaddress | ||
) |
Deletes an extension.
provider_name | The name of the provider |
macaddress | The mac address of the extension |
Definition at line 1585 of file res_phoneprov.c.
References CMP_MATCH.
Referenced by phoneprov_destroy().
void ast_phoneprov_delete_extensions | ( | char * | provider_name | ) |
Deletes all extensions for this provider.
provider_name | The name of the provider |
Definition at line 1595 of file res_phoneprov.c.
int ast_phoneprov_provider_register | ( | char * | provider_name, |
ast_phoneprov_load_users_cb | load_users | ||
) |
Registers a config provider to phoneprov.
provider_name | The name of the provider |
load_users | Callback that gathers user variables then loads them by calling ast_phoneprov_add_extension once for each extension. |
0 | if successful |
non-zero | if failure |
Definition at line 1514 of file res_phoneprov.c.
References ao2_alloc, ao2_link, ao2_ref, ast_log, ast_string_field_init, ast_string_field_set, ast_strlen_zero, find_provider(), phoneprov_provider::load_users, LOG_ERROR, LOG_WARNING, NULL, provider, provider_destructor(), var, and variable_lookup.
Referenced by load_module(), and reload_module().
void ast_phoneprov_provider_unregister | ( | char * | provider_name | ) |
Unegisters a config provider from phoneprov and frees its resources.
provider_name | The name of the provider |
Definition at line 1604 of file res_phoneprov.c.
References ao2_callback, extensions_delete_cb(), OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.
Referenced by reload_module(), and unload_module().
const char* ast_phoneprov_std_variable_lookup | ( | enum ast_phoneprov_std_variables | var | ) |
Returns the string respresentation of a phoneprov standard variable.
var | One of enum ast_phoneprov_std_variables |
Definition at line 1505 of file res_phoneprov.c.
Referenced by load_endpoint(), and users_apply_handler().
Definition at line 681 of file res_phoneprov.c.
|
static |
Build a phone profile and add it to the list of phone profiles.
name | the name of the profile |
v | ast_variable from parsing phoneprov.conf |
Definition at line 580 of file res_phoneprov.c.
References ao2_alloc, args, AST_APP_ARG, ast_calloc_with_stringfields, AST_DECLARE_APP_ARGS, ast_http_ftype2mtype(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_string_field_build, ast_string_field_init, ast_string_field_set, ast_strip(), ast_strlen_zero, ast_var_assign, ast_var_list_create(), AST_VAR_LIST_INSERT_TAIL(), build_route(), phone_profile::default_mime_type, phone_profile::dynamic_files, format, phoneprov_file::format, phone_profile::headp, phoneprov_file::mime_type, ast_variable::name, ast_variable::next, NULL, profile_destructor(), S_OR, phone_profile::static_files, phone_profile::staticdir, unref_profile(), and ast_variable::value.
|
static |
Build a route structure and add it to the list of available http routes.
pp_file | File to link to the route |
user | User to link to the route (NULL means static route) |
uri | URI of the route |
Definition at line 507 of file res_phoneprov.c.
References ao2_alloc, ao2_link, ast_log, ast_string_field_init, ast_string_field_set, http_route::file, phoneprov_file::format, LOG_ERROR, http_route::profile, route_destructor(), S_OR, unref_route(), user, and http_route::user.
Referenced by build_profile(), and build_user_routes().
|
static |
Build and return a user structure based on gathered config data.
Definition at line 776 of file res_phoneprov.c.
|
static |
Add an http route for dynamic files attached to the profile of the user.
Definition at line 843 of file res_phoneprov.c.
References AST_LIST_FIRST, AST_LIST_TRAVERSE, ast_str_buffer(), ast_str_create, ast_str_substitute_variables_varshead(), build_route(), phone_profile::dynamic_files, user::extensions, phoneprov_file::format, user::profile, and str.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Definition at line 1573 of file res_phoneprov.c.
References CMP_MATCH.
|
static |
Definition at line 1563 of file res_phoneprov.c.
Referenced by ast_phoneprov_provider_unregister().
|
static |
|
static |
Definition at line 367 of file res_phoneprov.c.
Referenced by ast_phoneprov_provider_register().
|
static |
Return a user looked up by name.
Definition at line 727 of file res_phoneprov.c.
References ao2_cleanup, and NULL.
Referenced by pp_each_extension_helper().
|
static |
Definition at line 1191 of file res_phoneprov.c.
References ast_config_destroy(), ast_config_load, ast_inet_ntoa(), ast_log, AST_PHONEPROV_STD_EXTENSION_LENGTH, AST_PHONEPROV_STD_PROFILE, AST_PHONEPROV_STD_SERVER, AST_PHONEPROV_STD_SERVER_IFACE, AST_PHONEPROV_STD_SERVER_PORT, AST_PHONEPROV_STD_VOICEMAIL_EXTEN, ast_var_assign, ast_var_list_create(), ast_var_list_destroy(), AST_VAR_LIST_INSERT_TAIL(), ast_variable_browse(), ast_variable_retrieve(), CONFIG_STATUS_FILEINVALID, LOG_ERROR, LOG_WARNING, lookup_iface(), ast_variable::name, ast_variable::next, NULL, pp_general_lookup, pp_user_lookup, S_OR, value, ast_variable::value, var, and variable_lookup.
|
static |
CLI command to list static and dynamic routes.
Definition at line 1149 of file res_phoneprov.c.
|
static |
|
static |
|
static |
Definition at line 1343 of file res_phoneprov.c.
Referenced by load_module().
|
static |
Read a TEXT file into a string and return the length.
Definition at line 395 of file res_phoneprov.c.
Referenced by make_ari_stubs::main(), and pp_each_extension_helper().
|
static |
Load the module.
Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 1409 of file res_phoneprov.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, ast_custom_function_register, ast_http_uri_link(), ast_log, AST_MODULE_LOAD_DECLINE, ast_phoneprov_provider_register(), error(), http_route_cmp_fn(), http_route_hash_fn(), load_common(), phoneprov_provider::load_users, LOG_ERROR, LOG_WARNING, MAX_PROFILE_BUCKETS, MAX_PROVIDER_BUCKETS, MAX_ROUTE_BUCKETS, MAX_USER_BUCKETS, NULL, phone_profile_hash_fn(), user_cmp_fn(), and user_hash_fn().
|
static |
Definition at line 1273 of file res_phoneprov.c.
|
static |
Definition at line 337 of file res_phoneprov.c.
References __ourip, ast_copy_string(), ast_log, errno, LOG_ERROR, and LOG_WARNING.
Referenced by get_defaults().
|
static |
Definition at line 309 of file res_phoneprov.c.
|
static |
|
static |
Callback that is executed everytime an http request is received by this module.
Definition at line 862 of file res_phoneprov.c.
|
static |
A dialplan function that can be used to output a template for each extension attached to a user.
Definition at line 1054 of file res_phoneprov.c.
References args, AST_APP_ARG, ast_build_string(), ast_config_AST_DATA_DIR, AST_DECLARE_APP_ARGS, ast_free, AST_LIST_TRAVERSE, ast_log, AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_substitute_variables_varshead(), ast_strlen_zero, exten, user::extensions, make_ari_stubs::file, find_user(), extension::headp, len(), load_file(), LOG_WARNING, ast_custom_function::name, PATH_MAX, pp_each_user_read(), pp_each_user_read2(), str, and user.
Referenced by pp_each_extension_read2().
|
static |
Definition at line 1115 of file res_phoneprov.c.
|
static |
Definition at line 1120 of file res_phoneprov.c.
References NULL, and pp_each_extension_helper().
|
static |
A dialplan function that can be used to print a string for each phoneprov user.
Definition at line 997 of file res_phoneprov.c.
Referenced by pp_each_user_read2().
|
static |
|
static |
Definition at line 1042 of file res_phoneprov.c.
References NULL, and pp_each_user_helper().
Referenced by pp_each_extension_helper().
|
static |
Definition at line 544 of file res_phoneprov.c.
References ao2_find, ast_free, AST_LIST_REMOVE_HEAD, ast_var_delete(), delete_file(), phone_profile::dynamic_files, ast_var_t::entries, make_ari_stubs::file, phone_profile::headp, OBJ_SEARCH_KEY, phone_profile::static_files, and var.
Referenced by build_profile().
|
static |
Definition at line 382 of file res_phoneprov.c.
Referenced by ast_phoneprov_provider_register().
|
static |
Definition at line 1462 of file res_phoneprov.c.
|
static |
|
static |
Definition at line 1133 of file res_phoneprov.c.
References ast_cli(), http_route::file, phone_profile::name, http_route::profile, user::provider_name, phoneprov_file::template, http_route::uri, and http_route::user.
|
static |
Definition at line 732 of file res_phoneprov.c.
References ao2_find, user::macaddress, OBJ_SEARCH_KEY, and http_route::user.
|
static |
Set all timezone-related variables based on a zone (i.e. America/New_York)
headp | pointer to list of user variables |
zone | A time zone. NULL sets variables based on timezone of the machine |
Definition at line 431 of file res_phoneprov.c.
References ast_get_dst_info(), ast_localtime(), ast_var_assign, AST_VAR_LIST_INSERT_TAIL(), ast_tm::tm_hour, ast_tm::tm_mday, and ast_tm::tm_mon.
|
static |
Definition at line 1372 of file res_phoneprov.c.
|
static |
Definition at line 531 of file res_phoneprov.c.
Referenced by build_profile(), and user_destructor().
|
static |
Definition at line 719 of file res_phoneprov.c.
|
static |
|
static |
Free all memory associated with a user.
Definition at line 745 of file res_phoneprov.c.
References AST_LIST_REMOVE_HEAD, CMP_MATCH, delete_extension(), exten, user::extensions, user::profile, and unref_profile().
|
static |
|
static |
for use in lookup_iface
Definition at line 263 of file res_phoneprov.c.
Referenced by lookup_iface().
struct ao2_container* http_routes |
Definition at line 330 of file res_phoneprov.c.
|
static |
Definition at line 1182 of file res_phoneprov.c.
|
static |
Definition at line 1178 of file res_phoneprov.c.
|
static |
Definition at line 1125 of file res_phoneprov.c.
|
static |
Definition at line 1047 of file res_phoneprov.c.
|
static |
Definition at line 236 of file res_phoneprov.c.
Referenced by get_defaults().
|
static |
Definition at line 209 of file res_phoneprov.c.
Referenced by get_defaults().
struct ao2_container* profiles |
Definition at line 307 of file res_phoneprov.c.
struct ao2_container* providers |
Definition at line 272 of file res_phoneprov.c.
Referenced by load_module(), prometheus_metrics_provider_register(), reload_module(), and unload_module().
struct ao2_container* users |
Definition at line 318 of file res_phoneprov.c.
Referenced by load_users().
|
static |
Definition at line 182 of file res_phoneprov.c.
Referenced by ast_phoneprov_provider_register(), and get_defaults().