Asterisk - The Open Source Telephony Project GIT-master-0bf3178
Macros | Typedefs | Enumerations | Functions
phoneprov.h File Reference
#include "asterisk.h"
#include "asterisk/inline_api.h"
Include dependency graph for phoneprov.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _ASTERISK_PHONEPROV_H
 

Typedefs

typedef int(* ast_phoneprov_load_users_cb) (void)
 Causes the provider to load its users. More...
 

Enumerations

enum  ast_phoneprov_std_variables {
  AST_PHONEPROV_STD_MAC = 0 , AST_PHONEPROV_STD_PROFILE , AST_PHONEPROV_STD_USERNAME , AST_PHONEPROV_STD_DISPLAY_NAME ,
  AST_PHONEPROV_STD_SECRET , AST_PHONEPROV_STD_LABEL , AST_PHONEPROV_STD_CALLERID , AST_PHONEPROV_STD_TIMEZONE ,
  AST_PHONEPROV_STD_LINENUMBER , AST_PHONEPROV_STD_LINEKEYS , AST_PHONEPROV_STD_SERVER , AST_PHONEPROV_STD_SERVER_PORT ,
  AST_PHONEPROV_STD_SERVER_IFACE , AST_PHONEPROV_STD_VOICEMAIL_EXTEN , AST_PHONEPROV_STD_EXTENSION_LENGTH , AST_PHONEPROV_STD_TZOFFSET ,
  AST_PHONEPROV_STD_DST_ENABLE , AST_PHONEPROV_STD_DST_START_MONTH , AST_PHONEPROV_STD_DST_START_MDAY , AST_PHONEPROV_STD_DST_START_HOUR ,
  AST_PHONEPROV_STD_DST_END_MONTH , AST_PHONEPROV_STD_DST_END_MDAY , AST_PHONEPROV_STD_DST_END_HOUR , AST_PHONEPROV_STD_VAR_LIST_LENGTH
}
 

Functions

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...
 

Macro Definition Documentation

◆ _ASTERISK_PHONEPROV_H

#define _ASTERISK_PHONEPROV_H

Definition at line 24 of file phoneprov.h.

Typedef Documentation

◆ ast_phoneprov_load_users_cb

typedef int(* ast_phoneprov_load_users_cb) (void)

Causes the provider to load its users.

This function is called by phoneprov in response to a ast_phoneprov_provider_register call by the provider. It may also be called by phoneprov to request a reload in response to the res_phoneprov module being reloaded.

Return values
0if successful
non-zeroif failure

Definition at line 75 of file phoneprov.h.

Enumeration Type Documentation

◆ ast_phoneprov_std_variables

Enumerator
AST_PHONEPROV_STD_MAC 
AST_PHONEPROV_STD_PROFILE 
AST_PHONEPROV_STD_USERNAME 
AST_PHONEPROV_STD_DISPLAY_NAME 
AST_PHONEPROV_STD_SECRET 
AST_PHONEPROV_STD_LABEL 
AST_PHONEPROV_STD_CALLERID 
AST_PHONEPROV_STD_TIMEZONE 
AST_PHONEPROV_STD_LINENUMBER 
AST_PHONEPROV_STD_LINEKEYS 
AST_PHONEPROV_STD_SERVER 
AST_PHONEPROV_STD_SERVER_PORT 
AST_PHONEPROV_STD_SERVER_IFACE 
AST_PHONEPROV_STD_VOICEMAIL_EXTEN 
AST_PHONEPROV_STD_EXTENSION_LENGTH 
AST_PHONEPROV_STD_TZOFFSET 
AST_PHONEPROV_STD_DST_ENABLE 
AST_PHONEPROV_STD_DST_START_MONTH 
AST_PHONEPROV_STD_DST_START_MDAY 
AST_PHONEPROV_STD_DST_START_HOUR 
AST_PHONEPROV_STD_DST_END_MONTH 
AST_PHONEPROV_STD_DST_END_MDAY 
AST_PHONEPROV_STD_DST_END_HOUR 
AST_PHONEPROV_STD_VAR_LIST_LENGTH 

Definition at line 29 of file phoneprov.h.

