[asterisk-commits] may: branch may/ooh323_qsig r397992 - in /team/may/ooh323_qsig: ./ apps/ chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 30 08:51:07 CDT 2013


Author: may
Date: Fri Aug 30 08:51:04 2013
New Revision: 397992

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397992
Log:
Multiple revisions 397956-397957,397959,397962

........
  r397956 | mmichelson | 2013-08-30 02:25:16 +0400 (Fri, 30 Aug 2013) | 29 lines
  
  Fix a race condition where a canceled call was answered.
  
  RFC 5407 section 3.1.2 details a scenario where a UAC sends
  a CANCEL at the same time that a UAS sends a 200 OK for the
  INVITE that the UAC is canceling. When this occurs, it is the
  role of the UAC to immediately send a BYE to terminate
  the call.
  
  This scenario was reproducible by have a Digium phone with two lines
  place a call to a second phone that forwarded the call to the second
  line on the original phone. The Digium phone, upon realizing that it
  was connecting to itself, would attempt to cancel the call. The timing
  of this happened to trigger the aforementioned race condition about
  80% of the time. Asterisk was not doing its job of sending a BYE
  when receiving a 200 OK on a cancelled INVITE. The result was that
  the ast_channel structure was destroyed but the underlying SIP
  session, as well as the PJSIP inv_session and dialog, were still
  alive. Attempting to perform an action such as a transfer, once in
  this state, would result in Asterisk crashing.
  
  The circumstances are now detected properly and the session is ended
  as recommended in RFC 5407.
  
  (closes issue AST-1209)
  reported by John Bigelow
  ........
  
  Merged revisions 397945 from http://svn.asterisk.org/svn/asterisk/branches/12
........
  r397957 | mmichelson | 2013-08-30 02:26:03 +0400 (Fri, 30 Aug 2013) | 10 lines
  
  Fix when the subscription_terminated callback is called for subscription handlers.
  
  The previous placement would result in the resubscribe() callback called instead of
  the subscription_terminated() callback being called when a subscription was ended
  via a SUBSCRIBE request. This would result in confusing PJSIP and having it throw
  an assertion.
  ........
  
  Merged revisions 397955 from http://svn.asterisk.org/svn/asterisk/branches/12
........
  r397959 | kharwell | 2013-08-30 02:49:24 +0400 (Fri, 30 Aug 2013) | 18 lines
  
  Verbose logging discrepancies
  
  Refactored cases where a combination of ast_verbose/options_verbose were
  present.  Also in general tried to eliminate, in as many places as possible,
  where the options_verbose global variable was being used.  Refactored the way
  local and remote consoles handle verbose message logging in an attempt to
  solve the various discrepancies that sometimes would show between the two.
  
  (closes issue AST-1193)
  Reported by: Guenther Kelleter
  Review: https://reviewboard.asterisk.org/r/2798/
  ........
  
  Merged revisions 397948 from http://svn.asterisk.org/svn/asterisk/branches/11
  ........
  
  Merged revisions 397958 from http://svn.asterisk.org/svn/asterisk/branches/12
........
  r397962 | mmichelson | 2013-08-30 02:54:05 +0400 (Fri, 30 Aug 2013) | 13 lines
  
  Fix method for creating activities string in PIDF bodies.
  
  The previous method did not allocate enough space to create
  the entire string, but adjusted the string's slen value to
  be larger than the actual allocation. This resulted in garbled
  text in NOTIFY requests from Asterisk.
  
  This method allocates the proper amount of space first and then
  writes the content into the buffer.
  ........
  
  Merged revisions 397960 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 397956-397957,397959,397962 from http://svn.asterisk.org/svn/asterisk/trunk

Modified:
    team/may/ooh323_qsig/   (props changed)
    team/may/ooh323_qsig/apps/app_dumpchan.c
    team/may/ooh323_qsig/apps/app_verbose.c
    team/may/ooh323_qsig/channels/chan_misdn.c
    team/may/ooh323_qsig/main/asterisk.c
    team/may/ooh323_qsig/main/logger.c
    team/may/ooh323_qsig/res/res_pjsip_pidf.c
    team/may/ooh323_qsig/res/res_pjsip_pubsub.c
    team/may/ooh323_qsig/res/res_pjsip_session.c

Propchange: team/may/ooh323_qsig/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Fri Aug 30 08:51:04 2013
@@ -1,1 +1,1 @@
-/branches/12:1-397927,397938,397946
+/branches/12:1-397927,397938,397945-397946,397955,397958,397960

Propchange: team/may/ooh323_qsig/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Aug 30 08:51:04 2013
@@ -1,1 +1,1 @@
-/trunk:1-397949
+/trunk:1-397949,397956-397962

