Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Achou.Wang
accel-ppp
提交
e5eddec6
A
accel-ppp
项目概览
Achou.Wang
/
accel-ppp
通知
6
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
accel-ppp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e5eddec6
编写于
11月 26, 2010
作者:
K
Kozlov Dmitry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cli: show sessions: implemented sorting by username and regexp matching username
上级
46bf66f9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
120 addition
and
5 deletion
+120
-5
accel-pptpd/cli/std_cmd.c
accel-pptpd/cli/std_cmd.c
+116
-4
accel-pptpd/triton/mempool.c
accel-pptpd/triton/mempool.c
+4
-1
未找到文件。
accel-pptpd/cli/std_cmd.c
浏览文件 @
e5eddec6
...
...
@@ -6,6 +6,8 @@
#include "ppp.h"
#include "cli.h"
#include "utils.h"
#include "log.h"
#include "memdebug.h"
static
int
show_stat_exec
(
const
char
*
cmd
,
char
*
const
*
fields
,
int
fields_cnt
,
void
*
client
)
{
...
...
@@ -51,19 +53,81 @@ static void exit_help(char * const *fields, int fields_cnt, void *client)
static
int
show_ses_exec
(
const
char
*
cmd
,
char
*
const
*
fields
,
int
fields_cnt
,
void
*
client
)
{
char
buf
[
128
];
struct
row_t
{
struct
list_head
entry
;
char
buf
[
128
];
char
*
match_key
;
char
*
order_key
;
};
char
ip_str
[
17
];
char
*
state_str
;
char
time_str
[
12
];
time_t
uptime
;
int
day
,
hour
,
min
,
sec
;
struct
ppp_t
*
ppp
;
int
i
;
enum
order_type
{
ORDER_NONE
,
ORDER_USERNAME
};
enum
match_type
{
MATCH_NONE
,
MATCH_USERNAME
};
int
order
=
ORDER_NONE
;
int
match
=
MATCH_NONE
;
struct
row_t
*
row
,
*
row2
,
*
row3
;
pcre
*
re
;
const
char
*
pcre_err
;
int
pcre_offset
;
LIST_HEAD
(
rows
);
LIST_HEAD
(
temp_rows
);
for
(
i
=
2
;
i
<
fields_cnt
;
i
++
)
{
if
(
!
strcmp
(
fields
[
i
],
"order"
))
{
if
(
i
==
fields_cnt
-
1
)
return
CLI_CMD_SYNTAX
;
i
++
;
if
(
!
strcmp
(
fields
[
i
],
"username"
))
order
=
ORDER_USERNAME
;
else
{
cli_send
(
client
,
"only order by username is supported yet
\r\n
"
);
return
CLI_CMD_OK
;
}
}
else
if
(
!
strcmp
(
fields
[
i
],
"match"
))
{
if
(
i
==
fields_cnt
-
2
)
return
CLI_CMD_SYNTAX
;
i
++
;
if
(
!
strcmp
(
fields
[
i
],
"username"
))
match
=
MATCH_USERNAME
;
else
{
cli_send
(
client
,
"only match by username is supported yet
\r\n
"
);
return
CLI_CMD_OK
;
}
i
++
;
re
=
pcre_compile2
(
fields
[
i
],
0
,
NULL
,
&
pcre_err
,
&
pcre_offset
,
NULL
);
if
(
!
re
)
{
cli_sendv
(
client
,
"match: %s at %i
\r\n
"
,
pcre_err
,
pcre_offset
);
return
CLI_CMD_OK
;
}
}
else
return
CLI_CMD_SYNTAX
;
}
cli_send
(
client
,
"interface: username: address: type: state: uptime:
\r\n
"
);
cli_send
(
client
,
"------------------------------------------------------------------------
\r\n
"
);
pthread_rwlock_rdlock
(
&
ppp_lock
);
list_for_each_entry
(
ppp
,
&
ppp_list
,
entry
)
{
row
=
_malloc
(
sizeof
(
*
row
));
if
(
!
row
)
{
log_emerg
(
"out of memory
\n
"
);
cli_send
(
client
,
"out of memory
\r\n
"
);
break
;
}
if
(
order
==
ORDER_USERNAME
)
row
->
order_key
=
_strdup
(
ppp
->
username
);
if
(
match
==
MATCH_USERNAME
)
row
->
match_key
=
_strdup
(
ppp
->
username
);
u_inet_ntoa
(
ppp
->
peer_ipaddr
,
ip_str
);
switch
(
ppp
->
state
)
{
...
...
@@ -95,17 +159,65 @@ static int show_ses_exec(const char *cmd, char * const *fields, int fields_cnt,
else
sprintf
(
time_str
,
"%02i:%02i:%02i"
,
hour
,
min
,
sec
);
sprintf
(
buf
,
"%9s %15s %16s %6s %6s %10s
\r\n
"
,
ppp
->
ifname
,
ppp
->
username
?
ppp
->
username
:
""
,
ip_str
,
ppp
->
ctrl
->
name
,
state_str
,
time_str
);
cli_send
(
client
,
buf
);
sprintf
(
row
->
buf
,
"%9s %15s %16s %6s %6s %10s
\r\n
"
,
ppp
->
ifname
,
ppp
->
username
?
ppp
->
username
:
""
,
ip_str
,
ppp
->
ctrl
->
name
,
state_str
,
time_str
);
if
(
order
||
match
)
list_add_tail
(
&
row
->
entry
,
&
temp_rows
);
else
list_add_tail
(
&
row
->
entry
,
&
rows
);
//cli_send(client, buf);
}
pthread_rwlock_unlock
(
&
ppp_lock
);
if
(
match
||
order
)
{
while
(
!
list_empty
(
&
temp_rows
))
{
row
=
list_entry
(
temp_rows
.
next
,
typeof
(
*
row
),
entry
);
list_del
(
&
row
->
entry
);
if
(
match
==
MATCH_USERNAME
)
{
if
(
pcre_exec
(
re
,
NULL
,
row
->
match_key
,
strlen
(
row
->
match_key
),
0
,
0
,
NULL
,
0
)
<
0
)
{
_free
(
row
->
match_key
);
if
(
order
)
_free
(
row
->
order_key
);
_free
(
row
);
continue
;
}
}
if
(
order
==
ORDER_USERNAME
)
{
row3
=
NULL
;
list_for_each_entry
(
row2
,
&
rows
,
entry
)
{
if
(
strcmp
(
row
->
order_key
,
row2
->
order_key
)
<=
0
)
{
row3
=
row2
;
break
;
}
}
if
(
row3
)
list_add_tail
(
&
row
->
entry
,
&
row3
->
entry
);
else
list_add_tail
(
&
row
->
entry
,
&
rows
);
}
else
list_add_tail
(
&
row
->
entry
,
&
rows
);
}
}
while
(
!
list_empty
(
&
rows
))
{
row
=
list_entry
(
rows
.
next
,
typeof
(
*
row
),
entry
);
list_del
(
&
row
->
entry
);
cli_send
(
client
,
row
->
buf
);
if
(
match
==
MATCH_USERNAME
)
_free
(
row
->
match_key
);
if
(
order
==
ORDER_USERNAME
)
_free
(
row
->
order_key
);
_free
(
row
);
}
if
(
match
==
MATCH_USERNAME
)
pcre_free
(
re
);
return
CLI_CMD_OK
;
}
static
void
show_ses_help
(
char
*
const
*
fields
,
int
fields_cnt
,
void
*
client
)
{
cli_send
(
client
,
"show sessions - shows all sessions
\r\n
"
);
cli_send
(
client
,
"show sessions
[order username] [match username <regexp>]
- shows all sessions
\r\n
"
);
}
//=============================
...
...
accel-pptpd/triton/mempool.c
浏览文件 @
e5eddec6
...
...
@@ -253,7 +253,10 @@ void sigclean(int num)
while
(
!
list_empty
(
&
p
->
items
))
{
it
=
list_entry
(
p
->
items
.
next
,
typeof
(
*
it
),
entry
);
list_del
(
&
it
->
entry
);
_free
(
it
);
if
(
p
->
mmap
)
munmap
(
it
,
size
);
else
_free
(
it
);
triton_stat
.
mempool_allocated
-=
size
;
triton_stat
.
mempool_available
-=
size
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录