[asterisk-commits] may: branch may/chan_ooh323_rework r228705 - in /team/may/chan_ooh323_rework/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 6 17:19:42 CST 2009


Author: may
Date: Fri Nov  6 17:19:40 2009
New Revision: 228705

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=228705
Log:
Latest changes which are in trunk

Modified:
    team/may/chan_ooh323_rework/addons/chan_ooh323.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.h
    team/may/chan_ooh323_rework/addons/ooh323cDriver.c

Modified: team/may/chan_ooh323_rework/addons/chan_ooh323.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/chan_ooh323.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/chan_ooh323.c (original)
+++ team/may/chan_ooh323_rework/addons/chan_ooh323.c Fri Nov  6 17:19:40 2009
@@ -18,6 +18,8 @@
 #include "chan_ooh323.h"
 #include <math.h>
 
+#define FORMAT_STRING_SIZE	512
+
 /* Defaults */
 #define DEFAULT_CONTEXT "default"
 #define DEFAULT_H323ID "Asterisk PBX"
@@ -58,7 +60,7 @@
 static struct ast_jb_conf global_jbconf;
 
 /* Channel Definition */
-static struct ast_channel *ooh323_request(const char *type, format_t format, 
+static struct ast_channel *ooh323_request(const char *type, int format, 
 			const struct ast_channel *requestor,  void *data, int *cause);
 static int ooh323_digit_begin(struct ast_channel *ast, char digit);
 static int ooh323_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
@@ -74,7 +76,7 @@
 static enum ast_rtp_glue_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
 static enum ast_rtp_glue_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
 static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, 
-          struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active);
+          struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active);
 
 static struct ast_udptl *ooh323_get_udptl_peer(struct ast_channel *chan);
 static int ooh323_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl);
@@ -193,7 +195,7 @@
 	unsigned    inUse;
 	char        accountcode[20];
 	int         amaflags;
-	format_t    capability;
+	int         capability;
 	struct ast_codec_pref prefs;
 	int         dtmfmode;
 	int	    dtmfcodec;
@@ -212,7 +214,7 @@
 	char        name[256];
 	unsigned    outgoinglimit;
 	unsigned    outUse;
-	format_t    capability;
+	int         capability;
 	struct ast_codec_pref prefs;
 	char        accountcode[20];
 	int         amaflags;
@@ -271,7 +273,7 @@
 static char gIP[20];
 static char gCallerID[AST_MAX_EXTENSION] = "";
 static struct ooAliases *gAliasList;
-static format_t gCapability = AST_FORMAT_ULAW;
+static int  gCapability = AST_FORMAT_ULAW;
 static struct ast_codec_pref gPrefs;
 static int  gDTMFMode = H323_DTMF_RFC2833;
 static int  gDTMFCodec = 101;
@@ -464,7 +466,7 @@
 		ast_log(LOG_ERROR, "Invalid OOH323 driver ip address\n");
 		ast_mutex_unlock(&pvt->lock);
 		ast_mutex_destroy(&pvt->lock);
-		free(pvt);
+		ast_free(pvt);
 		return NULL;
 	}
 
@@ -474,7 +476,7 @@
 				  strerror(errno));
 		ast_mutex_unlock(&pvt->lock);
 		ast_mutex_destroy(&pvt->lock);
-		free(pvt);
+		ast_free(pvt);
 		return NULL;
 	}
  
@@ -485,7 +487,7 @@
 				strerror(errno));
 		ast_mutex_unlock(&pvt->lock);
 		ast_mutex_destroy(&pvt->lock);
-		free(pvt);
+		ast_free(pvt);
 		return NULL;
 	}
 
@@ -528,7 +530,7 @@
 /*
 	Possible data values - peername, exten/peername, exten at ip
  */