Modified: team/may/ooh323_qsig/apps/app_dumpchan.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/apps/app_dumpchan.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/apps/app_dumpchan.c (original)
+++ team/may/ooh323_qsig/apps/app_dumpchan.c Fri Aug 30 08:51:04 2013
@@ -183,17 +183,15 @@
 	if (!ast_strlen_zero(data))
 		level = atoi(data);
 
-	if (option_verbose >= level) {
-		serialize_showchan(chan, info, sizeof(info));
-		pbx_builtin_serialize_variables(chan, &vars);
-		ast_verbose("\n"
-			"Dumping Info For Channel: %s:\n"
-			"%s\n"
-			"Info:\n"
-			"%s\n"
-			"Variables:\n"
-			"%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
-	}
+	serialize_showchan(chan, info, sizeof(info));
+	pbx_builtin_serialize_variables(chan, &vars);
+	ast_verb(level, "\n"
+		 "Dumping Info For Channel: %s:\n"
+		 "%s\n"
+		 "Info:\n"
+		 "%s\n"
+		 "Variables:\n"
+		 "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
 
 	return 0;
 }

Modified: team/may/ooh323_qsig/apps/app_verbose.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/apps/app_verbose.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/apps/app_verbose.c (original)
+++ team/may/ooh323_qsig/apps/app_verbose.c Fri Aug 30 08:51:04 2013
@@ -63,7 +63,7 @@
 		<syntax>
 			<parameter name="level" required="true">
 				<para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
-				<literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>	
+				<literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>
 			</parameter>
 			<parameter name="message" required="true">
 				<para>Output text message.</para>
@@ -100,24 +100,8 @@
 		vsize = 0;
 		ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
 	}
-	if (option_verbose >= vsize) {
-		switch (vsize) {
-		case 0:
-			ast_verb(0, "%s\n", args.msg);
-			break;
-		case 1:
-			ast_verb(1, "%s\n", args.msg);
-			break;
-		case 2:
-			ast_verb(2, "%s\n", args.msg);
-			break;
-		case 3:
-			ast_verb(3, "%s\n", args.msg);
-			break;
-		default:
-			ast_verb(4, "%s\n", args.msg);
-		}
-	}
+
+	ast_verb(vsize, "%s\n", args.msg);
 
 	return 0;
 }
@@ -171,7 +155,7 @@
 	res = ast_unregister_application(app_verbose);
 	res |= ast_unregister_application(app_log);
 
-	return res;	
+	return res;
 }
 
 static int load_module(void)

