clean up reg_source_db
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5543 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
6cd346ebe1
commit
f07020fa1c
1 changed files with 55 additions and 54 deletions
|
@ -1318,7 +1318,7 @@ static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newpeername) {
|
if (newpeername) {
|
||||||
peer = build_peer(newpeername, var, ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS) ? 0 : 1);
|
peer = build_peer(newpeername, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS));
|
||||||
|
|
||||||
if (peer) {
|
if (peer) {
|
||||||
if(ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
|
if(ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
|
||||||
|
@ -4733,61 +4733,63 @@ static int sip_poke_peer_s(void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--- reg_source_db: Save registration in Asterisk DB ---*/
|
/*--- reg_source_db: Get registration details from Asterisk DB ---*/
|
||||||
static void reg_source_db(struct sip_peer *p)
|
static void reg_source_db(struct sip_peer *peer)
|
||||||
{
|
{
|
||||||
char data[256];
|
char data[256];
|
||||||
char iabuf[INET_ADDRSTRLEN];
|
char iabuf[INET_ADDRSTRLEN];
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
char *c, *d, *u, *e;
|
|
||||||
int expiry;
|
int expiry;
|
||||||
if (!ast_db_get("SIP/Registry", p->name, data, sizeof(data))) {
|
int port;
|
||||||
c = strchr(data, ':');
|
char *scan, *addr, *port_str, *expiry_str, *username, *contact;
|
||||||
if (c) {
|
|
||||||
*c = '\0';
|
if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data)))
|
||||||
c++;
|
return;
|
||||||
if (inet_aton(data, &in)) {
|
|
||||||
d = strchr(c, ':');
|
scan = data;
|
||||||
if (d) {
|
addr = strsep(&scan, ":");
|
||||||
*d = '\0';
|
port_str = strsep(&scan, ":");
|
||||||
d++;
|
expiry_str = strsep(&scan, ":");
|
||||||
u = strchr(d, ':');
|
username = strsep(&scan, ":");
|
||||||
if (u) {
|
contact = strsep(&scan, ":");
|
||||||
*u = '\0';
|
|
||||||
u++;
|
if (!inet_aton(addr, &in))
|
||||||
e = strchr(u, ':');
|
return;
|
||||||
if (e) {
|
|
||||||
*e = '\0';
|
if (port_str)
|
||||||
e++;
|
port = atoi(port_str);
|
||||||
strncpy(p->fullcontact, e, sizeof(p->fullcontact) - 1);
|
else
|
||||||
}
|
return;
|
||||||
strncpy(p->username, u, sizeof(p->username) - 1);
|
|
||||||
|
if (expiry_str)
|
||||||
|
expiry = atoi(expiry_str);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (username)
|
||||||
|
strncpy(peer->username, username, sizeof(peer->username)-1);
|
||||||
|
if (contact)
|
||||||
|
strncpy(peer->fullcontact, contact, sizeof(peer->fullcontact)-1);
|
||||||
|
|
||||||
}
|
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding peers from Astdb: '%s' at %s@%s:%d for %d\n", p->name,
|
ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding peer from astdb: '%s' at %s@%s:%d for %d\n",
|
||||||
p->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), atoi(c), atoi(d));
|
peer->name, peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), port, expiry);
|
||||||
expiry = atoi(d);
|
|
||||||
memset(&p->addr, 0, sizeof(p->addr));
|
memset(&peer->addr, 0, sizeof(peer->addr));
|
||||||
p->addr.sin_family = AF_INET;
|
peer->addr.sin_family = AF_INET;
|
||||||
p->addr.sin_addr = in;
|
peer->addr.sin_addr = in;
|
||||||
p->addr.sin_port = htons(atoi(c));
|
peer->addr.sin_port = htons(port);
|
||||||
if (sipsock < 0) {
|
if (sipsock < 0) {
|
||||||
/* SIP isn't up yet, so schedule a poke only, pretty soon */
|
/* SIP isn't up yet, so schedule a poke only, pretty soon */
|
||||||
if (p->pokeexpire > -1)
|
if (peer->pokeexpire > -1)
|
||||||
ast_sched_del(sched, p->pokeexpire);
|
ast_sched_del(sched, peer->pokeexpire);
|
||||||
p->pokeexpire = ast_sched_add(sched, rand() % 5000 + 1, sip_poke_peer_s, p);
|
peer->pokeexpire = ast_sched_add(sched, rand() % 5000 + 1, sip_poke_peer_s, peer);
|
||||||
} else
|
} else
|
||||||
sip_poke_peer(p);
|
sip_poke_peer(peer);
|
||||||
if (p->expire > -1)
|
if (peer->expire > -1)
|
||||||
ast_sched_del(sched, p->expire);
|
ast_sched_del(sched, peer->expire);
|
||||||
p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, (void *)p);
|
peer->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, peer);
|
||||||
register_peer_exten(p, 1);
|
register_peer_exten(peer, 1);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--- parse_ok_contact: Parse contact header for 200 OK on INVITE ---*/
|
/*--- parse_ok_contact: Parse contact header for 200 OK on INVITE ---*/
|
||||||
|
@ -10176,8 +10178,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int
|
||||||
ASTOBJ_UNREF(peer, sip_destroy_peer);
|
ASTOBJ_UNREF(peer, sip_destroy_peer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp(v->name, "permit") ||
|
} else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
|
||||||
!strcasecmp(v->name, "deny")) {
|
|
||||||
peer->ha = ast_append_ha(v->name, v->value, peer->ha);
|
peer->ha = ast_append_ha(v->name, v->value, peer->ha);
|
||||||
} else if (!strcasecmp(v->name, "mask")) {
|
} else if (!strcasecmp(v->name, "mask")) {
|
||||||
maskfound++;
|
maskfound++;
|
||||||
|
|
Loading…
Reference in a new issue