Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


iax2-provision.c File Reference

IAX Provisioning Protocol. More...

#include "asterisk.h"
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <sys/socket.h>
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/frame.h"
#include "asterisk/md5.h"
#include "asterisk/astdb.h"
#include "asterisk/utils.h"
#include "asterisk/acl.h"
#include "iax2.h"
#include "iax2-provision.h"
#include "iax2-parser.h"

Go to the source code of this file.

Data Structures

struct  iax_flag
 
struct  iax_template
 
struct  templates
 

Functions

static int iax_process_template (struct ast_config *cfg, char *s, char *def)
 
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)
 
static void iax_provision_free_templates (int dead)
 
static int iax_provision_init (void)
 
int iax_provision_reload (int reload)
 
int iax_provision_unload (void)
 
int iax_provision_version (unsigned int *version, const char *template, int force)
 
static const char * iax_server (unsigned int addr)
 
static char * iax_show_provisioning (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static unsigned int iax_str2flags (const char *buf)
 
static void iax_template_copy (struct iax_template *dst, struct iax_template *src)
 
static struct iax_templateiax_template_find (const char *s, int allowdead)
 
static int iax_template_parse (struct iax_template *cur, struct ast_config *cfg, const char *s, const char *def)
 
static const char * ifthere (const char *s)
 
static unsigned int prov_ver_calc (struct iax_ie_data *provdata)
 

Variables

static struct ast_cli_entry cli_iax2_provision []
 
static struct iax_flag iax_flags []
 
static int provinit = 0
 
static ast_mutex_t provlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
 
static struct templates templates = { .first = NULL, .last = NULL, }
 

Detailed Description

IAX Provisioning Protocol.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file iax2-provision.c.

Function Documentation

static int iax_process_template ( struct ast_config cfg,
char *  s,
char *  def 
)
static

Definition at line 384 of file iax2-provision.c.

References ast_calloc, AST_LIST_INSERT_HEAD, ast_log(), ast_mutex_lock, ast_mutex_unlock, iax_template::dead, iax_template_find(), iax_template_parse(), iax_template::list, LOG_WARNING, iax_template::name, and provlock.

Referenced by iax_provision_reload().

385 {
386  /* Find an already existing one if there */
387  struct iax_template *cur;
388  int mallocd = 0;
389 
390  cur = iax_template_find(s, 1 /* allow dead */);
391  if (!cur) {
392  mallocd = 1;
393  cur = ast_calloc(1, sizeof(*cur));
394  if (!cur) {
395  ast_log(LOG_WARNING, "Out of memory!\n");
396  return -1;
397  }
398  /* Initialize entry */
399  strncpy(cur->name, s, sizeof(cur->name) - 1);
400  cur->dead = 1;
401  }
402  if (!iax_template_parse(cur, cfg, s, def))
403  cur->dead = 0;
404 
405  /* Link if we're mallocd */
406  if (mallocd) {
410  }
411  return 0;
412 }
static ast_mutex_t provlock
char name[80]
#define LOG_WARNING
Definition: logger.h:144
#define ast_mutex_lock(a)
Definition: lock.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg, const char *s, const char *def)
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
static struct iax_template * iax_template_find(const char *s, int allowdead)
#define ast_calloc(a, b)
Definition: astmm.h:82
struct iax_template::@117 list
#define ast_mutex_unlock(a)
Definition: lock.h:156
char* iax_prov_complete_template ( const char *  line,
const char *  word,
int  pos,
int  state 
)

Definition at line 178 of file iax2-provision.c.

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

Referenced by handle_cli_iax2_provision(), and iax_show_provisioning().

179 {
180  struct iax_template *c;
181  int which=0;
182  char *ret = NULL;
183  int wordlen = strlen(word);
184 
185  if (pos == 3) {
188  if (!strncasecmp(word, c->name, wordlen) && ++which > state) {
189  ret = ast_strdup(c->name);
190  break;
191  }
192  }
194  }
195  return ret;
196 }
static ast_mutex_t provlock
#define ast_strdup(a)
Definition: astmm.h:109
char name[80]
#define ast_mutex_lock(a)
Definition: lock.h:155
Definition: ael.tab.c:203
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct iax_template::@117 list
#define ast_mutex_unlock(a)
Definition: lock.h:156
char* iax_provflags2str ( char *  buf,
int  buflen,
unsigned int  flags 
)

