35 #include <netinet/in.h>
36 #include <netinet/in_systm.h>
37 #include <netinet/ip.h>
38 #include <sys/socket.h>
93 if (!buf || buflen < 1)
101 strncat(buf,
",", buflen - strlen(buf) - 1);
106 buf[strlen(buf) - 1] =
'\0';
108 strncpy(buf,
"none", buflen - 1);
117 unsigned int flags = 0;
120 e = strchr(buf,
',');
127 (!len && !strcasecmp(
iax_flags[x].name, buf))) {
134 while(*buf && (*buf < 33))
167 if (!strcasecmp(s, cur->
name)) {
168 if (!allowdead && cur->
dead) {
183 int wordlen = strlen(word);
188 if (!strncasecmp(word, c->
name, wordlen) && ++which > state) {
204 MD5Final((
unsigned char *)tmp, &md5);
205 return tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3];
213 memset(provdata, 0,
sizeof(*provdata));
221 if (force || strlen(cur->
user))
223 if (force || strlen(cur->
pass))
225 if (force || strlen(cur->
lang))
227 if (force || cur->
port)
235 if (force || cur->
flags)
239 if (force || cur->
tos)
249 snprintf(tmp,
sizeof(tmp),
"v0x%08x", sig);
250 ast_db_put(
"iax/provisioning/cache",
template, tmp);
252 ast_db_put(
"iax/provisioning/cache",
template,
"u");
262 memset(&ied, 0,
sizeof(ied));
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);
268 if (sscanf(tmp,
"v%30x", version) != 1) {
269 if (strcmp(tmp,
"u")) {
272 ast_debug(1,
"Unable to create provisioning packet for '%s'\n",
template);
276 ast_debug(1,
"Retrieved cached version '%s' = '%08x'\n", tmp, *version);
285 int foundserverportno = 0;
295 if (t && strlen(t)) {
298 ast_log(
LOG_WARNING,
"Unable to find base template '%s' for creating '%s'. Trying '%s'\n", t, s, def);
305 ast_log(
LOG_WARNING,
"Unable to locate default base template '%s' for creating '%s', omitting.\n", def, s);
320 strncpy(cur->
src, def,
sizeof(cur->
src) - 1);
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")) {
332 foundserverportno = 1;
336 }
else if (!strcasecmp(v->
name,
"server") || !strcasecmp(v->
name,
"altserver")) {
339 memcpy(&ia, hp->h_addr,
sizeof(ia));
340 if (!strcasecmp(v->
name,
"server"))
341 cur->
server = ntohl(ia.s_addr);
346 }
else if (!strcasecmp(v->
name,
"codec")) {
351 }
else if (!strcasecmp(v->
name,
"tos")) {
354 }
else if (!strcasecmp(v->
name,
"user")) {
358 }
else if (!strcasecmp(v->
name,
"pass")) {
362 }
else if (!strcasecmp(v->
name,
"language")) {
366 }
else if (!strcasecmp(v->
name,
"flags")) {
368 }
else if (!strncasecmp(v->
name,
"flags", 5) && strchr(v->
name,
'+')) {
370 }
else if (!strncasecmp(v->
name,
"flags", 5) && strchr(v->
name,
'-')) {
372 }
else if (strcasecmp(v->
name,
"template")) {
379 if (!foundserverportno)
399 strncpy(cur->
name, s,
sizeof(cur->
name) - 1);
419 return "<unspecified>";
427 return "<unspecified>";
429 ia.s_addr = htonl(addr);
438 char server[INET_ADDRSTRLEN];
439 char alternate[INET_ADDRSTRLEN];
445 e->
command =
"iax2 show provisioning";
447 "Usage: iax2 show provisioning [template]\n"
448 " Lists all known IAX provisioning templates or a\n"
449 " specific one if specified.\n";
455 if ((a->
argc != 3) && (a->
argc != 4))
460 if ((a->
argc == 3) || (!strcasecmp(a->
argv[3], cur->
name))) {
466 ast_cli(a->
fd,
"Base Templ: %s\n", strlen(cur->
src) ? cur->
src :
"<none>");
473 ast_cli(a->
fd,
"Alternate: %s\n", alternate);
483 ast_cli(a->
fd,
"No provisioning templates found\n");
485 ast_cli(a->
fd,
"No provisioning template matching '%s' found\n", a->
argv[3]);
508 if ((dead && cur->
dead) || !dead) {
546 if (strcasecmp(cat,
"general")) {
549 ast_verb(3,
"Loaded provisioning template '%s'\n", cat);
557 ast_log(
LOG_NOTICE,
"No IAX provisioning configuration found, IAX provisioning disabled.\n");
#define PROV_FLAG_DIS_CALLERID
static ast_mutex_t provlock
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
static int iax_provision_init(void)
static const char * iax_server(unsigned int addr)
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
static void iax_provision_free_templates(int dead)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
static char * iax_show_provisioning(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define PROV_FLAG_HEARTBEAT
static unsigned int iax_str2flags(const char *buf)
int iax_provision_reload(int reload)
descriptor for a cli entry.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
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_DIS_THREEWAY
Configuration File Parser.
#define ast_mutex_lock(a)
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
char * iax_prov_complete_template(const char *line, const char *word, int pos, int state)
void ast_cli(int fd, const char *fmt,...)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define ast_verb(level,...)
#define PROV_FLAG_REGISTER
void ast_config_destroy(struct ast_config *config)
Destroys a config.
void MD5Init(struct MD5Context *context)
#define PROV_FLAG_DIS_CALLWAIT
#define ast_debug(level,...)
Log a DEBUG message.
static const char * ifthere(const char *s)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Access Control of various sorts.
Asterisk internal frame definitions.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
unsigned short serverport
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
#define PROV_IE_SERVERPORT
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)
void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
format_t ast_getformatbyname(const char *name)
Gets a format from a name.
char * ast_getformatname(format_t format)
Get the name of a format.
#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.c.
static struct ast_cli_entry cli_iax2_provision[]
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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...
static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg, const char *s, const char *def)
#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.
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
#define PROV_IE_ALTSERVER
#define PROV_FLAG_DIS_CIDCW
static struct iax_flag iax_flags[]
structure to hold users read from users.conf
static struct iax_template * iax_template_find(const char *s, int allowdead)
Structure used to handle boolean flags.
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Implementation of the IAX2 protocol.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
IAX2 Provisioning protocol.
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.
struct ast_variable * next
#define CONFIG_STATUS_FILEINVALID
char * iax_provflags2str(char *buf, int buflen, unsigned int flags)
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
static struct hostent * hp
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
int iax_provision_unload(void)
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 If both parameters are NULL, the entire database will be purged...
struct iax_template::@117 list
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define CONFIG_STATUS_FILEUNCHANGED
#define ast_mutex_unlock(a)