[asterisk-commits] rizzo: branch rizzo/astobj2 r47243 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 7 04:25:01 MST 2006


Author: rizzo
Date: Tue Nov  7 05:25:00 2006
New Revision: 47243

URL: http://svn.digium.com/view/asterisk?rev=47243&view=rev
Log:
Replace ASTOBJ_UNREF(peer, sip_destroy_peer) with unref_peer(peer);

This places the name of the destructor in one place only (where it
should be), eliminates the chance of errors in case you specify the wrong
destructor, and also lets the compiler do type checking on the argument,
again helping with keeping the code clean.

Trunk candidate.


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?rev=47243&r1=47242&r2=47243&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Nov  7 05:25:00 2006
@@ -1607,6 +1607,16 @@
 	ast_mutex_unlock(&pvt->pvt_lock);
 }
 
+/*!
+ * helper functions to unreference various types of objects.
+ * By handling them this way, we don't have to declare the
+ * destructor on each call, which removes the chance of errors.
+ */
+static void unref_peer(struct sip_peer *peer)
+{
+	ASTOBJ_UNREF(peer, sip_destroy_peer);
+}
+
 /*! \brief Interface structure with callbacks used to connect to UDPTL module*/
 static struct ast_udptl_protocol sip_udptl = {
 	type: "SIP",
@@ -2010,7 +2020,7 @@
 
 	if (p->subscribed == MWI_NOTIFICATION)
 		if (p->relatedpeer)
-			ASTOBJ_UNREF(p->relatedpeer,sip_destroy_peer);	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
+			unref_peer(p->relatedpeer);	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
 
 	/* Reset schedule ID */
 	p->autokillid = -1;
@@ -2786,7 +2796,7 @@
 
 	if (peer) {
 		int res = create_addr_from_peer(dialog, peer);
-		ASTOBJ_UNREF(peer, sip_destroy_peer);
+		unref_peer(peer);
 		return res;
 	}
 	hostn = peername;
@@ -3121,7 +3131,7 @@
 				if (u)
 					ASTOBJ_UNREF(u, sip_destroy_user);
 				else
-					ASTOBJ_UNREF(p, sip_destroy_peer);
+					unref_peer(p);
 				return -1; 
 			}
 		}
@@ -3156,7 +3166,7 @@
 	}
 	if (p) {
 		ast_device_state_changed("SIP/%s", p->name);
-		ASTOBJ_UNREF(p, sip_destroy_peer);
+		unref_peer(p);
 	} else /* u must be set */
 		ASTOBJ_UNREF(u, sip_destroy_user);
 	return 0;
@@ -7512,7 +7522,7 @@
 	if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT) ||
 	    ast_test_flag(&peer->flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
 		peer = ASTOBJ_CONTAINER_UNLINK(&peerl, peer);	/* Remove from peer list */
-		ASTOBJ_UNREF(peer, sip_destroy_peer);		/* Remove from memory */
+		unref_peer(peer);		/* Remove from memory */
 	}
 
 	return 0;
@@ -8210,7 +8220,7 @@
 	if (!(peer && ast_apply_ha(peer->ha, sin))) {
 		/* Peer fails ACL check */
 		if (peer)
-			ASTOBJ_UNREF(peer, sip_destroy_peer);
+			unref_peer(peer);
 		peer = NULL;
 	}
 	if (peer) {
@@ -8329,7 +8339,7 @@
 		}
 	}
 	if (peer)
-		ASTOBJ_UNREF(peer, sip_destroy_peer);
+		unref_peer(peer);
 
 	return res;
 }
@@ -9175,7 +9185,7 @@
 		if (p->t38.peercapability)
 			p->t38.jointcapability &= p->t38.peercapability;
 	}
-	ASTOBJ_UNREF(peer, sip_destroy_peer);
+	unref_peer(peer);
 	return res;
 }
 
@@ -9897,7 +9907,7 @@
 					ASTOBJ_CONTAINER_LINK(&peerl, peer);
 				} else
 					ast_cli(fd, "Peer '%s' pruned.\n", name);
-				ASTOBJ_UNREF(peer, sip_destroy_peer);
+				unref_peer(peer);
 			} else
 				ast_cli(fd, "Peer '%s' not found.\n", name);
 		}
@@ -10132,7 +10142,7 @@
  				ast_cli(fd, "                 %s = %s\n", v->name, v->value);
 		}
 		ast_cli(fd,"\n");
-		ASTOBJ_UNREF(peer,sip_destroy_peer);
+		unref_peer(peer);
 	} else  if (peer && type == 1) { /* manager listing */
 		char buf[256];
 		astman_append(s, "Channeltype: SIP\r\n");
@@ -10206,7 +10216,7 @@
 			}
 		}
 
