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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 6 18:22:04 CDT 2009


Author: may
Date: Mon Jul  6 18:22:00 2009
New Revision: 205013

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205013
Log:
intergrated reworked verision of chan_ooh323 into trunk
many warnings on compile but work stable
join caps into altCapSets by capability type (voice, video, dtmf)


Modified:
    team/may/chan_ooh323_rework/   (props changed)
    team/may/chan_ooh323_rework/addons/Makefile
    team/may/chan_ooh323_rework/addons/chan_ooh323.c
    team/may/chan_ooh323_rework/addons/chan_ooh323.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/context.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/decode.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/dlist.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/encode.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/errmgmt.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/eventHandler.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/memheap.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooCalls.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/ooCapability.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooCmdChannel.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooGkClient.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooLogChan.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/ooh323c/src/ooStackCmds.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooStackCmds.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooTimer.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooUtils.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooasn1.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/oochannels.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooh245.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323ep.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooh323ep.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooports.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ooq931.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ootrace.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/ootrace.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/ootypes.h
    team/may/chan_ooh323_rework/addons/ooh323c/src/perutil.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/printHandler.c
    team/may/chan_ooh323_rework/addons/ooh323c/src/rtctype.c
    team/may/chan_ooh323_rework/addons/ooh323cDriver.c

Propchange: team/may/chan_ooh323_rework/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/may/chan_ooh323_rework/
------------------------------------------------------------------------------
    automerge-email = may at telecom-service.ru

Modified: team/may/chan_ooh323_rework/addons/Makefile
URL: http://svn.asterisk.org/svn-view/asterisk/team/may/chan_ooh323_rework/addons/Makefile?view=diff&rev=205013&r1=205012&r2=205013
==============================================================================
--- team/may/chan_ooh323_rework/addons/Makefile (original)
+++ team/may/chan_ooh323_rework/addons/Makefile Mon Jul  6 18:22:00 2009
@@ -46,5 +46,7 @@
 
 chan_ooh323.o: ASTCFLAGS+=$(H323CFLAGS)
 
+chan_ooh323.so: ASTLDFLAGS+=-lrt
+
 $(if $(filter chan_ooh323,$(EMBEDDED_MODS)),modules.link,chan_ooh323.so): ASTCFLAGS+=$(H323CFLAGS)
 $(if $(filter chan_ooh323,$(EMBEDDED_MODS)),modules.link,chan_ooh323.so): $(addprefix ooh323c/src/,$(H323OBJS)) chan_ooh323.o ooh323cDriver.o

Modified: team/may/chan_ooh323_rework/addons/chan_ooh323.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/may/chan_ooh323_rework/addons/chan_ooh323.c?view=diff&rev=205013&r1=205012&r2=205013
==============================================================================
--- team/may/chan_ooh323_rework/addons/chan_ooh323.c (original)
+++ team/may/chan_ooh323_rework/addons/chan_ooh323.c Mon Jul  6 18:22:00 2009
@@ -17,10 +17,6 @@
 
 #include "chan_ooh323.h"
 
-/*** MODULEINFO
-	<defaultenabled>no</defaultenabled>
- ***/
-
 /* Defaults */
 #define DEFAULT_CONTEXT "default"
 #define DEFAULT_H323ID "Asterisk PBX"
@@ -36,17 +32,17 @@
 #define H323_ALREADYGONE        (1<<5)
 #define H323_NEEDDESTROY        (1<<6)
 #define H323_DISABLEGK          (1<<7)
+#define H323_NEEDSTART		(1<<8)
 
 /* Channel description */
 static const char type[] = "OOH323";
 static const char tdesc[] = "Objective Systems H323 Channel Driver";
-static const char config[] = "chan_ooh323.conf";
-static const char config_old[] = "ooh323.conf";
+static const char config[] = "ooh323.conf";
 
 
 /* Channel Definition */
 static struct ast_channel *ooh323_request(const char *type, int format, 
-                                        void *data, int *cause);
+			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);
 static int ooh323_call(struct ast_channel *ast, char *dest, int timeout);
@@ -57,16 +53,14 @@
 static int ooh323_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
 static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 
-static enum ast_rtp_get_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static enum ast_rtp_get_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, 
-                             struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
+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, int codecs, int nat_active);
 
 static void print_codec_to_cli(int fd, struct ast_codec_pref *pref);
-
-#if 0
 static void ast_ooh323c_exit();
-#endif
+
 
 static const struct ast_channel_tech ooh323_tech = {
 	.type = type,
@@ -84,22 +78,28 @@
 	.indicate = ooh323_indicate,
 	.fixup = ooh323_fixup,
 	.send_html = 0,
-	.bridge = ast_rtp_bridge,
+   /* .bridge = ast_rtp_bridge, */
 };
 
