Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
e561fa1c
提交
e561fa1c
authored
9月 27, 2006
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@2849
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
074e9d2d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
66 行增加
和
6 行删除
+66
-6
mod_event_multicast.c
.../event_handlers/mod_event_multicast/mod_event_multicast.c
+66
-6
没有找到文件。
src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
浏览文件 @
e561fa1c
...
...
@@ -30,6 +30,7 @@
*
*/
#include <switch.h>
static
char
*
MARKER
=
"1"
;
static
const
char
modname
[]
=
"mod_event_multicast"
;
...
...
@@ -37,13 +38,17 @@ static switch_memory_pool_t *module_pool = NULL;
static
struct
{
char
*
address
;
char
*
bindings
;
switch_port_t
port
;
switch_sockaddr_t
*
addr
;
switch_socket_t
*
udp_socket
;
switch_hash_t
*
event_hash
;
uint8_t
event_list
[
SWITCH_EVENT_ALL
+
1
];
int
running
;
}
globals
;
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_address
,
globals
.
address
)
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_bindings
,
globals
.
bindings
)
#define MULTICAST_EVENT "multicast::event"
...
...
@@ -53,6 +58,9 @@ static switch_status_t load_config(void)
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
char
*
cf
=
"event_multicast.conf"
;
switch_xml_t
cfg
,
xml
,
settings
,
param
;
char
*
next
,
*
cur
;
uint32_t
count
=
0
,
key_count
=
0
;
uint8_t
custom
=
0
;
if
(
!
(
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"open of %s failed
\n
"
,
cf
);
...
...
@@ -71,6 +79,8 @@ static switch_status_t load_config(void)
if
(
!
strcasecmp
(
var
,
"address"
))
{
set_global_address
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"bindings"
))
{
set_global_bindings
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"port"
))
{
globals
.
port
=
(
switch_port_t
)
atoi
(
val
);
}
...
...
@@ -79,20 +89,63 @@ static switch_status_t load_config(void)
switch_xml_free
(
xml
);
if
(
globals
.
bindings
)
{
for
(
cur
=
globals
.
bindings
;
cur
;
count
++
)
{
switch_event_types_t
type
;
if
((
next
=
strchr
(
cur
,
' '
)))
{
*
next
++
=
'\0'
;
}
if
(
custom
)
{
switch_core_hash_insert_dup
(
globals
.
event_hash
,
cur
,
MARKER
);
}
else
if
(
switch_name_event
(
cur
,
&
type
)
==
SWITCH_STATUS_SUCCESS
)
{
key_count
++
;
if
(
type
==
SWITCH_EVENT_ALL
)
{
uint32_t
x
=
0
;
for
(
x
=
0
;
x
<
SWITCH_EVENT_ALL
;
x
++
)
{
globals
.
event_list
[
x
]
=
0
;
}
}
globals
.
event_list
[
type
]
=
1
;
if
(
type
==
SWITCH_EVENT_CUSTOM
)
{
custom
++
;
}
}
cur
=
next
;
}
}
if
(
!
key_count
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"No Bindings Assuming ALL!
\n
"
);
globals
.
event_list
[
SWITCH_EVENT_ALL
]
=
1
;
}
return
status
;
}
static
void
event_handler
(
switch_event_t
*
event
)
{
char
buf
[
1024
];
char
buf
[
65536
];
size_t
len
;
uint8_t
send
=
0
;
if
(
event
->
subclass
&&
!
strcmp
(
event
->
subclass
->
name
,
MULTICAST_EVENT
))
{
/* ignore our own events to avoid ping pong*/
return
;
}
if
(
globals
.
event_list
[(
uint8_t
)
SWITCH_EVENT_ALL
])
{
send
=
1
;
}
else
if
((
globals
.
event_list
[(
uint8_t
)
event
->
event_id
]))
{
if
(
event
->
event_id
!=
SWITCH_EVENT_CUSTOM
||
(
event
->
subclass
&&
switch_core_hash_find
(
globals
.
event_hash
,
event
->
subclass
->
name
)))
{
send
=
1
;
}
}
switch
(
event
->
event_id
)
{
case
SWITCH_EVENT_LOG
:
...
...
@@ -159,6 +212,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
return
SWITCH_STATUS_TERM
;
}
switch_core_hash_init
(
&
globals
.
event_hash
,
module_pool
);
/* connect my internal structure to the blank pointer passed to me */
*
module_interface
=
&
event_test_module_interface
;
...
...
@@ -192,13 +246,15 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
SWITCH_MOD_DECLARE
(
switch_status_t
)
switch_module_runtime
(
void
)
{
switch_event_t
*
local_event
;
char
buf
[
1024
];
char
buf
[
65536
];
globals
.
running
=
1
;
while
(
globals
.
running
==
1
)
{
switch_sockaddr_t
addr
=
{
0
};
size_t
len
=
sizeof
(
buf
);
memset
(
buf
,
0
,
len
);
if
(
switch_socket_recvfrom
(
&
addr
,
globals
.
udp_socket
,
0
,
buf
,
&
len
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_event_create_subclass
(
&
local_event
,
SWITCH_EVENT_CUSTOM
,
MULTICAST_EVENT
)
==
SWITCH_STATUS_SUCCESS
)
{
char
*
var
,
*
val
,
*
term
=
NULL
;
...
...
@@ -206,7 +262,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
var
=
buf
;
while
(
*
var
)
{
if
((
val
=
strchr
(
var
,
':'
))
!=
0
)
{
char
varname
[
512
];
*
val
++
=
'\0'
;
while
(
*
val
==
' '
)
{
val
++
;
...
...
@@ -217,15 +272,20 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
term
++
;
}
}
snprintf
(
varname
,
sizeof
(
varname
),
"Remote-%s"
,
var
);
switch_event_add_header
(
local_event
,
SWITCH_STACK_BOTTOM
,
var
name
,
val
);
switch_event_add_header
(
local_event
,
SWITCH_STACK_BOTTOM
,
var
,
val
);
var
=
term
+
1
;
}
else
{
break
;
}
}
if
(
!
switch_strlen_zero
(
var
))
{
switch_event_add_body
(
local_event
,
var
);
}
switch_event_fire
(
&
local_event
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论