Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
c4cea0cf
提交
c4cea0cf
authored
1月 27, 2016
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-8787 #resolve [fs_cli prompt modifications]
上级
a729ebe6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
106 行增加
和
23 行删除
+106
-23
fs_cli.c
libs/esl/fs_cli.c
+106
-23
没有找到文件。
libs/esl/fs_cli.c
浏览文件 @
c4cea0cf
...
...
@@ -68,6 +68,7 @@ typedef struct {
char
prompt_color
[
12
];
char
input_text_color
[
12
];
char
output_text_color
[
12
];
char
prompt_string
[
512
];
}
cli_profile_t
;
static
const
int
log_uuid_short_length
=
8
;
...
...
@@ -99,7 +100,9 @@ static History *myhistory;
static
HistEvent
ev
;
#endif
static
char
hostname
[
256
]
=
""
;
static
char
switchname
[
256
]
=
""
;
static
char
switch_hostname
[
256
]
=
""
;
static
esl_mutex_t
*
MUTEX
=
NULL
;
static
void
_sleep_ns
(
int
secs
,
long
nsecs
)
{
...
...
@@ -1300,6 +1303,8 @@ static void read_config(const char *dft_cfile, const char *cfile) {
profiles
[
pcount
-
1
].
use_history_file
=
!
esl_true
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"prompt-color"
))
{
esl_set_string
(
profiles
[
pcount
-
1
].
prompt_color
,
match_color
(
val
));
}
else
if
(
!
strcasecmp
(
var
,
"prompt-string"
))
{
esl_set_string
(
profiles
[
pcount
-
1
].
prompt_string
,
val
);
}
else
if
(
!
strcasecmp
(
var
,
"input-text-color"
))
{
esl_set_string
(
profiles
[
pcount
-
1
].
input_text_color
,
match_color
(
val
));
}
else
if
(
!
strcasecmp
(
var
,
"output-text-color"
))
{
...
...
@@ -1340,6 +1345,58 @@ static void clear_el_buffer(void) {
#endif
}
static
void
expand_prompt
(
char
*
s
,
size_t
len
,
cli_profile_t
*
profile
)
{
char
tmp
[
512
]
=
""
;
char
*
p
,
*
q
=
tmp
;
for
(
p
=
s
;
p
&&
*
p
;
p
++
)
{
if
(
*
p
==
'%'
)
{
p
++
;
switch
(
*
p
)
{
case
's'
:
esl_copy_string
(
q
,
switchname
,
len
-
(
q
-
&
tmp
[
0
]));
q
+=
strlen
(
switchname
);
break
;
case
'h'
:
esl_copy_string
(
q
,
hostname
,
len
-
(
q
-
&
tmp
[
0
]));
q
+=
strlen
(
hostname
);
break
;
case
'H'
:
esl_copy_string
(
q
,
switch_hostname
,
len
-
(
q
-
&
tmp
[
0
]));
q
+=
strlen
(
switch_hostname
);
break
;
case
'p'
:
esl_copy_string
(
q
,
profile
->
name
,
len
-
(
q
-
&
tmp
[
0
]));
q
+=
strlen
(
profile
->
name
);
break
;
case
'o'
:
esl_copy_string
(
q
,
profile
->
host
,
len
-
(
q
-
&
tmp
[
0
]));
q
+=
strlen
(
profile
->
host
);
break
;
case
'P'
:
{
char
ptmp
[
35
]
=
""
;
esl_snprintf
(
ptmp
,
sizeof
(
ptmp
),
"%d"
,
profile
->
port
);
esl_copy_string
(
q
,
ptmp
,
len
-
(
q
-
&
tmp
[
0
]));
q
+=
strlen
(
ptmp
);
}
break
;
case
'%'
:
*
q
++
=
'%'
;
break
;
}
}
else
{
*
q
++
=
*
p
;
}
}
esl_copy_string
(
s
,
tmp
,
len
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
esl_handle_t
handle
=
{{
0
}};
...
...
@@ -1403,6 +1460,7 @@ int main(int argc, char *argv[])
int
loops
=
2
,
reconnect
=
0
;
char
*
ccheck
;
gethostname
(
hostname
,
sizeof
(
hostname
));
esl_mutex_create
(
&
MUTEX
);
...
...
@@ -1430,7 +1488,7 @@ int main(int argc, char *argv[])
strncpy
(
internal_profile
.
host
,
"127.0.0.1"
,
sizeof
(
internal_profile
.
host
));
strncpy
(
internal_profile
.
pass
,
"ClueCon"
,
sizeof
(
internal_profile
.
pass
));
strncpy
(
internal_profile
.
name
,
"internal"
,
sizeof
(
internal_profile
.
name
));
strncpy
(
internal_profile
.
name
,
hostname
,
sizeof
(
internal_profile
.
name
));
internal_profile
.
port
=
8021
;
set_fn_keys
(
&
internal_profile
);
esl_set_string
(
internal_profile
.
prompt_color
,
prompt_color
);
...
...
@@ -1541,10 +1599,17 @@ int main(int argc, char *argv[])
}
if
(
!
profile
)
{
if
(
get_profile
(
"default"
,
&
profile
))
{
esl_log
(
ESL_LOG_DEBUG
,
"profile default does not exist using builtin profile
\n
"
);
profile
=
&
internal_profile
;
if
(
!
esl_strlen_zero
(
profiles
[
0
].
name
))
{
profile
=
&
profiles
[
0
];
}
}
}
if
(
!
profile
)
{
esl_log
(
ESL_LOG_DEBUG
,
"no profiles found, using builtin profile
\n
"
);
profile
=
&
internal_profile
;
}
if
(
temp_log
<
0
)
{
esl_global_set_default_logger
(
profile
->
debug
);
}
...
...
@@ -1582,25 +1647,7 @@ int main(int argc, char *argv[])
esl_set_string
(
prompt_color
,
profile
->
prompt_color
);
esl_set_string
(
input_text_color
,
profile
->
input_text_color
);
esl_set_string
(
output_text_color
,
profile
->
output_text_color
);
if
(
argv_host
)
{
if
(
argv_port
&&
profile
->
port
!=
8021
)
{
snprintf
(
bare_prompt_str
,
sizeof
(
bare_prompt_str
),
"freeswitch@%s:%u@%s> "
,
profile
->
host
,
profile
->
port
,
profile
->
name
);
}
else
{
snprintf
(
bare_prompt_str
,
sizeof
(
bare_prompt_str
),
"freeswitch@%s@%s> "
,
profile
->
host
,
profile
->
name
);
}
}
else
{
snprintf
(
bare_prompt_str
,
sizeof
(
bare_prompt_str
),
"freeswitch@%s> "
,
profile
->
name
);
}
bare_prompt_str_len
=
(
int
)
strlen
(
bare_prompt_str
);
if
(
feature_level
)
{
#if HAVE_DECL_EL_PROMPT_ESC
snprintf
(
prompt_str
,
sizeof
(
prompt_str
),
"
\1
%s
\1
%s
\1
%s
\1
"
,
prompt_color
,
bare_prompt_str
,
input_text_color
);
#else
snprintf
(
prompt_str
,
sizeof
(
prompt_str
),
"%s%s%s"
,
prompt_color
,
bare_prompt_str
,
input_text_color
);
#endif
}
else
{
snprintf
(
prompt_str
,
sizeof
(
prompt_str
),
"%s"
,
bare_prompt_str
);
}
connect:
connected
=
0
;
while
(
--
loops
>
0
)
{
...
...
@@ -1657,6 +1704,42 @@ int main(int argc, char *argv[])
return
0
;
}
snprintf
(
cmd_str
,
sizeof
(
cmd_str
),
"api switchname
\n\n
"
);
esl_send_recv
(
global_handle
,
cmd_str
);
if
(
global_handle
->
last_sr_event
&&
global_handle
->
last_sr_event
->
body
)
{
esl_set_string
(
switchname
,
global_handle
->
last_sr_event
->
body
);
}
else
{
esl_set_string
(
switchname
,
profile
->
name
);
}
snprintf
(
cmd_str
,
sizeof
(
cmd_str
),
"api hostname
\n\n
"
);
esl_send_recv
(
global_handle
,
cmd_str
);
if
(
global_handle
->
last_sr_event
&&
global_handle
->
last_sr_event
->
body
)
{
esl_set_string
(
switch_hostname
,
global_handle
->
last_sr_event
->
body
);
}
else
{
esl_set_string
(
switch_hostname
,
profile
->
name
);
}
if
(
!
esl_strlen_zero
(
profile
->
prompt_string
))
{
expand_prompt
(
profile
->
prompt_string
,
sizeof
(
profile
->
prompt_string
),
profile
);
snprintf
(
bare_prompt_str
,
sizeof
(
bare_prompt_str
),
"%s> "
,
profile
->
prompt_string
);
}
else
{
snprintf
(
bare_prompt_str
,
sizeof
(
bare_prompt_str
),
"freeswitch@%s> "
,
switchname
);
}
bare_prompt_str_len
=
(
int
)
strlen
(
bare_prompt_str
);
if
(
feature_level
)
{
#if HAVE_DECL_EL_PROMPT_ESC
snprintf
(
prompt_str
,
sizeof
(
prompt_str
),
"
\1
%s
\1
%s
\1
%s
\1
"
,
prompt_color
,
bare_prompt_str
,
input_text_color
);
#else
snprintf
(
prompt_str
,
sizeof
(
prompt_str
),
"%s%s%s"
,
prompt_color
,
bare_prompt_str
,
input_text_color
);
#endif
}
else
{
snprintf
(
prompt_str
,
sizeof
(
prompt_str
),
"%s"
,
bare_prompt_str
);
}
#ifdef HAVE_LIBEDIT
el
=
el_init
(
__FILE__
,
stdin
,
stdout
,
stderr
);
#if HAVE_DECL_EL_PROMPT_ESC
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论