Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
provision.h File Reference

IAX2 Provisioning protocol. More...

#include "parser.h"
Include dependency graph for provision.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PROV_FLAG_DEBUG   (1 << 3)
 
#define PROV_FLAG_DIS_CALLERID   (1 << 4) /* Caller-ID Disabled */
 
#define PROV_FLAG_DIS_CALLWAIT   (1 << 5) /* Caller-ID / Call Waiting Disable */
 
#define PROV_FLAG_DIS_CIDCW   (1 << 6) /* CID/CW Disabled */
 
#define PROV_FLAG_DIS_THREEWAY   (1 << 7) /* Three-way calling, transfer disabled */
 
#define PROV_FLAG_HEARTBEAT   (1 << 2)
 
#define PROV_FLAG_REGISTER   (1 << 0)
 
#define PROV_FLAG_SECURE   (1 << 1)
 
#define PROV_IE_AESKEY   14 /* 128-bits */
 
#define PROV_IE_ALTSERVER   19 /* 32-bits */
 
#define PROV_IE_FLAGS   12 /* 32-bits */
 
#define PROV_IE_FORMAT   13 /* 32-bits */
 
#define PROV_IE_GATEWAY   4 /* 32-bit */
 
#define PROV_IE_IPADDR   2 /* 32-bit */
 
#define PROV_IE_LANG   10 /* < 10 bytes */
 
#define PROV_IE_NEWAESKEY   17 /* 128-bits */
 
#define PROV_IE_PASS   7 /* < 20 bytes */
 
#define PROV_IE_PORTNO   5 /* 16-bit */
 
#define PROV_IE_PROVVER   18 /* 32-bits */
 
#define PROV_IE_SERVERIP   15 /* 32-bits */
 
#define PROV_IE_SERVERPASS   9 /* < 20 bytes */
 
#define PROV_IE_SERVERPORT   16 /* 16-bits */
 
#define PROV_IE_SERVERUSER   8 /* < 20 bytes */
 
#define PROV_IE_SUBNET   3 /* 32-bit */
 
#define PROV_IE_TOS   11 /* 8-bits */
 
#define PROV_IE_USEDHCP   1 /* Presense only */
 
#define PROV_IE_USER   6 /* < 20 bytes */
 

Functions

char * iax_prov_complete_template (const char *line, const char *word, int pos, int state)
 
char * iax_provflags2str (char *buf, int buflen, unsigned int flags)
 