29 {
53 AST_PHONEPROV_STD_VAR_LIST_LENGTH, /* This entry must always be the last in the list */
54};
@ AST_PHONEPROV_STD_DST_END_MDAY
Definition: phoneprov.h:51
@ AST_PHONEPROV_STD_SERVER_IFACE
Definition: phoneprov.h:42
@ AST_PHONEPROV_STD_VAR_LIST_LENGTH
Definition: phoneprov.h:53
@ AST_PHONEPROV_STD_SERVER_PORT
Definition: phoneprov.h:41
@ AST_PHONEPROV_STD_DST_START_MDAY
Definition: phoneprov.h:48
@ AST_PHONEPROV_STD_MAC
Definition: phoneprov.h:30
@ AST_PHONEPROV_STD_CALLERID
Definition: phoneprov.h:36
@ AST_PHONEPROV_STD_DST_START_MONTH
Definition: phoneprov.h:47
@ AST_PHONEPROV_STD_TZOFFSET
Definition: phoneprov.h:45
@ AST_PHONEPROV_STD_USERNAME
Definition: phoneprov.h:32
@ AST_PHONEPROV_STD_DST_END_MONTH
Definition: phoneprov.h:50
@ AST_PHONEPROV_STD_LINENUMBER
Definition: phoneprov.h:38
@ AST_PHONEPROV_STD_TIMEZONE
Definition: phoneprov.h:37
@ AST_PHONEPROV_STD_SERVER
Definition: phoneprov.h:40
@ AST_PHONEPROV_STD_LABEL
Definition: phoneprov.h:35
@ AST_PHONEPROV_STD_PROFILE
Definition: phoneprov.h:31
@ AST_PHONEPROV_STD_EXTENSION_LENGTH
Definition: phoneprov.h:44
@ AST_PHONEPROV_STD_DST_END_HOUR
Definition: phoneprov.h:52
@ AST_PHONEPROV_STD_DST_ENABLE
Definition: phoneprov.h:46
@ AST_PHONEPROV_STD_DISPLAY_NAME
Definition: phoneprov.h:33
@ AST_PHONEPROV_STD_SECRET
Definition: phoneprov.h:34
@ AST_PHONEPROV_STD_DST_START_HOUR
Definition: phoneprov.h:49
@ AST_PHONEPROV_STD_VOICEMAIL_EXTEN
Definition: phoneprov.h:43
@ AST_PHONEPROV_STD_LINEKEYS
Definition: phoneprov.h:39

Function Documentation

◆ ast_phoneprov_add_extension()

int ast_phoneprov_add_extension ( char *  provider_name,
struct varshead vars 
)

Adds an extension.

Parameters
provider_nameThe name of the provider
varsAn 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.
Return values
0if successful
non-zeroif failure

Definition at line 1633 of file res_phoneprov.c.