Definition at line 89 of file iax2-provision.c.

References ARRAY_LEN, ast_strlen_zero(), iax_flags, iax_template::name, and value.

Referenced by dump_prov_flags(), and iax_show_provisioning().

90 {
91  int x;
92 
93  if (!buf || buflen < 1)
94  return NULL;
95 
96  buf[0] = '\0';
97 
98  for (x = 0; x < ARRAY_LEN(iax_flags); x++) {
99  if (flags & iax_flags[x].value){
100  strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1);
101  strncat(buf, ",", buflen - strlen(buf) - 1);
102  }
103  }
104 
105  if (!ast_strlen_zero(buf))
106  buf[strlen(buf) - 1] = '\0';
107  else
108  strncpy(buf, "none", buflen - 1);
109 
110  return buf;
111 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
unsigned int flags
static const char name[]
static struct iax_flag iax_flags[]
int iax_provision_build ( struct iax_ie_data provdata,
unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 208 of file iax2-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, iax_template::tos, and iax_template::user.

Referenced by iax2_provision(), and iax_provision_version().

209 {
210  struct iax_template *cur;
211  unsigned int sig;
212  char tmp[40];
213  memset(provdata, 0, sizeof(*provdata));
215  cur = iax_template_find(template, 1);
216  /* If no match, try searching for '*' */
217  if (!cur)
218  cur = iax_template_find("*", 1);
219  if (cur) {
220  /* found it -- add information elements as appropriate */
221  if (force || strlen(cur->user))
222  iax_ie_append_str(provdata, PROV_IE_USER, cur->user);
223  if (force || strlen(cur->pass))
224  iax_ie_append_str(provdata, PROV_IE_PASS, cur->pass);
225  if (force || strlen(cur->lang))
226  iax_ie_append_str(provdata, PROV_IE_LANG, cur->lang);
227  if (force || cur->port)
228  iax_ie_append_short(provdata, PROV_IE_PORTNO, cur->port);
229  if (force || cur->server)
230  iax_ie_append_int(provdata, PROV_IE_SERVERIP, cur->server);
231  if (force || cur->serverport)
233  if (force || cur->altserver)
235  if (force || cur->flags)
236  iax_ie_append_int(provdata, PROV_IE_FLAGS, cur->flags);
237  if (force || cur->format)
238  iax_ie_append_int(provdata, PROV_IE_FORMAT, cur->format);
239  if (force || cur->tos)
240  iax_ie_append_byte(provdata, PROV_IE_TOS, cur->tos);
241 
242  /* Calculate checksum of message so far */
243  sig = prov_ver_calc(provdata);
244  if (signature)
245  *signature = sig;
246  /* Store signature */
247  iax_ie_append_int(provdata, PROV_IE_PROVVER, sig);
248  /* Cache signature for later verification so we need not recalculate all this */
249  snprintf(tmp, sizeof(tmp), "v0x%08x", sig);
250  ast_db_put("iax/provisioning/cache", template, tmp);
251  } else
252  ast_db_put("iax/provisioning/cache", template, "u");
254  return cur ? 0 : -1;
255 }
static ast_mutex_t provlock
#define PROV_IE_FORMAT
#define PROV_IE_PASS
unsigned int format
char lang[10]
#define ast_mutex_lock(a)
Definition: lock.h:155
unsigned int altserver
#define PROV_IE_PROVVER
unsigned short port
#define PROV_IE_FLAGS
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
Definition: iax2-parser.c:730
unsigned short serverport
#define PROV_IE_SERVERPORT
#define PROV_IE_SERVERIP
char user[20]
char pass[20]
unsigned int flags
unsigned int server
#define PROV_IE_LANG
#define PROV_IE_ALTSERVER
static struct iax_template * iax_template_find(const char *s, int allowdead)
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
unsigned int tos
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
Definition: iax2-parser.c:723
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: db.c:260
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
Definition: iax2-parser.c:742
#define PROV_IE_PORTNO
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
Definition: iax2-parser.c:737
#define PROV_IE_USER
#define PROV_IE_TOS
#define ast_mutex_unlock(a)
Definition: lock.h:156
static void iax_provision_free_templates ( int  dead)
static

Definition at line 501 of file iax2-provision.c.

References ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_mutex_lock, ast_mutex_unlock, iax_template::dead, iax_template::list, and provlock.

Referenced by iax_provision_reload(), and iax_provision_unload().

502 {
503  struct iax_template *cur;
504 
505  /* Drop dead or not (depending on dead) entries while locked */
508  if ((dead && cur->dead) || !dead) {
510  ast_free(cur);
511  }
512  }
515 }
static ast_mutex_t provlock
#define ast_mutex_lock(a)
Definition: lock.h:155
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
#define ast_free(a)
Definition: astmm.h:97
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
struct iax_template::@117 list
#define ast_mutex_unlock(a)
Definition: lock.h:156
static int iax_provision_init ( void  )
static