-static struct ast_rtp_protocol ooh323_rtp = {
+static struct ast_rtp_glue ooh323_rtp = {
 	.type = type,
 	.get_rtp_info = ooh323_get_rtp_peer,
 	.get_vrtp_info = ooh323_get_vrtp_peer,
-	.set_rtp_peer = ooh323_set_rtp_peer
+	.update_peer = ooh323_set_rtp_peer,
 };
+
+struct ooh323_user;
 
 /* H.323 channel private structure */
 static struct ooh323_pvt {
 	ast_mutex_t lock;		/* Channel private lock */
-	struct ast_rtp *rtp;
-	struct ast_rtp *vrtp; /* Placeholder for now */
+	struct ast_rtp_instance *rtp;
+	struct ast_rtp_instance *vrtp; /* Placeholder for now */
 	struct ast_channel *owner;	/* Master Channel */
+   union {
+    	char  *user;	/* cooperating user/peer */
+    	char  *peer;
+   } neighbor;
 	time_t lastrtptx;
 	time_t lastrtprx;
 	unsigned int flags;
@@ -129,6 +129,7 @@
 	char accountcode[256];	/* Account code */
 	int nat;
 	int amaflags;
+   int progsent;			/* progress is sent */
 	struct ast_dsp *vad;
 	struct ooh323_pvt *next;	/* Next entity */
 } *iflist = NULL;
@@ -198,16 +199,21 @@
 
 AST_MUTEX_DEFINE_STATIC(ooh323c_cmd_lock);
 
+static long callnumber = 0;
+AST_MUTEX_DEFINE_STATIC(ooh323c_cn_lock);
+
 /* stack callbacks */
 int onAlerting(ooCallData *call);
+int onProgress(ooCallData *call);
 int onNewCallCreated(ooCallData *call);
+int onOutgoingCall(ooCallData *call);
 int onCallEstablished(ooCallData *call);
 int onCallCleared(ooCallData *call);
 
 static char gLogFile[256] = DEFAULT_LOGFILE;
 static int  gPort = 1720;
 static char gIP[20];
-static char gCallerID[AST_MAX_EXTENSION] = DEFAULT_H323ID;
+static char gCallerID[AST_MAX_EXTENSION] = "";
 static struct ooAliases *gAliasList;
 static int  gCapability = AST_FORMAT_ULAW;
 static struct ast_codec_pref gPrefs;
@@ -218,15 +224,22 @@
 static int  gIsGateway = 0;
 static int  gFastStart = 1;
 static int  gTunneling = 1;
+static int  gBeMaster = 0;
 static int  gMediaWaitForConnect = 0;
 static int  gTOS = 0;
 static int  gRTPTimeout = 60;
 static char gAccountcode[80] = DEFAULT_H323ACCNT;
 static int  gAMAFLAGS;
 static char gContext[AST_MAX_EXTENSION] = DEFAULT_CONTEXT;
-static int  gIncomingLimit = 4;
-static int  gOutgoingLimit = 4;
+static int  gIncomingLimit = 1024;
+static int  gOutgoingLimit = 1024;
 OOBOOL gH323Debug = FALSE;
+
+static int t35countrycode = 0;
+static int t35extensions = 0;
+static int manufacturer = 0;
+static char vendor[AST_MAX_EXTENSION] =  "";
+static char version[AST_MAX_EXTENSION] = "";
 
 static struct ooh323_config
 {
@@ -249,7 +262,7 @@
 
 
 static struct ast_channel *ooh323_new(struct ooh323_pvt *i, int state,
-                                             const char *host) 
+                                             const char *host, int capability, const char *linkedid) 
 {
 	struct ast_channel *ch = NULL;
 	int fmt;
@@ -259,28 +272,37 @@
 
 	/* Don't hold a h323 pvt lock while we allocate a channel */
 	ast_mutex_unlock(&i->lock);
-	ch = ast_channel_alloc(1, state, i->callerid_num, i->callerid_name, i->accountcode, i->exten, i->context, i->amaflags, "OOH323/%s-%08x", host, (unsigned int)(unsigned long) i);
+   	ch = ast_channel_alloc(1, state, i->callerid_num, i->callerid_name, 
+				i->accountcode, i->exten, i->context, linkedid, i->amaflags,
+				"OOH323/%s-%ld", host, callnumber);
+   	ast_mutex_lock(&ooh323c_cn_lock);
+   	callnumber++;
+   	ast_mutex_unlock(&ooh323c_cn_lock);
+   
 	ast_mutex_lock(&i->lock);
 
 	if (ch) {
 		ast_channel_lock(ch);
 		ch->tech = &ooh323_tech;
 
-		ch->nativeformats = i->capability;
-
-		fmt = ast_best_codec(ch->nativeformats);
-
-		ch->fds[0] = ast_rtp_fd(i->rtp);
-		ch->fds[1] = ast_rtcp_fd(i->rtp);
+		fmt = ast_codec_pref_index(&i->prefs, 0); 
+		if (!fmt) 
+			fmt = ast_best_codec(capability);
+
+		ch->nativeformats = fmt;
+		/* ch->nativeformats = (capability) ? 0 : AST_FORMAT_SLINEAR; */
+
+		ast_channel_set_fd(ch, 0, ast_rtp_instance_fd(i->rtp, 0));
+		ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(i->rtp, 1));
 
 		if (state == AST_STATE_RING)
 			ch->rings = 1;
 
 		ch->adsicpe = AST_ADSI_UNAVAILABLE;
-		ch->writeformat = fmt;
-		ch->rawwriteformat = fmt;
-		ch->readformat = fmt;
-		ch->rawreadformat = fmt;
+		ch->writeformat = capability;
+		ch->rawwriteformat = 0;
+		ch->readformat = capability;
+		ch->rawreadformat = 0;
 		ch->tech_pvt = i;
 		i->owner = ch;
 
@@ -301,15 +323,8 @@
 		ast_copy_string(ch->exten, i->exten, sizeof(ch->exten));
 
 		ch->priority = 1;
-		if (i->callerid_name) {
-			ch->cid.cid_name = strdup(i->callerid_name);
-		}
-		if (i->callerid_num) {
-
-			ch->cid.cid_num = strdup(i->callerid_num);
-		}
-
-		if (!ast_test_flag(i, H323_OUTGOING)) {
+
+      		if(!ast_test_flag(i, H323_OUTGOING)) {
 		
 			if (!ast_strlen_zero(i->caller_h323id)) {
 				pbx_builtin_setvar_helper(ch, "_CALLER_H323ID", i->caller_h323id);
@@ -336,19 +351,18 @@
 
 		ast_setstate(ch, state);
 		if (state != AST_STATE_DOWN) {
-			if (ast_pbx_start(ch)) {
+         		if (ast_pbx_start(ch)) {
 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name);
-				ast_channel_unlock(ch);
+            			ast_channel_unlock(ch);
 				ast_hangup(ch);
 				ch = NULL;
-			}
-		}
+			} 
+	 	}
 	} else
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
 
 
-	if (ch)
-		ast_channel_unlock(ch);
+   	if(ch)   ast_channel_unlock(ch);
 
 	if (gH323Debug)
 		ast_verbose("+++   h323_new\n");
@@ -361,6 +375,7 @@
 static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken) 
 {
 	struct ooh323_pvt *pvt = NULL;
+	struct sockaddr_in ouraddr;
 	struct in_addr ipAddr;
 	if (gH323Debug)
 		ast_verbose("---   ooh323_alloc\n");
@@ -372,6 +387,7 @@
 
 	ast_mutex_init(&pvt->lock);
 	ast_mutex_lock(&pvt->lock);
+
 
 	if (!inet_aton(gIP, &ipAddr)) {
 		ast_log(LOG_ERROR, "Invalid OOH323 driver ip address\n");
@@ -381,7 +397,8 @@
 		return NULL;
 	}
 
-	if (!(pvt->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, ipAddr))) {
+	ouraddr.sin_addr = ipAddr;
+	if (!(pvt->rtp = ast_rtp_instance_new(NULL, sched, &ouraddr, NULL))) {
 		ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", 
 				  strerror(errno));
 		ast_mutex_unlock(&pvt->lock);
@@ -390,7 +407,7 @@
 		return NULL;
 	}
  
-	ast_rtp_setqos(pvt->rtp, gTOS, 0, "ooh323");
+	ast_rtp_instance_set_qos(pvt->rtp, gTOS, 0, "ooh323-rtp");
 
 	pvt->call_reference = callref;
 	if (callToken)
@@ -403,6 +420,7 @@
 	pvt->dtmfmode = gDTMFMode;
 	ast_copy_string(pvt->context, gContext, sizeof(pvt->context));
 	ast_copy_string(pvt->accountcode, gAccountcode, sizeof(pvt->accountcode));
+
 	pvt->amaflags = gAMAFLAGS;
 	pvt->capability = gCapability;
 	memcpy(&pvt->prefs, &gPrefs, sizeof(pvt->prefs));
@@ -425,7 +443,8 @@
 	Possible data values - peername, exten/peername, exten at ip
  */
 static struct ast_channel *ooh323_request(const char *type, int format, 
-													 void *data, int *cause)
+		const struct ast_channel *requestor, void *data, int *cause)
+
 {
 	struct ast_channel *chan = NULL;
 	struct ooh323_pvt *p = NULL;
@@ -460,14 +479,16 @@
 	/* This is an outgoing call, since ooh323_request is called */
 	ast_set_flag(p, H323_OUTGOING);
 
-	ast_copy_string(tmp, data, sizeof(data));
+
+   	ast_copy_string(tmp, data, sizeof(tmp));
 
 	dest = strchr(tmp, '/');
 
 	if (dest) {  
 		*dest = '\0';
 		dest++;
-		ext = tmp;
+		ext = dest;
+		dest = tmp;
 	} else if ((dest = strchr(tmp, '@'))) {
 		*dest = '\0';
 		dest++;
@@ -497,16 +518,16 @@
 		p->host = strdup(peer->ip);
 		p->port = peer->port;
 		/* Disable gk as we are going to call a known peer*/
-		OO_SETFLAG(p->flags, H323_DISABLEGK);
+		/* OO_SETFLAG(p->flags, H323_DISABLEGK); */
 
 		if (ext)
 			ast_copy_string(p->exten, ext, sizeof(p->exten));
 
-		if (peer->capability & format) {
+		/* if (peer->capability & format) {
 			p->capability = peer->capability & format;
-		} else {
+		} else { */
 		  p->capability = peer->capability;
-		}
+		/* } */
 		memcpy(&p->prefs, &peer->prefs, sizeof(struct ast_codec_pref));
 		p->dtmfmode = peer->dtmfmode;
 		ast_copy_string(p->accountcode, peer->accountcode, sizeof(p->accountcode));
@@ -528,7 +549,8 @@
 	}
 
 
-	chan = ooh323_new(p, AST_STATE_DOWN, p->username);
+	chan = ooh323_new(p, AST_STATE_DOWN, p->username, format,
+				 requestor ? requestor->linkedid : NULL);
 	
 	ast_mutex_unlock(&p->lock);
 
@@ -536,6 +558,23 @@
 		ast_mutex_lock(&iflock);
 		ooh323_destroy(p);
 		ast_mutex_unlock(&iflock);
+   } else {
+      ast_mutex_lock(&p->lock);
+      p->callToken = (char*)malloc(AST_MAX_EXTENSION);
+      if(!p->callToken)
+      {
+       ast_mutex_unlock(&p->lock);
+       ast_mutex_lock(&iflock);
+       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?? */
+      }
+
+      ast_mutex_unlock(&p->lock);
+      ast_mutex_lock(&ooh323c_cmd_lock);
+      ooMakeCall(data, p->callToken, AST_MAX_EXTENSION, NULL);
+      ast_mutex_unlock(&ooh323c_cmd_lock);
 	}
 
 	restart_monitor();