1634{
1636 RAII_VAR(struct user *, user, NULL, ao2_cleanup);
1637 RAII_VAR(struct phone_profile *, profile, NULL, ao2_cleanup);
1638 struct extension *exten;
1639 char *profile_name;
1640 char *mac;
1641 char *username;
1642
1643 if (ast_strlen_zero(provider_name)) {
1644 ast_log(LOG_ERROR, "Provider name can't be empty.\n");
1645 return -1;
1646 }
1647 if (!vars) {
1648 ast_log(LOG_ERROR, "Variable list can't be empty.\n");
1649 return -1;
1650 }
1651
1653 if (!username) {
1654 ast_log(LOG_ERROR, "Extension name can't be empty.\n");
1655 return -1;
1656 }
1657
1659 if (!mac) {
1660 ast_log(LOG_ERROR, "MAC Address can't be empty.\n");
1661 return -1;
1662 }
1663
1664 provider = find_provider(provider_name);
1665 if (!provider) {
1666 ast_log(LOG_ERROR, "Provider '%s' wasn't found in the registry.\n", provider_name);
1667 return -1;
1668 }
1669
1670 profile_name = ast_var_find(vars,
1672 if (!profile_name) {
1673 ast_log(LOG_ERROR, "No profile could be found for user '%s' - skipping.\n", username);
1674 return -1;
1675 }
1676 if (!(profile = find_profile(profile_name))) {
1677 ast_log(LOG_ERROR, "Could not look up profile '%s' - skipping.\n", profile_name);
1678 return -1;
1679 }
1680
1681 if (!(user = find_user(mac))) {
1682
1683 if (!(user = build_user(mac, profile, provider_name))) {
1684 ast_log(LOG_ERROR, "Could not create user for '%s' - skipping\n", mac);
1685 return -1;
1686 }
1687
1688 if (!(exten = build_extension(username, vars))) {
1689 ast_log(LOG_ERROR, "Could not create extension for '%s' - skipping\n", user->macaddress);
1690 return -1;
1691 }
1692
1693 if (add_user_extension(user, exten)) {
1694 ast_log(LOG_WARNING, "Could not add extension '%s' to user '%s'\n", exten->name, user->macaddress);
1695 exten = delete_extension(exten);
1696 return -1;
1697 }
1698
1699 if (build_user_routes(user)) {
1700 ast_log(LOG_WARNING, "Could not create http routes for '%s' - skipping\n", user->macaddress);
1701 return -1;
1702 }
1704
1705 } else {
1706 if (strcmp(provider_name, user->provider_name)) {
1707 ast_log(LOG_ERROR, "MAC address '%s' was already added by provider '%s' - skipping\n", user->macaddress, user->provider_name);
1708 return -1;
1709 }
1710
1711 if (!(exten = build_extension(username, vars))) {
1712 ast_log(LOG_ERROR, "Could not create extension for '%s' - skipping\n", user->macaddress);
1713 return -1;
1714 }
1715
1716 if (add_user_extension(user, exten)) {
1717 ast_log(LOG_WARNING, "Could not add extension '%s' to user '%s'\n", exten->name, user->macaddress);
1718 exten = delete_extension(exten);
1719 return -1;
1720 }
1721 }
1722
1723 return 0;
1724}
#define ast_log
Definition: astobj2.c:42
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
static struct prometheus_metrics_provider provider
Definition: bridges.c:201
char * ast_var_find(const struct varshead *head, const char *name)
Definition: chanvars.c:85
#define LOG_ERROR
#define LOG_WARNING
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.
static struct user * find_user(const char *macaddress)
Return a user looked up by name.
static struct phone_profile * find_profile(const char *name)
Return a phone profile looked up by name.
static struct phoneprov_provider * find_provider(char *name)
static int build_user_routes(struct user *user)
Add an http route for dynamic files attached to the profile of the user.
static const char * variable_lookup[]
static struct extension * delete_extension(struct extension *exten)
static int add_user_extension(struct user *user, struct extension *exten)
Add an extension to a user ordered by index/linenumber.
static struct extension * build_extension(const char *name, struct varshead *vars)
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
structure to hold extensions
const ast_string_field name
structure to hold phone profiles read from phoneprov.conf
structure to hold config providers
structure to hold users read from users.conf
const ast_string_field macaddress
const ast_string_field provider_name
list of users found in the config file
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References add_user_extension(), ao2_cleanup, ao2_link, ast_log, AST_PHONEPROV_STD_MAC, AST_PHONEPROV_STD_PROFILE, AST_PHONEPROV_STD_USERNAME, ast_strlen_zero(), ast_var_find(), build_extension(), build_user(), build_user_routes(), delete_extension(), find_profile(), find_provider(), find_user(), LOG_ERROR, LOG_WARNING, user::macaddress, extension::name, NULL, user::profile, provider, user::provider_name, RAII_VAR, and variable_lookup.

Referenced by load_users(), and users_apply_handler().

◆ ast_phoneprov_delete_extension()

void ast_phoneprov_delete_extension ( char *  provider_name,
char *  macaddress 
)

Deletes an extension.

Parameters
provider_nameThe name of the provider
macaddressThe mac address of the extension

Definition at line 1604 of file res_phoneprov.c.

1605{
1606 if (!users) {
1607 return;
1608 }
1609
1611 extension_delete_cb, macaddress, provider_name);
1612}
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1723
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_UNLINK
Definition: astobj2.h:1039
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
static int extension_delete_cb(void *obj, void *arg, void *data, int flags)

References ao2_callback_data, extension_delete_cb(), user::macaddress, OBJ_MULTIPLE, OBJ_NODATA, OBJ_SEARCH_KEY, OBJ_UNLINK, and user::provider_name.

Referenced by phoneprov_destroy().

◆ ast_phoneprov_delete_extensions()

void ast_phoneprov_delete_extensions ( char *  provider_name)