-		ASTOBJ_UNREF(peer,sip_destroy_peer);
+		unref_peer(peer);
 
 	} else {
 		ast_cli(fd,"Peer %s not found.\n", argv[3]);
@@ -10906,7 +10916,7 @@
 			ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
 		} else
 			ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[3]);
-		ASTOBJ_UNREF(peer,sip_destroy_peer);
+		unref_peer(peer);
 	} else
 		ast_cli(fd, "No such peer '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
@@ -11454,7 +11464,7 @@
 		}
 	}
 
-	ASTOBJ_UNREF(peer, sip_destroy_peer);
+	unref_peer(peer);
 
 	return 0;
 }
@@ -14209,7 +14219,7 @@
 		transmit_response(p, "403 Forbidden (policy)", req);
 		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
 		if (authpeer)
-			ASTOBJ_UNREF(authpeer,sip_destroy_peer);
+			unref_peer(authpeer);
 		return 0;
 	}
 
@@ -14231,7 +14241,7 @@
 		transmit_response(p, "404 Not Found", req);
 		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 		if (authpeer)
-			ASTOBJ_UNREF(authpeer,sip_destroy_peer);
+			unref_peer(authpeer);
 		return 0;
 	}
 
@@ -14241,7 +14251,7 @@
 
 	if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
 		if (authpeer)	/* We do not need the authpeer any more */
-			ASTOBJ_UNREF(authpeer,sip_destroy_peer);
+			unref_peer(authpeer);
 
 		/* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */
 		/* Polycom phones only handle xpidf+xml, even if they say they can
@@ -14272,7 +14282,7 @@
 				ast_log(LOG_DEBUG, "Received SIP mailbox subscription for unknown format: %s\n", accept);
 			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 			if (authpeer)
-				ASTOBJ_UNREF(authpeer,sip_destroy_peer);
+				unref_peer(authpeer);
 			return 0;
 		}
 		/* Looks like they actually want a mailbox status 
@@ -14285,7 +14295,7 @@
 			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 			ast_log(LOG_NOTICE, "Received SIP subscribe for peer without mailbox: %s\n", authpeer->name);
 			if (authpeer)
-				ASTOBJ_UNREF(authpeer,sip_destroy_peer);
+				unref_peer(authpeer);
 			return 0;
 		}
 
@@ -14302,7 +14312,7 @@
 			ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: %s\n", event);
 		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 		if (authpeer)
-			ASTOBJ_UNREF(authpeer,sip_destroy_peer);
+			unref_peer(authpeer);
 		return 0;
 	}
 
@@ -14941,7 +14951,7 @@
 			ASTOBJ_WRLOCK(peer);
 			sip_send_mwi_to_peer(peer);
 			ASTOBJ_UNLOCK(peer);
-			ASTOBJ_UNREF(peer,sip_destroy_peer);
+			unref_peer(peer);
 		} else {
 			/* Reset where we come from */
 			lastpeernum = -1;
@@ -15128,7 +15138,7 @@
 			/* there is no address, it's unavailable */
 			res = AST_DEVICE_UNAVAILABLE;
 		}
-		ASTOBJ_UNREF(p,sip_destroy_peer);
+		unref_peer(p);
 	} else {
 		hp = ast_gethostbyname(host, &ahp);
 		if (hp)
@@ -15809,7 +15819,7 @@
 				ast_clear_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
 				if (!obproxyfound || !strcasecmp(v->name, "outboundproxy")) {
 					if (ast_get_ip_or_srv(&peer->addr, v->value, global_srvlookup ? "_sip._udp" : NULL)) {
-						ASTOBJ_UNREF(peer, sip_destroy_peer);
+						unref_peer(peer);
 						return NULL;
 					}
 				}
@@ -15823,7 +15833,7 @@
 			}
 		} else if (!strcasecmp(v->name, "defaultip")) {
 			if (ast_get_ip(&peer->defaddr, v->value)) {
-				ASTOBJ_UNREF(peer, sip_destroy_peer);
+				unref_peer(peer);
 				return NULL;
 			}
 		} else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
@@ -16345,7 +16355,7 @@
 					peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
 					if (peer) {
 						ASTOBJ_CONTAINER_LINK(&peerl,peer);
-						ASTOBJ_UNREF(peer, sip_destroy_peer);
+						unref_peer(peer);
 						peer_count++;
 					}
 				}
@@ -16413,7 +16423,7 @@
 				peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
 				if (peer) {
 					ASTOBJ_CONTAINER_LINK(&peerl,peer);
-					ASTOBJ_UNREF(peer, sip_destroy_peer);
+					unref_peer(peer);
 					peer_count++;
 				}
 			}



More information about the asterisk-commits mailing list