int iax_provision_build (struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
 
int iax_provision_reload (int reload)
 
int iax_provision_unload (void)
 
int iax_provision_version (unsigned int *signature, const char *template, int force)
 

Detailed Description

IAX2 Provisioning protocol.

Definition in file provision.h.

Macro Definition Documentation

◆ PROV_FLAG_DEBUG

#define PROV_FLAG_DEBUG   (1 << 3)

Definition at line 44 of file provision.h.

◆ PROV_FLAG_DIS_CALLERID

#define PROV_FLAG_DIS_CALLERID   (1 << 4) /* Caller-ID Disabled */

Definition at line 46 of file provision.h.

◆ PROV_FLAG_DIS_CALLWAIT

#define PROV_FLAG_DIS_CALLWAIT   (1 << 5) /* Caller-ID / Call Waiting Disable */

Definition at line 47 of file provision.h.

◆ PROV_FLAG_DIS_CIDCW

#define PROV_FLAG_DIS_CIDCW   (1 << 6) /* CID/CW Disabled */

Definition at line 48 of file provision.h.

◆ PROV_FLAG_DIS_THREEWAY

#define PROV_FLAG_DIS_THREEWAY   (1 << 7) /* Three-way calling, transfer disabled */

Definition at line 49 of file provision.h.

◆ PROV_FLAG_HEARTBEAT

#define PROV_FLAG_HEARTBEAT   (1 << 2)

Definition at line 43 of file provision.h.

◆ PROV_FLAG_REGISTER

#define PROV_FLAG_REGISTER   (1 << 0)

Definition at line 41 of file provision.h.

◆ PROV_FLAG_SECURE

#define PROV_FLAG_SECURE   (1 << 1)

Definition at line 42 of file provision.h.

◆ PROV_IE_AESKEY

#define PROV_IE_AESKEY   14 /* 128-bits */

Definition at line 34 of file provision.h.

◆ PROV_IE_ALTSERVER

#define PROV_IE_ALTSERVER   19 /* 32-bits */

Definition at line 39 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_FLAGS

#define PROV_IE_FLAGS   12 /* 32-bits */

Definition at line 32 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_FORMAT

#define PROV_IE_FORMAT   13 /* 32-bits */

Definition at line 33 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_GATEWAY

#define PROV_IE_GATEWAY   4 /* 32-bit */

Definition at line 24 of file provision.h.

◆ PROV_IE_IPADDR

#define PROV_IE_IPADDR   2 /* 32-bit */

Definition at line 22 of file provision.h.

◆ PROV_IE_LANG

#define PROV_IE_LANG   10 /* < 10 bytes */

Definition at line 30 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_NEWAESKEY

#define PROV_IE_NEWAESKEY   17 /* 128-bits */

Definition at line 37 of file provision.h.

◆ PROV_IE_PASS

#define PROV_IE_PASS   7 /* < 20 bytes */

Definition at line 27 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_PORTNO

#define PROV_IE_PORTNO   5 /* 16-bit */

Definition at line 25 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_PROVVER

#define PROV_IE_PROVVER   18 /* 32-bits */

Definition at line 38 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_SERVERIP

#define PROV_IE_SERVERIP   15 /* 32-bits */

Definition at line 35 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_SERVERPASS

#define PROV_IE_SERVERPASS   9 /* < 20 bytes */

Definition at line 29 of file provision.h.

◆ PROV_IE_SERVERPORT

#define PROV_IE_SERVERPORT   16 /* 16-bits */

Definition at line 36 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_SERVERUSER

#define PROV_IE_SERVERUSER   8 /* < 20 bytes */

Definition at line 28 of file provision.h.

◆ PROV_IE_SUBNET

#define PROV_IE_SUBNET   3 /* 32-bit */

Definition at line 23 of file provision.h.

◆ PROV_IE_TOS

#define PROV_IE_TOS   11 /* 8-bits */

Definition at line 31 of file provision.h.

Referenced by iax_provision_build().

◆ PROV_IE_USEDHCP

#define PROV_IE_USEDHCP   1 /* Presense only */

Definition at line 21 of file provision.h.

◆ PROV_IE_USER

#define PROV_IE_USER   6 /* < 20 bytes */

Definition at line 26 of file provision.h.

Referenced by iax_provision_build().

Function Documentation

◆ iax_prov_complete_template()

char* iax_prov_complete_template ( const char *  line,
const char *  word,
int  pos,
int  state 
)

Definition at line 179 of file provision.c.

References AST_LIST_TRAVERSE, ast_mutex_lock, ast_mutex_unlock, ast_strdup, c, iax_template::list, iax_template::name, NULL, and provlock.

Referenced by handle_cli_iax2_provision(), and iax_show_provisioning().

180 {
181  struct iax_template *c;
182  int which=0;
183  char *ret = NULL;
184  int wordlen = strlen(word);
185 
186  if (pos == 3) {
189  if (!strncasecmp(word, c->name, wordlen) && ++which > state) {
190  ret = ast_strdup(c->name);
191  break;
192  }
193  }
195  }
196  return ret;
197 }
char name[80]
Definition: provision.c:57
struct iax_template::@157 list
#define ast_mutex_lock(a)
Definition: lock.h:187
static struct test_val c
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static ast_mutex_t provlock
Definition: provision.c:74
short word
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ iax_provflags2str()

char* iax_provflags2str ( char *  buf,
int  buflen,
unsigned int  flags 
)

Definition at line 90 of file provision.c.

References ARRAY_LEN, ast_strlen_zero, buf, iax_flags, iax_template::name, NULL, and value.

Referenced by dump_prov_flags(), and iax_show_provisioning().

91 {
92  int x;
93 
94  if (!buf || buflen < 1)
95  return NULL;
96 
97  buf[0] = '\0';
98 
99  for (x = 0; x < ARRAY_LEN(iax_flags); x++) {
100  if (flags & iax_flags[x].value){
101  strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1);
102  strncat(buf, ",", buflen - strlen(buf) - 1);
103  }
104  }
105 
106  if (!ast_strlen_zero(buf))
107  buf[strlen(buf) - 1] = '\0';
108  else
109  strncpy(buf, "none", buflen - 1);
110 
111  return buf;
112 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
unsigned int flags
Definition: provision.c:66
static const char name[]
Definition: cdr_mysql.c:74
static struct iax_flag iax_flags[]