Deletes all extensions for this provider.

Parameters
provider_nameThe name of the provider

Definition at line 1614 of file res_phoneprov.c.

1615{
1616 if (!users) {
1617 return;
1618 }
1619
1621}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
static int extensions_delete_cb(void *obj, void *arg, int flags)

References ao2_callback, extensions_delete_cb(), OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, and user::provider_name.

Referenced by ast_phoneprov_provider_unregister().

◆ ast_phoneprov_provider_register()

int ast_phoneprov_provider_register ( char *  provider_name,
ast_phoneprov_load_users_cb  load_users 
)

Registers a config provider to phoneprov.

Parameters
provider_nameThe name of the provider
load_usersCallback that gathers user variables then loads them by calling ast_phoneprov_add_extension once for each extension.
Return values
0if successful
non-zeroif failure

Definition at line 1533 of file res_phoneprov.c.

1535{
1537
1539 ast_log(LOG_ERROR, "Provider name can't be empty.\n");
1540 return -1;
1541 }
1542
1543 if (!providers) {
1544 ast_log(LOG_WARNING, "Provider '%s' cannot be registered: res_phoneprov not loaded.\n", provider_name);
1545 return -1;
1546 }
1547
1549 if (provider) {
1550 ast_log(LOG_ERROR, "There is already a provider registered named '%s'.\n", provider_name);
1551 ao2_ref(provider, -1);
1552 return -1;
1553 }
1554
1556 if (!provider) {
1557 ast_log(LOG_ERROR, "Unable to allocate sufficient memory for provider '%s'.\n", provider_name);
1558 return -1;
1559 }
1560
1562 ao2_ref(provider, -1);
1563 ast_log(LOG_ERROR, "Unable to allocate sufficient memory for provider '%s' stringfields.\n", provider_name);
1564 return -1;
1565 }
1566
1568 provider->load_users = load_users;
1569
1571 ao2_ref(provider, -1);
1572
1573 if (provider->load_users()) {
1574 ast_log(LOG_ERROR, "Unable to load provider '%s' users. Register aborted.\n", provider_name);
1576 return -1;
1577 }
1578
1579 return 0;
1580}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static void provider_destructor(void *obj)
void ast_phoneprov_provider_unregister(char *provider_name)
Unegisters a config provider from phoneprov and frees its resources.
static int load_users(void)
struct ao2_container * providers
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
const ast_string_field provider_name

References ao2_alloc, ao2_link, ao2_ref, ast_log, ast_phoneprov_provider_unregister(), ast_string_field_init, ast_string_field_set, ast_strlen_zero(), find_provider(), load_users(), LOG_ERROR, LOG_WARNING, provider, provider_destructor(), phoneprov_provider::provider_name, and providers.

Referenced by load_module(), and reload_module().

◆ ast_phoneprov_provider_unregister()

void ast_phoneprov_provider_unregister ( char *  provider_name)

Unegisters a config provider from phoneprov and frees its resources.

Parameters
provider_nameThe name of the provider

Definition at line 1623 of file res_phoneprov.c.

1624{
1625 if (!providers) {
1626 return;
1627 }
1628
1629 ast_phoneprov_delete_extensions(provider_name);
1631}
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
void ast_phoneprov_delete_extensions(char *provider_name)
Deletes all extensions for this provider.

References ao2_find, ast_phoneprov_delete_extensions(), OBJ_NODATA, OBJ_SEARCH_KEY, OBJ_UNLINK, user::provider_name, and providers.

Referenced by ast_phoneprov_provider_register(), reload_module(), and unload_module().

◆ ast_phoneprov_std_variable_lookup()

const char * ast_phoneprov_std_variable_lookup ( enum ast_phoneprov_std_variables  var)

Returns the string respresentation of a phoneprov standard variable.

Parameters
varOne of enum ast_phoneprov_std_variables
Returns
The string representation or NULL if not found.

Definition at line 1524 of file res_phoneprov.c.

1525{
1527 return NULL;
1528 }
1529
1530 return variable_lookup[var];
1531}
#define var
Definition: ast_expr2f.c:605

References AST_PHONEPROV_STD_VAR_LIST_LENGTH, NULL, var, and variable_lookup.

Referenced by load_endpoint(), and users_apply_handler().