-static struct ast_channel *ooh323_request(const char *type, format_t format,
+static struct ast_channel *ooh323_request(const char *type, int format,
 		const struct ast_channel *requestor, void *data, int *cause)
 
 {
@@ -538,18 +540,19 @@
 	char *dest = NULL; 
 	char *ext = NULL;
 	char tmp[256];
-	char formats[512];
+	char formats[FORMAT_STRING_SIZE];
 	int oldformat;
 	int port = 0;
 
 	if (gH323Debug)
 		ast_verbose("---   ooh323_request - data %s format %s\n", (char*)data,  
-										ast_getformatname_multiple(formats,512,format));
+										ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,format));
 
 	oldformat = format;
 	format &= AST_FORMAT_AUDIO_MASK;
 	if (!format) {
-		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%Ld'\n", (long long) format);
+		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format "
+								  "'%d'\n", format);
 		return NULL;
 	}
 
@@ -651,7 +654,7 @@
 		ast_mutex_unlock(&iflock);
    } else {
       ast_mutex_lock(&p->lock);
-      p->callToken = (char*)malloc(AST_MAX_EXTENSION);
+      p->callToken = (char*)ast_malloc(AST_MAX_EXTENSION);
       if(!p->callToken)
       {
        ast_mutex_unlock(&p->lock);
@@ -659,7 +662,7 @@
        ooh323_destroy(p);
        ast_mutex_unlock(&iflock);
        ast_log(LOG_ERROR, "Failed to allocate memory for callToken\n");
-       return NULL; /* TODO: need to clean/hangup?? */
+       return NULL;
       }
 
       ast_mutex_unlock(&p->lock);
@@ -862,15 +865,16 @@
 {
 	struct ooh323_pvt *p = ast->tech_pvt;
 	char destination[256];
-   int res=0, i;
+   	int res=0, i;
 	const char *val = NULL;
 	ooCallOptions opts = {
 		.fastStart = TRUE,
 		.tunneling = TRUE,
 		.disableGk = TRUE,
-      .callMode = OO_CALLMODE_AUDIOCALL,
-      .transfercap = 0
+      		.callMode = OO_CALLMODE_AUDIOCALL,
+      		.transfercap = 0
 	};
+
 	if (gH323Debug)
 		ast_verbose("---   ooh323_call- %s\n", dest);
 
@@ -931,16 +935,11 @@
 
    opts.transfercap = ast->transfercapability;
 
+   for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
+
    if(OO_TESTFLAG(p->flags, H323_DISABLEGK)) {
-
-      for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
-
       res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, &opts);
-
    } else {
-
-      for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
-
       res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, NULL);
    }
 
@@ -1013,8 +1012,7 @@
 		ast_update_use_count();
 	  
 	} else {
-		ast_log(LOG_ERROR, "No call to hangup\n" );
-      /* return -1; */
+		ast_log(LOG_DEBUG, "No call to hangup\n" );
 	}
 	
 	if (gH323Debug)