@@ -574,9 +613,10 @@
 	struct ooh323_user *user;
 
 	if (gH323Debug)
-		ast_verbose("---   find_user\n");
+      ast_verbose("---   find_user: %s, %s\n",name,ip);
 
 	ast_mutex_lock(&userl.lock);
+
 	for (user = userl.users; user; user = user->next) {
 		if (ip && user->mUseIP && !strcmp(user->mIP, ip)) {
 			break;
@@ -585,6 +625,7 @@
 			break;
 		}
 	}
+
 	ast_mutex_unlock(&userl.lock);
 
 	if (gH323Debug)
@@ -631,6 +672,7 @@
 
 	if (gH323Debug)
 		ast_verbose("---   find_peer \"%s\"\n", name);
+
 
 	ast_mutex_lock(&peerl.lock);
 	for (peer = peerl.peers; peer; peer = peer->next) {
@@ -676,15 +718,13 @@
 	}
 	ast_mutex_lock(&p->lock);
 	if (p->rtp && (p->dtmfmode & H323_DTMF_RFC2833)) {
-		ast_rtp_senddigit_begin(p->rtp, digit);
+		ast_rtp_instance_dtmf_begin(p->rtp, digit);
 	} else if (((p->dtmfmode & H323_DTMF_Q931) ||
 						 (p->dtmfmode & H323_DTMF_H245ALPHANUMERIC) ||
 						 (p->dtmfmode & H323_DTMF_H245SIGNAL))) {
 		dtmf[0] = digit;
 		dtmf[1] = '\0';
-		ast_mutex_lock(&ooh323c_cmd_lock);
 		ooSendDTMFDigit(p->callToken, dtmf);
-		ast_mutex_unlock(&ooh323c_cmd_lock);
 	}
 	ast_mutex_unlock(&p->lock);
 	if (gH323Debug)
