[asterisk-commits] russell: branch russell/events r61785 - in
/team/russell/events: channels/ co...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Apr 24 13:24:06 MST 2007
Author: russell
Date: Tue Apr 24 15:24:05 2007
New Revision: 61785
URL: http://svn.digium.com/view/asterisk?view=rev&rev=61785
Log:
Allow "register=yes" to be specified in peer entires in iax.conf. This will
make it easier to add more registration related options to the config.
Modified:
team/russell/events/channels/chan_iax2.c
team/russell/events/configs/iax.conf.sample
Modified: team/russell/events/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/channels/chan_iax2.c?view=diff&rev=61785&r1=61784&r2=61785
==============================================================================
--- team/russell/events/channels/chan_iax2.c (original)
+++ team/russell/events/channels/chan_iax2.c Tue Apr 24 15:24:05 2007
@@ -5556,9 +5556,38 @@
return 0;
}
+static int iax2_append_register(const char *hostname, const char *username,
+ const char *secret, const char *porta)
+{
+ struct iax2_registry *reg;
+
+ if (!(reg = ast_calloc(1, sizeof(*reg))))
+ return -1;
+
+ if (ast_dnsmgr_lookup(hostname, ®->addr.sin_addr, ®->dnsmgr) < 0) {
+ free(reg);
+ return -1;
+ }
+
+ ast_copy_string(reg->username, username, sizeof(reg->username));
+
+ if (secret)
+ ast_copy_string(reg->secret, secret, sizeof(reg->secret));
+
+ reg->expire = -1;
+ reg->refresh = IAX_DEFAULT_REG_EXPIRE;
+ reg->addr.sin_family = AF_INET;
+ reg->addr.sin_port = porta ? htons(atoi(porta)) : htons(IAX_DEFAULT_PORTNO);
+
+ AST_LIST_LOCK(®istrations);
+ AST_LIST_INSERT_HEAD(®istrations, reg, entry);
+ AST_LIST_UNLOCK(®istrations);
+
+ return 0;
+}
+
static int iax2_register(char *value, int lineno)
{
- struct iax2_registry *reg;
char copy[256];
char *username, *hostname, *secret;
char *porta;
@@ -5566,18 +5595,21 @@
if (!value)
return -1;
+
ast_copy_string(copy, value, sizeof(copy));
- stringp=copy;
+ stringp = copy;
username = strsep(&stringp, "@");
hostname = strsep(&stringp, "@");
+
if (!hostname) {
ast_log(LOG_WARNING, "Format for registration is user[:secret]@host[:port] at line %d\n", lineno);
return -1;
}
- stringp=username;
+
+ stringp = username;
username = strsep(&stringp, ":");
secret = strsep(&stringp, ":");
- stringp=hostname;
+ stringp = hostname;
hostname = strsep(&stringp, ":");
porta = strsep(&stringp, ":");
@@ -5585,25 +5617,10 @@
ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno);
return -1;
}
- if (!(reg = ast_calloc(1, sizeof(*reg))))
- return -1;
- if (ast_dnsmgr_lookup(hostname, ®->addr.sin_addr, ®->dnsmgr) < 0) {
- free(reg);
- return -1;
- }
- ast_copy_string(reg->username, username, sizeof(reg->username));
- if (secret)
- ast_copy_string(reg->secret, secret, sizeof(reg->secret));
- reg->expire = -1;
- reg->refresh = IAX_DEFAULT_REG_EXPIRE;
- reg->addr.sin_family = AF_INET;
- reg->addr.sin_port = porta ? htons(atoi(porta)) : htons(IAX_DEFAULT_PORTNO);
- AST_LIST_LOCK(®istrations);
- AST_LIST_INSERT_HEAD(®istrations, reg, entry);
- AST_LIST_UNLOCK(®istrations);
-
- return 0;
-}
+
+ return iax2_append_register(hostname, username, secret, porta);
+}
+
static void register_peer_exten(struct iax2_peer *peer, int onoff)
{
@@ -8557,9 +8574,12 @@
{
struct iax2_peer *peer = NULL;
struct ast_ha *oldha = NULL;
- int maskfound=0;
- int found=0;
- int firstpass=1;
+ int maskfound = 0;
+ int found = 0;
+ int firstpass = 1;
+ unsigned int reg = 0;
+ const char *host = NULL;
+ const char *port = NULL;
AST_LIST_LOCK(&peers);
if (!temponly) {
@@ -8675,6 +8695,7 @@
}
if (!peer->addr.sin_port)
peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
+ host = ast_strdupa(v->value);
}
if (!maskfound)
inet_aton("255.255.255.255", &peer->mask);
@@ -8703,6 +8724,7 @@
peer->defaddr.sin_port = htons(atoi(v->value));
else
peer->addr.sin_port = htons(atoi(v->value));
+ port = ast_strdupa(v->value);
} else if (!strcasecmp(v->name, "username")) {
ast_string_field_set(peer, username, v->value);
} else if (!strcasecmp(v->name, "allow")) {
@@ -8751,6 +8773,8 @@
ast_string_field_set(peer, zonetag, v->value);
} else if (!strcasecmp(v->name, "adsi")) {
peer->adsi = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "register")) {
+ reg = ast_true(v->value);
}/* else if (strcasecmp(v->name,"type")) */
/* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
v = v->next;
@@ -8773,6 +8797,15 @@
peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox,
AST_EVENT_IE_END);
+ }
+
+ if (reg) {
+ if (ast_test_flag(peer, IAX_DYNAMIC)) {
+ ast_log(LOG_ERROR, "You can't set register=yes with host=dynamic for peer '%s'!\n",
+ peer->name);
+ } else if (!ast_strlen_zero(host)) {
+ iax2_append_register(host, peer->username, peer->secret, port);
+ }
}
return peer;
Modified: team/russell/events/configs/iax.conf.sample
URL: http://svn.digium.com/view/asterisk/team/russell/events/configs/iax.conf.sample?view=diff&rev=61785&r1=61784&r2=61785
==============================================================================
--- team/russell/events/configs/iax.conf.sample (original)
+++ team/russell/events/configs/iax.conf.sample Tue Apr 24 15:24:05 2007
@@ -435,3 +435,10 @@
;context=default
;permit=0.0.0.0/0.0.0.0
+; Registrations can be specified in a peer entry, as well.
+;[mypeer]
+;type=peer
+;host=mypeer.whatever.com
+;register=yes
+;username=myuser
+;secret=mysecret
More information about the asterisk-commits
mailing list