[asterisk-commits] russell: branch russell/iax_refcount r79627 - /team/russell/iax_refcount/chan...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 15 17:09:59 CDT 2007
Author: russell
Date: Wed Aug 15 17:09:59 2007
New Revision: 79627
URL: http://svn.digium.com/view/asterisk?view=rev&rev=79627
Log:
fix a couple bugs and add peer_ref and peer_unref functions for convenience
Modified:
team/russell/iax_refcount/channels/chan_iax2.c
Modified: team/russell/iax_refcount/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax_refcount/channels/chan_iax2.c?view=diff&rev=79627&r1=79626&r2=79627
==============================================================================
--- team/russell/iax_refcount/channels/chan_iax2.c (original)
+++ team/russell/iax_refcount/channels/chan_iax2.c Wed Aug 15 17:09:59 2007
@@ -1078,6 +1078,18 @@
return peer;
}
+static struct iax2_peer *peer_ref(struct iax2_peer *peer)
+{
+ ao2_ref(peer, +1);
+ return peer;
+}
+
+static struct iax2_peer *peer_unref(struct iax2_peer *peer)
+{
+ ao2_ref(peer, -1);
+ return NULL;
+}
+
static int iax2_getpeername(struct sockaddr_in sin, char *host, int len)
{
struct iax2_peer *peer = NULL;
@@ -1089,18 +1101,18 @@
if ((peer->addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
(peer->addr.sin_port == sin.sin_port)) {
ast_copy_string(host, peer->name, len);
- ao2_ref(peer, -1);
+ peer_unref(peer);
res = 1;
break;
}
- ao2_ref(peer, -1);
+ peer_unref(peer);
}
if (!peer) {
peer = realtime_peer(NULL, &sin);
if (peer) {
ast_copy_string(host, peer->name, len);
- ao2_ref(peer, -1);
+ peer_unref(peer);
res = 1;
}
}
@@ -1998,7 +2010,7 @@
} else {
ast_cli(fd, "SORRY peer %s is not eligible for this operation.\n", argv[3]);
}
- ao2_ref(peer, -1);
+ peer_unref(peer);
} else {
ast_cli(fd, "SORRY peer %s was not found in the cache.\n", argv[3]);
}
@@ -2125,7 +2137,7 @@
ast_cli(fd, "%s\n",status);
ast_cli(fd, " Qualify : every %dms when OK, every %dms when UNREACHABLE (sample smoothing %s)\n", peer->pokefreqok, peer->pokefreqnotok, peer->smoothing ? "On" : "Off");
ast_cli(fd,"\n");
- ao2_ref(peer, -1);
+ peer_unref(peer);
} else {
ast_cli(fd,"Peer %s not found.\n", argv[3]);
ast_cli(fd,"\n");
@@ -2150,10 +2162,10 @@
while ((peer = ao2_iterator_next(&i))) {
if (!strncasecmp(peer->name, word, wordlen) && ++which > state) {
res = ast_strdup(peer->name);
- ao2_ref(peer, -1);
+ peer_unref(peer);
break;
}
- ao2_ref(peer, -1);
+ peer_unref(peer);
}
return res;
@@ -2567,8 +2579,7 @@
if (strcasecmp(tmp->value, "friend") &&
strcasecmp(tmp->value, "peer")) {
/* Whoops, we weren't supposed to exist! */
- ao2_ref(peer, -1);
- peer = NULL;
+ peer = peer_unref(peer);
break;
}
} else if (!strcasecmp(tmp->name, "regseconds")) {
@@ -2595,7 +2606,7 @@
ast_sched_del(sched, peer->expire);
peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, (void*)peer->name);
}
- ao2_link(peers, peer);
+ ao2_link(peers, peer_ref(peer));
if (ast_test_flag(peer, IAX_DYNAMIC))
reg_source_db(peer);
} else {
@@ -2772,7 +2783,7 @@
res = 0;
return_unref:
- ao2_ref(peer, -1);
+ peer_unref(peer);
return res;
}
@@ -3354,10 +3365,10 @@
if ((peer->addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
(peer->addr.sin_port == sin.sin_port)) {
res = ast_test_flag(peer, IAX_TRUNK);
- ao2_ref(peer, -1);
+ peer_unref(peer);
break;
}
- ao2_ref(peer, -1);
+ peer_unref(peer);
}
return res;
@@ -4185,7 +4196,7 @@
i = ao2_iterator_init(peers, 0);
for (peer = ao2_iterator_next(&i); peer;
- ao2_ref(peer, -1), peer = ao2_iterator_next(&i)) {
+ peer_unref(peer), peer = ao2_iterator_next(&i)) {
char nm[20];
char status[20];
char srch[2000];
@@ -5174,7 +5185,7 @@
res = 0;
return_unref:
- ao2_ref(p, -1);
+ peer_unref(p);
return res;
}
@@ -5273,7 +5284,7 @@
/* No specified host, or this is our host */
) {
res = authenticate(p->challenge, peer->secret, peer->outkey, authmethods, &ied, sin, &p->ecx, &p->dcx);
- ao2_ref(peer, -1);
+ peer_unref(peer);
if (!res)
break;
}
@@ -5286,11 +5297,11 @@
if ((peer = realtime_peer(peer_name, NULL))) {
ast_mutex_lock(&iaxsl[callno]);
if (!(p = iaxs[callno])) {
- ao2_ref(peer, -1);
+ peer_unref(peer);
return -1;
}
res = authenticate(p->challenge, peer->secret,peer->outkey, authmethods, &ied, sin, &p->ecx, &p->dcx);
- ao2_ref(peer, -1);
+ peer_unref(peer);
}
if (!peer) {
ast_mutex_lock(&iaxsl[callno]);
@@ -5619,8 +5630,8 @@
if (ast_test_flag(peer, IAX_RTAUTOCLEAR))
ao2_unlink(peers, peer);
-
- ao2_ref(peer, -1);
+
+ peer_unref(peer);
}
static int expire_registry(void *data)
@@ -5789,7 +5800,7 @@
res = 0;
return_unref:
- ao2_ref(p, -1);
+ peer_unref(p);
return res ? res : send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGACK, 0, ied.buf, ied.pos, -1);
}
@@ -5826,7 +5837,7 @@
iax_ie_append_str(&ied, IAX_IE_USERNAME, peer_name);
return_unref:
- ao2_ref(p, -1);
+ peer_unref(p);
return res ? res : send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGAUTH, 0, ied.buf, ied.pos, -1);;
}
@@ -8685,7 +8696,7 @@
if (!temponly) {
peer = ao2_find(peers, (void *) name, OBJ_NODATA);
- if (!ast_test_flag(peer, IAX_DELME))
+ if (peer && !ast_test_flag(peer, IAX_DELME))
firstpass = 0;
}
@@ -8700,10 +8711,8 @@
peer->expire = -1;
peer->pokeexpire = -1;
peer->sockfd = defaultsockfd;
- if (ast_string_field_init(peer, 32)) {
- ao2_ref(peer, -1);
- peer = NULL;
- }
+ if (ast_string_field_init(peer, 32))
+ peer = peer_unref(peer);
}
if (peer) {
@@ -8791,8 +8800,7 @@
ast_clear_flag(peer, IAX_DYNAMIC);
if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr)) {
ast_string_field_free_pools(peer);
- ao2_ref(peer, -1);
- return NULL;
+ return peer_unref(peer);
}
if (!peer->addr.sin_port)
peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
@@ -8802,8 +8810,7 @@
} else if (!strcasecmp(v->name, "defaultip")) {
if (ast_get_ip(&peer->defaddr, v->value)) {
ast_string_field_free_pools(peer);
- ao2_ref(peer, -1);
- return NULL;
+ return peer_unref(peer);
}
} else if (!strcasecmp(v->name, "sourceaddress")) {
peer_set_srcaddr(peer, v->value);
@@ -9206,7 +9213,7 @@
while ((peer = ao2_iterator_next(&i))) {
if (ast_test_flag(peer, IAX_DELME))
ao2_unlink(peers, peer);
- ao2_ref(peer, -1);
+ peer_unref(peer);
}
}
@@ -10019,7 +10026,7 @@
}
}
- ao2_ref(peer, -1);
+ peer_unref(peer);
return 0;
}
@@ -10080,7 +10087,7 @@
res = AST_DEVICE_UNKNOWN;
}
- ao2_ref(p, -1);
+ peer_unref(p);
return res;
}
More information about the asterisk-commits
mailing list