@@ -706,7 +746,7 @@
 	}
 	ast_mutex_lock(&p->lock);
 	if (p->rtp && (p->dtmfmode & H323_DTMF_RFC2833)) 
-		ast_rtp_senddigit_end(p->rtp, digit);
+		ast_rtp_instance_dtmf_end(p->rtp, digit);
 
 	ast_mutex_unlock(&p->lock);
 	if (gH323Debug)
@@ -720,43 +760,41 @@
 {
 	struct ooh323_pvt *p = ast->tech_pvt;
 	char destination[256];
-	int res = 0;
+   int res=0, i;
 	const char *val = NULL;
 	ooCallOptions opts = {
 		.fastStart = TRUE,
 		.tunneling = TRUE,
 		.disableGk = TRUE,
-		.callMode = OO_CALLMODE_AUDIOCALL
+      .callMode = OO_CALLMODE_AUDIOCALL,
+      .transfercap = 0
 	};
 	if (gH323Debug)
 		ast_verbose("---   ooh323_call- %s\n", dest);
 
-	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
+
+   if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) 
+   {
 		ast_log(LOG_WARNING, "ooh323_call called on %s, neither down nor "
 									"reserved\n", ast->name);
 		return -1;
 	}
 	ast_mutex_lock(&p->lock);
 	ast_set_flag(p, H323_OUTGOING);
-	if (ast->cid.cid_num) {
-		if (p->callerid_num) {
-			free(p->callerid_num);
-		}
-		p->callerid_num = strdup(ast->cid.cid_num);
-	}
-
-	if (ast->cid.cid_name) {
-		if (p->callerid_name) {
+	if (ast->connected.id.number) {
+     		if(p->callerid_num)   free(p->callerid_num);
+		p->callerid_num = strdup(ast->connected.id.number);
+	}
+
+	if (ast->connected.id.name) {
+      		if(p->callerid_name)
 			free(p->callerid_name);
-		}
-		p->callerid_name = strdup(ast->cid.cid_name);
-	}
-	else{
-		ast->cid.cid_name = strdup(gCallerID);
-		if (p->callerid_name) {
+		p->callerid_name = strdup(ast->connected.id.name);
+	} else {
+		ast->connected.id.name = strdup(gCallerID);
+      		if(p->callerid_name)
 			free(p->callerid_name);
-		}
-		p->callerid_name = strdup(ast->cid.cid_name);
+		p->callerid_name = strdup(ast->connected.id.name);
 	}
 
 	/* Retrieve vars */
@@ -768,9 +806,8 @@
 	
 	if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323DIALEDDIGITS"))) {
 		ast_copy_string(p->caller_dialedDigits, val, sizeof(p->caller_dialedDigits));
-		if (!p->callerid_num) {
+      		if(!p->callerid_num)
 			p->callerid_num = strdup(val);
-		}
 	}
 
 	if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323EMAIL"))) {
@@ -780,13 +817,6 @@
 	if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323URL"))) {
 		ast_copy_string(p->caller_url, val, sizeof(p->caller_url));
 	}
-
-
-	if (!(p->callToken = (char*)malloc(AST_MAX_EXTENSION))) {
-		ast_mutex_unlock(&p->lock);
-		ast_log(LOG_ERROR, "Failed to allocate memory for callToken\n");
-		return -1; /* TODO: need to clean/hangup?? */
-	}		
 
 	if (p->host && p->port != 0)
 		snprintf(destination, sizeof(destination), "%s:%d", p->host, p->port);
@@ -795,17 +825,27 @@
 	else
 		ast_copy_string(destination, dest, sizeof(destination));
 
-	ast_mutex_lock(&ooh323c_cmd_lock);
-	if (OO_TESTFLAG(p->flags, H323_DISABLEGK))
-		res = ooMakeCall(destination, p->callToken, AST_MAX_EXTENSION, &opts);
-	else
-		res = ooMakeCall(destination, p->callToken, AST_MAX_EXTENSION, NULL);
-	ast_mutex_unlock(&ooh323c_cmd_lock);
+   destination[sizeof(destination)-1]='\0';
+
+   opts.transfercap = ast->transfercapability;
+
+   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);
+   }
 
 	ast_mutex_unlock(&p->lock);
 	if (res != OO_OK) {
 		ast_log(LOG_ERROR, "Failed to make call\n");
-		return -1; /* TODO: cleanup */
+      		return -1; /* ToDO: cleanup */
 	}
 	if (gH323Debug)
 		ast_verbose("+++   ooh323_call\n");