Definition at line 494 of file iax2-provision.c.

References ast_cli_register_multiple(), and cli_iax2_provision.

Referenced by iax_provision_reload().

495 {
497  provinit = 1;
498  return 0;
499 }
descriptor for a cli entry.
Definition: cli.h:165
static int provinit
static struct ast_cli_entry cli_iax2_provision[]
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
int iax_provision_reload ( int  reload)

Definition at line 526 of file iax2-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, and LOG_NOTICE.

Referenced by load_module(), and reload_config().

527 {
528  struct ast_config *cfg;
529  struct iax_template *cur;
530  char *cat;
531  int found = 0;
532  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
533  if (!provinit)
535 
536  cfg = ast_config_load2("iaxprov.conf", "chan_iax2", config_flags);
537  if (cfg != NULL && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {
538  /* Mark all as dead. No need for locking */
539  AST_LIST_TRAVERSE(&templates, cur, list) {
540  cur->dead = 1;
541  }
542 
543  /* Load as appropriate */
544  cat = ast_category_browse(cfg, NULL);
545  while(cat) {
546  if (strcasecmp(cat, "general")) {
547  iax_process_template(cfg, cat, found ? "default" : NULL);
548  found++;
549  ast_verb(3, "Loaded provisioning template '%s'\n", cat);
550  }
551  cat = ast_category_browse(cfg, cat);
552  }
553  ast_config_destroy(cfg);
554  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
555  return 0;
556  else
557  ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
558 
559  iax_provision_free_templates(1 /* remove only marked as dead */);
560 
561  /* Purge cached signature DB entries */
562  ast_db_deltree("iax/provisioning/cache", NULL);
563  return 0;
564 }
static int iax_provision_init(void)
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
static void iax_provision_free_templates(int dead)
static int provinit
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: config.c:2499
#define ast_verb(level,...)
Definition: logger.h:243
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
static int reload(void)
Definition: app_amd.c:497
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
Structure used to handle boolean flags.
Definition: utils.h:200
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged...
Definition: db.c:241
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
int iax_provision_unload ( void  )

Definition at line 517 of file iax2-provision.c.

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

Referenced by __unload_module().

518 {
519  provinit = 0;
521  iax_provision_free_templates(0 /* Remove all templates. */);
522 
523  return 0;
524 }
static void iax_provision_free_templates(int dead)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
descriptor for a cli entry.
Definition: cli.h:165
static int provinit
static struct ast_cli_entry cli_iax2_provision[]
int iax_provision_version ( unsigned int *  version,
const char *  template,
int  force 
)

Definition at line 257 of file iax2-provision.c.

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

Referenced by check_provisioning().

258 {
259  char tmp[80] = "";
260  struct iax_ie_data ied;
261  int ret=0;
262  memset(&ied, 0, sizeof(ied));
263 
265  if (ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp))) {
266  ast_log(LOG_ERROR, "ast_db_get failed to retrieve iax/provisioning/cache/%s\n", template);
267  }
268  if (sscanf(tmp, "v%30x", version) != 1) {
269  if (strcmp(tmp, "u")) {
270  ret = iax_provision_build(&ied, version, template, force);
271  if (ret)
272  ast_debug(1, "Unable to create provisioning packet for '%s'\n", template);
273  } else
274  ret = -1;
275  } else
276  ast_debug(1, "Retrieved cached version '%s' = '%08x'\n", tmp, *version);
278  return ret;
279 }
static ast_mutex_t provlock
uint32_t version
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
Definition: db.c:348
#define ast_mutex_lock(a)
Definition: lock.h:155
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_mutex_unlock(a)
Definition: lock.h:156
static const char* iax_server ( unsigned int  addr)
static