Modified: team/may/ooh323_qsig/channels/chan_misdn.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/channels/chan_misdn.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/channels/chan_misdn.c (original)
+++ team/may/ooh323_qsig/channels/chan_misdn.c Fri Aug 30 08:51:04 2013
@@ -11235,7 +11235,7 @@
 static int unload_module(void)
 {
 	/* First, take us out of the channel loop */
-	ast_log(LOG_VERBOSE, "-- Unregistering mISDN Channel Driver --\n");
+	ast_verb(0, "-- Unregistering mISDN Channel Driver --\n");
 
 	misdn_tasks_destroy();
 

Modified: team/may/ooh323_qsig/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/main/asterisk.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/main/asterisk.c (original)
+++ team/may/ooh323_qsig/main/asterisk.c Fri Aug 30 08:51:04 2013
@@ -1872,8 +1872,8 @@
 		time_t s, e;
 		/* Begin shutdown routine, hanging up active channels */
 		ast_begin_shutdown(1);
-		if (option_verbose && ast_opt_console) {
-			ast_verbose("Beginning asterisk %s....\n", restart ? "restart" : "shutdown");
+		if (ast_opt_console) {
+			ast_verb(0, "Beginning asterisk %s....\n", restart ? "restart" : "shutdown");
 		}
 		time(&s);
 		for (;;) {
@@ -1889,7 +1889,7 @@
 		if (niceness != SHUTDOWN_REALLY_NICE) {
 			ast_begin_shutdown(0);
 		}
-		if (option_verbose && ast_opt_console) {
+		if (ast_opt_console) {
 			ast_verb(0, "Waiting for inactivity to perform %s...\n", restart ? "restart" : "halt");
 		}
 		for (;;) {
@@ -1905,7 +1905,7 @@
 	 */
 	ast_mutex_lock(&safe_system_lock);
 	if (shuttingdown != niceness) {
-		if (shuttingdown == NOT_SHUTTING_DOWN && option_verbose && ast_opt_console) {
+		if (shuttingdown == NOT_SHUTTING_DOWN && ast_opt_console) {
 			ast_verb(0, "Asterisk %s cancelled.\n", restart ? "restart" : "shutdown");
 		}
 		ast_mutex_unlock(&safe_system_lock);
@@ -2030,17 +2030,45 @@
 	sig_flags.need_quit = 1;
 }
 
-static const char *fix_header(char *outbuf, int maxout, const char *s, char *cmp)
-{
-	const char *c;
+static const char *fix_header(char *outbuf, int maxout, const char *s, char level)
+{
+	const char *cmp;
+
+	switch (level) {
+	case 0: *outbuf = '\0';
+		return s;
+	case 1: cmp = VERBOSE_PREFIX_1;
+		break;
+	case 2: cmp = VERBOSE_PREFIX_2;
+		break;
+	case 3: cmp = VERBOSE_PREFIX_3;
+		break;
+	default: cmp = VERBOSE_PREFIX_4;
+		break;
+	}
 
 	if (!strncmp(s, cmp, strlen(cmp))) {
-		c = s + strlen(cmp);
-		term_color(outbuf, cmp, COLOR_GRAY, 0, maxout);
-		return c;
-	}
-	return NULL;
-}
+		s += strlen(cmp);
+	}
+	term_color(outbuf, cmp, COLOR_GRAY, 0, maxout);
+
+	return s;
+}
+
+struct console_state_data {
+	int newline;
+	char verbose_line_level;
+};
+
+static int console_state_init(void *ptr)
+{
+	struct console_state_data *state = ptr;
+	state->newline = 1;
+	state->verbose_line_level = 0;
+	return 0;
+}
+
+AST_THREADSTORAGE_CUSTOM(console_state, console_state_init, ast_free_ptr);
 
 /* These gymnastics are due to platforms which designate char as unsigned by
  * default. Level is the negative character -- offset by 1, because \0 is the
@@ -2048,31 +2076,78 @@
 #define VERBOSE_MAGIC2LEVEL(x) (((char) -*(signed char *) (x)) - 1)
 #define VERBOSE_HASMAGIC(x)	(*(signed char *) (x) < 0)
 
+static int console_log_verbose(const char *s)
+{
+	/* verbose level of 0 evaluates to a magic of -1, 1 to -2, etc...
+	   search up to -7 (level = 6) as this is currently the largest
+	   level used */
+	static const char find_set[9] = { -1, -2, -3, -4, -5, -6, -7, '\n'};
+
+	struct console_state_data *state =
+		ast_threadstorage_get(&console_state, sizeof(*state));
+
+	char prefix[80];
+	const char *c = s;
+	int res = 0;
+
+	do {
+		if (VERBOSE_HASMAGIC(s)) {
+			/* if it has one always use the given line's level,
+			   otherwise we'll use the last line's level */
+			state->verbose_line_level = VERBOSE_MAGIC2LEVEL(s);
+			/* move past magic */
+			s++;
+		}
+
+		c = fix_header(prefix, sizeof(prefix), s,
+			       state->verbose_line_level);
+
+		if (!state->newline) {
+			/* don't use the prefix if line continuation */
+			*prefix = '\0';
+		}
+
+		/* for a given line separate on verbose magic and newlines */
+		if (!(s = strpbrk(c, find_set))) {
+			s = strchr(c, '\0');
+		} else if (*s == '\n') {
+			++s;
+		}
+
+		/* check if we should write this line after calculating begin/end
+		   so we process the case of a higher level line embedded within
+		   two lower level lines */
+		if (state->verbose_line_level > option_verbose) {
+			continue;
+		}
+
+		state->newline = *(s - 1) == '\n';
+		if (!ast_strlen_zero(prefix)) {
+			fputs(prefix, stdout);
+		}
+
+		fwrite(c, sizeof(char), s - c, stdout);
+
+		if (!res) {
+			/* if at least some info has been written
+			   we'll want to return true */
+			res = 1;
+		}
+		c = s;
+	} while (*s);
+
+	if (res) {
+		fflush(stdout);
+	}
+
+	return res;
+}
+
 static void console_verboser(const char *s)
 {
-	char tmp[80];
-	const char *c = NULL;
-	char level = 0;
-
-	if (VERBOSE_HASMAGIC(s)) {
-		level = VERBOSE_MAGIC2LEVEL(s);
-		s++;
-		if (level > option_verbose) {
-			return;
-		}
-	}
-
-	if ((c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_4)) ||
-	    (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_3)) ||
-	    (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_2)) ||
-	    (c = fix_header(tmp, sizeof(tmp), s, VERBOSE_PREFIX_1))) {
-		fputs(tmp, stdout);
-		fputs(c, stdout);
-	} else {
-		fputs(s, stdout);
-	}
-
-	fflush(stdout);
+	if (!console_log_verbose(s)) {
+		return;
+	}
 
 	/* Wake up a poll()ing console */
 	if (ast_opt_console && consolethread != AST_PTHREADT_NULL) {
@@ -2480,23 +2555,6 @@
 #endif /* ! LOW_MEMORY */
 };
 
-struct el_read_char_state_struct {
-	unsigned int line_full:1;
-	unsigned int prev_line_full:1;
-	char prev_line_verbosity;
-};
-
-static int el_read_char_state_init(void *ptr)
-{
-	struct el_read_char_state_struct *state = ptr;
-	state->line_full = 1;
-	state->prev_line_full = 1;
-	state->prev_line_verbosity = 0;
-	return 0;
-}
-
-AST_THREADSTORAGE_CUSTOM(el_read_char_state, el_read_char_state_init, ast_free_ptr);
-
 static int ast_el_read_char(EditLine *editline, char *cp)
 {
 	int num_read = 0;
@@ -2506,7 +2564,6 @@
 	int max;
 #define EL_BUF_SIZE 512
 	char buf[EL_BUF_SIZE];
-	struct el_read_char_state_struct *state = ast_threadstorage_get(&el_read_char_state, sizeof(*state));
 
 	for (;;) {
 		max = 1;
@@ -2536,8 +2593,6 @@
 			}
 		}
 		if (fds[0].revents) {
-			char level = 0;
-			char *curline = buf, *nextline;
 			res = read(ast_consock, buf, sizeof(buf) - 1);
 			/* if the remote side disappears exit */
 			if (res < 1) {
@@ -2577,33 +2632,7 @@
 				}
 			}
 
-			do {
-				state->prev_line_full = state->line_full;
-				if ((nextline = strchr(curline, '\n'))) {
-					state->line_full = 1;
-					nextline++;
-				} else {
-					state->line_full = 0;
-					nextline = strchr(curline, '\0');
-				}
-
-				if (state->prev_line_full && VERBOSE_HASMAGIC(curline)) {
-					level = VERBOSE_MAGIC2LEVEL(curline);
-					curline++;
-				} else if (state->prev_line_full && !VERBOSE_HASMAGIC(curline)) {
-					/* Non-verbose output */
-					level = 0;
-				} else {
-					level = state->prev_line_verbosity;
-				}
-				if ((!state->prev_line_full && state->prev_line_verbosity <= option_verbose) || (state->prev_line_full && level <= option_verbose)) {
-					if (write(STDOUT_FILENO, curline, nextline - curline) < 0) {
-					}
-				}
-
-				state->prev_line_verbosity = level;
-				curline = nextline;
-			} while (!ast_strlen_zero(curline));
+			console_log_verbose(buf);
 
 			if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (buf[res-2] == '\n'))) {
 				*cp = CC_REFRESH;
@@ -3627,7 +3656,7 @@
 
 static void print_intro_message(const char *runuser, const char *rungroup)
 {
-	if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) {
+ 	if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) {
 		if (ast_register_verbose(console_verboser)) {
 			fprintf(stderr, "Unable to register console verboser?\n");
 			return;
@@ -4121,8 +4150,8 @@
 
 	print_intro_message(runuser, rungroup);
 
-	if (ast_opt_console && !option_verbose) {
-		ast_verbose("[ Initializing Custom Configuration Options ]\n");
+	if (ast_opt_console) {
+		ast_verb(0, "[ Initializing Custom Configuration Options ]\n");
 	}
 	/* custom config setup */
 	register_config_cli();

Modified: team/may/ooh323_qsig/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/main/logger.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/main/logger.c (original)
+++ team/may/ooh323_qsig/main/logger.c Fri Aug 30 08:51:04 2013
@@ -1552,7 +1552,11 @@
 	callid = ast_read_threadstorage_callid();
 
 	va_start(ap, fmt);
-	ast_log_full(level, file, line, function, callid, fmt, ap);
+	if (level == __LOG_VERBOSE) {
+		__ast_verbose_ap(file, line, function, 0, callid, fmt, ap);
+	} else {
+		ast_log_full(level, file, line, function, callid, fmt, ap);
+	}
 	va_end(ap);
 
 	if (callid) {
@@ -1826,4 +1830,3 @@
 		AST_RWLIST_UNLOCK(&logchannels);
 	}
 }
-

Modified: team/may/ooh323_qsig/res/res_pjsip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/res/res_pjsip_pidf.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/res/res_pjsip_pidf.c (original)
+++ team/may/ooh323_qsig/res/res_pjsip_pidf.c Fri Aug 30 08:51:04 2013
@@ -159,8 +159,11 @@
 
 	if (pidfstate[0] != '-') {
 		pj_xml_node *activities = create_node(pool, status, "ep:activities");
-		pj_strdup2(pool, &activities->content, "ep:");
-		pj_strcat2(&activities->content, pidfstate);
+		size_t str_size = sizeof("ep:") + strlen(pidfstate);
+
+		activities->content.ptr = pj_pool_alloc(pool, str_size);
+		activities->content.slen = pj_ansi_snprintf(activities->content.ptr, str_size,
+				"ep:%s", pidfstate);
 	}
 
 	create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);

Modified: team/may/ooh323_qsig/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/res/res_pjsip_pubsub.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/res/res_pjsip_pubsub.c (original)
+++ team/may/ooh323_qsig/res/res_pjsip_pubsub.c Fri Aug 30 08:51:04 2013
@@ -962,15 +962,6 @@
 		return;
 	}
 
-	if (event->type == PJSIP_EVENT_RX_MSG) {
-		sub->handler->subscription_terminated(sub, event->body.rx_msg.rdata);
-	}
-
-	if (event->type == PJSIP_EVENT_TSX_STATE &&
-			event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) {
-		sub->handler->subscription_terminated(sub, event->body.tsx_state.src.rdata);
-	}
-
 	if (sub->handler->subscription_shutdown) {
 		sub->handler->subscription_shutdown(sub);
 	}
@@ -1052,6 +1043,11 @@
 		return;
 	}
 