@@ -816,6 +856,7 @@
 static int ooh323_hangup(struct ast_channel *ast)
 {
 	struct ooh323_pvt *p = ast->tech_pvt;
+   	int q931cause = AST_CAUSE_NORMAL_CLEARING;
 
 	if (gH323Debug)
 		ast_verbose("---   ooh323_hangup\n");
@@ -823,19 +864,39 @@
 	if (p) {
 		ast_mutex_lock(&p->lock);
 
+        if (ast->hangupcause) {
+                q931cause = ast->hangupcause;
+        } else {
+                const char *cause = pbx_builtin_getvar_helper(ast, "DIALSTATUS");
+                if (cause) {
+                        if (!strcmp(cause, "CONGESTION")) {
+                                q931cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
+                        } else if (!strcmp(cause, "BUSY")) {
+                                q931cause = AST_CAUSE_USER_BUSY;
+                        } else if (!strcmp(cause, "CHANISUNVAIL")) {
+                                q931cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
+                        } else if (!strcmp(cause, "NOANSWER")) {
+                                q931cause = AST_CAUSE_NO_ANSWER;
+                        } else if (!strcmp(cause, "CANCEL")) {
+                                q931cause = AST_CAUSE_CALL_REJECTED;
+                        }
+                }
+        }
+
+
+
 		if (gH323Debug)
-			ast_verbose("	 hanging %s\n", p->username);
+			ast_verbose("    hanging %s with cause: %d\n", p->username, q931cause);
 		ast->tech_pvt = NULL; 
 		if (!ast_test_flag(p, H323_ALREADYGONE)) {
 			ast_mutex_lock(&ooh323c_cmd_lock);
-			ooHangCall(p->callToken, 
-				 ooh323_convert_hangupcause_asteriskToH323(p->owner->hangupcause));
+         		ooHangCall(p->callToken, 
+				ooh323_convert_hangupcause_asteriskToH323(q931cause), q931cause);
 			ast_mutex_unlock(&ooh323c_cmd_lock);
 			ast_set_flag(p, H323_ALREADYGONE);
 			/* ast_mutex_unlock(&p->lock); */
-		} else {
+      		} else 
 			ast_set_flag(p, H323_NEEDDESTROY);
-		}
 		/* detach channel here */
 		if (p->owner) {
 			p->owner->tech_pvt = NULL;
@@ -852,7 +913,7 @@
 	  
 	} else {
 		ast_log(LOG_ERROR, "No call to hangup\n" );
-		return -1;
+      /* return -1; */
 	}
 	
 	if (gH323Debug)
@@ -868,17 +929,21 @@
 	if (gH323Debug)
 		ast_verbose("--- ooh323_answer\n");
 
-	ast_mutex_lock(&p->lock);
-	if (ast->_state != AST_STATE_UP) {
-		ast_channel_lock(ast);
-		ast_setstate(ast, AST_STATE_UP);
-		ast_debug(1, "ooh323_answer(%s)\n", ast->name);
-		ast_channel_unlock(ast);
-		ast_mutex_lock(&ooh323c_cmd_lock);
-		ooAnswerCall(p->callToken);
-		ast_mutex_unlock(&ooh323c_cmd_lock);
-	}
-	ast_mutex_unlock(&p->lock);
+	if (p) {
+
+		ast_mutex_lock(&p->lock);
+		if (ast->_state != AST_STATE_UP) {
+			ast_channel_lock(ast);
+			ast_setstate(ast, AST_STATE_UP);
+      			if (option_debug)
+				ast_debug(1, "ooh323_answer(%s)\n", ast->name);
+			ast_channel_unlock(ast);
+      			/* ast_mutex_lock(&ooh323c_cmd_lock); */
+			ooAnswerCall(p->callToken);
+      			/* ast_mutex_unlock(&ooh323c_cmd_lock); */
+		}
+		ast_mutex_unlock(&p->lock);
+	}
 
 	if (gH323Debug)
 		ast_verbose("+++ ooh323_answer\n");
@@ -891,6 +956,8 @@
 	struct ast_frame *fr;
 	static struct ast_frame null_frame = { AST_FRAME_NULL, };
 	struct ooh323_pvt *p = ast->tech_pvt;
+
+	if (!p) return &null_frame;
 
 	ast_mutex_lock(&p->lock);
 	if (p->rtp)
@@ -906,27 +973,50 @@
 {
 	struct ooh323_pvt *p = ast->tech_pvt;
 	int res = 0;
-
-	if (f->frametype == AST_FRAME_VOICE) {
-		if (!(f->subclass & ast->nativeformats)) {
-			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,
+	char *callToken = (char *)NULL;
+
+	if (p) {
+		ast_mutex_lock(&p->lock);
+	
+/* sending progress for first */
+		if (!ast_test_flag(p, H323_OUTGOING) && !p->progsent) {
+			callToken = (p->callToken ? strdup(p->callToken) : NULL);
+			ooManualProgress(callToken);
+			p->progsent = 1;
+			free(callToken);
+		}
+		if (f->frametype == AST_FRAME_VOICE) {
+			if (!(f->subclass & ast->nativeformats)) {
+				if (ast->nativeformats != 0) {
+					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; */
+				}
+			ast_mutex_unlock(&p->lock);
 			return 0;
-		}
-		if (p) {
-			ast_mutex_lock(&p->lock);
-			if (p->rtp)
-				res = ast_rtp_write(p->rtp, f);
+			}
+
+		if (p->rtp)
+			res = ast_rtp_instance_write(p->rtp, f);
+
+		ast_mutex_unlock(&p->lock);
+
+		} else if (f->frametype == AST_FRAME_IMAGE) {
 			ast_mutex_unlock(&p->lock);
-		}
-	} else if (f->frametype == AST_FRAME_IMAGE) {
-		return 0;
-	} else {
-		ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", 
+			return 0;
+		} else {
+			ast_log(LOG_WARNING, "Can't send %d type frames with OOH323 write\n", 
 									 f->frametype);
-		return 0;
+			ast_mutex_unlock(&p->lock);
+			return 0;
+		}
+
 	}
 
 	return res;
@@ -937,6 +1027,8 @@
 
 	struct ooh323_pvt *p = (struct ooh323_pvt *) ast->tech_pvt;
 	char *callToken = (char *)NULL;
+
+	if (!p) return -1;
 
 	ast_mutex_lock(&p->lock);
 	callToken = (p->callToken ? strdup(p->callToken) : NULL);
@@ -951,12 +1043,12 @@
 	if (gH323Debug)
 		ast_verbose("----- ooh323_indicate %d on call %s\n", condition, callToken);
 	 
-
+   ast_mutex_lock(&p->lock);
 	switch (condition) {
 	case AST_CONTROL_CONGESTION:
 		if (!ast_test_flag(p, H323_ALREADYGONE)) {
 			ast_mutex_lock(&ooh323c_cmd_lock);
-			ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED);
+            ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED, AST_CAUSE_SWITCH_CONGESTION);
 			ast_mutex_unlock(&ooh323c_cmd_lock);
 			ast_set_flag(p, H323_ALREADYGONE);
 		}
@@ -964,7 +1056,7 @@
 	case AST_CONTROL_BUSY:
 		if (!ast_test_flag(p, H323_ALREADYGONE)) {
 			ast_mutex_lock(&ooh323c_cmd_lock);
-			ooHangCall(callToken, OO_REASON_LOCAL_BUSY);
+            ooHangCall(callToken, OO_REASON_LOCAL_BUSY, AST_CAUSE_USER_BUSY);
 			ast_mutex_unlock(&ooh323c_cmd_lock);
 			ast_set_flag(p, H323_ALREADYGONE);
 		}
@@ -975,9 +1067,29 @@
 	case AST_CONTROL_UNHOLD:
 		ast_moh_stop(ast);
 		break;
-	case AST_CONTROL_PROCEEDING:
-	case AST_CONTROL_RINGING:
 	case AST_CONTROL_PROGRESS:
+	    if (!p->progsent) {
+             /* ast_mutex_lock(&ooh323c_cmd_lock); */
+	     if (gH323Debug) 
+		ast_log(LOG_DEBUG,"Sending manual progress for %s, res = %d\n", callToken,
+             ooManualProgress(callToken)); else
+	     ooManualProgress(callToken);
+	     p->progsent = 1;
+             /* ast_mutex_unlock(&ooh323c_cmd_lock); */
+	    }
+	    break;
+      case AST_CONTROL_RINGING:
+            /* ast_mutex_lock(&ooh323c_cmd_lock); */
+	    if (gH323Debug) 
+		ast_log(LOG_DEBUG,"Sending manual ringback for %s, res = %d\n", callToken,
+            ooManualRingback(callToken)); else
+	    ooManualRingback(callToken);
+            /* ast_mutex_unlock(&ooh323c_cmd_lock); */
+	 break;
+      case AST_CONTROL_SRCUPDATE:
+		ast_rtp_instance_new_source(p->rtp);
+		break;
+      case AST_CONTROL_PROCEEDING:
 	case -1:
 		break;
 	default:
@@ -985,10 +1097,12 @@
 									condition, callToken);
 	}
 