Definition at line 422 of file iax2-provision.c.

References ast_inet_ntoa().

Referenced by iax_show_provisioning().

423 {
424  struct in_addr ia;
425 
426  if (!addr)
427  return "<unspecified>";
428 
429  ia.s_addr = htonl(addr);
430 
431  return ast_inet_ntoa(ia);
432 }
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:564
static char* iax_show_provisioning ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 435 of file iax2-provision.c.

References iax_template::altserver, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), ast_getformatname(), AST_LIST_TRAVERSE, ast_mutex_lock, ast_mutex_unlock, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, iax_template::flags, iax_template::format, iax_prov_complete_template(), iax_provflags2str(), iax_server(), ifthere(), iax_template::lang, ast_cli_args::line, iax_template::list, ast_cli_args::n, iax_template::name, iax_template::pass, iax_template::port, ast_cli_args::pos, provlock, iax_template::server, iax_template::serverport, iax_template::src, iax_template::tos, ast_cli_entry::usage, iax_template::user, and ast_cli_args::word.

436 {
437  struct iax_template *cur;
438  char server[INET_ADDRSTRLEN];
439  char alternate[INET_ADDRSTRLEN];
440  char flags[80]; /* Has to be big enough for 'flags' too */
441  int found = 0;
442 
443  switch (cmd) {
444  case CLI_INIT:
445  e->command = "iax2 show provisioning";
446  e->usage =
447  "Usage: iax2 show provisioning [template]\n"
448  " Lists all known IAX provisioning templates or a\n"
449  " specific one if specified.\n";
450  return NULL;
451  case CLI_GENERATE:
452  return iax_prov_complete_template(a->line, a->word, a->pos, a->n);
453  }
454 
455  if ((a->argc != 3) && (a->argc != 4))
456  return CLI_SHOWUSAGE;
457 
460  if ((a->argc == 3) || (!strcasecmp(a->argv[3], cur->name))) {
461  if (found)
462  ast_cli(a->fd, "\n");
463  ast_copy_string(server, iax_server(cur->server), sizeof(server));
464  ast_copy_string(alternate, iax_server(cur->altserver), sizeof(alternate));
465  ast_cli(a->fd, "== %s ==\n", cur->name);
466  ast_cli(a->fd, "Base Templ: %s\n", strlen(cur->src) ? cur->src : "<none>");
467  ast_cli(a->fd, "Username: %s\n", ifthere(cur->user));
468  ast_cli(a->fd, "Secret: %s\n", ifthere(cur->pass));
469  ast_cli(a->fd, "Language: %s\n", ifthere(cur->lang));
470  ast_cli(a->fd, "Bind Port: %d\n", cur->port);
471  ast_cli(a->fd, "Server: %s\n", server);
472  ast_cli(a->fd, "Server Port: %d\n", cur->serverport);
473  ast_cli(a->fd, "Alternate: %s\n", alternate);
474  ast_cli(a->fd, "Flags: %s\n", iax_provflags2str(flags, sizeof(flags), cur->flags));
475  ast_cli(a->fd, "Format: %s\n", ast_getformatname(cur->format));
476  ast_cli(a->fd, "TOS: 0x%x\n", cur->tos);
477  found++;
478  }
479  }
481  if (!found) {
482  if (a->argc == 3)
483  ast_cli(a->fd, "No provisioning templates found\n");
484  else
485  ast_cli(a->fd, "No provisioning template matching '%s' found\n", a->argv[3]);
486  }
487  return CLI_SUCCESS;
488 }
static ast_mutex_t provlock
static const char * iax_server(unsigned int addr)
char name[80]
unsigned int format
const int argc
Definition: cli.h:154
Definition: cli.h:146
char lang[10]
#define ast_mutex_lock(a)
Definition: lock.h:155
unsigned int altserver
char * iax_prov_complete_template(const char *line, const char *word, int pos, int state)
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
const char * line
Definition: cli.h:156
unsigned short port
const int fd
Definition: cli.h:153
static const char * ifthere(const char *s)
const int n
Definition: cli.h:159
unsigned short serverport
const char *const * argv
Definition: cli.h:155
char user[20]
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
#define CLI_SHOWUSAGE
Definition: cli.h:44
char pass[20]
unsigned int flags
unsigned int server
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:180
const char * word
Definition: cli.h:157
unsigned int tos
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
const int pos
Definition: cli.h:158
char src[80]
char * iax_provflags2str(char *buf, int buflen, unsigned int flags)
struct iax_template::@117 list
#define ast_mutex_unlock(a)
Definition: lock.h:156
static unsigned int iax_str2flags ( const char *  buf)
static