@@ -1072,15 +1070,13 @@
 {
 	struct ooh323_pvt *p = ast->tech_pvt;
 	int res = 0;
-	char *callToken = (char *)NULL;
-	char buf[256];
 
 	if (p) {
 		ast_mutex_lock(&p->lock);
 
 		if (f->frametype == AST_FRAME_MODEM) {
 			ast_debug(1, "Send UDPTL %d/%d len %d for %s\n",
-				f->frametype, f->subclass.integer, f->datalen, ast->name);
+				f->frametype, f->subclass, f->datalen, ast->name);
 			if (p->udptl)
 				res = ast_udptl_write(p->udptl, f);
 			ast_mutex_unlock(&p->lock);
@@ -1090,24 +1086,21 @@
 	
 		if (f->frametype == AST_FRAME_VOICE) {
 /* sending progress for first */
-			if (!ast_test_flag(p, H323_OUTGOING) && !p->progsent) {
-				callToken = (p->callToken ? strdup(p->callToken) : NULL);
-				ooManualProgress(callToken);
+			if (!ast_test_flag(p, H323_OUTGOING) && !p->progsent &&
+			 		p->callToken) {
+				ooManualProgress(p->callToken);
 				p->progsent = 1;
-				free(callToken);
 			}
 
 
-			if (!(f->subclass.codec & ast->nativeformats)) {
+			if (!(f->subclass & ast->nativeformats)) {
 				if (ast->nativeformats != 0) {
-					ast_log(LOG_WARNING,
-							"Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
-							ast_getformatname(f->subclass.codec),
-							ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
-							ast_getformatname(ast->readformat),
-							ast_getformatname(ast->writeformat));
-
-					ast_set_write_format(ast, f->subclass.codec);
+					ast_log(LOG_WARNING, "Asked to transmit frame type %d,"
+						" while native "
+						 "formats is %d (read/write = %d/%d)\n",
+						f->subclass, ast->nativeformats, ast->readformat,
+										ast->writeformat);
+					ast_set_write_format(ast, f->subclass);
 				} else {
 					/* ast_set_write_format(ast, f->subclass);
 					ast->nativeformats = f->subclass; */
@@ -1355,11 +1348,11 @@
 void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
 {
 	struct ooh323_pvt *p = NULL;
-	char formats[512];
+	char formats[FORMAT_STRING_SIZE];
 
 	if (gH323Debug)
 		ast_verbose("---   ooh323_update_writeformat %s/%d\n", 
-				ast_getformatname_multiple(formats,512, fmt), txframes);
+				ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt), txframes);
 	
 	p = find_call(call);
 	if (!p) {
@@ -1374,9 +1367,7 @@
 	if (p->owner) {
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		}
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);
@@ -1385,8 +1376,8 @@
 		}
 		if (gH323Debug)
 	  		ast_verbose("Writeformat before update %s/%s\n", 
-			  ast_getformatname_multiple(formats,512, p->owner->writeformat),
-			  ast_getformatname_multiple(formats,512, p->owner->nativeformats));
+			  ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->writeformat),
+			  ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->nativeformats));
 		if (txframes)
 			ast_codec_pref_setsize(&p->prefs, fmt, txframes);
 		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
@@ -1416,11 +1407,11 @@
 void ooh323_set_read_format(ooCallData *call, int fmt)
 {
 	struct ooh323_pvt *p = NULL;
-	char formats[512];
+	char formats[FORMAT_STRING_SIZE];
 
 	if (gH323Debug)
 		ast_verbose("---   ooh323_update_readformat %s\n", 
-				ast_getformatname_multiple(formats,512, fmt));
+				ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt));
 	
 	p = find_call(call);
 	if (!p) {
@@ -1436,9 +1427,7 @@
 	if (p->owner) {
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		}
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);
@@ -1448,7 +1437,7 @@
 
 		if (gH323Debug)
 	  		ast_verbose("Readformat before update %s\n", 
-				  ast_getformatname_multiple(formats,512, p->owner->readformat));
+				  ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->readformat));
 		p->owner->nativeformats = fmt;
 	  	ast_set_read_format(p->owner, p->owner->readformat);
 		ast_channel_unlock(p->owner);
