[asterisk-commits] pcadach: branch pcadach/chan_h323-live r40959 - /team/pcadach/chan_h323-live/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Aug 23 14:00:47 MST 2006


Author: pcadach
Date: Wed Aug 23 16:00:46 2006
New Revision: 40959

URL: http://svn.digium.com/view/asterisk?rev=40959&view=rev
Log:
Improvements of the Asterisk part:
1) add more debugging output;
2) remove unused code;
3) fix possible memory leaks;
4) temporarily disable native bridge calls - this functionality
   is not implemented anyway.

Modified:
    team/pcadach/chan_h323-live/channels/chan_h323.c

Modified: team/pcadach/chan_h323-live/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/chan_h323.c?rev=40959&r1=40958&r2=40959&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/chan_h323.c (original)
+++ team/pcadach/chan_h323-live/channels/chan_h323.c Wed Aug 23 16:00:46 2006
@@ -382,6 +382,9 @@
 
 static void oh323_destroy(struct oh323_pvt *pvt)
 {
+	if (h323debug) {
+		ast_log(LOG_DEBUG, "Destroying channel %s\n", (pvt->owner ? pvt->owner->name : "<unknown>"));
+	}
 	ast_mutex_lock(&iflock);
 	__oh323_destroy(pvt);
 	ast_mutex_unlock(&iflock);
@@ -509,13 +512,12 @@
 static int oh323_hangup(struct ast_channel *c)
 {
 	struct oh323_pvt *pvt = (struct oh323_pvt *) c->tech_pvt;
-	int needcancel = 0;
 	int q931cause = AST_CAUSE_NORMAL_CLEARING;
 	char *call_token;
 
 
 	if (h323debug)
-		ast_log(LOG_DEBUG, "Hanging up call %s\n", c->name);
+		ast_log(LOG_DEBUG, "Hanging up and scheduling destroy of call %s\n", c->name);
 
 	if (!c->tech_pvt) {
 		ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n");
@@ -527,9 +529,6 @@
 		ast_log(LOG_WARNING, "Huh?  We aren't the owner?\n");
 		ast_mutex_unlock(&pvt->lock);
 		return 0;
-	}
-	if (!c || (c->_state != AST_STATE_UP)) {
-		needcancel = 1;
 	}
 	
 	pvt->owner = NULL;
@@ -872,17 +871,20 @@
 		return NULL;
 	}
 	ast_rtp_settos(pvt->rtp, tos);
-	ast_mutex_init(&pvt->lock);
-	/* Ensure the call token is allocated */
-	if ((pvt->cd).call_token == NULL) {
-		(pvt->cd).call_token = (char *)malloc(128);
-	}
-	if (!pvt->cd.call_token) {
-		ast_log(LOG_ERROR, "Not enough memory to alocate call token\n");
-		return NULL;
-	}
-	memset((char *)(pvt->cd).call_token, 0, 128);
-	pvt->cd.call_reference = callid;
+	/* Ensure the call token is allocated for outgoing call */
+	if (!callid) {
+		if ((pvt->cd).call_token == NULL) {
+			(pvt->cd).call_token = (char *)malloc(128);
+		}
+		if (!pvt->cd.call_token) {
+			ast_log(LOG_ERROR, "Not enough memory to alocate call token\n");
+			ast_rtp_destroy(pvt->rtp);
+			free(pvt);
+			return NULL;
+		}
+		memset((char *)(pvt->cd).call_token, 0, 128);
+		pvt->cd.call_reference = callid;
+	}
 	memcpy(&pvt->options, &global_options, sizeof(pvt->options));
 	pvt->jointcapability = pvt->options.capability;
 	if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
@@ -892,6 +894,7 @@
 	}
 	strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
 	pvt->newstate = pvt->newcontrol = pvt->newdigit = -1;
+	ast_mutex_init(&pvt->lock);
 	/* Add to interface list */
 	ast_mutex_lock(&iflock);
 	pvt->next = iflist;
@@ -1098,6 +1101,7 @@
 	format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1);
 	if (!format) {
 		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format);
+		oh323_destroy(pvt);
 		return NULL;
 	}
 	strncpy(tmp, dest, sizeof(tmp) - 1);	
@@ -1380,6 +1384,7 @@
 
 	if (!pvt) {
 		ast_log(LOG_ERROR, "Unable to allocate private structure, this is bad.\n");
+		cleanup_call_details(cd);
 		return NULL;
 	}
 
@@ -1407,6 +1412,7 @@
 			alias = find_alias(cd->call_dest_alias);
 			if (!alias) {
 				ast_log(LOG_ERROR, "Call for %s rejected, alias not found\n", cd->call_dest_alias);
+				oh323_destroy(pvt);
 				return NULL;
 			}
 			strncpy(pvt->exten, alias->name, sizeof(pvt->exten) - 1);
@@ -1424,6 +1430,7 @@
 			}
 			if (ast_strlen_zero(default_context)) {
 				ast_log(LOG_ERROR, "Call from '%s' rejected due to no default context\n", pvt->cd.call_source_aliases);
+				oh323_destroy(pvt);
 				return NULL;
 			}
 			strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
@@ -1438,7 +1445,8 @@
 					if (ast_strlen_zero(user->context)) {
 						if (ast_strlen_zero(default_context)) {
 							ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s) and no default context\n", user->name, cd->sourceIp);
-                					return NULL;
+							oh323_destroy(pvt);
+							return NULL;
 						}
 						strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
 					} else {
@@ -1447,6 +1455,7 @@
 					pvt->exten[0] = 'i';
 					pvt->exten[1] = '\0';
 					ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s)s\n", user->name, cd->sourceIp);
+					oh323_destroy(pvt);
 					return NULL;	/* XXX: Hmmm... Why to setup context if we drop connection immediately??? */
 				}
 			}
@@ -1597,10 +1606,15 @@
 {
 	struct oh323_pvt *pvt;
 
-	ast_log(LOG_DEBUG, "Hanging up connection to %s with cause %d\n", token, cause);
+	if (h323debug) {
+		ast_log(LOG_DEBUG, "Hanging up connection to %s with cause %d\n", token, cause);
+	}
 	
 	pvt = find_call_locked(call_reference, token); 
 	if (!pvt) {
+		if (h323debug) {
+			ast_log(LOG_DEBUG, "Connection to %s already cleared\n", token);
+		}
 		return;
 	}
 	if (pvt->owner && !ast_mutex_trylock(&pvt->owner->lock)) {
@@ -1695,6 +1709,16 @@
 		}
 		/* Check for interfaces needing to be killed */
 		ast_mutex_lock(&iflock);
+#if 1
+		do {
+			for (oh323 = iflist; oh323; oh323 = oh323->next) {
+				if (oh323->needdestroy) {
+					__oh323_destroy(oh323);
+					break;
+				}
+			}
+		} while (oh323);
+#else
 restartsearch:		
 		oh323 = iflist;
 		while(oh323) {
@@ -1704,6 +1728,7 @@
 			}
 			oh323 = oh323->next;
 		}
+#endif
 		ast_mutex_unlock(&iflock);
 		pthread_testcancel();
 		/* Wait for sched or io */
@@ -2415,7 +2440,9 @@
 	}
 	ast_rtp_get_peer(rtp, &them);	
 	ast_rtp_get_us(rtp, &us);
+#if 0	/* Native bridge still isn't ready */
 	h323_native_bridge(pvt->cd.call_token, ast_inet_ntoa(them.sin_addr), mode);
+#endif
 	return 0;
 }
 



More information about the asterisk-commits mailing list