Definition at line 113 of file iax2-provision.c.

References ARRAY_LEN, iax_template::flags, iax_flags, len(), iax_template::name, and iax_flag::value.

Referenced by iax_template_parse().

114 {
115  int x;
116  int len;
117  unsigned int flags = 0;
118  char *e;
119  while(buf && *buf) {
120  e = strchr(buf, ',');
121  if (e)
122  len = e - buf;
123  else
124  len = 0;
125  for (x = 0; x < ARRAY_LEN(iax_flags); x++) {
126  if ((len && !strncasecmp(iax_flags[x].name, buf, len)) ||
127  (!len && !strcasecmp(iax_flags[x].name, buf))) {
128  flags |= iax_flags[x].value;
129  break;
130  }
131  }
132  if (e) {
133  buf = e + 1;
134  while(*buf && (*buf < 33))
135  buf++;
136  } else
137  break;
138  }
139  return flags;
140 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
unsigned int flags
static const char name[]
static struct iax_flag iax_flags[]
static void iax_template_copy ( struct iax_template dst,
struct iax_template src 
)
static

Definition at line 142 of file iax2-provision.c.

References iax_template::altserver, ast_copy_string(), iax_template::dead, iax_template::flags, iax_template::format, iax_template::lang, iax_template::name, iax_template::pass, iax_template::port, iax_template::server, iax_template::src, iax_template::tos, and iax_template::user.

Referenced by iax_template_parse().

143 {
144  if (!dst || !src) {
145  return;
146  }
147 
148  dst->dead = src->dead;
149  ast_copy_string(dst->name, src->name, sizeof(dst->name));
150  ast_copy_string(dst->src, src->src, sizeof(dst->src));
151  ast_copy_string(dst->user, src->user, sizeof(dst->user));
152  ast_copy_string(dst->pass, src->pass, sizeof(dst->pass));
153  ast_copy_string(dst->lang, src->lang, sizeof(dst->lang));
154  dst->port = src->port;
155  dst->server = src->server;
156  dst->altserver = src->altserver;
157  dst->flags = src->flags;
158  dst->format = src->format;
159  dst->tos = src->tos;
160 }
char name[80]
unsigned int format
char lang[10]
unsigned int altserver
unsigned short port
char user[20]
char pass[20]
unsigned int flags
unsigned int server
unsigned int tos
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
char src[80]
static struct iax_template* iax_template_find ( const char *  s,
int  allowdead 
)
static

Definition at line 162 of file iax2-provision.c.

References AST_LIST_TRAVERSE, iax_template::dead, iax_template::list, and iax_template::name.

Referenced by iax_process_template(), iax_provision_build(), and iax_template_parse().

163 {
164  struct iax_template *cur;
165 
167  if (!strcasecmp(s, cur->name)) {
168  if (!allowdead && cur->dead) {
169  cur = NULL;
170  }
171  break;
172  }
173  }
174 
175  return cur;
176 }
char name[80]
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct iax_template::@117 list
static int iax_template_parse ( struct iax_template cur,
struct ast_config cfg,
const char *  s,
const char *  def 
)
static