+   ast_mutex_unlock(&p->lock);
+
 	if (gH323Debug)
 		ast_verbose("++++  ooh323_indicate %d on %s\n", condition, callToken);
 
-
+   free(callToken);
 	return -1;
 }
 
@@ -1023,13 +1137,12 @@
 
 void ooh323_set_write_format(ooCallData *call, int fmt)
 {
-#if 0
 	struct ooh323_pvt *p = NULL;
 	char formats[512];
-#ifdef print_debug
-	printf("---   ooh323_update_writeformat %s\n", 
-										ast_getformatname_multiple(formats,512, fmt));
-#endif
+
+	if (gH323Debug)
+		ast_verbose("---   ooh323_update_writeformat %s\n", 
+				ast_getformatname_multiple(formats,512, fmt));
 	
 	p = find_call(call);
 	if (!p) {
@@ -1040,34 +1153,49 @@
 	ast_mutex_lock(&p->lock);
 
 	p->writeformat = fmt;
+
+	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);
+		}
+		if (!p->owner) {
+			ast_mutex_unlock(&p->lock);
+			ast_log(LOG_ERROR, "Channel has no owner\n");
+			return;
+		}
+		if (gH323Debug)
+	  		ast_verbose("Writeformat before update %s\n", 
+				  ast_getformatname_multiple(formats,512, p->owner->writeformat));
+		p->owner->nativeformats = fmt;
+		if (p->owner->writeformat == 0)
+			p->owner->writeformat = fmt;
+	  	ast_set_write_format(p->owner, p->owner->writeformat);
+		if (p->owner->readformat == 0)
+			p->owner->readformat = fmt;
+	  	ast_set_read_format(p->owner, p->owner->readformat);
+		ast_channel_unlock(p->owner);
+   	} else
+		ast_log(LOG_ERROR, "No owner found\n");
+
+
 	ast_mutex_unlock(&p->lock);
 
