[Freeswitch-svn] [commit] r4997 - in freeswitch/trunk/src: include mod/applications/mod_dptools mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Sat Apr 21 11:04:01 EDT 2007


Author: anthm
Date: Sat Apr 21 11:04:01 2007
New Revision: 4997

Modified:
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c

Log:
add reject app to do custom sip rejects

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Sat Apr 21 11:04:01 2007
@@ -363,6 +363,7 @@
 	SWITCH_MESSAGE_INDICATE_HOLD      - indicate hold
 	SWITCH_MESSAGE_INDICATE_UNHOLD    - indicate unhold
 	SWITCH_MESSAGE_INDICATE_REDIRECT  - indicate redirect
+	SWITCH_MESSAGE_INDICATE_REJECT    - indicate reject
 </pre>
  */
 typedef enum {
@@ -378,7 +379,8 @@
 	SWITCH_MESSAGE_INDICATE_NOMEDIA,
 	SWITCH_MESSAGE_INDICATE_HOLD,
 	SWITCH_MESSAGE_INDICATE_UNHOLD,
-	SWITCH_MESSAGE_INDICATE_REDIRECT
+	SWITCH_MESSAGE_INDICATE_REDIRECT,
+	SWITCH_MESSAGE_INDICATE_REJECT
 } switch_core_session_message_types_t;
 
 

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Sat Apr 21 11:04:01 2007
@@ -298,6 +298,18 @@
 
 }
 
+static void reject_function(switch_core_session_t *session, char *data)
+{
+	switch_core_session_message_t msg = { 0 };
+
+	/* Tell the channel to reject the call */
+	msg.from = __FILE__;
+	msg.string_arg = data;
+	msg.message_id = SWITCH_MESSAGE_INDICATE_REJECT;
+	switch_core_session_receive_message(session, &msg);
+
+}
+
 
 static void set_function(switch_core_session_t *session, char *data)
 {
@@ -711,6 +723,16 @@
 	/*.next */ &sched_hangup_application_interface
 };
 
+static const switch_application_interface_t reject_application_interface = {
+	/*.interface_name */ "reject",
+	/*.application_function */ reject_function,
+	/* long_desc */ "Send a reject message to a session.",
+	/* short_desc */ "Send session reject",
+	/* syntax */ "<reject_data>",
+	/* flags */ SAF_SUPPORT_NOMEDIA,
+	/*.next */ &queuedtmf_application_interface
+};
+
 static const switch_application_interface_t redirect_application_interface = {
 	/*.interface_name */ "redirect",
 	/*.application_function */ redirect_function,
@@ -718,7 +740,7 @@
 	/* short_desc */ "Send session redirect",
 	/* syntax */ "<redirect_data>",
 	/* flags */ SAF_SUPPORT_NOMEDIA,
-	/*.next */ &queuedtmf_application_interface
+	/*.next */ &reject_application_interface
 };
 
 static const switch_application_interface_t ivr_application_interface = {

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	Sat Apr 21 11:04:01 2007
@@ -767,6 +767,32 @@
 			nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END());
 		}
 		break;
+	case SWITCH_MESSAGE_INDICATE_REJECT:
+		if (msg->string_arg) {
+			int code = 0;
+			char *reason;
+			
+			if (switch_channel_test_flag(channel, CF_ANSWERED)) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call is already answered, Rejecting with hangup\n");
+				switch_channel_hangup(channel, SWITCH_CAUSE_CALL_REJECTED);
+			} else {
+
+				if ((reason = strchr(msg->string_arg, ' '))) {
+					reason++;
+					code = atoi(msg->string_arg);
+				} else {
+					reason = "Call Refused";
+				}
+
+				if (!(code > 400 && code < 600)) {
+					code = 488;
+				}
+
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Rejecting with %d %s\n", code, reason);
+				nua_respond(tech_pvt->nh, code, reason, TAG_END());
+			}
+		}
+		break;
 	case SWITCH_MESSAGE_INDICATE_RINGING:
 		nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END());
 		switch_channel_mark_ring_ready(channel);



More information about the Freeswitch-svn mailing list