Definition at line 281 of file iax2-provision.c.

References iax_template::altserver, ast_getformatbyname(), ast_gethostbyname(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_str2tos(), ast_variable_browse(), ast_variable_retrieve(), iax_template::dead, iax_template::flags, iax_template::format, hp, IAX_DEFAULT_PORTNO, iax_str2flags(), iax_template_copy(), iax_template_find(), iax_template::lang, ast_variable::lineno, LOG_WARNING, iax_template::name, ast_variable::name, ast_variable::next, iax_template::pass, iax_template::port, provlock, iax_template::server, iax_template::serverport, iax_template::src, iax_template::tos, iax_template::user, and ast_variable::value.

Referenced by iax_process_template().

282 {
283  struct ast_variable *v;
284  int foundportno = 0;
285  int foundserverportno = 0;
286  int x;
287  struct in_addr ia;
288  struct hostent *hp;
289  struct ast_hostent h;
290  struct iax_template *src, tmp;
291  const char *t;
292  if (def) {
293  t = ast_variable_retrieve(cfg, s ,"template");
294  src = NULL;
295  if (t && strlen(t)) {
296  src = iax_template_find(t, 0);
297  if (!src)
298  ast_log(LOG_WARNING, "Unable to find base template '%s' for creating '%s'. Trying '%s'\n", t, s, def);
299  else
300  def = t;
301  }
302  if (!src) {
303  src = iax_template_find(def, 0);
304  if (!src)
305  ast_log(LOG_WARNING, "Unable to locate default base template '%s' for creating '%s', omitting.\n", def, s);
306  }
307  if (!src)
308  return -1;
310  /* Backup old data */
311  iax_template_copy(&tmp, cur);
312  /* Restore from src */
313  iax_template_copy(cur, src);
314  /* Restore important headers */
315  memcpy(cur->name, tmp.name, sizeof(cur->name));
316  cur->dead = tmp.dead;
318  }
319  if (def)
320  strncpy(cur->src, def, sizeof(cur->src) - 1);
321  else
322  cur->src[0] = '\0';
323  v = ast_variable_browse(cfg, s);
324  while(v) {
325  if (!strcasecmp(v->name, "port") || !strcasecmp(v->name, "serverport")) {
326  if ((sscanf(v->value, "%5d", &x) == 1) && (x > 0) && (x < 65535)) {
327  if (!strcasecmp(v->name, "port")) {
328  cur->port = x;
329  foundportno = 1;
330  } else {
331  cur->serverport = x;
332  foundserverportno = 1;
333  }
334  } else
335  ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);
336  } else if (!strcasecmp(v->name, "server") || !strcasecmp(v->name, "altserver")) {
337  hp = ast_gethostbyname(v->value, &h);
338  if (hp) {
339  memcpy(&ia, hp->h_addr, sizeof(ia));
340  if (!strcasecmp(v->name, "server"))
341  cur->server = ntohl(ia.s_addr);
342  else
343  cur->altserver = ntohl(ia.s_addr);
344  } else
345  ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);
346  } else if (!strcasecmp(v->name, "codec")) {
347  if ((x = ast_getformatbyname(v->value)) > 0) {
348  cur->format = x;
349  } else
350  ast_log(LOG_WARNING, "Ignoring invalid codec '%s' for '%s' at line %d\n", v->value, s, v->lineno);
351  } else if (!strcasecmp(v->name, "tos")) {
352  if (ast_str2tos(v->value, &cur->tos))
353  ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
354  } else if (!strcasecmp(v->name, "user")) {
355  strncpy(cur->user, v->value, sizeof(cur->user) - 1);
356  if (strcmp(cur->user, v->value))
357  ast_log(LOG_WARNING, "Truncating username from '%s' to '%s' for '%s' at line %d\n", v->value, cur->user, s, v->lineno);
358  } else if (!strcasecmp(v->name, "pass")) {
359  strncpy(cur->pass, v->value, sizeof(cur->pass) - 1);
360  if (strcmp(cur->pass, v->value))
361  ast_log(LOG_WARNING, "Truncating password from '%s' to '%s' for '%s' at line %d\n", v->value, cur->pass, s, v->lineno);
362  } else if (!strcasecmp(v->name, "language")) {
363  strncpy(cur->lang, v->value, sizeof(cur->lang) - 1);
364  if (strcmp(cur->lang, v->value))
365  ast_log(LOG_WARNING, "Truncating language from '%s' to '%s' for '%s' at line %d\n", v->value, cur->lang, s, v->lineno);
366  } else if (!strcasecmp(v->name, "flags")) {
367  cur->flags = iax_str2flags(v->value);
368  } else if (!strncasecmp(v->name, "flags", 5) && strchr(v->name, '+')) {
369  cur->flags |= iax_str2flags(v->value);
370  } else if (!strncasecmp(v->name, "flags", 5) && strchr(v->name, '-')) {
371  cur->flags &= ~iax_str2flags(v->value);
372  } else if (strcasecmp(v->name, "template")) {
373  ast_log(LOG_WARNING, "Unknown keyword '%s' in definition of '%s' at line %d\n", v->name, s, v->lineno);
374  }
375  v = v->next;
376  }
377  if (!foundportno)
378  cur->port = IAX_DEFAULT_PORTNO;
379  if (!foundserverportno)
381  return 0;
382 }
static ast_mutex_t provlock
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
Definition: config.c:625
char name[80]
static unsigned int iax_str2flags(const char *buf)
unsigned int format
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
int lineno
Definition: config.h:87
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define IAX_DEFAULT_PORTNO
Definition: iax2.h:128
char lang[10]
#define ast_mutex_lock(a)
Definition: lock.h:155
unsigned int altserver
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
Definition: acl.c:667
unsigned short port
const char * value
Definition: config.h:79
unsigned short serverport
const char * name
Definition: config.h:77
static void iax_template_copy(struct iax_template *dst, struct iax_template *src)
format_t ast_getformatbyname(const char *name)
Gets a format from a name.
Definition: frame.c:641
char user[20]
char pass[20]
unsigned int flags
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
unsigned int server
static struct iax_template * iax_template_find(const char *s, int allowdead)
unsigned int tos
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Definition: utils.c:195
char src[80]
struct ast_variable * next
Definition: config.h:82
static struct hostent * hp
Definition: chan_skinny.c:1048
#define ast_mutex_unlock(a)
Definition: lock.h:156
static const char* ifthere ( const char *  s)
static