@@ -1484,9 +1473,7 @@
 	}
 	while (p->owner && ast_channel_trylock(p->owner)) {
 		ast_debug(1,"Failed to grab lock, trying again\n");
-		ast_mutex_unlock(&p->lock);
-		usleep(1);
-		ast_mutex_lock(&p->lock);
+		DEADLOCK_AVOIDANCE(&p->lock);
 	}
 	if (!p->owner) {
 		ast_mutex_unlock(&p->lock);
@@ -1529,9 +1516,7 @@
 	}
 	while (p->owner && ast_channel_trylock(p->owner)) {
 		ast_debug(1,"Failed to grab lock, trying again\n");
-		ast_mutex_unlock(&p->lock);
-		usleep(1);
-		ast_mutex_lock(&p->lock);
+		DEADLOCK_AVOIDANCE(&p->lock);
 	}
 	if (!p->owner) {
 		ast_mutex_unlock(&p->lock);
@@ -1575,7 +1560,7 @@
 	ast_mutex_lock(&p->lock);
 	memset(&f, 0, sizeof(f));
 	f.frametype = AST_FRAME_DTMF;
-	f.subclass.integer = digit[0];
+	f.subclass = digit[0];
 	f.datalen = 0;
 	f.samples = 800;
 	f.offset = 0;
@@ -1585,9 +1570,7 @@
 
 	while (p->owner && ast_channel_trylock(p->owner)) {
 		ast_debug(1,"Failed to grab lock, trying again\n");
-		ast_mutex_unlock(&p->lock);
-		usleep(1);
-		ast_mutex_lock(&p->lock);
+		DEADLOCK_AVOIDANCE(&p->lock);
 	}
 	if (!p->owner) {
 		ast_mutex_unlock(&p->lock);
@@ -1678,41 +1661,32 @@
       		p->exten[1]='\0';
 	}
 
-	/* May there isn't needed to setup ip as name */
-	/* if (!p->callerid_name) {
-		p->callerid_name = strdup(call->remoteIP);
-	}
-	
-	if (p->callerid_name) { */
-      		user = find_user(p->callerid_name, call->remoteIP);
-      		if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) {
-			ast_mutex_lock(&user->lock);
-			p->username = strdup(user->name);
-	 		p->neighbor.user = user->mUseIP ? ast_strdup(user->mIP) :
-							  ast_strdup(user->name);
-			ast_copy_string(p->context, user->context, sizeof(p->context));
-			ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
-			p->amaflags = user->amaflags;
-			p->capability = user->capability;
-			memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
-			p->dtmfmode |= user->dtmfmode;
-			p->dtmfcodec = user->dtmfcodec;
-			p->t38support = user->t38support;
-			p->rtptimeout = user->rtptimeout;
-			if (user->rtpmask && user->rtpmaskstr[0]) {
-				p->rtpmask = user->rtpmask;
-				ast_copy_string(p->rtpmaskstr, user->rtpmaskstr, 
-								 sizeof(p->rtpmaskstr));
-			}
-			/* Since, call is coming from a pbx user, no need to use gk */
-			/* OO_SETFLAG(p->flags, H323_DISABLEGK);
-			OO_SETFLAG(call->flags, OO_M_DISABLEGK); */
-	 		if (user->incominglimit) user->inUse++;
-			ast_mutex_unlock(&user->lock);
-      } else {
+      	user = find_user(p->callerid_name, call->remoteIP);
+      	if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) {
+		ast_mutex_lock(&user->lock);
+		p->username = strdup(user->name);
+ 		p->neighbor.user = user->mUseIP ? ast_strdup(user->mIP) :
+						  ast_strdup(user->name);
+		ast_copy_string(p->context, user->context, sizeof(p->context));
+		ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
+		p->amaflags = user->amaflags;
+		p->capability = user->capability;
+		memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
+		p->dtmfmode |= user->dtmfmode;
+		p->dtmfcodec = user->dtmfcodec;
+		p->t38support = user->t38support;
+		p->rtptimeout = user->rtptimeout;
+		if (user->rtpmask && user->rtpmaskstr[0]) {
+			p->rtpmask = user->rtpmask;
+			ast_copy_string(p->rtpmaskstr, user->rtpmaskstr, 
+							 sizeof(p->rtpmaskstr));
+		}
+	 	if (user->incominglimit) user->inUse++;
+		ast_mutex_unlock(&user->lock);
+	} else {
 	 if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) {
 		p->username = strdup(call->remoteIP);
-	 } else {
+	} else {
 	  ast_mutex_unlock(&p->lock);
 	  ast_log(LOG_ERROR, "Unacceptable ip %s\n", call->remoteIP);
 	  if (!user) 
@@ -1927,9 +1901,7 @@
 	
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		}
 		if (p->owner) {
 			struct ast_channel* c = p->owner;
@@ -1964,9 +1936,7 @@
 		if (ast_channel_trylock(p->owner)) {
 			ooTrace(OOTRCLVLINFO, "Failed to grab lock, trying again\n");
          		ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		} else {
          		ownerLock = 1; break;
 		}
@@ -2751,7 +2721,7 @@
 static char *handle_cli_ooh323_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ooh323_peer *prev = NULL, *peer = NULL;
-   char formats[512];
+   char formats[FORMAT_STRING_SIZE];
    char ip_port[30];
 #define FORMAT  "%-15.15s  %-15.15s  %-23.23s  %-s\n"
 
@@ -2779,7 +2749,7 @@
      ast_cli(a->fd, FORMAT, peer->name, 
 					peer->accountcode,
 					ip_port,
-                 ast_getformatname_multiple(formats,512,peer->capability));
+                 ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,peer->capability));
 		prev = peer;
 		peer = peer->next;
 		ast_mutex_unlock(&prev->lock);
