33 #include <netinet/in.h> 34 #include <netinet/in_systm.h> 35 #include <netinet/ip.h> 36 #include <sys/socket.h> 94 if (!buf || buflen < 1)
102 strncat(buf,
",", buflen - strlen(buf) - 1);
107 buf[strlen(buf) - 1] =
'\0';
109 strncpy(buf,
"none", buflen - 1);
118 unsigned int flags = 0;
121 e = strchr(buf,
',');
128 (!len && !strcasecmp(
iax_flags[x].name, buf))) {
135 while(*buf && (*buf < 33))
168 if (!strcasecmp(s, cur->
name)) {
169 if (!allowdead && cur->
dead) {
184 int wordlen = strlen(word);
189 if (!strncasecmp(word, c->
name, wordlen) && ++which > state) {
205 MD5Final((
unsigned char *)tmp, &md5);
206 return tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3];
214 memset(provdata, 0,
sizeof(*provdata));
222 if (force || strlen(cur->
user))
224 if (force || strlen(cur->
pass))
226 if (force || strlen(cur->
lang))
228 if (force || cur->
port)
236 if (force || cur->
flags)
240 if (force || cur->
tos)
250 snprintf(tmp,
sizeof(tmp),
"v0x%08x", sig);
251 ast_db_put(
"iax/provisioning/cache",
template, tmp);
253 ast_db_put(
"iax/provisioning/cache",
template,
"u");
263 memset(&ied, 0,
sizeof(ied));
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);
269 if (sscanf(tmp,
"v%30x", version) != 1) {
270 if (strcmp(tmp,
"u")) {
273 ast_debug(1,
"Unable to create provisioning packet for '%s'\n",
template);
277 ast_debug(1,
"Retrieved cached version '%s' = '%08x'\n", tmp, *version);
286 int foundserverportno = 0;
296 if (t && strlen(t)) {
299 ast_log(
LOG_WARNING,
"Unable to find base template '%s' for creating '%s'. Trying '%s'\n", t, s, def);
306 ast_log(
LOG_WARNING,
"Unable to locate default base template '%s' for creating '%s', omitting.\n", def, s);
326 if (!strcasecmp(v->
name,
"port") || !strcasecmp(v->
name,
"serverport")) {
327 if ((sscanf(v->
value,
"%5d", &x) == 1) && (x > 0) && (x < 65535)) {
328 if (!strcasecmp(v->
name,
"port")) {
333 foundserverportno = 1;
337 }
else if (!strcasecmp(v->
name,
"server") || !strcasecmp(v->
name,
"altserver")) {
340 memcpy(&ia, hp->h_addr,
sizeof(ia));
341 if (!strcasecmp(v->
name,
"server"))
342 cur->
server = ntohl(ia.s_addr);
347 }
else if (!strcasecmp(v->
name,
"codec")) {
354 }
else if (!strcasecmp(v->
name,
"tos")) {
357 }
else if (!strcasecmp(v->
name,
"user")) {
361 }
else if (!strcasecmp(v->
name,
"pass")) {
365 }
else if (!strcasecmp(v->
name,
"language")) {
369 }
else if (!strcasecmp(v->
name,
"flags")) {
371 }
else if (!strncasecmp(v->
name,
"flags", 5) && strchr(v->
name,
'+')) {
373 }
else if (!strncasecmp(v->
name,
"flags", 5) && strchr(v->
name,
'-')) {
375 }
else if (strcasecmp(v->
name,
"template")) {
382 if (!foundserverportno)
422 return "<unspecified>";
430 return "<unspecified>";
432 ia.s_addr = htonl(addr);
441 char server[INET_ADDRSTRLEN];
442 char alternate[INET_ADDRSTRLEN];
448 e->
command =
"iax2 show provisioning";
450 "Usage: iax2 show provisioning [template]\n" 451 " Lists all known IAX provisioning templates or a\n" 452 " specific one if specified.\n";
458 if ((a->
argc != 3) && (a->
argc != 4))
463 if ((a->
argc == 3) || (!strcasecmp(a->
argv[3], cur->
name))) {
469 ast_cli(a->
fd,
"Base Templ: %s\n", strlen(cur->
src) ? cur->
src :
"<none>");
476 ast_cli(a->
fd,
"Alternate: %s\n", alternate);
486 ast_cli(a->
fd,
"No provisioning templates found\n");
488 ast_cli(a->
fd,
"No provisioning template matching '%s' found\n", a->
argv[3]);
511 if ((dead && cur->
dead) || !dead) {
549 if (strcasecmp(cat,
"general")) {
552 ast_verb(3,
"Loaded provisioning template '%s'\n", cat);
560 ast_log(
LOG_NOTICE,
"No IAX provisioning configuration found, IAX provisioning disabled.\n");
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
#define PROV_FLAG_HEARTBEAT
struct ast_variable * next
#define AST_CLI_DEFINE(fn, txt,...)
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int iax_provision_version(unsigned int *version, const char *template, int force)
static void iax_template_copy(struct iax_template *dst, struct iax_template *src)
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
const char * iax2_getformatname(iax2_format format)
iax2 wrapper function for ast_getformatname
descriptor for a cli entry.
static void iax_provision_free_templates(int dead)
#define CONFIG_STATUS_FILEINVALID
static const char * iax_server(unsigned int addr)
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
void MD5Final(unsigned char digest[16], struct MD5Context *context)
#define IAX_DEFAULT_PORTNO
#define PROV_FLAG_REGISTER
static int iax_provision_init(void)
struct iax_template::@157 list
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define ast_mutex_lock(a)
#define ast_strdup(str)
A wrapper for strdup()
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
static const char * ifthere(const char *s)
void ast_cli(int fd, const char *fmt,...)
char * iax_provflags2str(char *buf, int buflen, unsigned int flags)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define ast_verb(level,...)
void MD5Init(struct MD5Context *context)
Implementation of the IAX2 protocol.
#define ast_strlen_zero(foo)
#define PROV_FLAG_DIS_THREEWAY
Configuration File Parser.
#define ast_debug(level,...)
Log a DEBUG message.
char * iax_prov_complete_template(const char *line, const char *word, int pos, int state)
static struct iax_template * iax_template_find(const char *s, int allowdead)
Access Control of various sorts.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Asterisk internal frame definitions.
unsigned short serverport
#define ao2_ref(o, delta)
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
#define PROV_IE_SERVERPORT
#define CONFIG_STATUS_FILEUNCHANGED
#define PROV_FLAG_DIS_CALLERID
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
IAX2 Provisioning protocol.
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
Implementation of Inter-Asterisk eXchange, version 2 iax2-parser::c iax2-parser.h chan_iax2...
#define PROV_FLAG_DIS_CIDCW
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
static char version[AST_MAX_EXTENSION]
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
#define ast_calloc(num, len)
A wrapper for calloc()
static unsigned int iax_str2flags(const char *buf)
static struct iax_flag iax_flags[]
static struct ast_cli_entry cli_iax2_provision[]
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
structure to hold users read from users.conf
Structure used to handle boolean flags.
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg, const char *s, const char *def)
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
static ast_mutex_t provlock
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int iax_provision_unload(void)
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
#define PROV_IE_ALTSERVER
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define PROV_FLAG_DIS_CALLWAIT
int iax_provision_reload(int reload)
static struct hostent * hp
Persistant data storage (akin to *doze registry)
#define AST_MUTEX_DEFINE_STATIC(mutex)
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
#define ast_mutex_unlock(a)
static char * iax_show_provisioning(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)