+	if (pjsip_evsub_get_state(sub->evsub) == PJSIP_EVSUB_STATE_TERMINATED) {
+		sub->handler->subscription_terminated(sub, rdata);
+		return;
+	}
+
 	sub->handler->resubscribe(sub, rdata, &response_data);
 
 	if (!response_data_changed(&response_data)) {

Modified: team/may/ooh323_qsig/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_qsig/res/res_pjsip_session.c?view=diff&rev=397992&r1=397991&r2=397992
==============================================================================
--- team/may/ooh323_qsig/res/res_pjsip_session.c (original)
+++ team/may/ooh323_qsig/res/res_pjsip_session.c Fri Aug 30 08:51:04 2013
@@ -1868,17 +1868,33 @@
 		break;
 	case PJSIP_EVENT_RX_MSG:
 		if (tsx->method.id == PJSIP_INVITE_METHOD) {
-			if (tsx->role == PJSIP_ROLE_UAC && tsx->state == PJSIP_TSX_STATE_COMPLETED) {
-				/* This means we got a non 2XX final response to our outgoing INVITE */
-				if (tsx->status_code == PJSIP_SC_REQUEST_PENDING) {
-					reschedule_reinvite(session, tsx->mod_data[session_module.id], tsx->last_tx);
-					return;
-				} else if (inv->state == PJSIP_INV_STATE_CONFIRMED &&
-					   tsx->status_code != 488) {
-					/* Other reinvite failures (except 488) result in destroying the session. */
-					pjsip_tx_data *tdata;
-					if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS) {
-						ast_sip_session_send_request(session, tdata);
+			if (tsx->role == PJSIP_ROLE_UAC) {
+				if (tsx->state == PJSIP_TSX_STATE_COMPLETED) {
+					/* This means we got a non 2XX final response to our outgoing INVITE */
+					if (tsx->status_code == PJSIP_SC_REQUEST_PENDING) {
+						reschedule_reinvite(session, tsx->mod_data[session_module.id], tsx->last_tx);
+						return;
+					} else if (inv->state == PJSIP_INV_STATE_CONFIRMED &&
+						   tsx->status_code != 488) {
+						/* Other reinvite failures (except 488) result in destroying the session. */
+						pjsip_tx_data *tdata;
+						if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS) {
+							ast_sip_session_send_request(session, tdata);
+						}
+					}
+				} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+					if (inv->cancelling && tsx->status_code == PJSIP_SC_OK) {
+						/* This is a race condition detailed in RFC 5407 section 3.1.2.
+						 * We sent a CANCEL at the same time that the UAS sent us a 200 OK for
+						 * the original INVITE. As a result, we have now received a 200 OK for
+						 * a cancelled call. Our role is to immediately send a BYE to end the
+						 * dialog.
+						 */
+						pjsip_tx_data *tdata;
+
+						if (pjsip_inv_end_session(inv, 500, NULL, &tdata) == PJ_SUCCESS) {
+							ast_sip_session_send_request(session, tdata);
+						}
 					}
 				}
 			}




More information about the asterisk-commits mailing list