@@ -2893,7 +2863,7 @@
 static char *handle_cli_ooh323_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ooh323_user *prev = NULL, *user = NULL;
-   char formats[512];
+   char formats[FORMAT_STRING_SIZE];
 #define FORMAT1  "%-15.15s  %-15.15s  %-15.15s  %-s\n"
 
 	switch (cmd) {
@@ -2920,7 +2890,7 @@
 		ast_mutex_lock(&user->lock);
      		ast_cli(a->fd, FORMAT1, user->name, 
 					user->accountcode, user->context,
-					ast_getformatname_multiple(formats, 512, user->capability));
+					ast_getformatname_multiple(formats, FORMAT_STRING_SIZE, user->capability));
 		prev = user;
 		user = user->next;
 		ast_mutex_unlock(&prev->lock);
@@ -2965,7 +2935,7 @@
 
 static char *handle_cli_ooh323_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	char value[512];
+	char value[FORMAT_STRING_SIZE];
 	ooAliases *pAlias = NULL, *pAliasNext = NULL;;
 
 	switch (cmd) {
@@ -3019,7 +2989,7 @@
    ast_cli(a->fd,  "%-20s%s\n", "Context:", gContext);
    
    ast_cli(a->fd,  "%-20s%s\n", "Capability:", 
-           ast_getformatname_multiple(value,512,gCapability));
+           ast_getformatname_multiple(value,FORMAT_STRING_SIZE,gCapability));
 
    ast_cli(a->fd, "%-20s", "DTMF Mode: ");
 	if (gDTMFMode & H323_DTMF_CISCO) {
@@ -3373,8 +3343,9 @@
 			iflist = cur->next;
 
 		if (cur->callToken) {
-	 if (gH323Debug) ast_verbose(" Destroying %s\n", cur->callToken);
-			free(cur->callToken);
+	 		if (gH323Debug) 
+				ast_verbose(" Destroying %s\n", cur->callToken);
+			ast_free(cur->callToken);
 			cur->callToken = 0;
 		}
 
@@ -3412,9 +3383,7 @@
 		if (cur->owner) {
          		while(ast_channel_trylock(cur->owner)) {
             			ast_debug(1,"Failed to grab lock, trying again\n");
-            			ast_mutex_unlock(&cur->lock);
-            			usleep(1);
-            			ast_mutex_lock(&cur->lock);
+				DEADLOCK_AVOIDANCE(&cur->lock);
          		}           
 			ast_debug(1, "Detaching from %s\n", cur->owner->name);
 			cur->owner->tech_pvt = NULL;
@@ -3447,7 +3416,7 @@
 		ast_mutex_unlock(&cur->lock);
 		ast_mutex_destroy(&cur->lock);
 
-		free(cur);
+		ast_free(cur);
 	}
 
 	if (gH323Debug)
@@ -3700,7 +3669,7 @@
 
 int ooh323_convertAsteriskCapToH323Cap(int cap)
 {
-	char formats[512];
+	char formats[FORMAT_STRING_SIZE];
 	switch (cap) {
 	case AST_FORMAT_ULAW:
 		return OO_G711ULAW64K;
@@ -3730,13 +3699,13 @@
 		return OO_H263VIDEO;
 	default:
 		ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n", 
-                        ast_getformatname_multiple(formats,512,cap));
+                        ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
 		return -1;
 	}
 }
 
 static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp,
-	 struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
+	 struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active)
 {
 	/* XXX Deal with Video */
 	struct ooh323_pvt *p;
@@ -3954,9 +3923,7 @@
 	if (p->owner) {
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		}
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);
@@ -4010,9 +3977,7 @@
 	if (p->owner) {
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		}
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);
@@ -4093,7 +4058,7 @@
 	case 5:
 		f = ast_udptl_read(p->udptl);		/* UDPTL t.38 data */
 		if (gH323Debug) ast_debug(1, "Got UDPTL %d/%d len %d for %s\n",
-				f->frametype, f->subclass.integer, f->datalen, ast->name);
+				f->frametype, f->subclass, f->datalen, ast->name);
 		break;
 
 	default:
