Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
f25c4f6d
提交
f25c4f6d
authored
5月 08, 2012
作者:
Ken Rice
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
ssh://git.freeswitch.org:222/freeswitch
上级
eb92a4d2
1fc57f98
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
330 行增加
和
466 行删除
+330
-466
bootstrap.sh
debian/bootstrap.sh
+29
-5
switch_ivr.h
src/include/switch_ivr.h
+9
-0
switch_types.h
src/include/switch_types.h
+1
-0
Makefile
src/mod/event_handlers/mod_json_cdr/Makefile
+0
-23
mod_json_cdr.c
src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c
+7
-428
switch_ivr.c
src/switch_ivr.c
+254
-0
switch_ivr_bridge.c
src/switch_ivr_bridge.c
+30
-10
没有找到文件。
debian/bootstrap.sh
浏览文件 @
f25c4f6d
...
...
@@ -56,16 +56,23 @@ xread () {
}
avoid_mod_filter
()
{
local
mods
=(
"
$(
eval echo
\$
{
avoid_mods_
$codename
[
@]
}
)
"
"
${
avoid_mods
[@]
}
"
)
local
x
=
"avoid_mods_
$codename
[@]"
local
-a
mods
=(
"
${
avoid_mods
[@]
}
"
"
${
!x
}
"
)
for
x
in
"
${
mods
[@]
}
"
;
do
[
"
$1
"
=
"
$x
"
]
&&
return
1
if
[
"
$1
"
=
"
$x
"
]
;
then
[
"
$2
"
=
"show"
]
&&
echo
"excluding module
$x
"
>
&2
return
1
fi
done
return
0
}
modconf_filter
()
{
while
xread line
;
do
[
"
$1
"
=
"
$line
"
]
&&
return
0
while
xread l
;
do
if
[
"
$1
"
=
"
$l
"
]
;
then
[
"
$2
"
=
"show"
]
&&
echo
"including module
$l
"
>
&2
return
0
fi
done
< modules.conf
return
1
}
...
...
@@ -78,6 +85,10 @@ mod_filter () {
fi
}
mod_filter_show
()
{
mod_filter
"
$1
"
show
}
map_fs_modules
()
{
local
filterfn
=
"
$1
"
percatfns
=
"
$2
"
permodfns
=
"
$3
"
for
x
in
$mod_dir
/
*
;
do
...
...
@@ -803,30 +814,42 @@ echo "Bootstrapping debian/ for ${codename}" >&2
echo
>
&2
echo
"Please wait, this takes a few seconds..."
>
&2
echo
"Adding any new modules to control-modules..."
>
&2
parse_dir
=
control-modules.parse
map_fs_modules
':'
'genmodctl_new_cat'
'genmodctl_new_mod'
>>
control-modules
echo
"Parsing control-modules..."
>
&2
parse_mod_control
echo
"Displaying includes/excludes..."
>
&2
map_modules
'mod_filter_show'
''
''
echo
"Generating control-modules.gen as sanity check..."
>
&2
(
echo
"# -*- mode:debian-control -*-"
;
echo
;
\
map_modules
':'
'genmodctl_cat'
'genmodctl_mod'
\
)
>
control-modules.gen
print_edit_warning
>
modules_.conf
echo
"Accumulating build dependencies from modules..."
>
&2
map_modules
'mod_filter'
''
'accumulate_build_depends'
echo
"Generating debian/..."
>
&2
>
control
(
print_edit_warning
;
print_source_control
;
print_core_control
)
>>
control
echo
"Generating debian/ (music)..."
>
&2
for
r
in
8000 16000 32000 48000
;
do
genmusic
$r
;
done
echo
"Generating debian/ (sounds)..."
>
&2
for
x
in
'en/us/callie'
;
do
for
r
in
8000 16000 32000 48000
;
do
gensound
$r
$x
done
done
echo
"Generating debian/ (conf)..."
>
&2
(
echo
"### conf"
;
echo
)
>>
control
map_confs
'genconf'
echo
"Generating debian/ (modules)..."
>
&2
(
echo
"### modules"
;
echo
)
>>
control
print_edit_warning
>
modules_.conf
map_modules
"mod_filter"
\
"gencontrol_per_cat genmodules_per_cat"
\
"gencontrol_per_mod geninstall_per_mod genoverrides_per_mod genmodules_per_mod"
echo
"Generating additional lintian overrides..."
>
&2
grep
-e
'^Package:'
control |
while
xread l
;
do
m
=
"
${
l
#*
:
}
"
f
=
$m
.lintian-overrides
...
...
@@ -839,4 +862,5 @@ f=freeswitch.lintian-overrides
[
-s
$f
]
||
print_edit_warning
>>
$f
print_gpl_openssl_override
"freeswitch"
>>
$f
echo
"Done bootstrapping debian/"
>
&2
touch
.stamp-bootstrap
src/include/switch_ivr.h
浏览文件 @
f25c4f6d
...
...
@@ -41,6 +41,7 @@
#define SWITCH_IVR_H
#include <switch.h>
#include "switch_json.h"
SWITCH_BEGIN_EXTERN_C
struct
switch_unicast_conninfo
{
switch_core_session_t
*
session
;
...
...
@@ -82,6 +83,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_
char
*
local_ip
,
switch_port_t
local_port
,
char
*
remote_ip
,
switch_port_t
remote_port
,
char
*
transport
,
char
*
flags
);
/*!
\brief Generate an JSON CDR report.
\param session the session to get the data from.
\param json_cdr pointer to the json object
\return SWITCH_STATUS_SUCCESS if successful
\note on success the json object must be freed
*/
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_generate_json_cdr
(
switch_core_session_t
*
session
,
cJSON
**
json_cdr
,
switch_bool_t
urlencode
);
/*!
\brief Generate an XML CDR report.
...
...
src/include/switch_types.h
浏览文件 @
f25c4f6d
...
...
@@ -131,6 +131,7 @@ SWITCH_BEGIN_EXTERN_C
#define SWITCH_READ_RESULT_VARIABLE "read_result"
#define SWITCH_ATT_XFER_RESULT_VARIABLE "att_xfer_result"
#define SWITCH_COPY_XML_CDR_VARIABLE "copy_xml_cdr"
#define SWITCH_COPY_JSON_CDR_VARIABLE "copy_json_cdr"
#define SWITCH_CURRENT_APPLICATION_VARIABLE "current_application"
#define SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE "proto_specific_hangup_cause"
#define SWITCH_TRANSFER_HISTORY_VARIABLE "transfer_history"
...
...
src/mod/event_handlers/mod_json_cdr/Makefile
浏览文件 @
f25c4f6d
json-c
=
json-c-0.9
BASE
=
../../../..
JSON_DIR
=
$(switch_srcdir)
/libs/
$
(
json-c
)
JSON_BUILDDIR
=
$(switch_builddir)
/libs/
$
(
json-c
)
JSONLA
=
$(JSON_BUILDDIR)
/libjson.la
LOCAL_CFLAGS
=
-I
$(JSON_DIR)
LOCAL_LIBADD
=
$(JSONLA)
include
$(BASE)/build/modmake.rules
$(JSON_DIR)
:
$(GETLIB)
$
(
json-c
)
.tar.gz
$(JSON_BUILDDIR)/Makefile
:
$(JSON_DIR)
mkdir
-p
$(JSON_BUILDDIR)
cd
$(JSON_BUILDDIR)
&&
$(DEFAULT_VARS)
$(JSON_DIR)
/configure
$(DEFAULT_ARGS)
--srcdir
=
$(JSON_DIR)
CPPFLAGS
=
LDFLAGS
=
$(TOUCH_TARGET)
$(JSONLA)
:
$(JSON_BUILDDIR)/Makefile
cd
$(JSON_BUILDDIR)
&&
$(MAKE)
$(TOUCH_TARGET)
src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c
浏览文件 @
f25c4f6d
...
...
@@ -33,7 +33,6 @@
#include <sys/stat.h>
#include <switch.h>
#include <switch_curl.h>
#include <json.h>
#define MAX_URLS 20
#define MAX_ERR_DIRS 20
...
...
@@ -181,432 +180,11 @@ static switch_status_t set_json_cdr_log_dirs()
return
status
;
}
#define json_object_safe_new_string(str) json_object_new_string(str ? str : "")
#define JSON_ENSURE_SUCCESS(obj) if (is_error(obj)) { return; }
static
void
set_json_profile_data
(
struct
json_object
*
json
,
switch_caller_profile_t
*
caller_profile
)
{
struct
json_object
*
param
=
NULL
;
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
username
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"username"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
dialplan
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"dialplan"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
caller_id_name
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"caller_id_name"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
ani
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"ani"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
aniii
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"aniii"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
caller_id_number
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"caller_id_number"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
network_addr
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"network_addr"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
rdnis
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"rdnis"
,
param
);
param
=
json_object_safe_new_string
(
caller_profile
->
destination_number
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"destination_number"
,
param
);
param
=
json_object_safe_new_string
(
caller_profile
->
uuid
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"uuid"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
source
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"source"
,
param
);
param
=
json_object_safe_new_string
((
char
*
)
caller_profile
->
context
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"context"
,
param
);
param
=
json_object_safe_new_string
(
caller_profile
->
chan_name
);
JSON_ENSURE_SUCCESS
(
param
);
json_object_object_add
(
json
,
"chan_name"
,
param
);
}
static
void
set_json_chan_vars
(
struct
json_object
*
json
,
switch_channel_t
*
channel
)
{
struct
json_object
*
variable
=
NULL
;
switch_event_header_t
*
hi
=
switch_channel_variable_first
(
channel
);
if
(
!
hi
)
return
;
for
(;
hi
;
hi
=
hi
->
next
)
{
if
(
!
zstr
(
hi
->
name
)
&&
!
zstr
(
hi
->
value
))
{
char
*
data
=
hi
->
value
;
if
(
globals
.
encode_values
==
ENCODING_DEFAULT
)
{
switch_size_t
dlen
=
strlen
(
hi
->
value
)
*
3
;
if
((
data
=
malloc
(
dlen
)))
{
memset
(
data
,
0
,
dlen
);
switch_url_encode
(
hi
->
value
,
data
,
dlen
);
}
}
variable
=
json_object_safe_new_string
(
data
);
if
(
!
is_error
(
variable
))
{
json_object_object_add
(
json
,
hi
->
name
,
variable
);
}
if
(
data
!=
hi
->
value
)
{
switch_safe_free
(
data
);
}
}
}
switch_channel_variable_last
(
channel
);
}
static
switch_status_t
generate_json_cdr
(
switch_core_session_t
*
session
,
struct
json_object
**
json_cdr
)
{
struct
json_object
*
cdr
=
json_object_new_object
();
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_caller_profile_t
*
caller_profile
;
struct
json_object
*
variables
,
*
j_main_cp
,
*
j_caller_profile
,
*
j_caller_extension
,
*
j_times
,
*
time_tag
,
*
j_application
,
*
j_callflow
,
*
j_inner_extension
,
*
j_apps
,
*
j_o
,
*
j_channel_data
,
*
j_field
;
switch_app_log_t
*
app_log
;
char
tmp
[
512
],
*
f
;
if
(
is_error
(
cdr
))
{
return
SWITCH_STATUS_FALSE
;
}
j_channel_data
=
json_object_new_object
();
if
(
is_error
(
j_channel_data
))
{
goto
error
;
}
json_object_object_add
(
cdr
,
"channel_data"
,
j_channel_data
);
j_field
=
json_object_safe_new_string
((
char
*
)
switch_channel_state_name
(
switch_channel_get_state
(
channel
)));
json_object_object_add
(
j_channel_data
,
"state"
,
j_field
);
j_field
=
json_object_safe_new_string
(
switch_channel_direction
(
channel
)
==
SWITCH_CALL_DIRECTION_OUTBOUND
?
"outbound"
:
"inbound"
);
json_object_object_add
(
j_channel_data
,
"direction"
,
j_field
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%d"
,
switch_channel_get_state
(
channel
));
j_field
=
json_object_new_string
((
char
*
)
tmp
);
json_object_object_add
(
j_channel_data
,
"state_number"
,
j_field
);
if
((
f
=
switch_channel_get_flag_string
(
channel
)))
{
j_field
=
json_object_safe_new_string
((
char
*
)
f
);
json_object_object_add
(
j_channel_data
,
"flags"
,
j_field
);
free
(
f
);
}
if
((
f
=
switch_channel_get_cap_string
(
channel
)))
{
j_field
=
json_object_safe_new_string
((
char
*
)
f
);
json_object_object_add
(
j_channel_data
,
"caps"
,
j_field
);
free
(
f
);
}
variables
=
json_object_new_object
();
json_object_object_add
(
cdr
,
"variables"
,
variables
);
if
(
is_error
(
variables
))
{
goto
error
;
}
set_json_chan_vars
(
variables
,
channel
);
if
((
app_log
=
switch_core_session_get_app_log
(
session
)))
{
switch_app_log_t
*
ap
;
j_apps
=
json_object_new_object
();
if
(
is_error
(
j_apps
))
{
goto
error
;
}
json_object_object_add
(
cdr
,
"app_log"
,
j_apps
);
for
(
ap
=
app_log
;
ap
;
ap
=
ap
->
next
)
{
j_application
=
json_object_new_object
();
if
(
is_error
(
j_application
))
{
goto
error
;
}
json_object_object_add
(
j_application
,
"app_name"
,
json_object_safe_new_string
(
ap
->
app
));
json_object_object_add
(
j_application
,
"app_data"
,
json_object_safe_new_string
(
ap
->
arg
));
json_object_object_add
(
j_apps
,
"application"
,
j_application
);
}
}
caller_profile
=
switch_channel_get_caller_profile
(
channel
);
while
(
caller_profile
)
{
j_callflow
=
json_object_new_object
();
if
(
is_error
(
j_callflow
))
{
goto
error
;
}
json_object_object_add
(
cdr
,
"callflow"
,
j_callflow
);
if
(
!
zstr
(
caller_profile
->
dialplan
))
{
json_object_object_add
(
j_callflow
,
"dialplan"
,
json_object_safe_new_string
((
char
*
)
caller_profile
->
dialplan
));
}
if
(
!
zstr
(
caller_profile
->
profile_index
))
{
json_object_object_add
(
j_callflow
,
"profile_index"
,
json_object_safe_new_string
((
char
*
)
caller_profile
->
profile_index
));
}
if
(
caller_profile
->
caller_extension
)
{
switch_caller_application_t
*
ap
;
j_caller_extension
=
json_object_new_object
();
if
(
is_error
(
j_caller_extension
))
{
goto
error
;
}
json_object_object_add
(
j_callflow
,
"extension"
,
j_caller_extension
);
json_object_object_add
(
j_caller_extension
,
"name"
,
json_object_safe_new_string
(
caller_profile
->
caller_extension
->
extension_name
));
json_object_object_add
(
j_caller_extension
,
"number"
,
json_object_safe_new_string
(
caller_profile
->
caller_extension
->
extension_number
));
if
(
caller_profile
->
caller_extension
->
current_application
)
{
json_object_object_add
(
j_caller_extension
,
"current_app"
,
json_object_safe_new_string
(
caller_profile
->
caller_extension
->
current_application
->
application_name
));
}
for
(
ap
=
caller_profile
->
caller_extension
->
applications
;
ap
;
ap
=
ap
->
next
)
{
j_application
=
json_object_new_object
();
if
(
is_error
(
j_application
))
{
goto
error
;
}
json_object_object_add
(
j_caller_extension
,
"application"
,
j_application
);
if
(
ap
==
caller_profile
->
caller_extension
->
current_application
)
{
json_object_object_add
(
j_application
,
"last_executed"
,
json_object_new_string
(
"true"
));
}
json_object_object_add
(
j_application
,
"app_name"
,
json_object_safe_new_string
(
ap
->
application_name
));
json_object_object_add
(
j_application
,
"app_data"
,
json_object_safe_new_string
(
switch_str_nil
(
ap
->
application_data
)));
}
if
(
caller_profile
->
caller_extension
->
children
)
{
switch_caller_profile_t
*
cp
=
NULL
;
for
(
cp
=
caller_profile
->
caller_extension
->
children
;
cp
;
cp
=
cp
->
next
)
{
if
(
!
cp
->
caller_extension
)
{
continue
;
}
j_inner_extension
=
json_object_new_object
();
if
(
is_error
(
j_inner_extension
))
{
goto
error
;
}
json_object_object_add
(
j_caller_extension
,
"sub_extensions"
,
j_inner_extension
);
j_caller_extension
=
json_object_new_object
();
if
(
is_error
(
j_caller_extension
))
{
goto
error
;
}
json_object_object_add
(
j_inner_extension
,
"extension"
,
j_caller_extension
);
json_object_object_add
(
j_caller_extension
,
"name"
,
json_object_safe_new_string
(
cp
->
caller_extension
->
extension_name
));
json_object_object_add
(
j_caller_extension
,
"number"
,
json_object_safe_new_string
(
cp
->
caller_extension
->
extension_number
));
json_object_object_add
(
j_caller_extension
,
"dialplan"
,
json_object_safe_new_string
((
char
*
)
cp
->
dialplan
));
if
(
cp
->
caller_extension
->
current_application
)
{
json_object_object_add
(
j_caller_extension
,
"current_app"
,
json_object_safe_new_string
(
cp
->
caller_extension
->
current_application
->
application_name
));
}
for
(
ap
=
cp
->
caller_extension
->
applications
;
ap
;
ap
=
ap
->
next
)
{
j_application
=
json_object_new_object
();
if
(
is_error
(
j_application
))
{
goto
error
;
}
json_object_object_add
(
j_caller_extension
,
"application"
,
j_application
);
if
(
ap
==
cp
->
caller_extension
->
current_application
)
{
json_object_object_add
(
j_application
,
"last_executed"
,
json_object_new_string
(
"true"
));
}
json_object_object_add
(
j_application
,
"app_name"
,
json_object_safe_new_string
(
ap
->
application_name
));
json_object_object_add
(
j_application
,
"app_data"
,
json_object_safe_new_string
(
switch_str_nil
(
ap
->
application_data
)));
}
}
}
}
j_main_cp
=
json_object_new_object
();
if
(
is_error
(
j_main_cp
))
{
goto
error
;
}
json_object_object_add
(
j_callflow
,
"caller_profile"
,
j_main_cp
);
set_json_profile_data
(
j_main_cp
,
caller_profile
);
if
(
caller_profile
->
originator_caller_profile
)
{
switch_caller_profile_t
*
cp
=
NULL
;
j_o
=
json_object_new_object
();
if
(
is_error
(
j_o
))
{
goto
error
;
}
json_object_object_add
(
j_main_cp
,
"originator"
,
j_o
);
for
(
cp
=
caller_profile
->
originator_caller_profile
;
cp
;
cp
=
cp
->
next
)
{
j_caller_profile
=
json_object_new_object
();
if
(
is_error
(
j_caller_profile
))
{
goto
error
;
}
json_object_object_add
(
j_o
,
"originator_caller_profile"
,
j_caller_profile
);
set_json_profile_data
(
j_caller_profile
,
cp
);
}
}
if
(
caller_profile
->
originatee_caller_profile
)
{
switch_caller_profile_t
*
cp
=
NULL
;
j_o
=
json_object_new_object
();
if
(
is_error
(
j_o
))
{
goto
error
;
}
json_object_object_add
(
j_main_cp
,
"originatee"
,
j_o
);
for
(
cp
=
caller_profile
->
originatee_caller_profile
;
cp
;
cp
=
cp
->
next
)
{
j_caller_profile
=
json_object_new_object
();
if
(
is_error
(
j_caller_profile
))
{
goto
error
;
}
json_object_object_add
(
j_o
,
"originatee_caller_profile"
,
j_caller_profile
);
set_json_profile_data
(
j_caller_profile
,
cp
);
}
}
if
(
caller_profile
->
times
)
{
j_times
=
json_object_new_object
();
if
(
is_error
(
j_times
))
{
goto
error
;
}
json_object_object_add
(
j_callflow
,
"times"
,
j_times
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
created
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"created_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
profile_created
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"profile_created_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
progress
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"progress_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
progress_media
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"progress_media_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
answered
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"answered_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
hungup
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"hangup_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
resurrected
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"resurrect_time"
,
time_tag
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
transferred
);
time_tag
=
json_object_new_string
(
tmp
);
if
(
is_error
(
time_tag
))
{
goto
error
;
}
json_object_object_add
(
j_times
,
"transfer_time"
,
time_tag
);
}
caller_profile
=
caller_profile
->
next
;
}
*
json_cdr
=
cdr
;
return
SWITCH_STATUS_SUCCESS
;
error:
if
(
cdr
)
{
json_object_put
(
cdr
);
}
return
SWITCH_STATUS_FALSE
;
}
static
switch_status_t
my_on_reporting
(
switch_core_session_t
*
session
)
{
struct
json_object
*
json_cdr
=
NULL
;
c
onst
c
har
*
json_text
=
NULL
;
cJSON
*
json_cdr
=
NULL
;
char
*
json_text
=
NULL
;
char
*
path
=
NULL
;
char
*
curl_json_text
=
NULL
;
const
char
*
logdir
=
NULL
;
...
...
@@ -637,12 +215,12 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
a_prefix
=
"a_"
;
if
(
generate_json_cdr
(
session
,
&
json_cdr
)
!=
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_ivr_generate_json_cdr
(
session
,
&
json_cdr
,
globals
.
encode_values
==
ENCODING_DEFAULT
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error Generating Data!
\n
"
);
return
SWITCH_STATUS_FALSE
;
}
json_text
=
json_object_to_json_string
(
json_cdr
);
json_text
=
cJSON_PrintUnformatted
(
json_cdr
);
if
(
!
json_text
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Memory Error!
\n
"
);
...
...
@@ -705,6 +283,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
switch_b64_encode
((
unsigned
char
*
)
json_text
,
need_bytes
/
3
,
(
unsigned
char
*
)
json_text_escaped
,
need_bytes
);
}
switch_safe_free
(
json_text
);
json_text
=
json_text_escaped
;
if
(
!
(
curl_json_text
=
switch_mprintf
(
"cdr=%s"
,
json_text
)))
{
...
...
@@ -861,8 +440,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
switch_safe_free
(
curl_json_text
);
}
json_object_put
(
json_cdr
);
switch_safe_free
(
json_text
_escaped
);
cJSON_Delete
(
json_cdr
);
switch_safe_free
(
json_text
);
return
status
;
}
...
...
src/switch_ivr.c
浏览文件 @
f25c4f6d
...
...
@@ -2472,6 +2472,260 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
return
SWITCH_STATUS_FALSE
;
}
static
void
switch_ivr_set_json_profile_data
(
cJSON
*
json
,
switch_caller_profile_t
*
caller_profile
)
{
cJSON_AddItemToObject
(
json
,
"username"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
username
));
cJSON_AddItemToObject
(
json
,
"dialplan"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
dialplan
));
cJSON_AddItemToObject
(
json
,
"caller_id_name"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
caller_id_name
));
cJSON_AddItemToObject
(
json
,
"ani"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
ani
));
cJSON_AddItemToObject
(
json
,
"aniii"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
aniii
));
cJSON_AddItemToObject
(
json
,
"caller_id_number"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
caller_id_number
));
cJSON_AddItemToObject
(
json
,
"network_addr"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
network_addr
));
cJSON_AddItemToObject
(
json
,
"rdnis"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
rdnis
));
cJSON_AddItemToObject
(
json
,
"destination_number"
,
cJSON_CreateString
(
caller_profile
->
destination_number
));
cJSON_AddItemToObject
(
json
,
"uuid"
,
cJSON_CreateString
(
caller_profile
->
uuid
));
cJSON_AddItemToObject
(
json
,
"source"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
source
));
cJSON_AddItemToObject
(
json
,
"context"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
context
));
cJSON_AddItemToObject
(
json
,
"chan_name"
,
cJSON_CreateString
(
caller_profile
->
chan_name
));
}
static
void
switch_ivr_set_json_chan_vars
(
cJSON
*
json
,
switch_channel_t
*
channel
,
switch_bool_t
urlencode
)
{
switch_event_header_t
*
hi
=
switch_channel_variable_first
(
channel
);
if
(
!
hi
)
return
;
for
(;
hi
;
hi
=
hi
->
next
)
{
if
(
!
zstr
(
hi
->
name
)
&&
!
zstr
(
hi
->
value
))
{
char
*
data
=
hi
->
value
;
if
(
urlencode
)
{
switch_size_t
dlen
=
strlen
(
hi
->
value
)
*
3
;
if
((
data
=
malloc
(
dlen
)))
{
memset
(
data
,
0
,
dlen
);
switch_url_encode
(
hi
->
value
,
data
,
dlen
);
}
}
cJSON_AddItemToObject
(
json
,
hi
->
name
,
cJSON_CreateString
(
data
));
if
(
data
!=
hi
->
value
)
{
switch_safe_free
(
data
);
}
}
}
switch_channel_variable_last
(
channel
);
}
SWITCH_DECLARE
(
switch_status_t
)
switch_ivr_generate_json_cdr
(
switch_core_session_t
*
session
,
cJSON
**
json_cdr
,
switch_bool_t
urlencode
)
{
cJSON
*
cdr
=
cJSON_CreateObject
();
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_caller_profile_t
*
caller_profile
;
cJSON
*
variables
,
*
j_main_cp
,
*
j_caller_profile
,
*
j_caller_extension
,
*
j_times
,
*
j_application
,
*
j_callflow
,
*
j_inner_extension
,
*
j_apps
,
*
j_o
,
*
j_channel_data
;
switch_app_log_t
*
app_log
;
char
tmp
[
512
],
*
f
;
j_channel_data
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
cdr
,
"channel_data"
,
j_channel_data
);
cJSON_AddItemToObject
(
j_channel_data
,
"state"
,
cJSON_CreateString
((
char
*
)
switch_channel_state_name
(
switch_channel_get_state
(
channel
))));
cJSON_AddItemToObject
(
j_channel_data
,
"direction"
,
cJSON_CreateString
(
switch_channel_direction
(
channel
)
==
SWITCH_CALL_DIRECTION_OUTBOUND
?
"outbound"
:
"inbound"
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%d"
,
switch_channel_get_state
(
channel
));
cJSON_AddItemToObject
(
j_channel_data
,
"state_number"
,
cJSON_CreateString
((
char
*
)
tmp
));
if
((
f
=
switch_channel_get_flag_string
(
channel
)))
{
cJSON_AddItemToObject
(
j_channel_data
,
"flags"
,
cJSON_CreateString
((
char
*
)
f
));
free
(
f
);
}
if
((
f
=
switch_channel_get_cap_string
(
channel
)))
{
cJSON_AddItemToObject
(
j_channel_data
,
"caps"
,
cJSON_CreateString
((
char
*
)
f
));
free
(
f
);
}
variables
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
cdr
,
"variables"
,
variables
);
switch_ivr_set_json_chan_vars
(
variables
,
channel
,
urlencode
);
if
((
app_log
=
switch_core_session_get_app_log
(
session
)))
{
switch_app_log_t
*
ap
;
j_apps
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
cdr
,
"app_log"
,
j_apps
);
for
(
ap
=
app_log
;
ap
;
ap
=
ap
->
next
)
{
j_application
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_application
,
"app_name"
,
cJSON_CreateString
(
ap
->
app
));
cJSON_AddItemToObject
(
j_application
,
"app_data"
,
cJSON_CreateString
(
ap
->
arg
));
cJSON_AddItemToObject
(
j_apps
,
"application"
,
j_application
);
}
}
caller_profile
=
switch_channel_get_caller_profile
(
channel
);
while
(
caller_profile
)
{
j_callflow
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
cdr
,
"callflow"
,
j_callflow
);
if
(
!
zstr
(
caller_profile
->
dialplan
))
{
cJSON_AddItemToObject
(
j_callflow
,
"dialplan"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
dialplan
));
}
if
(
!
zstr
(
caller_profile
->
profile_index
))
{
cJSON_AddItemToObject
(
j_callflow
,
"profile_index"
,
cJSON_CreateString
((
char
*
)
caller_profile
->
profile_index
));
}
if
(
caller_profile
->
caller_extension
)
{
switch_caller_application_t
*
ap
;
j_caller_extension
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_callflow
,
"extension"
,
j_caller_extension
);
cJSON_AddItemToObject
(
j_caller_extension
,
"name"
,
cJSON_CreateString
(
caller_profile
->
caller_extension
->
extension_name
));
cJSON_AddItemToObject
(
j_caller_extension
,
"number"
,
cJSON_CreateString
(
caller_profile
->
caller_extension
->
extension_number
));
if
(
caller_profile
->
caller_extension
->
current_application
)
{
cJSON_AddItemToObject
(
j_caller_extension
,
"current_app"
,
cJSON_CreateString
(
caller_profile
->
caller_extension
->
current_application
->
application_name
));
}
for
(
ap
=
caller_profile
->
caller_extension
->
applications
;
ap
;
ap
=
ap
->
next
)
{
j_application
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_caller_extension
,
"application"
,
j_application
);
if
(
ap
==
caller_profile
->
caller_extension
->
current_application
)
{
cJSON_AddItemToObject
(
j_application
,
"last_executed"
,
cJSON_CreateString
(
"true"
));
}
cJSON_AddItemToObject
(
j_application
,
"app_name"
,
cJSON_CreateString
(
ap
->
application_name
));
cJSON_AddItemToObject
(
j_application
,
"app_data"
,
cJSON_CreateString
(
switch_str_nil
(
ap
->
application_data
)));
}
if
(
caller_profile
->
caller_extension
->
children
)
{
switch_caller_profile_t
*
cp
=
NULL
;
for
(
cp
=
caller_profile
->
caller_extension
->
children
;
cp
;
cp
=
cp
->
next
)
{
if
(
!
cp
->
caller_extension
)
{
continue
;
}
j_inner_extension
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_caller_extension
,
"sub_extensions"
,
j_inner_extension
);
j_caller_extension
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_inner_extension
,
"extension"
,
j_caller_extension
);
cJSON_AddItemToObject
(
j_caller_extension
,
"name"
,
cJSON_CreateString
(
cp
->
caller_extension
->
extension_name
));
cJSON_AddItemToObject
(
j_caller_extension
,
"number"
,
cJSON_CreateString
(
cp
->
caller_extension
->
extension_number
));
cJSON_AddItemToObject
(
j_caller_extension
,
"dialplan"
,
cJSON_CreateString
((
char
*
)
cp
->
dialplan
));
if
(
cp
->
caller_extension
->
current_application
)
{
cJSON_AddItemToObject
(
j_caller_extension
,
"current_app"
,
cJSON_CreateString
(
cp
->
caller_extension
->
current_application
->
application_name
));
}
for
(
ap
=
cp
->
caller_extension
->
applications
;
ap
;
ap
=
ap
->
next
)
{
j_application
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_caller_extension
,
"application"
,
j_application
);
if
(
ap
==
cp
->
caller_extension
->
current_application
)
{
cJSON_AddItemToObject
(
j_application
,
"last_executed"
,
cJSON_CreateString
(
"true"
));
}
cJSON_AddItemToObject
(
j_application
,
"app_name"
,
cJSON_CreateString
(
ap
->
application_name
));
cJSON_AddItemToObject
(
j_application
,
"app_data"
,
cJSON_CreateString
(
switch_str_nil
(
ap
->
application_data
)));
}
}
}
}
j_main_cp
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_callflow
,
"caller_profile"
,
j_main_cp
);
switch_ivr_set_json_profile_data
(
j_main_cp
,
caller_profile
);
if
(
caller_profile
->
originator_caller_profile
)
{
switch_caller_profile_t
*
cp
=
NULL
;
j_o
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_main_cp
,
"originator"
,
j_o
);
for
(
cp
=
caller_profile
->
originator_caller_profile
;
cp
;
cp
=
cp
->
next
)
{
j_caller_profile
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_o
,
"originator_caller_profile"
,
j_caller_profile
);
switch_ivr_set_json_profile_data
(
j_caller_profile
,
cp
);
}
}
if
(
caller_profile
->
originatee_caller_profile
)
{
switch_caller_profile_t
*
cp
=
NULL
;
j_o
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_main_cp
,
"originatee"
,
j_o
);
for
(
cp
=
caller_profile
->
originatee_caller_profile
;
cp
;
cp
=
cp
->
next
)
{
j_caller_profile
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_o
,
"originatee_caller_profile"
,
j_caller_profile
);
switch_ivr_set_json_profile_data
(
j_caller_profile
,
cp
);
}
}
if
(
caller_profile
->
times
)
{
j_times
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
j_callflow
,
"times"
,
j_times
);
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
created
);
cJSON_AddItemToObject
(
j_times
,
"created_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
profile_created
);
cJSON_AddItemToObject
(
j_times
,
"profile_created_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
progress
);
cJSON_AddItemToObject
(
j_times
,
"progress_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
progress_media
);
cJSON_AddItemToObject
(
j_times
,
"progress_media_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
answered
);
cJSON_AddItemToObject
(
j_times
,
"answered_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
hungup
);
cJSON_AddItemToObject
(
j_times
,
"hangup_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
resurrected
);
cJSON_AddItemToObject
(
j_times
,
"resurrect_time"
,
cJSON_CreateString
(
tmp
));
switch_snprintf
(
tmp
,
sizeof
(
tmp
),
"%"
SWITCH_TIME_T_FMT
,
caller_profile
->
times
->
transferred
);
cJSON_AddItemToObject
(
j_times
,
"transfer_time"
,
cJSON_CreateString
(
tmp
));
}
caller_profile
=
caller_profile
->
next
;
}
*
json_cdr
=
cdr
;
return
SWITCH_STATUS_SUCCESS
;
}
SWITCH_DECLARE
(
void
)
switch_ivr_park_session
(
switch_core_session_t
*
session
)
{
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
...
...
src/switch_ivr_bridge.c
浏览文件 @
f25c4f6d
...
...
@@ -1366,21 +1366,41 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_channel_set_variable
(
caller_channel
,
SWITCH_BRIDGE_HANGUP_CAUSE_VARIABLE
,
switch_channel_cause2str
(
cause
));
}
if
(
switch_channel_down_nosig
(
peer_channel
)
&&
switch_true
(
switch_channel_get_variable
(
peer_channel
,
SWITCH_COPY_XML_CDR_VARIABLE
))
)
{
switch_
xml_t
cdr
=
NULL
;
char
*
xml_text
;
if
(
switch_channel_down_nosig
(
peer_channel
))
{
switch_
bool_t
copy_xml_cdr
=
switch_true
(
switch_channel_get_variable
(
peer_channel
,
SWITCH_COPY_XML_CDR_VARIABLE
))
;
switch_bool_t
copy_json_cdr
=
switch_true
(
switch_channel_get_variable
(
peer_channel
,
SWITCH_COPY_JSON_CDR_VARIABLE
))
;
switch_channel_wait_for_state
(
peer_channel
,
caller_channel
,
CS_DESTROY
);
if
(
copy_xml_cdr
||
copy_json_cdr
)
{
char
*
cdr_text
=
NULL
;
if
(
switch_ivr_generate_xml_cdr
(
peer_session
,
&
cdr
)
==
SWITCH_STATUS_SUCCESS
)
{
if
((
xml_text
=
switch_xml_toxml
(
cdr
,
SWITCH_FALSE
)))
{
switch_channel_set_variable
(
caller_channel
,
"b_leg_cdr"
,
xml_text
);
switch_safe_free
(
xml_text
);
switch_channel_wait_for_state
(
peer_channel
,
caller_channel
,
CS_DESTROY
);
if
(
copy_xml_cdr
)
{
switch_xml_t
cdr
=
NULL
;
if
(
switch_ivr_generate_xml_cdr
(
peer_session
,
&
cdr
)
==
SWITCH_STATUS_SUCCESS
)
{
cdr_text
=
switch_xml_toxml
(
cdr
,
SWITCH_FALSE
);
switch_xml_free
(
cdr
);
}
}
if
(
copy_json_cdr
)
{
cJSON
*
cdr
=
NULL
;
if
(
switch_ivr_generate_json_cdr
(
peer_session
,
&
cdr
,
SWITCH_TRUE
)
==
SWITCH_STATUS_SUCCESS
)
{
cdr_text
=
cJSON_PrintUnformatted
(
cdr
);
cJSON_Delete
(
cdr
);
}
}
if
(
cdr_text
)
{
switch_channel_set_variable
(
caller_channel
,
"b_leg_cdr"
,
cdr_text
);
switch_channel_set_variable_name_printf
(
caller_channel
,
cdr_text
,
"b_leg_cdr_%s"
,
switch_core_session_get_uuid
(
peer_session
));
switch_safe_free
(
cdr_text
);
}
switch_xml_free
(
cdr
);
}
}
switch_core_session_rwunlock
(
peer_session
);
}
else
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论