Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
f0853c6e
提交
f0853c6e
authored
4月 02, 2013
作者:
Raymond Chandler
提交者:
Travis Cross
6月 06, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add number translation module
上级
a1723a1a
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
547 行增加
和
0 行删除
+547
-0
modules.conf.in
build/modules.conf.in
+1
-0
modules.conf.xml
conf/insideout/autoload_configs/modules.conf.xml
+1
-0
translate.conf.xml
conf/insideout/autoload_configs/translate.conf.xml
+28
-0
modules.conf.xml
conf/sbc/autoload_configs/modules.conf.xml
+1
-0
translate.conf.xml
conf/sbc/autoload_configs/translate.conf.xml
+28
-0
modules.conf.xml
conf/vanilla/autoload_configs/modules.conf.xml
+1
-0
translate.conf.xml
conf/vanilla/autoload_configs/translate.conf.xml
+28
-0
translate.conf.xml
...ns/mod_translate/conf/autoload_configs/translate.conf.xml
+28
-0
translate.xml
...cations/mod_translate/conf/dialplan/default/translate.xml
+11
-0
mod_translate.c
src/mod/applications/mod_translate/mod_translate.c
+420
-0
没有找到文件。
build/modules.conf.in
浏览文件 @
f0853c6e
...
...
@@ -38,6 +38,7 @@ applications/mod_sms
applications/mod_spandsp
#applications/mod_spy
#applications/mod_stress
#applications/mod_translate
applications/mod_valet_parking
#applications/mod_vmd
applications/mod_voicemail
...
...
conf/insideout/autoload_configs/modules.conf.xml
浏览文件 @
f0853c6e
...
...
@@ -46,6 +46,7 @@
<load
module=
"mod_limit"
/>
<load
module=
"mod_esf"
/>
<load
module=
"mod_fsv"
/>
<!--<load module="mod_translate"/>-->
<!-- SNOM Module -->
<!--<load module="mod_snom"/>-->
...
...
conf/insideout/autoload_configs/translate.conf.xml
0 → 100644
浏览文件 @
f0853c6e
<include>
<configuration
name=
"translate.conf"
description=
"Number Translation Rules"
>
<profiles>
<profile
name=
"US"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(1[2-9]\d{2}[2-9]\d{6})$"
replace=
"$1"
/>
<rule
regex=
"^([2-9]\d{2}[2-9]\d{6})$"
replace=
"1$1"
/>
<rule
regex=
"^([2-9]\d{6})$"
replace=
"1${areacode}$1"
/>
<rule
regex=
"^011(\d+)$"
replace=
"$1"
/>
</profile>
<profile
name=
"GB"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^$"
replace=
"$1"
/>
</profile>
<profile
name=
"HK"
>
<rule
regex=
"\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(852\d{8})$"
replace=
"$1"
/>
<rule
regex=
"^(\d{8})$"
replace=
"852$1"
/>
</profile>
</profiles>
<!--
<profile name="">
<rule regex="^\+(\d+)$" replace="$1"/>
<rule regex="^$" replace="$1"/>
</profile>
-->
</configuration>
</include>
conf/sbc/autoload_configs/modules.conf.xml
浏览文件 @
f0853c6e
...
...
@@ -30,6 +30,7 @@
<load
module=
"mod_dptools"
/>
<load
module=
"mod_expr"
/>
<load
module=
"mod_limit"
/>
<!--<load module="mod_translate"/>-->
<!-- Dialplan Interfaces -->
<load
module=
"mod_dialplan_xml"
/>
...
...
conf/sbc/autoload_configs/translate.conf.xml
0 → 100644
浏览文件 @
f0853c6e
<include>
<configuration
name=
"translate.conf"
description=
"Number Translation Rules"
>
<profiles>
<profile
name=
"US"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(1[2-9]\d{2}[2-9]\d{6})$"
replace=
"$1"
/>
<rule
regex=
"^([2-9]\d{2}[2-9]\d{6})$"
replace=
"1$1"
/>
<rule
regex=
"^([2-9]\d{6})$"
replace=
"1${areacode}$1"
/>
<rule
regex=
"^011(\d+)$"
replace=
"$1"
/>
</profile>
<profile
name=
"GB"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^$"
replace=
"$1"
/>
</profile>
<profile
name=
"HK"
>
<rule
regex=
"\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(852\d{8})$"
replace=
"$1"
/>
<rule
regex=
"^(\d{8})$"
replace=
"852$1"
/>
</profile>
</profiles>
<!--
<profile name="">
<rule regex="^\+(\d+)$" replace="$1"/>
<rule regex="^$" replace="$1"/>
</profile>
-->
</configuration>
</include>
conf/vanilla/autoload_configs/modules.conf.xml
浏览文件 @
f0853c6e
...
...
@@ -66,6 +66,7 @@
<!--<load module="mod_spy"/>-->
<!--<load module="mod_random"/>-->
<load
module=
"mod_httapi"
/>
<!--<load module="mod_translate"/>-->
<!-- SNOM Module -->
<!--<load module="mod_snom"/>-->
...
...
conf/vanilla/autoload_configs/translate.conf.xml
0 → 100644
浏览文件 @
f0853c6e
<include>
<configuration
name=
"translate.conf"
description=
"Number Translation Rules"
>
<profiles>
<profile
name=
"US"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(1[2-9]\d{2}[2-9]\d{6})$"
replace=
"$1"
/>
<rule
regex=
"^([2-9]\d{2}[2-9]\d{6})$"
replace=
"1$1"
/>
<rule
regex=
"^([2-9]\d{6})$"
replace=
"1${areacode}$1"
/>
<rule
regex=
"^011(\d+)$"
replace=
"$1"
/>
</profile>
<profile
name=
"GB"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^$"
replace=
"$1"
/>
</profile>
<profile
name=
"HK"
>
<rule
regex=
"\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(852\d{8})$"
replace=
"$1"
/>
<rule
regex=
"^(\d{8})$"
replace=
"852$1"
/>
</profile>
</profiles>
<!--
<profile name="">
<rule regex="^\+(\d+)$" replace="$1"/>
<rule regex="^$" replace="$1"/>
</profile>
-->
</configuration>
</include>
src/mod/applications/mod_translate/conf/autoload_configs/translate.conf.xml
0 → 100644
浏览文件 @
f0853c6e
<include>
<configuration
name=
"translate.conf"
description=
"Number Translation Rules"
>
<profiles>
<profile
name=
"US"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(1[2-9]\d{2}[2-9]\d{6})$"
replace=
"$1"
/>
<rule
regex=
"^([2-9]\d{2}[2-9]\d{6})$"
replace=
"1$1"
/>
<rule
regex=
"^([2-9]\d{6})$"
replace=
"1${areacode}$1"
/>
<rule
regex=
"^011(\d+)$"
replace=
"$1"
/>
</profile>
<profile
name=
"GB"
>
<rule
regex=
"^\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^$"
replace=
"$1"
/>
</profile>
<profile
name=
"HK"
>
<rule
regex=
"\+(\d+)$"
replace=
"$1"
/>
<rule
regex=
"^(852\d{8})$"
replace=
"$1"
/>
<rule
regex=
"^(\d{8})$"
replace=
"852$1"
/>
</profile>
</profiles>
<!--
<profile name="">
<rule regex="^\+(\d+)$" replace="$1"/>
<rule regex="^$" replace="$1"/>
</profile>
-->
</configuration>
</include>
src/mod/applications/mod_translate/conf/dialplan/default/translate.xml
0 → 100644
浏览文件 @
f0853c6e
<include>
<extension>
<condition>
<!-- translate the desintation_number and caller_id_number
according to the default numbering plan (as seen in brian.xml) -->
<action
application=
"translate"
data=
"${destination_number} ${numbering_plan}"
/>
<action
application=
"log"
data=
"info Before: ${destination_number}"
/>
<action
application=
"log"
data=
"info After: ${translated}"
/>
</condition>
</extension>
</include>
\ No newline at end of file
src/mod/applications/mod_translate/mod_translate.c
0 → 100644
浏览文件 @
f0853c6e
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
*
* 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
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthm@freeswitch.org>
* Raymond Chandler <intralanman@freeswitch.org>
*
* mod_translate.c -- TRANSLATE
*
*/
#include <switch.h>
SWITCH_MODULE_LOAD_FUNCTION
(
mod_translate_load
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_translate_shutdown
);
SWITCH_MODULE_DEFINITION
(
mod_translate
,
mod_translate_load
,
mod_translate_shutdown
,
NULL
);
static
switch_mutex_t
*
MUTEX
=
NULL
;
static
struct
{
switch_memory_pool_t
*
pool
;
switch_hash_t
*
translate_profiles
;
switch_thread_rwlock_t
*
profile_hash_rwlock
;
}
globals
;
struct
rule
{
char
*
regex
;
char
*
replace
;
struct
rule
*
next
;
};
typedef
struct
rule
translate_rule_t
;
static
switch_event_node_t
*
NODE
=
NULL
;
static
switch_status_t
load_config
(
void
)
{
char
*
cf
=
"translate.conf"
;
switch_xml_t
cfg
,
xml
,
rule
,
profile
,
profiles
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
if
(
!
(
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Open of %s failed
\n
"
,
cf
);
status
=
SWITCH_STATUS_FALSE
;
goto
done
;
}
if
((
profiles
=
switch_xml_child
(
cfg
,
"profiles"
)))
{
for
(
profile
=
switch_xml_child
(
profiles
,
"profile"
);
profile
;
profile
=
profile
->
next
)
{
translate_rule_t
*
rules_list
=
NULL
;
char
*
name
=
(
char
*
)
switch_xml_attr_soft
(
profile
,
"name"
);
if
(
!
name
)
{
continue
;
}
for
(
rule
=
switch_xml_child
(
profile
,
"rule"
);
rule
;
rule
=
rule
->
next
)
{
char
*
regex
=
(
char
*
)
switch_xml_attr_soft
(
rule
,
"regex"
);
char
*
replace
=
(
char
*
)
switch_xml_attr_soft
(
rule
,
"replace"
);
if
(
regex
&&
replace
)
{
translate_rule_t
*
this_rule
=
NULL
,
*
rl
=
NULL
;
this_rule
=
switch_core_alloc
(
globals
.
pool
,
sizeof
(
translate_rule_t
));
this_rule
->
regex
=
switch_core_strdup
(
globals
.
pool
,
regex
);
this_rule
->
replace
=
switch_core_strdup
(
globals
.
pool
,
replace
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Replace number matching [%s] with [%s]
\n
"
,
regex
,
replace
);
if
(
rules_list
==
NULL
)
{
rules_list
=
switch_core_alloc
(
globals
.
pool
,
sizeof
(
translate_rule_t
));
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"starting with an empty list
\n
"
);
rules_list
=
this_rule
;
}
else
{
for
(
rl
=
rules_list
;
rl
&&
rl
->
next
;
rl
=
rl
->
next
);
rl
->
next
=
this_rule
;
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid Translation!
\n
"
);
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Adding rules to profile [%s]
\n
"
,
name
);
switch_core_hash_insert_wrlock
(
globals
.
translate_profiles
,
name
,
rules_list
,
globals
.
profile_hash_rwlock
);
}
}
done:
if
(
xml
)
{
switch_xml_free
(
xml
);
}
return
status
;
}
static
void
translate_number
(
char
*
number
,
char
*
profile
,
char
**
translated
,
switch_core_session_t
*
session
,
switch_event_t
*
event
)
{
translate_rule_t
*
hi
=
NULL
;
translate_rule_t
*
rule
=
NULL
;
switch_regex_t
*
re
=
NULL
;
int
proceed
=
0
,
ovector
[
30
];
char
*
substituted
=
NULL
;
uint32_t
len
=
0
;
if
(
!
profile
)
{
profile
=
"US"
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"translating [%s] against [%s] profile
\n
"
,
number
,
profile
);
hi
=
switch_core_hash_find_rdlock
(
globals
.
translate_profiles
,
(
const
char
*
)
profile
,
globals
.
profile_hash_rwlock
);
if
(
!
hi
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"can't find key for profile matching [%s]
\n
"
,
profile
);
return
;
}
for
(
rule
=
hi
;
rule
;
rule
=
rule
->
next
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"%s =~ /%s/
\n
"
,
number
,
rule
->
regex
);
if
((
proceed
=
switch_regex_perform
(
number
,
rule
->
regex
,
&
re
,
ovector
,
sizeof
(
ovector
)
/
sizeof
(
ovector
[
0
]))))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"%s matched %s, replacing with %s
\n
"
,
number
,
rule
->
regex
,
rule
->
replace
);
if
(
!
(
substituted
=
malloc
(
len
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_CRIT
,
"Memory Error!
\n
"
);
switch_regex_safe_free
(
re
);
goto
end
;
}
memset
(
substituted
,
0
,
len
);
switch_perform_substitution
(
re
,
proceed
,
rule
->
replace
,
number
,
substituted
,
len
,
ovector
);
if
((
switch_string_var_check_const
(
substituted
)
||
switch_string_has_escaped_data
(
substituted
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"perform variable expansion
\n
"
);
if
(
session
)
{
substituted
=
switch_channel_expand_variables
(
switch_core_session_get_channel
(
session
),
substituted
);
}
else
if
(
event
)
{
substituted
=
switch_event_expand_headers
(
event
,
substituted
);
}
}
break
;
}
}
end:
*
translated
=
substituted
?
substituted
:
NULL
;
}
static
void
do_unload
(
void
)
{
switch_hash_index_t
*
hi
=
NULL
;
switch_mutex_lock
(
MUTEX
);
while
((
hi
=
switch_hash_first
(
NULL
,
globals
.
translate_profiles
)))
{
void
*
val
=
NULL
;
const
void
*
key
;
switch_ssize_t
keylen
;
translate_rule_t
*
rl
,
*
nrl
;
switch_hash_this
(
hi
,
&
key
,
&
keylen
,
&
val
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"deleting translate profile [%s]
\n
"
,
(
char
*
)
key
);
for
(
nrl
=
val
;
rl
;)
{
rl
=
nrl
;
nrl
=
nrl
->
next
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"deleting rule for [%s]
\n
"
,
rl
->
regex
);
switch_safe_free
(
rl
->
regex
);
switch_safe_free
(
rl
->
replace
);
switch_safe_free
(
rl
);
}
switch_core_hash_delete_wrlock
(
globals
.
translate_profiles
,
key
,
globals
.
profile_hash_rwlock
);
}
switch_thread_rwlock_destroy
(
globals
.
profile_hash_rwlock
);
switch_core_hash_destroy
(
&
globals
.
translate_profiles
);
switch_mutex_unlock
(
MUTEX
);
}
static
void
do_load
(
void
)
{
switch_mutex_lock
(
MUTEX
);
switch_core_hash_init
(
&
globals
.
translate_profiles
,
globals
.
pool
);
switch_thread_rwlock_create
(
&
globals
.
profile_hash_rwlock
,
globals
.
pool
);
load_config
();
switch_mutex_unlock
(
MUTEX
);
}
static
void
event_handler
(
switch_event_t
*
event
)
{
switch_mutex_lock
(
MUTEX
);
do_unload
();
do_load
();
switch_mutex_unlock
(
MUTEX
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Number Translations Reloaded
\n
"
);
}
SWITCH_STANDARD_APP
(
translate_app_function
)
{
int
argc
=
0
;
char
*
argv
[
32
]
=
{
0
};
char
*
mydata
=
NULL
;
char
*
translated
=
NULL
;
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_memory_pool_t
*
pool
;
switch_event_t
*
event
;
if
(
!
(
mydata
=
switch_core_session_strdup
(
session
,
data
)))
{
goto
end
;
}
if
((
argc
=
switch_separate_string
(
mydata
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
])))))
{
char
*
areacode
=
switch_core_get_variable
(
"default_areacode"
);
if
(
session
)
{
pool
=
switch_core_session_get_pool
(
session
);
}
else
{
switch_core_new_memory_pool
(
&
pool
);
switch_event_create
(
&
event
,
SWITCH_EVENT_MESSAGE
);
if
(
zstr
(
areacode
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"no default_areacode set, using default of 777
\n
"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"areacode"
,
"777"
);
}
else
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"areacode"
,
areacode
);
}
}
translate_number
(
argv
[
0
],
argv
[
1
],
&
translated
,
session
,
event
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Translated: %s
\n
"
,
translated
);
switch_channel_set_variable_var_check
(
channel
,
"translated"
,
translated
,
SWITCH_FALSE
);
}
end
:
if
(
!
session
)
{
if
(
pool
)
{
switch_core_destroy_memory_pool
(
&
pool
);
}
}
return
;
}
SWITCH_STANDARD_DIALPLAN
(
translate_dialplan_hunt
)
{
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
char
*
translated_dest
=
NULL
;
char
*
translated_cid_num
=
NULL
;
char
*
translate_profile
=
NULL
;
char
*
areacode
=
NULL
;
switch_event_t
*
event
=
NULL
;
if
(
!
caller_profile
)
{
if
(
!
(
caller_profile
=
switch_channel_get_caller_profile
(
channel
)))
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"Error Obtaining Profile!
\n
"
);
goto
done
;
}
}
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_INFO
,
"Processing %s <%s>->%s in translate
\n
"
,
caller_profile
->
caller_id_name
,
caller_profile
->
caller_id_number
,
caller_profile
->
destination_number
);
if
((
translate_profile
=
(
char
*
)
switch_channel_get_variable
(
channel
,
"translate_profile"
)))
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"using translate_profile variable [%s] for translate profile
\n
"
,
translate_profile
);
}
else
if
((
translate_profile
=
(
char
*
)
switch_channel_get_variable
(
channel
,
"country"
)))
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"using country variable [%s] for translate profile
\n
"
,
translate_profile
);
}
else
if
((
translate_profile
=
(
char
*
)
switch_channel_get_variable
(
channel
,
"default_country"
)))
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_DEBUG
,
"using default_country variable [%s] for translate profile
\n
"
,
translate_profile
);
}
else
{
translate_profile
=
"US"
;
}
areacode
=
(
char
*
)
switch_channel_get_variable
(
channel
,
"areacode"
);
if
(
zstr
(
areacode
))
{
areacode
=
(
char
*
)
switch_channel_get_variable
(
channel
,
"default_areacode"
);
if
(
!
zstr
(
areacode
))
{
switch_channel_set_variable_safe
(
channel
,
"areacode"
,
areacode
);
}
}
translate_number
((
char
*
)
caller_profile
->
destination_number
,
translate_profile
,
&
translated_dest
,
session
,
event
);
translate_number
((
char
*
)
caller_profile
->
caller_id_number
,
translate_profile
,
&
translated_cid_num
,
session
,
event
);
/* maybe we should translate ani/aniii here too? */
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_INFO
,
"Profile: [%s] Translated Destination: [%s] Translated CID: [%s]
\n
"
,
translate_profile
,
translated_dest
,
translated_cid_num
);
if
(
!
zstr
(
translated_cid_num
))
{
caller_profile
->
caller_id_number
=
translated_cid_num
;
}
if
(
!
zstr
(
translated_dest
))
{
caller_profile
->
destination_number
=
translated_dest
;
}
done
:
return
NULL
;
}
#define TRANSLATE_SYNTAX "translate <number> [<profile>]"
SWITCH_STANDARD_API
(
translate_function
)
{
char
*
mydata
=
NULL
;
switch_memory_pool_t
*
pool
=
NULL
;
char
*
translated
=
NULL
;
switch_event_t
*
event
=
NULL
;
char
*
argv
[
32
]
=
{
0
};
int
argc
=
0
;
if
(
zstr
(
cmd
))
{
goto
usage
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"%s
\n
"
,
cmd
);
mydata
=
switch_core_strdup
(
globals
.
pool
,
cmd
);
if
((
argc
=
switch_separate_string
(
mydata
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
])))))
{
if
(
!
session
)
{
char
*
areacode
=
switch_core_get_variable
(
"default_areacode"
);
switch_event_create
(
&
event
,
SWITCH_EVENT_REQUEST_PARAMS
);
if
(
zstr
(
areacode
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"no default_areacode set, using default of 777
\n
"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"areacode"
,
"777"
);
}
else
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"areacode"
,
areacode
);
}
}
translate_number
(
argv
[
0
],
argv
[
1
],
&
translated
,
session
,
event
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Translated: %s
\n
"
,
translated
);
stream
->
write_function
(
stream
,
"%s"
,
translated
);
}
end
:
if
(
!
session
)
{
if
(
pool
)
{
switch_core_destroy_memory_pool
(
&
pool
);
}
}
return
SWITCH_STATUS_SUCCESS
;
usage
:
stream
->
write_function
(
stream
,
"USAGE: %s
\n
"
,
TRANSLATE_SYNTAX
);
goto
end
;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_translate_shutdown
)
{
switch_event_unbind
(
&
NODE
);
do_unload
();
return
SWITCH_STATUS_UNLOAD
;
}
SWITCH_MODULE_LOAD_FUNCTION
(
mod_translate_load
)
{
switch_api_interface_t
*
api_interface
;
switch_application_interface_t
*
app_interface
;
switch_dialplan_interface_t
*
dp_interface
;
memset
(
&
globals
,
0
,
sizeof
(
globals
));
globals
.
pool
=
pool
;
switch_mutex_init
(
&
MUTEX
,
SWITCH_MUTEX_NESTED
,
pool
);
if
((
switch_event_bind_removable
(
modname
,
SWITCH_EVENT_RELOADXML
,
NULL
,
event_handler
,
NULL
,
&
NODE
)
!=
SWITCH_STATUS_SUCCESS
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Couldn't bind!
\n
"
);
return
SWITCH_STATUS_TERM
;
}
do_load
();
*
module_interface
=
switch_loadable_module_create_module_interface
(
pool
,
modname
);
SWITCH_ADD_API
(
api_interface
,
"translate"
,
"TRANSLATE"
,
translate_function
,
""
);
SWITCH_ADD_APP
(
app_interface
,
"translate"
,
"Perform an TRANSLATE lookup"
,
"Translate a number based on predefined rules"
,
translate_app_function
,
"<number> <profile>]"
,
SAF_SUPPORT_NOMEDIA
|
SAF_ROUTING_EXEC
);
SWITCH_ADD_DIALPLAN
(
dp_interface
,
"translate"
,
translate_dialplan_hunt
);
return
SWITCH_STATUS_SUCCESS
;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论