2005-11-19 20:07:43 +00:00
/*
* FreeSWITCH Modular Media Switching Software Library / Soft - Switch Application
2012-04-18 16:51:48 +00:00
* Copyright ( C ) 2005 - 2012 , Anthony Minessale II < anthm @ freeswitch . org >
2005-11-19 20:07:43 +00:00
*
* Version : MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 ( the " License " ) ; you may not use this file except in compliance with
* the License . You may obtain a copy of the License at
* http : //www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
* for the specific language governing rights and limitations under the
* License .
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft - Switch Application
*
* The Initial Developer of the Original Code is
2009-02-04 21:20:54 +00:00
* Anthony Minessale II < anthm @ freeswitch . org >
2005-11-19 20:07:43 +00:00
* Portions created by the Initial Developer are Copyright ( C )
* the Initial Developer . All Rights Reserved .
*
2007-12-06 19:51:55 +00:00
2005-11-19 20:07:43 +00:00
*
2009-02-04 21:20:54 +00:00
* Anthony Minessale II < anthm @ freeswitch . org >
2005-11-19 20:07:43 +00:00
*
*
* switch_caller . c - - Caller Identification
*
*/
2008-01-27 17:36:53 +00:00
2006-04-29 01:00:52 +00:00
# include <switch.h>
2006-04-29 06:05:03 +00:00
# include <switch_caller.h>
2005-11-19 20:07:43 +00:00
2009-10-23 16:03:42 +00:00
# define profile_dup(a,b,p) if (!zstr(a)) { b = switch_core_strdup(p, a); } else { b = SWITCH_BLANK_STRING; }
# define profile_dup_clean(a,b,p) if (!zstr(a)) { b = switch_var_clean_string(switch_clean_string(switch_core_strdup(p, a)));} else { b = SWITCH_BLANK_STRING; }
2007-09-29 01:06:08 +00:00
2007-03-30 00:15:25 +00:00
SWITCH_DECLARE ( switch_caller_profile_t * ) switch_caller_profile_new ( switch_memory_pool_t * pool ,
2007-02-19 03:23:02 +00:00
const char * username ,
const char * dialplan ,
const char * caller_id_name ,
const char * caller_id_number ,
const char * network_addr ,
const char * ani ,
2007-03-29 22:31:56 +00:00
const char * aniii ,
2008-05-27 04:30:03 +00:00
const char * rdnis ,
const char * source , const char * context , const char * destination_number )
2005-11-19 20:07:43 +00:00
{
2006-04-29 06:05:03 +00:00
switch_caller_profile_t * profile = NULL ;
2011-10-11 20:13:23 +00:00
char uuid_str [ SWITCH_UUID_FORMATTED_LENGTH + 1 ] ;
2005-11-19 20:07:43 +00:00
2007-09-29 01:06:08 +00:00
profile = switch_core_alloc ( pool , sizeof ( * profile ) ) ;
2010-02-06 03:38:24 +00:00
switch_assert ( profile ! = NULL ) ;
2009-06-05 01:16:02 +00:00
memset ( profile , 0 , sizeof ( * profile ) ) ;
2008-05-27 04:30:03 +00:00
2011-10-11 20:13:23 +00:00
switch_uuid_str ( uuid_str , sizeof ( uuid_str ) ) ;
profile - > uuid_str = switch_core_strdup ( pool , uuid_str ) ;
2007-09-29 01:06:08 +00:00
if ( ! context ) {
context = " default " ;
2005-11-19 20:07:43 +00:00
}
2009-10-23 16:03:42 +00:00
if ( zstr ( caller_id_name ) ) {
2010-01-23 20:35:40 +00:00
caller_id_name = SWITCH_DEFAULT_CLID_NAME ;
2008-07-16 22:02:41 +00:00
}
2009-10-23 16:03:42 +00:00
if ( zstr ( caller_id_number ) ) {
2012-09-17 19:26:00 +00:00
caller_id_number = SWITCH_DEFAULT_CLID_NUMBER ;
2008-07-16 22:02:41 +00:00
}
2007-09-29 01:06:08 +00:00
profile_dup_clean ( username , profile - > username , pool ) ;
profile_dup_clean ( dialplan , profile - > dialplan , pool ) ;
profile_dup_clean ( caller_id_name , profile - > caller_id_name , pool ) ;
profile_dup_clean ( caller_id_number , profile - > caller_id_number , pool ) ;
2010-02-26 16:33:02 +00:00
profile - > caller_ton = SWITCH_TON_UNDEF ;
profile - > caller_numplan = SWITCH_NUMPLAN_UNDEF ;
2007-09-29 01:06:08 +00:00
profile_dup_clean ( network_addr , profile - > network_addr , pool ) ;
profile_dup_clean ( ani , profile - > ani , pool ) ;
2010-02-26 16:33:02 +00:00
profile - > ani_ton = SWITCH_TON_UNDEF ;
profile - > ani_numplan = SWITCH_NUMPLAN_UNDEF ;
2007-09-29 01:06:08 +00:00
profile_dup_clean ( aniii , profile - > aniii , pool ) ;
profile_dup_clean ( rdnis , profile - > rdnis , pool ) ;
2010-02-26 16:33:02 +00:00
profile - > rdnis_ton = SWITCH_TON_UNDEF ;
profile - > rdnis_numplan = SWITCH_NUMPLAN_UNDEF ;
2007-09-29 01:06:08 +00:00
profile_dup_clean ( source , profile - > source , pool ) ;
profile_dup_clean ( context , profile - > context , pool ) ;
profile_dup_clean ( destination_number , profile - > destination_number , pool ) ;
2010-02-26 16:33:02 +00:00
profile - > destination_number_ton = SWITCH_TON_UNDEF ;
profile - > destination_number_numplan = SWITCH_NUMPLAN_UNDEF ;
2007-09-29 01:06:08 +00:00
profile - > uuid = SWITCH_BLANK_STRING ;
profile - > chan_name = SWITCH_BLANK_STRING ;
2009-10-07 22:35:21 +00:00
profile - > callee_id_name = SWITCH_BLANK_STRING ;
profile - > callee_id_number = SWITCH_BLANK_STRING ;
2007-09-29 01:06:08 +00:00
switch_set_flag ( profile , SWITCH_CPF_SCREEN ) ;
profile - > pool = pool ;
2005-11-19 20:07:43 +00:00
return profile ;
}
2007-08-28 16:41:38 +00:00
SWITCH_DECLARE ( switch_caller_profile_t * ) switch_caller_profile_dup ( switch_memory_pool_t * pool , switch_caller_profile_t * tocopy )
2005-11-19 20:07:43 +00:00
{
2006-04-29 06:05:03 +00:00
switch_caller_profile_t * profile = NULL ;
2011-10-11 20:13:23 +00:00
char uuid_str [ SWITCH_UUID_FORMATTED_LENGTH + 1 ] ;
2007-08-28 16:41:38 +00:00
2007-09-29 01:06:08 +00:00
profile = switch_core_alloc ( pool , sizeof ( * profile ) ) ;
2007-12-11 19:23:57 +00:00
switch_assert ( profile ! = NULL ) ;
2007-09-29 01:06:08 +00:00
2011-10-11 20:13:23 +00:00
switch_uuid_str ( uuid_str , sizeof ( uuid_str ) ) ;
profile - > uuid_str = switch_core_strdup ( pool , uuid_str ) ;
profile - > clone_of = switch_core_strdup ( pool , tocopy - > uuid_str ) ;
2007-09-29 01:06:08 +00:00
profile_dup ( tocopy - > username , profile - > username , pool ) ;
profile_dup ( tocopy - > dialplan , profile - > dialplan , pool ) ;
profile_dup ( tocopy - > caller_id_name , profile - > caller_id_name , pool ) ;
profile_dup ( tocopy - > caller_id_number , profile - > caller_id_number , pool ) ;
2009-10-07 22:35:21 +00:00
profile_dup ( tocopy - > callee_id_name , profile - > callee_id_name , pool ) ;
profile_dup ( tocopy - > callee_id_number , profile - > callee_id_number , pool ) ;
2007-09-29 01:06:08 +00:00
profile_dup ( tocopy - > network_addr , profile - > network_addr , pool ) ;
profile_dup ( tocopy - > ani , profile - > ani , pool ) ;
profile_dup ( tocopy - > aniii , profile - > aniii , pool ) ;
profile_dup ( tocopy - > rdnis , profile - > rdnis , pool ) ;
profile_dup ( tocopy - > source , profile - > source , pool ) ;
profile_dup ( tocopy - > context , profile - > context , pool ) ;
profile_dup ( tocopy - > destination_number , profile - > destination_number , pool ) ;
profile_dup ( tocopy - > uuid , profile - > uuid , pool ) ;
profile_dup ( tocopy - > chan_name , profile - > chan_name , pool ) ;
profile - > caller_ton = tocopy - > caller_ton ;
profile - > caller_numplan = tocopy - > caller_numplan ;
profile - > ani_ton = tocopy - > ani_ton ;
profile - > ani_numplan = tocopy - > ani_numplan ;
profile - > rdnis_ton = tocopy - > rdnis_ton ;
profile - > rdnis_numplan = tocopy - > rdnis_numplan ;
profile - > destination_number_ton = tocopy - > destination_number_ton ;
profile - > destination_number_numplan = tocopy - > destination_number_numplan ;
profile - > flags = tocopy - > flags ;
profile - > pool = pool ;
2010-08-17 22:26:36 +00:00
profile - > direction = tocopy - > direction ;
2011-10-14 12:14:39 +00:00
2012-10-11 16:04:09 +00:00
if ( tocopy - > times ) {
profile - > old_times = ( switch_channel_timetable_t * ) switch_core_alloc ( profile - > pool , sizeof ( switch_channel_timetable_t ) ) ;
* profile - > old_times = * tocopy - > times ;
}
2011-10-14 12:14:39 +00:00
if ( tocopy - > soft ) {
profile_node_t * pn ;
for ( pn = tocopy - > soft ; pn ; pn = pn - > next ) {
profile_node_t * pp , * n = switch_core_alloc ( profile - > pool , sizeof ( * n ) ) ;
n - > var = switch_core_strdup ( profile - > pool , pn - > var ) ;
n - > val = switch_core_strdup ( profile - > pool , pn - > val ) ;
if ( ! profile - > soft ) {
profile - > soft = n ;
} else {
for ( pp = profile - > soft ; pp & & pp - > next ; pp = pp - > next ) ;
if ( pp ) {
pp - > next = n ;
}
}
}
}
2005-11-19 20:07:43 +00:00
return profile ;
}
2007-08-28 16:41:38 +00:00
SWITCH_DECLARE ( switch_caller_profile_t * ) switch_caller_profile_clone ( switch_core_session_t * session , switch_caller_profile_t * tocopy )
{
switch_memory_pool_t * pool ;
pool = switch_core_session_get_pool ( session ) ;
return switch_caller_profile_dup ( pool , tocopy ) ;
}
2007-11-01 11:28:26 +00:00
SWITCH_DECLARE ( const char * ) switch_caller_get_field_by_name ( switch_caller_profile_t * caller_profile , const char * name )
2006-05-10 03:23:05 +00:00
{
if ( ! strcasecmp ( name , " dialplan " ) ) {
return caller_profile - > dialplan ;
}
2006-05-26 16:00:08 +00:00
if ( ! strcasecmp ( name , " username " ) ) {
return caller_profile - > username ;
}
2006-05-10 03:23:05 +00:00
if ( ! strcasecmp ( name , " caller_id_name " ) ) {
return caller_profile - > caller_id_name ;
}
2009-10-07 22:35:21 +00:00
if ( ! strcasecmp ( name , " caller_id_number " ) ) {
return caller_profile - > caller_id_number ;
}
if ( ! strcasecmp ( name , " callee_id_name " ) ) {
return caller_profile - > callee_id_name ;
}
if ( ! strcasecmp ( name , " callee_id_number " ) ) {
return caller_profile - > callee_id_number ;
}
2006-05-10 03:23:05 +00:00
if ( ! strcasecmp ( name , " ani " ) ) {
return caller_profile - > ani ;
}
2006-10-17 23:33:32 +00:00
if ( ! strcasecmp ( name , " aniii " ) ) {
return caller_profile - > aniii ;
2006-05-10 03:23:05 +00:00
}
if ( ! strcasecmp ( name , " network_addr " ) ) {
return caller_profile - > network_addr ;
}
if ( ! strcasecmp ( name , " rdnis " ) ) {
return caller_profile - > rdnis ;
}
if ( ! strcasecmp ( name , " destination_number " ) ) {
return caller_profile - > destination_number ;
}
if ( ! strcasecmp ( name , " uuid " ) ) {
return caller_profile - > uuid ;
}
if ( ! strcasecmp ( name , " source " ) ) {
return caller_profile - > source ;
}
2011-10-11 20:13:23 +00:00
if ( ! strcasecmp ( name , " transfer_source " ) ) {
return caller_profile - > transfer_source ;
}
2006-05-10 03:23:05 +00:00
if ( ! strcasecmp ( name , " context " ) ) {
return caller_profile - > context ;
}
2008-02-26 23:29:58 +00:00
2006-05-10 03:23:05 +00:00
if ( ! strcasecmp ( name , " chan_name " ) ) {
return caller_profile - > chan_name ;
}
2008-02-26 23:29:58 +00:00
if ( ! strcasecmp ( name , " profile_index " ) ) {
return caller_profile - > profile_index ;
}
2007-08-28 16:41:38 +00:00
if ( ! strcasecmp ( name , " caller_ton " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > caller_ton ) ;
}
if ( ! strcasecmp ( name , " caller_numplan " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > caller_numplan ) ;
}
if ( ! strcasecmp ( name , " destination_number_ton " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > destination_number_ton ) ;
}
if ( ! strcasecmp ( name , " destination_number_numplan " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > destination_number_numplan ) ;
}
if ( ! strcasecmp ( name , " ani_ton " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > ani_ton ) ;
}
if ( ! strcasecmp ( name , " ani_numplan " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > ani_numplan ) ;
}
if ( ! strcasecmp ( name , " rdnis_ton " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > rdnis_ton ) ;
}
if ( ! strcasecmp ( name , " rdnis_numplan " ) ) {
return switch_core_sprintf ( caller_profile - > pool , " %u " , caller_profile - > rdnis_numplan ) ;
}
2008-09-03 15:20:21 +00:00
if ( ! strcasecmp ( name , " screen_bit " ) ) {
return switch_test_flag ( caller_profile , SWITCH_CPF_SCREEN ) ? " true " : " false " ;
}
if ( ! strcasecmp ( name , " privacy_hide_name " ) ) {
return switch_test_flag ( caller_profile , SWITCH_CPF_HIDE_NAME ) ? " true " : " false " ;
}
if ( ! strcasecmp ( name , " privacy_hide_number " ) ) {
return switch_test_flag ( caller_profile , SWITCH_CPF_HIDE_NUMBER ) ? " true " : " false " ;
}
2008-09-15 14:32:23 +00:00
if ( ! strcasecmp ( name , " profile_created_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > profile_created ) ;
2008-09-15 14:32:23 +00:00
}
if ( ! strcasecmp ( name , " created_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > created ) ;
2008-09-15 14:32:23 +00:00
}
if ( ! strcasecmp ( name , " answered_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > answered ) ;
2008-09-15 14:32:23 +00:00
}
if ( ! strcasecmp ( name , " progress_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > progress ) ;
2008-09-15 14:32:23 +00:00
}
if ( ! strcasecmp ( name , " progress_media_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > progress_media ) ;
2008-09-15 14:32:23 +00:00
}
if ( ! strcasecmp ( name , " hungup_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > hungup ) ;
2008-09-15 14:32:23 +00:00
}
if ( ! strcasecmp ( name , " transferred_time " ) ) {
2010-02-06 03:38:24 +00:00
return switch_core_sprintf ( caller_profile - > pool , " % " SWITCH_TIME_T_FMT , caller_profile - > times - > transferred ) ;
2008-09-15 14:32:23 +00:00
}
2010-02-06 03:38:24 +00:00
2008-09-15 14:32:23 +00:00
2006-05-10 03:23:05 +00:00
return NULL ;
}
2007-05-12 14:48:14 +00:00
SWITCH_DECLARE ( void ) switch_caller_profile_event_set_data ( switch_caller_profile_t * caller_profile , const char * prefix , switch_event_t * event )
2005-12-23 21:09:36 +00:00
{
2005-12-26 19:09:59 +00:00
char header_name [ 1024 ] ;
2012-10-11 16:04:09 +00:00
switch_channel_timetable_t * times = NULL ;
2005-12-26 19:09:59 +00:00
2010-08-17 22:26:36 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Direction " , prefix ) ;
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > direction = = SWITCH_CALL_DIRECTION_INBOUND ?
" inbound " : " outbound " ) ;
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > username ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Username " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > username ) ;
2006-05-26 16:00:08 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > dialplan ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Dialplan " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > dialplan ) ;
2005-12-26 19:09:59 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > caller_id_name ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Caller-ID-Name " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > caller_id_name ) ;
2005-12-26 19:09:59 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > caller_id_number ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Caller-ID-Number " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > caller_id_number ) ;
2005-12-26 19:09:59 +00:00
}
2010-04-27 21:52:29 +00:00
if ( ! zstr ( caller_profile - > callee_id_name ) ) {
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Callee-ID-Name " , prefix ) ;
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > callee_id_name ) ;
}
if ( ! zstr ( caller_profile - > callee_id_number ) ) {
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Callee-ID-Number " , prefix ) ;
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > callee_id_number ) ;
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > network_addr ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Network-Addr " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > network_addr ) ;
2005-12-26 19:09:59 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > ani ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-ANI " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > ani ) ;
2005-12-26 19:09:59 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > aniii ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-ANI-II " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > aniii ) ;
2005-12-26 19:09:59 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > destination_number ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Destination-Number " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > destination_number ) ;
2005-12-26 19:09:59 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > uuid ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Unique-ID " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > uuid ) ;
2006-04-11 14:55:14 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > source ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Source " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > source ) ;
2006-04-21 22:31:08 +00:00
}
2011-10-11 20:13:23 +00:00
if ( ! zstr ( caller_profile - > transfer_source ) ) {
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Transfer-Source " , prefix ) ;
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > transfer_source ) ;
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > context ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Context " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > context ) ;
2006-04-28 19:46:57 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > rdnis ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-RDNIS " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > rdnis ) ;
2006-04-21 22:31:08 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > chan_name ) ) {
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Name " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > chan_name ) ;
2006-04-11 14:55:14 +00:00
}
2009-10-23 16:03:42 +00:00
if ( ! zstr ( caller_profile - > profile_index ) ) {
2008-02-26 23:29:58 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Profile-Index " , prefix ) ;
2008-08-16 02:17:09 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , caller_profile - > profile_index ) ;
2008-02-26 23:29:58 +00:00
}
2011-05-13 20:29:40 +00:00
if ( caller_profile - > soft ) {
profile_node_t * pn ;
for ( pn = caller_profile - > soft ; pn ; pn = pn - > next ) {
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , pn - > var , pn - > val ) ;
}
}
2012-10-11 16:04:09 +00:00
if ( ! ( times = caller_profile - > times ) ) {
times = caller_profile - > old_times ;
}
2011-05-13 20:29:40 +00:00
2012-10-11 16:04:09 +00:00
if ( times ) {
2008-09-15 14:32:23 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Profile-Created-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > profile_created ) ;
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Created-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > created ) ;
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Answered-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > answered ) ;
2008-09-15 14:32:23 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Progress-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > progress ) ;
2008-09-15 14:32:23 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Progress-Media-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > progress_media ) ;
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Hangup-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > hungup ) ;
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Transfer-Time " , prefix ) ;
2012-10-11 16:04:09 +00:00
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > transferred ) ;
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Resurrect-Time " , prefix ) ;
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > resurrected ) ;
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Bridged-Time " , prefix ) ;
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > bridged ) ;
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Last-Hold " , prefix ) ;
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > last_hold ) ;
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Channel-Hold-Accum " , prefix ) ;
switch_event_add_header ( event , SWITCH_STACK_BOTTOM , header_name , " % " SWITCH_TIME_T_FMT , times - > hold_accum ) ;
2007-05-31 14:42:23 +00:00
}
2005-12-23 21:09:36 +00:00
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Screen-Bit " , prefix ) ;
2008-09-03 15:20:21 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , switch_test_flag ( caller_profile , SWITCH_CPF_SCREEN ) ? " true " : " false " ) ;
2006-10-16 04:39:00 +00:00
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Privacy-Hide-Name " , prefix ) ;
2008-09-03 15:20:21 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , switch_test_flag ( caller_profile , SWITCH_CPF_HIDE_NAME ) ? " true " : " false " ) ;
2006-10-16 04:39:00 +00:00
2007-12-12 21:53:32 +00:00
switch_snprintf ( header_name , sizeof ( header_name ) , " %s-Privacy-Hide-Number " , prefix ) ;
2008-09-03 15:20:21 +00:00
switch_event_add_header_string ( event , SWITCH_STACK_BOTTOM , header_name , switch_test_flag ( caller_profile , SWITCH_CPF_HIDE_NUMBER ) ? " true " : " false " ) ;
2005-12-23 21:09:36 +00:00
}
2010-02-06 03:38:24 +00:00
SWITCH_DECLARE ( switch_status_t ) switch_caller_extension_clone ( switch_caller_extension_t * * new_ext , switch_caller_extension_t * orig ,
2008-08-13 21:46:06 +00:00
switch_memory_pool_t * pool )
{
switch_caller_extension_t * caller_extension = NULL ;
switch_caller_application_t * caller_application = NULL , * ap = NULL ;
* new_ext = NULL ;
if ( ( caller_extension = switch_core_alloc ( pool , sizeof ( switch_caller_extension_t ) ) ) ! = 0 ) {
int match = 0 ;
2010-02-06 03:38:24 +00:00
caller_extension - > extension_name = switch_core_strdup ( pool , orig - > extension_name ) ;
caller_extension - > extension_number = switch_core_strdup ( pool , orig - > extension_number ) ;
2008-08-13 21:46:06 +00:00
2010-02-06 03:38:24 +00:00
for ( ap = orig - > applications ; ap ; ap = ap - > next ) {
2008-08-13 21:46:06 +00:00
if ( ! match ) {
if ( ap = = orig - > current_application ) {
match + + ;
} else {
continue ;
}
}
caller_application = switch_core_alloc ( pool , sizeof ( switch_caller_application_t ) ) ;
2010-02-06 03:38:24 +00:00
2008-08-13 21:46:06 +00:00
caller_application - > application_name = switch_core_strdup ( pool , ap - > application_name ) ;
caller_application - > application_data = switch_core_strdup ( pool , ap - > application_data ) ;
if ( ! caller_extension - > applications ) {
caller_extension - > applications = caller_application ;
} else if ( caller_extension - > last_application ) {
caller_extension - > last_application - > next = caller_application ;
}
2010-02-06 03:38:24 +00:00
2008-08-13 21:46:06 +00:00
caller_extension - > last_application = caller_application ;
if ( ap = = orig - > current_application ) {
caller_extension - > current_application = caller_application ;
}
}
* new_ext = caller_extension ;
return SWITCH_STATUS_SUCCESS ;
2010-02-06 03:38:24 +00:00
}
2008-08-13 21:46:06 +00:00
return SWITCH_STATUS_MEMERR ;
}
2008-05-27 04:30:03 +00:00
SWITCH_DECLARE ( switch_caller_extension_t * ) switch_caller_extension_new ( switch_core_session_t * session , const char * extension_name ,
const char * extension_number )
2005-11-19 20:07:43 +00:00
{
2006-04-29 06:05:03 +00:00
switch_caller_extension_t * caller_extension = NULL ;
2005-11-19 20:07:43 +00:00
2006-04-29 06:05:03 +00:00
if ( ( caller_extension = switch_core_session_alloc ( session , sizeof ( switch_caller_extension_t ) ) ) ! = 0 ) {
2005-11-19 20:07:43 +00:00
caller_extension - > extension_name = switch_core_session_strdup ( session , extension_name ) ;
caller_extension - > extension_number = switch_core_session_strdup ( session , extension_number ) ;
caller_extension - > current_application = caller_extension - > last_application = caller_extension - > applications ;
}
return caller_extension ;
}
2009-11-26 21:28:28 +00:00
SWITCH_DECLARE ( void ) switch_caller_extension_add_application_printf ( switch_core_session_t * session ,
2010-02-06 03:38:24 +00:00
switch_caller_extension_t * caller_extension , const char * application_name ,
const char * fmt , . . . )
2009-11-26 21:28:28 +00:00
{
va_list ap ;
char * data = NULL ;
2010-02-06 03:38:24 +00:00
2009-11-26 21:28:28 +00:00
va_start ( ap , fmt ) ;
switch_vasprintf ( & data , fmt , ap ) ;
va_end ( ap ) ;
2010-02-06 03:38:24 +00:00
2009-11-26 21:28:28 +00:00
if ( data ) {
2010-03-03 18:31:19 +00:00
char * p ;
if ( ( p = strstr ( data , " \\ ' " ) ) ) {
2012-04-10 21:17:16 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_WARNING , " App not added, Invalid character sequence in data string [%s] \n " , data ) ;
2010-03-03 18:31:19 +00:00
free ( data ) ;
return ;
}
2010-02-06 03:38:24 +00:00
switch_caller_extension_add_application ( session , caller_extension , application_name , data ) ;
2009-11-26 21:28:28 +00:00
free ( data ) ;
}
}
2006-04-29 06:05:03 +00:00
SWITCH_DECLARE ( void ) switch_caller_extension_add_application ( switch_core_session_t * session ,
2008-05-27 04:30:03 +00:00
switch_caller_extension_t * caller_extension , const char * application_name ,
const char * application_data )
2005-11-19 20:07:43 +00:00
{
2006-04-29 06:05:03 +00:00
switch_caller_application_t * caller_application = NULL ;
2010-03-03 18:31:19 +00:00
char * p ;
2005-11-19 20:07:43 +00:00
2007-12-11 19:23:57 +00:00
switch_assert ( session ! = NULL ) ;
2005-11-19 20:07:43 +00:00
2006-04-29 06:05:03 +00:00
if ( ( caller_application = switch_core_session_alloc ( session , sizeof ( switch_caller_application_t ) ) ) ! = 0 ) {
2005-11-19 20:07:43 +00:00
caller_application - > application_name = switch_core_session_strdup ( session , application_name ) ;
caller_application - > application_data = switch_core_session_strdup ( session , application_data ) ;
2010-03-03 18:31:19 +00:00
2010-03-03 22:30:01 +00:00
if ( caller_application - > application_data & & ( p = strstr ( caller_application - > application_data , " \\ ' " ) ) ) {
2012-04-10 21:17:16 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_WARNING , " App not added, Invalid character sequence in data string [%s] \n " ,
2010-03-03 18:31:19 +00:00
caller_application - > application_data ) ;
return ;
}
2005-11-19 20:07:43 +00:00
if ( ! caller_extension - > applications ) {
caller_extension - > applications = caller_application ;
2006-01-20 15:05:05 +00:00
} else if ( caller_extension - > last_application ) {
2005-11-19 20:07:43 +00:00
caller_extension - > last_application - > next = caller_application ;
}
caller_extension - > last_application = caller_application ;
caller_extension - > current_application = caller_extension - > applications ;
}
}
2006-11-27 22:30:48 +00:00
/* For Emacs:
* Local Variables :
* mode : c
2008-02-03 22:14:57 +00:00
* indent - tabs - mode : t
2006-11-27 22:30:48 +00:00
* tab - width : 4
* c - basic - offset : 4
* End :
* For VIM :
2008-07-03 19:12:26 +00:00
* vim : set softtabstop = 4 shiftwidth = 4 tabstop = 4 :
2006-11-27 22:30:48 +00:00
*/