[Freeswitch-svn] [commit] r9129 - freeswitch/trunk/src/mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Tue Jul 22 10:04:51 EDT 2008


Author: anthm
Date: Tue Jul 22 10:04:51 2008
New Revision: 9129

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h

Log:
add sip_bye_h prefix to add headers to bye

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Tue Jul 22 10:04:51 2008
@@ -284,6 +284,28 @@
 
 	if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
 		char reason[128] = "";
+		switch_stream_handle_t stream = { 0 };
+		switch_event_header_t *hi;
+		char *bye_headers = NULL;
+
+		SWITCH_STANDARD_STREAM(stream);
+		if ((hi = switch_channel_variable_first(channel))) {
+			for (; hi; hi = hi->next) {
+				const char *name = (char *) hi->name;
+				char *value = (char *) hi->value;
+				
+				if (!strncasecmp(name, SOFIA_SIP_BYE_HEADER_PREFIX, strlen(SOFIA_SIP_BYE_HEADER_PREFIX))) {
+					const char *hname = name + strlen(SOFIA_SIP_BYE_HEADER_PREFIX);
+					stream.write_function(&stream, "%s: %s\r\n", hname, value);
+				}
+			}
+			switch_channel_variable_last(channel);
+		}
+
+		if (stream.data) {
+			bye_headers = stream.data;
+		}
+		
 		if (cause > 1 && cause < 128) {
 			switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
 		} else if (cause == SWITCH_CAUSE_PICKED_OFF) {
@@ -294,17 +316,28 @@
 
 		if (switch_test_flag(tech_pvt, TFLAG_ANS)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel));
-			nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END());
+			nua_bye(tech_pvt->nh, 
+					SIPTAG_REASON_STR(reason),
+					TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
+					TAG_END());
 		} else {
 			if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending CANCEL to %s\n", switch_channel_get_name(channel));
-				nua_cancel(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END());
+				nua_cancel(tech_pvt->nh, 
+						   SIPTAG_REASON_STR(reason), 
+						   TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
+						   TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
+						   TAG_END());
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding to INVITE with: %d\n", sip_cause);
-				nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause), SIPTAG_REASON_STR(reason), TAG_END());
+				nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause), 
+							SIPTAG_REASON_STR(reason), 
+							TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
+							TAG_END());
 			}
 		}
 		switch_set_flag(tech_pvt, TFLAG_BYE);
+		switch_safe_free(stream.data);
 	}
 
 	switch_clear_flag(tech_pvt, TFLAG_IO);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Tue Jul 22 10:04:51 2008
@@ -78,6 +78,7 @@
 #define SOFIA_USER_AGENT "FreeSWITCH-mod_sofia/" SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO "-" SWITCH_VERSION_REVISION
 #define SOFIA_CHAT_PROTO "sip"
 #define SOFIA_SIP_HEADER_PREFIX "sip_h_"
+#define SOFIA_SIP_BYE_HEADER_PREFIX "sip_bye_h_"
 #define SOFIA_SIP_HEADER_PREFIX_T "~sip_h_"
 #define SOFIA_DEFAULT_PORT "5060"
 #define SOFIA_DEFAULT_TLS_PORT "5061"



More information about the Freeswitch-svn mailing list