@@ -4103,19 +4068,19 @@
 	if (p->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE && !p->faxmode) {
-			if (f->subclass.codec != p->owner->nativeformats) {
-            			ast_debug(1, "Oooh, voice format changed to %s\n", ast_getformatname(f->subclass.codec));
-				p->owner->nativeformats = f->subclass.codec;
+			if (f->subclass != p->owner->nativeformats) {
+            			ast_debug(1, "Oooh, format changed to %d\n", f->subclass);
+				p->owner->nativeformats = f->subclass;
 				ast_set_read_format(p->owner, p->owner->readformat);
 				ast_set_write_format(p->owner, p->owner->writeformat);
 			}
 
 			if ((p->dtmfmode & H323_DTMF_INBAND) && p->vad &&
-				(f->subclass.codec == AST_FORMAT_SLINEAR || f->subclass.codec == AST_FORMAT_ALAW ||
-					f->subclass.codec == AST_FORMAT_ULAW)) {
+				(f->subclass == AST_FORMAT_SLINEAR || f->subclass == AST_FORMAT_ALAW ||
+					f->subclass == AST_FORMAT_ULAW)) {
 				f = ast_dsp_process(p->owner, p->vad, f);
             			if (f && (f->frametype == AST_FRAME_DTMF)) 
-               				ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer);
+               				ast_debug(1, "* Detected inband DTMF '%c'\n",f->subclass);
 			}
 		}
 	}
@@ -4147,9 +4112,7 @@
 	if (p->owner) {
 		while (p->owner && ast_channel_trylock(p->owner)) {
 			ast_debug(1,"Failed to grab lock, trying again\n");
-			ast_mutex_unlock(&p->lock);
-			usleep(1);
-			ast_mutex_lock(&p->lock);
+			DEADLOCK_AVOIDANCE(&p->lock);
 		}
 		if (!p->owner) {
 			ast_mutex_unlock(&p->lock);

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.c Fri Nov  6 17:19:40 2009
@@ -747,26 +747,12 @@
       if ((pMemLink->blockType & RTMEMRAW) &&
            pMemLink->pMemBlk == mem_p) 
       {
-         if (pMemLink->blockType & RTMEMMALLOC)
-            if (1) {
-               void *newMemBlk = realloc (pMemLink->pMemBlk, nbytes_);
-               if (newMemBlk == 0) 
-                  return 0;
-               pMemLink->pMemBlk = newMemBlk;
-            }
-            else {
-               /* use malloc/memcpy/free sequence instead of realloc */
-               ASN1OCTET* newBuf;
-               int oldSize = *(int*)(((char*)pMemLink) + sizeof (OSMemLink));
-
-               if (oldSize == -1) return 0;
-               newBuf = (ASN1OCTET*) malloc (nbytes_);
-               if (newBuf == 0)
-                  return 0;
-               memcpy (newBuf, pMemLink->pMemBlk, ASN1MIN (oldSize, nbytes_));
-               free (pMemLink->pMemBlk);
-               pMemLink->pMemBlk = newBuf;
-            }
+         if (pMemLink->blockType & RTMEMMALLOC) {
+             void *newMemBlk = realloc (pMemLink->pMemBlk, nbytes_);
+             if (newMemBlk == 0) 
+                return 0;
+             pMemLink->pMemBlk = newMemBlk;
+	 }
          else 
             return 0;
          *(int*)(((char*)pMemLink) + sizeof (OSMemLink)) = nbytes_;

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.h Fri Nov  6 17:19:40 2009
@@ -156,7 +156,7 @@
    OOBOOL		fsSent;
    OOSOCKET		CmdChan;
    OOSOCKET		cmdSock;
-   void*		CmdChanLock;
+   ast_mutex_t*		CmdChanLock;
    char                 callToken[20]; /* ex: ooh323c_call_1 */
    char                 callType[10]; /* incoming/outgoing */
    OOCallMode           callMode;

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooCapability.c Fri Nov  6 17:19:40 2009
@@ -1680,7 +1680,7 @@
                                                               videoCap, dir);
    default:
      OOTRACEDBGC3("ooCapabilityCheckCompatibility_Video - Unsupported video "
-                  "capability. (%s, $s)\n", call->callType, call->callToken);
+                  "capability. (%s, %s)\n", call->callType, call->callToken);
    }
    return FALSE;
 }
