aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-24 22:35:06 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-24 22:35:06 +0000
commit3f366956a2293693e14c99e4a6c5fac59332feed (patch)
treeaf74dc4be29875bfe87ced7e250c1856d47b6d2e /channels
parent3ce635b33f0ca19de6ff586da41d6504ecd48bd8 (diff)
Make SIP registration persistent (bug #159)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1419 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rwxr-xr-xchannels/chan_iax2.c8
-rwxr-xr-xchannels/chan_sip.c63
2 files changed, 57 insertions, 14 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 4ae5de758..fb0e683a8 100755
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -3259,7 +3259,7 @@ static int expire_registry(void *data)
p->expire = -1;
/* Reset expirey value */
p->expirey = expirey;
- ast_db_del("IAX2/Registry", p->name);
+ ast_db_del("IAX/Registry", p->name);
if (iax2_regfunk)
iax2_regfunk(p->name, 0);
return 0;
@@ -3273,7 +3273,7 @@ static void reg_source_db(struct iax2_peer *p)
char data[80];
struct in_addr in;
char *c, *d;
- if (!ast_db_get("IAX2/Registry", p->name, data, sizeof(data))) {
+ if (!ast_db_get("IAX/Registry", p->name, data, sizeof(data))) {
c = strchr(data, ':');
if (c) {
*c = '\0';
@@ -3294,6 +3294,8 @@ static void reg_source_db(struct iax2_peer *p)
if (p->expire > -1)
ast_sched_del(sched, p->expire);
p->expire = ast_sched_add(sched, p->expirey * 1000, expire_registry, (void *)p);
+ if (iax2_regfunk)
+ iax2_regfunk(p->name, 1);
}
}
@@ -3315,7 +3317,7 @@ static int update_registry(char *name, struct sockaddr_in *sin, int callno)
if (iax2_regfunk)
iax2_regfunk(p->name, 1);
snprintf(data, sizeof(data), "%s:%d:%d", inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), p->expirey);
- ast_db_put("IAX2/Registry", p->name, data);
+ ast_db_put("IAX/Registry", p->name, data);
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Registered '%s' (%s) at %s:%d\n", p->name,
iaxs[callno]->state & IAX_STATE_AUTHENTICATED ? "AUTHENTICATED" : "UNAUTHENTICATED", inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 54cee4bb9..30d7f1bc4 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -37,6 +37,7 @@
#include <asterisk/parking.h>
#include <asterisk/acl.h>
#include <asterisk/srv.h>
+#include <asterisk/astdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
@@ -3024,6 +3025,7 @@ static int expire_register(void *data)
{
struct sip_peer *p = data;
memset(&p->addr, 0, sizeof(p->addr));
+ ast_db_del("SIP/Registry", p->name);
p->expire = -1;
ast_device_state_changed("SIP/%s", p->name);
return 0;
@@ -3031,9 +3033,44 @@ static int expire_register(void *data)
static int sip_poke_peer(struct sip_peer *peer);
+static void reg_source_db(struct sip_peer *p)
+{
+ char data[80];
+ struct in_addr in;
+ char *c, *d;
+ int expiry;
+ if (!ast_db_get("SIP/Registry", p->name, data, sizeof(data))) {
+ c = strchr(data, ':');
+ if (c) {
+ *c = '\0';
+ c++;
+ if (inet_aton(data, &in)) {
+ d = strchr(c, ':');
+ if (d) {
+ *d = '\0';
+ d++;
+ ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding '%s' at %s:%d for %d\n", p->name,
+ inet_ntoa(in), atoi(c), atoi(d));
+ sip_poke_peer(p);
+ expiry = atoi(d);
+ memset(&p->addr, 0, sizeof(p->addr));
+ p->addr.sin_family = AF_INET;
+ p->addr.sin_addr = in;
+ p->addr.sin_port = htons(atoi(c));
+ if (p->expire > -1)
+ ast_sched_del(sched, p->expire);
+ p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, (void *)p);
+ }
+
+ }
+ }
+ }
+}
+
static int parse_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req)
{
char contact[80]= "";
+ char data[256];
char *expires = get_header(req, "Expires");
int expiry = atoi(expires);
char *c, *n, *pt;
@@ -3068,7 +3105,7 @@ static int parse_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_req
ast_sched_del(sched, p->expire);
p->expire = -1;
if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Unregistered SIP '%s'\n", p->username);
+ ast_verbose(VERBOSE_PREFIX_3 "Unregistered SIP '%s'\n", p->name);
return 0;
}
/* Make sure it's a SIP URL */
@@ -3124,8 +3161,10 @@ static int parse_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_req
pvt->expiry = expiry;
if (inaddrcmp(&p->addr, &oldsin)) {
sip_poke_peer(p);
+ snprintf(data, sizeof(data), "%s:%d:%d", inet_ntoa(p->addr.sin_addr), ntohs(p->addr.sin_port), expiry);
+ ast_db_put("SIP/Registry", p->name, data);
if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d expires %d\n", p->username, inet_ntoa(p->addr.sin_addr), ntohs(p->addr.sin_port), expiry);
+ ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d expires %d\n", p->name, inet_ntoa(p->addr.sin_addr), ntohs(p->addr.sin_port), expiry);
}
return 0;
}
@@ -5606,6 +5645,8 @@ static struct sip_peer *build_peer(char *name, struct ast_variable *v)
}
if (!strlen(peer->methods))
strcpy(peer->methods, "md5,plaintext");
+ if (!found && peer->dynamic)
+ reg_source_db(peer);
peer->delme = 0;
}
return peer;
@@ -5876,6 +5917,15 @@ int load_module()
int res;
struct sip_peer *peer;
struct sip_registry *reg;
+ sched = sched_context_create();
+ if (!sched) {
+ ast_log(LOG_WARNING, "Unable to create schedule context\n");
+ }
+ io = io_context_create();
+ if (!io) {
+ ast_log(LOG_WARNING, "Unable to create I/O context\n");
+ }
+
res = reload_config();
if (!res) {
/* Make sure we can register our sip channel type */
@@ -5893,15 +5943,6 @@ int load_module()
ast_cli_register(&cli_inuse_show);
sip_rtp.type = type;
ast_rtp_proto_register(&sip_rtp);
- sched = sched_context_create();
- if (!sched) {
- ast_log(LOG_WARNING, "Unable to create schedule context\n");
- }
- io = io_context_create();
- if (!io) {
- ast_log(LOG_WARNING, "Unable to create I/O context\n");
- }
-
ast_mutex_lock(&peerl.lock);
for (peer = peerl.peers; peer; peer = peer->next)
sip_poke_peer(peer);