Asterisk - The Open Source Telephony Project GIT-master-a358458
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.

◆ PROV_IE_FLAGS

#define PROV_IE_FLAGS   12 /* 32-bits */

Definition at line 32 of file provision.h.

◆ PROV_IE_FORMAT

#define PROV_IE_FORMAT   13 /* 32-bits */

Definition at line 33 of file provision.h.

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

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

◆ PROV_IE_PORTNO

#define PROV_IE_PORTNO   5 /* 16-bit */

Definition at line 25 of file provision.h.

◆ PROV_IE_PROVVER

#define PROV_IE_PROVVER   18 /* 32-bits */

Definition at line 38 of file provision.h.

◆ PROV_IE_SERVERIP

#define PROV_IE_SERVERIP   15 /* 32-bits */

Definition at line 35 of file provision.h.

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

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

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

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.

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}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
short word
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189
static ast_mutex_t provlock
Definition: provision.c:74
#define NULL
Definition: resample.c:96
struct iax_template::@140 list
const char * name
static struct test_val c

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

Referenced by handle_cli_iax2_provision(), and iax_show_provisioning().

◆ iax_provflags2str()

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

Definition at line 90 of file provision.c.

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}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: format_mp3.c:68
static struct iax_flag iax_flags[]
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int value
Definition: syslog.c:37
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_strlen_zero(), buf, iax_flags, name, NULL, and value.

Referenced by dump_prov_flags(), and iax_show_provisioning().

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

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)
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 ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:342
static int tmp()
Definition: bt_open.c:389
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
Definition: parser.c:775
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
Definition: parser.c:756
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
Definition: parser.c:763
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
Definition: parser.c:770
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
Definition: provision.c:199
static struct iax_template * iax_template_find(const char *s, int allowdead)
Definition: provision.c:163
#define PROV_IE_PROVVER
Definition: provision.h:38
#define PROV_IE_PORTNO
Definition: provision.h:25
#define PROV_IE_SERVERIP
Definition: provision.h:35
#define PROV_IE_FORMAT
Definition: provision.h:33
#define PROV_IE_USER
Definition: provision.h:26
#define PROV_IE_FLAGS
Definition: provision.h:32
#define PROV_IE_TOS
Definition: provision.h:31
#define PROV_IE_SERVERPORT
Definition: provision.h:36
#define PROV_IE_PASS
Definition: provision.h:27
#define PROV_IE_LANG
Definition: provision.h:30
#define PROV_IE_ALTSERVER
Definition: provision.h:39
unsigned int tos
Definition: provision.c:68
unsigned int server
Definition: provision.c:63
unsigned int altserver
Definition: provision.c:65
char user[20]
Definition: provision.c:59
char pass[20]
Definition: provision.c:60
iax2_format format
Definition: provision.c:67
char lang[10]
Definition: provision.c:61
unsigned short port
Definition: provision.c:62
unsigned int flags
Definition: provision.c:66
unsigned short serverport
Definition: provision.c:64

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

◆ iax_provision_reload()

int iax_provision_reload ( int  reload)

Definition at line 526 of file provision.c.

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 }
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}
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:536
#define ast_log
Definition: astobj2.c:42
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:3321
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3326
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
@ CONFIG_FLAG_FILEUNCHANGED
#define ast_verb(level,...)
#define LOG_NOTICE
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
Definition: provision.c:384
static int provinit
Definition: provision.c:53
static int iax_provision_init(void)
Definition: provision.c:494
static void iax_provision_free_templates(int dead)
Definition: provision.c:501
static int reload(void)
Structure used to handle boolean flags.
Definition: utils.h:199

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(), LOG_NOTICE, NULL, provinit, and reload().

Referenced by load_module(), and reload_config().

◆ iax_provision_unload()

int iax_provision_unload ( void  )

Definition at line 517 of file provision.c.

518{
519 provinit = 0;
521 iax_provision_free_templates(0 /* Remove all templates. */);
522
523 return 0;
524}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry cli_iax2_provision[]
Definition: provision.c:490
descriptor for a cli entry.
Definition: cli.h:171

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

Referenced by __unload_module().

◆ iax_provision_version()

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

Definition at line 258 of file provision.c.

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}
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:427
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
Definition: provision.c:209

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

Referenced by check_provisioning().