@@ -1709,7 +1709,7 @@
 	return ooCapabilityCheckCompatibility_T38(call, epCap, dataType->u.data, dir);
    default:
       OOTRACEDBGC3("ooCapabilityCheckCompatibility - Unsupported  "
-                  "capability. (%s, $s)\n", call->callType, call->callToken);
+                  "capability. (%s, %s)\n", call->callType, call->callToken);
    }
 
    return FALSE;

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.c Fri Nov  6 17:19:40 2009
@@ -57,19 +57,19 @@
     OOTRACEINFO2("INFO: create cmd connect for call: %lx\n", call);
 
    call->CmdChanLock = malloc(sizeof(ast_mutex_t));
-   ast_mutex_init((ast_mutex_t *)call->CmdChanLock);
+   ast_mutex_init(call->CmdChanLock);
 
 
    if ((ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, thePipe)) == -1) {
-      ast_mutex_destroy((ast_mutex_t *)call->CmdChanLock);
+      ast_mutex_destroy(call->CmdChanLock);
       free(call->CmdChanLock);
       call->CmdChanLock = NULL;
       return OO_FAILED;
    }
-   ast_mutex_lock((ast_mutex_t *)call->CmdChanLock);
+   ast_mutex_lock(call->CmdChanLock);
    call->cmdSock = thePipe[0];
    call->CmdChan = thePipe[1];
-   ast_mutex_unlock((ast_mutex_t *)call->CmdChanLock);
+   ast_mutex_unlock(call->CmdChanLock);
    return OO_OK;
 }
 
@@ -92,7 +92,7 @@
    close(call->CmdChan);
    call->CmdChan = 0;
    ast_mutex_unlock(call->CmdChanLock);
-   ast_mutex_destroy((ast_mutex_t *)call->CmdChanLock);
+   ast_mutex_destroy(call->CmdChanLock);
    free(call->CmdChanLock);
    call->CmdChanLock = NULL;
 
@@ -137,12 +137,12 @@
 		bPoint += cmd->plen3;
 	}
 
-	ast_mutex_lock((ast_mutex_t *)call->CmdChanLock);
+	ast_mutex_lock(call->CmdChanLock);
    	if (write(call->CmdChan, buffer, bPoint - buffer) == -1) {
-		ast_mutex_unlock((ast_mutex_t *)call->CmdChanLock);
+		ast_mutex_unlock(call->CmdChanLock);
 		return OO_FAILED;
 	}
-	ast_mutex_unlock((ast_mutex_t *)call->CmdChanLock);
+	ast_mutex_unlock(call->CmdChanLock);
    
    	return OO_OK;
 }
@@ -287,9 +287,9 @@
    OOStackCommand cmd;
    memset(&cmd, 0, sizeof(OOStackCommand));
    if (call->CmdChanLock) {
-    ast_mutex_lock((ast_mutex_t *)call->CmdChanLock);
+    ast_mutex_lock(call->CmdChanLock);
     recvLen = read(call->cmdSock, buffer, MAXMSGLEN);
-    ast_mutex_unlock((ast_mutex_t *)call->CmdChanLock);
+    ast_mutex_unlock(call->CmdChanLock);
    } else {
     recvLen = read(call->cmdSock, buffer, MAXMSGLEN);
    }

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.c Fri Nov  6 17:19:40 2009
@@ -954,7 +954,7 @@
                   "RRQ message\n");
       memReset(pctxt);
       pGkClient->state = GkClientFailed;
-      ast_mutex_lock(&pGkClient->Lock);
+      ast_mutex_unlock(&pGkClient->Lock);
       return OO_FAILED;
    }
 