◆ iax_provision_build()

int iax_provision_build ( struct iax_ie_data provdata,
unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 209 of file provision.c.

References iax_template::altserver, ast_db_put(), ast_mutex_lock, ast_mutex_unlock, iax_template::flags, iax_template::format, iax_ie_append_byte(), iax_ie_append_int(), iax_ie_append_short(), iax_ie_append_str(), iax_template_find(), iax_template::lang, iax_template::pass, iax_template::port, PROV_IE_ALTSERVER, PROV_IE_FLAGS, PROV_IE_FORMAT, PROV_IE_LANG, PROV_IE_PASS, PROV_IE_PORTNO, PROV_IE_PROVVER, PROV_IE_SERVERIP, PROV_IE_SERVERPORT, PROV_IE_TOS, PROV_IE_USER, prov_ver_calc(), provlock, iax_template::server, iax_template::serverport, tmp(), iax_template::tos, and iax_template::user.

Referenced by iax2_provision(), and iax_provision_version().

210 {
211  struct iax_template *cur;
212  unsigned int sig;
213  char tmp[40];
214  memset(provdata, 0, sizeof(*provdata));
216  cur = iax_template_find(template, 1);
217  /* If no match, try searching for '*' */
218  if (!cur)
219  cur = iax_template_find("*", 1);
220  if (cur) {
221  /* found it -- add information elements as appropriate */
222  if (force || strlen(cur->user))
223  iax_ie_append_str(provdata, PROV_IE_USER, cur->user);
224  if (force || strlen(cur->pass))
225  iax_ie_append_str(provdata, PROV_IE_PASS, cur->pass);
226  if (force || strlen(cur->lang))
227  iax_ie_append_str(provdata, PROV_IE_LANG, cur->lang);
228  if (force || cur->port)
229  iax_ie_append_short(provdata, PROV_IE_PORTNO, cur->port);
230  if (force || cur->server)
231  iax_ie_append_int(provdata, PROV_IE_SERVERIP, cur->server);
232  if (force || cur->serverport)
234  if (force || cur->altserver)
236  if (force || cur->flags)
237  iax_ie_append_int(provdata, PROV_IE_FLAGS, cur->flags);
238  if (force || cur->format)
239  iax_ie_append_int(provdata, PROV_IE_FORMAT, cur->format);
240  if (force || cur->tos)
241  iax_ie_append_byte(provdata, PROV_IE_TOS, cur->tos);
242 
243  /* Calculate checksum of message so far */
244  sig = prov_ver_calc(provdata);
245  if (signature)
246  *signature = sig;
247  /* Store signature */
248  iax_ie_append_int(provdata, PROV_IE_PROVVER, sig);
249  /* Cache signature for later verification so we need not recalculate all this */
250  snprintf(tmp, sizeof(tmp), "v0x%08x", sig);
251  ast_db_put("iax/provisioning/cache", template, tmp);
252  } else
253  ast_db_put("iax/provisioning/cache", template, "u");
255  return cur ? 0 : -1;
256 }
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
Definition: parser.c:762
#define PROV_IE_FLAGS
Definition: provision.h:32
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
Definition: parser.c:755
static int tmp()
Definition: bt_open.c:389
char lang[10]
Definition: provision.c:61
#define ast_mutex_lock(a)
Definition: lock.h:187
unsigned int altserver
Definition: provision.c:65
#define PROV_IE_USER
Definition: provision.h:26
unsigned short port
Definition: provision.c:62
static struct iax_template * iax_template_find(const char *s, int allowdead)
Definition: provision.c:163
#define PROV_IE_FORMAT
Definition: provision.h:33
unsigned short serverport
Definition: provision.c:64
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
Definition: provision.c:199
#define PROV_IE_SERVERPORT
Definition: provision.h:36
char user[20]
Definition: provision.c:59
iax2_format format
Definition: provision.c:67
char pass[20]
Definition: provision.c:60
unsigned int flags
Definition: provision.c:66
unsigned int server
Definition: provision.c:63
#define PROV_IE_PORTNO
Definition: provision.h:25
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
Definition: parser.c:774
unsigned int tos
Definition: provision.c:68
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
Definition: parser.c:769
static ast_mutex_t provlock
Definition: provision.c:74
#define PROV_IE_SERVERIP
Definition: provision.h:35
#define PROV_IE_ALTSERVER
Definition: provision.h:39
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:327
#define PROV_IE_TOS
Definition: provision.h:31
#define PROV_IE_PASS
Definition: provision.h:27
#define PROV_IE_LANG
Definition: provision.h:30
#define ast_mutex_unlock(a)
Definition: lock.h:188
#define PROV_IE_PROVVER
Definition: provision.h:38

◆ iax_provision_reload()

int iax_provision_reload ( int  reload)

Definition at line 529 of file provision.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_db_deltree(), AST_LIST_TRAVERSE, ast_log, ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, iax_template::dead, iax_process_template(), iax_provision_free_templates(), iax_provision_init(), iax_template::list, LOG_NOTICE, NULL, and provinit.

Referenced by load_module(), and reload_config().

530 {
531  struct ast_config *cfg;
532  struct iax_template *cur;
533  char *cat;
534  int found = 0;
535  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
536  if (!provinit)
538 
539  cfg = ast_config_load2("iaxprov.conf", "chan_iax2", config_flags);
540  if (cfg != NULL && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {
541  /* Mark all as dead. No need for locking */
542  AST_LIST_TRAVERSE(&templates, cur, list) {
543  cur->dead = 1;
544  }
545 
546  /* Load as appropriate */
547  cat = ast_category_browse(cfg, NULL);
548  while(cat) {
549  if (strcasecmp(cat, "general")) {
550  iax_process_template(cfg, cat, found ? "default" : NULL);
551  found++;
552  ast_verb(3, "Loaded provisioning template '%s'\n", cat);
553  }
554  cat = ast_category_browse(cfg, cat);
555  }
556  ast_config_destroy(cfg);
557  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
558  return 0;
559  else
560  ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
561 
562  iax_provision_free_templates(1 /* remove only marked as dead */);
563 
564  /* Purge cached signature DB entries */
565  ast_db_deltree("iax/provisioning/cache", NULL);
566  return 0;
567 }
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
Definition: provision.c:387
static void iax_provision_free_templates(int dead)
Definition: provision.c:504
#define CONFIG_STATUS_FILEINVALID
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
static int iax_provision_init(void)
Definition: provision.c:497
static int provinit
Definition: provision.c:53
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define CONFIG_STATUS_FILEUNCHANGED
#define LOG_NOTICE
Definition: logger.h:263
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static int reload(void)
Definition: cdr_mysql.c:741
Structure used to handle boolean flags.
Definition: utils.h:199
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:457

◆ iax_provision_unload()

int iax_provision_unload ( void  )

Definition at line 520 of file provision.c.

References ast_cli_unregister_multiple(), iax_provision_free_templates(), and provinit.

Referenced by __unload_module().

521 {
522  provinit = 0;
524  iax_provision_free_templates(0 /* Remove all templates. */);
525 
526  return 0;
527 }
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
descriptor for a cli entry.
Definition: cli.h:171
static void iax_provision_free_templates(int dead)
Definition: provision.c:504
static int provinit
Definition: provision.c:53
static struct ast_cli_entry cli_iax2_provision[]
Definition: provision.c:493

◆ iax_provision_version()

int iax_provision_version ( unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 258 of file provision.c.

References ast_db_get(), ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, iax_provision_build(), LOG_ERROR, provlock, and tmp().

Referenced by check_provisioning().

259 {
260  char tmp[80] = "";
261  struct iax_ie_data ied;
262  int ret=0;
263  memset(&ied, 0, sizeof(ied));
264 
266  if (ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp))) {
267  ast_log(LOG_ERROR, "ast_db_get failed to retrieve iax/provisioning/cache/%s\n", template);
268  }
269  if (sscanf(tmp, "v%30x", version) != 1) {
270  if (strcmp(tmp, "u")) {
271  ret = iax_provision_build(&ied, version, template, force);
272  if (ret)
273  ast_debug(1, "Unable to create provisioning packet for '%s'\n", template);
274  } else
275  ret = -1;
276  } else
277  ast_debug(1, "Retrieved cached version '%s' = '%08x'\n", tmp, *version);
279  return ret;
280 }
static int tmp()
Definition: bt_open.c:389
#define ast_mutex_lock(a)
Definition: lock.h:187
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:412
static ast_mutex_t provlock
Definition: provision.c:74
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
Definition: provision.c:209
#define ast_mutex_unlock(a)
Definition: lock.h:188