]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add reject app to do custom sip rejects
authorAnthony Minessale <anthony.minessale@gmail.com>
Sat, 21 Apr 2007 15:04:01 +0000 (15:04 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Sat, 21 Apr 2007 15:04:01 +0000 (15:04 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4997 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_sofia/mod_sofia.c

index 0f5669ca56e7a0d472426bc66701ab469dd1006e..7f494d532e2c9b8b43bd456b505ba2e42208a4d9 100644 (file)
@@ -363,6 +363,7 @@ typedef enum {
        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 @@ typedef enum {
        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;
 
 
index 6770a933aa117389d2ba284ab48b1fc3462bf766..4c6807526b680e03a3df1062b0c5f8d54408cd8f 100644 (file)
@@ -298,6 +298,18 @@ static void redirect_function(switch_core_session_t *session, char *data)
 
 }
 
+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 @@ static const switch_application_interface_t queuedtmf_application_interface = {
        /*.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 @@ static const switch_application_interface_t redirect_application_interface = {
        /* 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 = {
index 8e9c9260e0c9c876e384f4a3057990cf2f491de8..983f04177abdc80c775cb7d872fd1b504ec32534 100644 (file)
@@ -767,6 +767,32 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                        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);