@@ -989,7 +989,7 @@
                   "RRQ message\n");
       	memReset(pctxt);
       	pGkClient->state = GkClientFailed;
-      	ast_mutex_lock(&pGkClient->Lock);
+      	ast_mutex_unlock(&pGkClient->Lock);
       	return OO_FAILED;
       }
 
@@ -2094,7 +2094,7 @@
    pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage));
    if(!pRasMsg)
    {
-      OOTRACEERR3("Error:Memory - ooGkClientSendAdmissionRequest - "
+      OOTRACEERR3("Error:Memory - ooGkClientSendIRR - "
                   "pRasMsg(%s, %s)\n", call->callType, call->callToken);
       pGkClient->state = GkClientFailed;
       ast_mutex_unlock(&pGkClient->Lock);

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.c Fri Nov  6 17:19:40 2009
@@ -284,10 +284,10 @@
 }
 
 
-int ooSocketGetSockName(OOSOCKET socket, struct sockaddr_in *name, int *size)
+int ooSocketGetSockName(OOSOCKET socket, struct sockaddr_in *name, socklen_t *size)
 {
    int ret;
-   ret = getsockname(socket, (struct sockaddr*)name, (socklen_t *) size);
+   ret = getsockname(socket, (struct sockaddr*)name, size);
    if(ret == 0)
       return ASN_OK;
    else{
@@ -298,7 +298,8 @@
 
 int ooSocketGetIpAndPort(OOSOCKET socket, char *ip, int len, int *port)
 {
-   int ret=ASN_OK, size;
+   int ret=ASN_OK;
+   socklen_t size;
    struct sockaddr_in addr;
    const char *host=NULL;
 

Modified: team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.h
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.h?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.h (original)
+++ team/may/chan_ooh323_rework/addons/ooh323c/src/ooSocket.h Fri Nov  6 17:19:40 2009
@@ -375,7 +375,7 @@
 
 
 EXTERN int ooSocketGetSockName(OOSOCKET socket, struct sockaddr_in *name, 
-                                                      int *size);
+                                                      socklen_t *size);
 
 
 EXTERN long ooSocketHTONL(long val);

Modified: team/may/chan_ooh323_rework/addons/ooh323cDriver.c
URL: http://svnview.digium.com/svn/asterisk/team/may/chan_ooh323_rework/addons/ooh323cDriver.c?view=diff&rev=228705&r1=228704&r2=228705
==============================================================================
--- team/may/chan_ooh323_rework/addons/ooh323cDriver.c (original)
+++ team/may/chan_ooh323_rework/addons/ooh323cDriver.c Fri Nov  6 17:19:40 2009
@@ -119,6 +119,8 @@
  
  ast_mutex_destroy(&mycthread->lock);
 
+ close(mycthread->thePipe[0]);
+ close(mycthread->thePipe[1]);
  free(mycthread);
  ast_module_unref(myself);
  ast_update_use_count();
@@ -126,7 +128,6 @@
 }
 
 int ooh323c_start_call_thread(ooCallData *call) {
- pthread_attr_t attr;
  char c = 'c';
  int res;
  struct callthread *cur = callThreads;
@@ -162,22 +163,19 @@
 
 	ast_mutex_init(&cur->lock);
 
-	pthread_attr_init(&attr);
-	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
 	if (gH323Debug)
 		ast_debug(1,"new call thread created for call %s\n", call->callToken);
 
-	if(ast_pthread_create_background(&call->callThread, &attr, ooh323c_call_thread, cur) < 0)
+	if(ast_pthread_create_detached_background(&call->callThread, NULL, ooh323c_call_thread, cur) < 0)
  	{
   		ast_log(LOG_ERROR, "Unable to start ooh323c call thread for call %s\n",
 					call->callToken);
-  		pthread_attr_destroy(&attr);
 		ast_mutex_destroy(&cur->lock);
+		close(cur->thePipe[0]);
+		close(cur->thePipe[1]);
 		free(cur);
   		return -1;
  	}
- 	pthread_attr_destroy(&attr);
 
  } else {
 	if (gH323Debug)




More information about the asterisk-commits mailing list