-	if (p->owner) {
-	  printf("Writeformat before update %s\n", 
-				  ast_getformatname_multiple(formats,512, p->owner->writeformat));
-	  ast_set_write_format(p->owner, fmt);
-	}
-	else
-	  ast_log(LOG_ERROR, "No owner found\n");
-
-
-#ifdef print_debug
-  printf("+++   ooh323_update_writeformat\n");
-#endif
-#endif
-}
-
+	if (gH323Debug)
+		ast_verbose("+++   ooh323_update_writeformat\n");
+}
 
 void ooh323_set_read_format(ooCallData *call, int fmt)
 {
-#if 0
 	struct ooh323_pvt *p = NULL;
 	char formats[512];
-#ifdef print_debug
-	printf("---   ooh323_update_readformat %s\n", 
-											ast_getformatname_multiple(formats,512, fmt));
-#endif
-
+
+	if (gH323Debug)
+		ast_verbose("---   ooh323_update_readformat %s\n", 
+				ast_getformatname_multiple(formats,512, fmt));
+	
 	p = find_call(call);
 	if (!p) {
 		ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
@@ -1075,15 +1203,43 @@
 	}
 
 	ast_mutex_lock(&p->lock);
+
 	p->readformat = fmt;
+
+
+	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);
+		}
+		if (!p->owner) {
+			ast_mutex_unlock(&p->lock);
+			ast_log(LOG_ERROR, "Channel has no owner\n");
+			return;
+		}
+
+		if (gH323Debug)
+	  		ast_verbose("Readformat before update %s\n", 
+				  ast_getformatname_multiple(formats,512, p->owner->readformat));
+		p->owner->nativeformats = fmt;
+		if (p->owner->readformat == 0)
+			p->owner->readformat = fmt;
+	  	ast_set_read_format(p->owner, p->owner->readformat);
+		/* if (p->owner->writeformat == 0)
+			p->owner->writeformat = fmt;
+	  	ast_set_write_format(p->owner, p->owner->writeformat); */
+		ast_channel_unlock(p->owner);
+   	} else
+		ast_log(LOG_ERROR, "No owner found\n");
+
 	ast_mutex_unlock(&p->lock);
-	ast_set_read_format(p->owner, fmt);	
-	
-#ifdef print_debug
-  printf("+++   ooh323_update_readformat\n");
-#endif
-#endif
-}
+
+	if (gH323Debug)
+		ast_verbose("+++   ooh323_update_readformat\n");
+}
+
 
 int onAlerting(ooCallData *call)
 {
@@ -1093,34 +1249,84 @@
 	if (gH323Debug)
 		ast_verbose("--- onAlerting %s\n", call->callToken);
 
-	if (!(p = find_call(call))) {
+   	p = find_call(call);
+
+   	if(!p) {
 		ast_log(LOG_ERROR, "No matching call found\n");
 		return -1;
 	}  
 	ast_mutex_lock(&p->lock);
-	if (!ast_test_flag(p, H323_OUTGOING)) {
-		if (!(c = ooh323_new(p, AST_STATE_RING, p->username))) {
-			ast_mutex_unlock(&p->lock);
-			ast_log(LOG_ERROR, "Could not create ast_channel\n");
-			return -1;
-		}
+	if (!p->owner) {
 		ast_mutex_unlock(&p->lock);
-	} else {
-		if (!p->owner) {
-			ast_mutex_unlock(&p->lock);
-			ast_log(LOG_ERROR, "Channel has no owner\n");
-			return 0;
-		}
-		c = p->owner;
+		ast_log(LOG_ERROR, "Channel has no owner\n");
+		return 0;
+	}
+	while (p->owner && ast_channel_trylock(p->owner)) {
+		ast_debug(1,"Failed to grab lock, trying again\n");
 		ast_mutex_unlock(&p->lock);
-		ast_channel_lock(c);
+		usleep(1);
+		ast_mutex_lock(&p->lock);
+	}
+	if (!p->owner) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_ERROR, "Channel has no owner\n");
+		return 0;
+	}
+	c = p->owner;
+	if (c->_state != AST_STATE_UP)
 		ast_setstate(c, AST_STATE_RINGING);
-		ast_channel_unlock(c);
-		ast_queue_control(c, AST_CONTROL_RINGING);
-	}
+
+	ast_queue_control(c, AST_CONTROL_RINGING);
+      	ast_channel_unlock(c);
+      	ast_mutex_unlock(&p->lock);
 
 	if (gH323Debug)
 		ast_verbose("+++ onAlerting %s\n", call->callToken);
+
+	return OO_OK;
+}
+
+int onProgress(ooCallData *call)
+{
+	struct ooh323_pvt *p = NULL;
+	struct ast_channel *c = NULL;
+
+	if (gH323Debug)
+		ast_verbose("--- onProgress %s\n", call->callToken);
+
+   	p = find_call(call);
+
+   	if(!p) {
+		ast_log(LOG_ERROR, "No matching call found\n");
+		return -1;
+	}  
+	ast_mutex_lock(&p->lock);
+	if (!p->owner) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_ERROR, "Channel has no owner\n");
+		return 0;
+	}
+	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);
+	}
+	if (!p->owner) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_ERROR, "Channel has no owner\n");
+		return 0;
+	}
+	c = p->owner;
+	if (c->_state != AST_STATE_UP)
+		ast_setstate(c, AST_STATE_RINGING);
+
+	ast_queue_control(c, AST_CONTROL_PROGRESS);
+      	ast_channel_unlock(c);
+      	ast_mutex_unlock(&p->lock);
+
+	if (gH323Debug)
+		ast_verbose("+++ onProgress %s\n", call->callToken);
 
 	return OO_OK;
 }
@@ -1155,8 +1361,21 @@
 	f.data.ptr = NULL;
 	f.mallocd = 0;
 	f.src = "SEND_DIGIT";
