Asterisk - The Open Source Telephony Project  18.5.0
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 };

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
defaultsAn 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 1614 of file res_phoneprov.c.

Referenced by users_apply_handler().

1622 {
1624  RAII_VAR(struct user *, user, NULL, ao2_cleanup);
1625  RAII_VAR(struct phone_profile *, profile, NULL, ao2_cleanup);
1626  struct extension *exten;
1627  char *profile_name;
1628  char *mac;
1629  char *username;
1630 
1631  if (ast_strlen_zero(provider_name)) {
1632  ast_log(LOG_ERROR, "Provider name can't be empty.\n");
1633  return -1;
1634  }
1635  if (!vars) {
1636  ast_log(LOG_ERROR, "Variable list can't be empty.\n");
1637  return -1;
1638  }
1639 
1641  if (!username) {
1642  ast_log(LOG_ERROR, "Extension name can't be empty.\n");
1643  return -1;
1644  }
1645 
1647  if (!mac) {
1648  ast_log(LOG_ERROR, "MAC Address can't be empty.\n");
1649  return -1;
1650  }
1651 
1652  provider = find_provider(provider_name);
1653  if (!provider) {
1654  ast_log(LOG_ERROR, "Provider '%s' wasn't found in the registry.\n", provider_name);
1655  return -1;
1656  }
1657 
1658  profile_name = ast_var_find(vars,
1660  if (!profile_name) {
1661  ast_log(LOG_ERROR, "No profile could be found for user '%s' - skipping.\n", username);
1662  return -1;
1663  }
1664  if (!(profile = find_profile(profile_name))) {
1665  ast_log(LOG_ERROR, "Could not look up profile '%s' - skipping.\n", profile_name);
1666  return -1;
1667  }
1668 
1669  if (!(user = find_user(mac))) {
1670 
1671  if (!(user = build_user(mac, profile, provider_name))) {
1672  ast_log(LOG_ERROR, "Could not create user for '%s' - skipping\n", mac);
1673  return -1;
1674  }
1675 
1676  if (!(exten = build_extension(username, vars))) {
1677  ast_log(LOG_ERROR, "Could not create extension for '%s' - skipping\n", user->macaddress);
1678  return -1;
1679  }
1680 
1681  if (add_user_extension(user, exten)) {
1682  ast_log(LOG_WARNING, "Could not add extension '%s' to user '%s'\n", exten->name, user->macaddress);
1683  exten = delete_extension(exten);
1684  return -1;
1685  }
1686 
1687  if (build_user_routes(user)) {
1688  ast_log(LOG_WARNING, "Could not create http routes for '%s' - skipping\n", user->macaddress);
1689  return -1;
1690  }
1691  ao2_link(users, user);
1692 
1693  } else {
1694  if (strcmp(provider_name, user->provider_name)) {
1695  ast_log(LOG_ERROR, "MAC address '%s' was already added by provider '%s' - skipping\n", user->macaddress, user->provider_name);
1696  return -1;
1697  }
1698 
1699  if (!(exten = build_extension(username, vars))) {
1700  ast_log(LOG_ERROR, "Could not create extension for '%s' - skipping\n", user->macaddress);
1701  return -1;
1702  }
1703 
1704  if (add_user_extension(user, exten)) {
1705  ast_log(LOG_WARNING, "Could not add extension '%s' to user '%s'\n", exten->name, user->macaddress);
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define LOG_WARNING
Definition: logger.h:274
static int build_user_routes(struct user *user)
Add an http route for dynamic files attached to the profile of the user.
#define NULL
Definition: resample.c:96
list of users found in the config file
static struct user * find_user(const char *macaddress)
Return a user looked up by name.
static struct phoneprov_provider * find_provider(char *name)
#define ast_strlen_zero(foo)
Definition: strings.h:52
structure to hold config providers
#define ast_log
Definition: astobj2.c:42
static struct extension * build_extension(const char *name, struct varshead *vars)
#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:911
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.
structure to hold extensions
#define LOG_ERROR
Definition: logger.h:285
const ast_string_field provider_name
char * ast_var_find(const struct varshead *head, const char *name)
Definition: chanvars.c:85
structure to hold phone profiles read from phoneprov.conf
static const char * variable_lookup[]
structure to hold users read from users.conf
const ast_string_field name
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct extension * delete_extension(struct extension *exten)
const ast_string_field macaddress
static int add_user_extension(struct user *user, struct extension *exten)
Add an extension to a user ordered by index/linenumber.
static struct phone_profile * find_profile(const char *name)
Return a phone profile looked up by name.
static struct prometheus_metrics_provider provider
Definition: bridges.c:178
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ 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 1585 of file res_phoneprov.c.

References CMP_MATCH.

Referenced by phoneprov_destroy().

1586  {
1587  return CMP_MATCH;
1588  }
1589  return 0;
1590 }
1591 
1592 void ast_phoneprov_delete_extension(char *provider_name, char *macaddress)
1593 {
void ast_phoneprov_delete_extension(char *provider_name, char *macaddress)
Deletes an extension.

◆ 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 1595 of file res_phoneprov.c.

1603 {

◆ 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 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().

1514  {
1515  return NULL;
1516  }
1517 
1518  return variable_lookup[var];
1519 }
1520 
1521 int ast_phoneprov_provider_register(char *provider_name,
1523 {
1524  struct phoneprov_provider *provider;
1525 
1526  if (ast_strlen_zero(provider_name)) {
1527  ast_log(LOG_ERROR, "Provider name can't be empty.\n");
1528  return -1;
1529  }
1530 
1531  if (!providers) {
1532  ast_log(LOG_WARNING, "Provider '%s' cannot be registered: res_phoneprov not loaded.\n", provider_name);
1533  return -1;
1534  }
1535 
1536  provider = find_provider(provider_name);
1537  if (provider) {
1538  ast_log(LOG_ERROR, "There is already a provider registered named '%s'.\n", provider_name);
1539  ao2_ref(provider, -1);
1540  return -1;
1541  }
1542 
1543  provider = ao2_alloc(sizeof(struct phoneprov_provider), provider_destructor);
1544  if (!provider) {
1545  ast_log(LOG_ERROR, "Unable to allocate sufficient memory for provider '%s'.\n", provider_name);
1546  return -1;
1547  }
1548 
1549  if (ast_string_field_init(provider, 32)) {
1550  ao2_ref(provider, -1);
1551  ast_log(LOG_ERROR, "Unable to allocate sufficient memory for provider '%s' stringfields.\n", provider_name);
1552  return -1;
1553  }
1554 
1555  ast_string_field_set(provider, provider_name, provider_name);
1556  provider->load_users = load_users;
1557 
1558  ao2_link(providers, provider);
1559  ao2_ref(provider, -1);
1560 
1561  if (provider->load_users()) {
int ast_phoneprov_provider_register(char *provider_name, ast_phoneprov_load_users_cb load_users)
Registers a config provider to phoneprov.
#define LOG_WARNING
Definition: logger.h:274
static int load_users(void)
#define var
Definition: ast_expr2f.c:614
#define NULL
Definition: resample.c:96
int(* ast_phoneprov_load_users_cb)(void)
Causes the provider to load its users.
Definition: phoneprov.h:75
static struct phoneprov_provider * find_provider(char *name)
#define ast_strlen_zero(foo)
Definition: strings.h:52
structure to hold config providers
#define ast_log
Definition: astobj2.c:42
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * providers
#define LOG_ERROR
Definition: logger.h:285
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static void provider_destructor(void *obj)
static const char * variable_lookup[]
ast_phoneprov_load_users_cb load_users
static struct prometheus_metrics_provider provider
Definition: bridges.c:178
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ 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 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().

1604  {
1605  return;
1606  }
1607 
1609 }
1610 
1612 {
static int extensions_delete_cb(void *obj, void *arg, int flags)
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
list of users found in the config file
void ast_phoneprov_provider_unregister(char *provider_name)
Unegisters a config provider from phoneprov and frees its resources.
const ast_string_field provider_name

◆ 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 1505 of file res_phoneprov.c.

Referenced by load_endpoint(), and users_apply_handler().

1513 {