From fb9b69f469ee503779f00d36b39158655c5e6f0a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 29 Aug 2012 15:34:17 -0500 Subject: [PATCH] add fire-message-events profile param --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 12 ++++++++++++ src/mod/endpoints/mod_sofia/sofia_presence.c | 12 +++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index ecbf36d7a4..817ea85063 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -271,6 +271,7 @@ typedef enum { PFLAG_CONFIRM_BLIND_TRANSFER, PFLAG_THREAD_PER_REG, PFLAG_MWI_USE_REG_CALLID, + PFLAG_FIRE_MESSAGE_EVENTS, /* No new flags below this line */ PFLAG_MAX } PFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 85162d61b9..582f4c0bdf 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3410,6 +3410,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) } else { sofia_clear_pflag(profile, PFLAG_IN_DIALOG_CHAT); } + } else if (!strcasecmp(var, "fire-message-events")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS); + } else { + sofia_clear_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS); + } } else if (!strcasecmp(var, "disable-hold")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_DISABLE_HOLD); @@ -4336,6 +4342,12 @@ switch_status_t config_sofia(int reload, char *profile_name) } else { sofia_clear_pflag(profile, PFLAG_IN_DIALOG_CHAT); } + } else if (!strcasecmp(var, "fire-message-events")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS); + } else { + sofia_clear_pflag(profile, PFLAG_FIRE_MESSAGE_EVENTS); + } } else if (!strcasecmp(var, "t38-passthru")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_T38_PASSTHRU); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 3f07d1c642..cc9e054258 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -4349,7 +4349,7 @@ void sofia_presence_handle_sip_i_message(int status, if (nh) { char hash_key[512]; private_object_t *tech_pvt; - switch_event_t *event; + switch_event_t *event, *event_dup; char *to_addr; char *from_addr; char *p; @@ -4379,6 +4379,8 @@ void sofia_presence_handle_sip_i_message(int status, } if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) { + event->flags |= EF_UNIQ_HEADERS; + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO); @@ -4407,6 +4409,14 @@ void sofia_presence_handle_sip_i_message(int status, if (msg) { switch_event_add_body(event, "%s", msg); } + + if (switch_event_dup(&event_dup, event) == SWITCH_STATUS_SUCCESS) { + event_dup->event_id = SWITCH_EVENT_RECV_MESSAGE; + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Name", switch_event_name(event->event_id)); + switch_event_fire(&event_dup); + } + + } else { abort(); }