Definition at line 414 of file iax2-provision.c.

Referenced by iax_show_provisioning().

415 {
416  if (strlen(s))
417  return s;
418  else
419  return "<unspecified>";
420 }
static unsigned int prov_ver_calc ( struct iax_ie_data provdata)
static

Definition at line 198 of file iax2-provision.c.

References iax_ie_data::buf, MD5Final(), MD5Init(), MD5Update(), and iax_ie_data::pos.

Referenced by iax_provision_build().

199 {
200  struct MD5Context md5;
201  unsigned int tmp[4];
202  MD5Init(&md5);
203  MD5Update(&md5, provdata->buf, provdata->pos);
204  MD5Final((unsigned char *)tmp, &md5);
205  return tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3];
206 }
void MD5Final(unsigned char digest[16], struct MD5Context *context)
Definition: md5.c:122
void MD5Init(struct MD5Context *context)
Definition: md5.c:59
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
Definition: md5.c:74
static int md5(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_md5.c:54
unsigned char buf[1024]
Definition: iax2-parser.h:147
Definition: md5.h:26

Variable Documentation

struct ast_cli_entry cli_iax2_provision[]
static
Initial value:
= {
AST_CLI_DEFINE(iax_show_provisioning, "Display iax provisioning"),
}
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static char * iax_show_provisioning(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

Definition at line 490 of file iax2-provision.c.

Referenced by iax_provision_init(), and iax_provision_unload().

struct iax_flag iax_flags[]
static

Referenced by iax_provflags2str(), and iax_str2flags().

int provinit = 0
static

Definition at line 52 of file iax2-provision.c.

ast_mutex_t provlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
static
struct templates templates = { .first = NULL, .last = NULL, }
static