[Asterisk-cvs] asterisk/channels chan_sip.c,1.713,1.714
kpfleming at lists.digium.com
kpfleming at lists.digium.com
Sun May 1 19:00:07 CDT 2005
Update of /usr/cvsroot/asterisk/channels
In directory localhost.localdomain:/tmp/cvs-serv23384/channels
Modified Files:
chan_sip.c
Log Message:
clean up reg_source_db
Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.713
retrieving revision 1.714
diff -u -d -r1.713 -r1.714
--- chan_sip.c 1 May 2005 18:37:37 -0000 1.713
+++ chan_sip.c 1 May 2005 23:07:05 -0000 1.714
@@ -1318,7 +1318,7 @@
}
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(ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
@@ -4733,61 +4733,63 @@
return 0;
}
-/*--- reg_source_db: Save registration in Asterisk DB ---*/
-static void reg_source_db(struct sip_peer *p)
+/*--- reg_source_db: Get registration details from Asterisk DB ---*/
+static void reg_source_db(struct sip_peer *peer)
{
char data[256];
char iabuf[INET_ADDRSTRLEN];
struct in_addr in;
- char *c, *d, *u, *e;
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++;
- u = strchr(d, ':');
- if (u) {
- *u = '\0';
- u++;
- e = strchr(u, ':');
- if (e) {
- *e = '\0';
- e++;
- strncpy(p->fullcontact, e, sizeof(p->fullcontact) - 1);
- }
- strncpy(p->username, u, sizeof(p->username) - 1);
-
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding peers from Astdb: '%s' at %s@%s:%d for %d\n", p->name,
- p->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), atoi(c), atoi(d));
- 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 (sipsock < 0) {
- /* SIP isn't up yet, so schedule a poke only, pretty soon */
- if (p->pokeexpire > -1)
- ast_sched_del(sched, p->pokeexpire);
- p->pokeexpire = ast_sched_add(sched, rand() % 5000 + 1, sip_poke_peer_s, p);
- } else
- sip_poke_peer(p);
- if (p->expire > -1)
- ast_sched_del(sched, p->expire);
- p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, (void *)p);
- register_peer_exten(p, 1);
- }
-
- }
- }
- }
+ int port;
+ char *scan, *addr, *port_str, *expiry_str, *username, *contact;
+
+ if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data)))
+ return;
+
+ scan = data;
+ addr = strsep(&scan, ":");
+ port_str = strsep(&scan, ":");
+ expiry_str = strsep(&scan, ":");
+ username = strsep(&scan, ":");
+ contact = strsep(&scan, ":");
+
+ if (!inet_aton(addr, &in))
+ return;
+
+ if (port_str)
+ port = atoi(port_str);
+ else
+ return;
+
+ 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)
+ ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding peer from astdb: '%s' at %s@%s:%d for %d\n",
+ peer->name, peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), port, expiry);
+
+ memset(&peer->addr, 0, sizeof(peer->addr));
+ peer->addr.sin_family = AF_INET;
+ peer->addr.sin_addr = in;
+ peer->addr.sin_port = htons(port);
+ if (sipsock < 0) {
+ /* SIP isn't up yet, so schedule a poke only, pretty soon */
+ if (peer->pokeexpire > -1)
+ ast_sched_del(sched, peer->pokeexpire);
+ peer->pokeexpire = ast_sched_add(sched, rand() % 5000 + 1, sip_poke_peer_s, peer);
+ } else
+ sip_poke_peer(peer);
+ if (peer->expire > -1)
+ ast_sched_del(sched, peer->expire);
+ peer->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, peer);
+ register_peer_exten(peer, 1);
}
/*--- parse_ok_contact: Parse contact header for 200 OK on INVITE ---*/
@@ -10074,7 +10076,7 @@
peer->expiry = expiry;
}
/* If we have channel variables, remove them (reload) */
- if(peer->chanvars) {
+ if (peer->chanvars) {
ast_variables_destroy(peer->chanvars);
peer->chanvars = NULL;
}
@@ -10176,8 +10178,7 @@
ASTOBJ_UNREF(peer, sip_destroy_peer);
return NULL;
}
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
+ } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
peer->ha = ast_append_ha(v->name, v->value, peer->ha);
} else if (!strcasecmp(v->name, "mask")) {
maskfound++;
More information about the svn-commits
mailing list