-	ast_mutex_unlock(&p->lock);
+
+	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);
+	}
+	if (!p->owner) {
+		ast_mutex_unlock(&p->lock);
+		ast_log(LOG_ERROR, "Channel has no owner\n");
+		return 0;
+	}
 	res = ast_queue_frame(p->owner, &f);
+   	ast_channel_unlock(p->owner);
+   	ast_mutex_unlock(&p->lock);
 	return res;
 }
 
@@ -1164,6 +1383,7 @@
 {
 	struct ooh323_pvt *p = NULL;
 	struct ooh323_user *user = NULL;
+   	struct ast_channel *c = NULL;
 	ooAliases *alias = NULL;
 	char *at = NULL;
 	char number [OO_MAX_NUMBER_LENGTH];
@@ -1195,30 +1415,35 @@
 					p->callerid_name = strdup(alias->value);
 				}
 				ast_copy_string(p->caller_h323id, alias->value, sizeof(p->caller_h323id));
-			} else if (alias->type == T_H225AliasAddress_dialedDigits) {
-				if (!p->callerid_num) {
-					p->callerid_num = strdup(alias->value);
 				}
+         else if(alias->type == T_H225AliasAddress_dialedDigits)
+         {
+            if(!p->callerid_num)
+               p->callerid_num = strdup(alias->value);
 				ast_copy_string(p->caller_dialedDigits, alias->value, 
 															sizeof(p->caller_dialedDigits));
-			} else if (alias->type == T_H225AliasAddress_email_ID) {
+         }
+         else if(alias->type == T_H225AliasAddress_email_ID)
+         {
 				ast_copy_string(p->caller_email, alias->value, sizeof(p->caller_email));
-			} else if (alias->type == T_H225AliasAddress_url_ID) {
+         }
+         else if(alias->type == T_H225AliasAddress_url_ID)
+         {
 				ast_copy_string(p->caller_url, alias->value, sizeof(p->caller_url));
 			}
 		}
 	}
 
 	number[0] = '\0';
-	if (ooCallGetCalledPartyNumber(call, number, OO_MAX_NUMBER_LENGTH) == OO_OK) {
-		ast_copy_string(p->exten, number, sizeof(p->exten));
-	} else {
+   	if(ooCallGetCalledPartyNumber(call, number, OO_MAX_NUMBER_LENGTH)== OO_OK) {
+      		strncpy(p->exten, number, sizeof(p->exten)-1);
+   	} else {
 		update_our_aliases(call, p);
 		if (!ast_strlen_zero(p->callee_dialedDigits)) {
-			ast_copy_string(p->exten, p->callee_dialedDigits, sizeof(p->exten));
-		} else if (!ast_strlen_zero(p->callee_h323id)) {
+         		ast_copy_string(p->exten, p->callee_dialedDigits, sizeof(p->exten));
+      		} else if(!ast_strlen_zero(p->callee_h323id)) {
 			ast_copy_string(p->exten, p->callee_h323id, sizeof(p->exten));
-		} else if (!ast_strlen_zero(p->callee_email)) {
+      		} else if(!ast_strlen_zero(p->callee_email)) {
 			ast_copy_string(p->exten, p->callee_email, sizeof(p->exten));
 			if ((at = strchr(p->exten, '@'))) {
 				*at = '\0';
@@ -1228,17 +1453,22 @@
 
 	/* if no extension found, set to default 's' */
 	if (ast_strlen_zero(p->exten)) {
-		ast_copy_string(p->exten, "s", sizeof(p->exten));
-	}
-
-	if (!p->callerid_name) {
+      		p->exten[0]='s';
+      		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) {
-		if ((user = find_user(p->callerid_name, 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;
@@ -1246,16 +1476,38 @@
 			memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
 			p->dtmfmode = user->dtmfmode;
 			/* 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);
+			/* OO_SETFLAG(p->flags, H323_DISABLEGK);
+			OO_SETFLAG(call->flags, OO_M_DISABLEGK); */
+	 		if (user->incominglimit) user->inUse++;
 			ast_mutex_unlock(&user->lock);
-		}
-	}
-
+      } else {
+	 if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) {
+	  p->username = strdup(call->remoteIP);
+	 } else {
+	  ast_mutex_unlock(&p->lock);
+	  ast_log(LOG_ERROR, "Unacceptable ip %s\n", call->remoteIP);
+	  ast_mutex_lock(&ooh323c_cmd_lock);
+	  if (!user) 
+	   ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_CALL_REJECTED), AST_CAUSE_CALL_REJECTED);
+	  else
+	   ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_NORMAL_CIRCUIT_CONGESTION), AST_CAUSE_NORMAL_CIRCUIT_CONGESTION);
+	  ast_mutex_unlock(&ooh323c_cmd_lock);
+	  ast_set_flag(p, H323_NEEDDESTROY);
+	  return -1;
+	 }
+	}
+/*	} */
 
 	ooh323c_set_capability_for_call(call, &p->prefs, p->capability, p->dtmfmode);
 	configure_local_rtp(p, call);
 
+/* Incoming call */
+  	c = ooh323_new(p, AST_STATE_RING, p->username, p->capability, NULL);
+  	if(!c) {
+   	ast_mutex_unlock(&p->lock);
+   	ast_log(LOG_ERROR, "Could not create ast_channel\n");
+         return -1;
+  }
 	ast_mutex_unlock(&p->lock);
 
 	if (gH323Debug)
@@ -1267,38 +1519,105 @@
 
 
 
-int onNewCallCreated(ooCallData *call)
+int onOutgoingCall(ooCallData *call)
 {
 	struct ooh323_pvt *p = NULL;
 	int i = 0;
 
 	if (gH323Debug)

[... 8882 lines stripped ...]



More information about the asterisk-commits mailing list