配置项和配置项变量相对应
例如:server.conf
pasv_enable=YES
port_enable=YES
listen_port=5188
max_clients=2000
max_per_ip=2
accept_timeout=60
connect_timeout=60
idle_session_timeout=300
data_connection_timeout=900
local_umask=077
upload_max_rate=102400
download_max_rate=204800
listen_address=192.168.1.108
根据配置项的数据类型来定义出对应表
extern int tunable_pasv_enable; //是否开启被动模式
extern int tunable_port_enable; //是否开启主动模式
extern unsigned int tunable_listen_port; //FTP服务端口
extern unsigned int tunable_max_clients; //最大连接数
extern unsigned int tunable_max_per_ip; //每个ip最大连接数
extern unsigned int tunable_accept_timeout; //accept超时时间
extern unsigned int tunable_connect_timeout; //connect超时时间
extern unsigned int tunable_idle_session_timeout; //控制连接超时时间
extern unsigned int tunable_data_connection_timeout; //数据连接超时时间
extern unsigned int tunable_local_umask; //掩码
extern unsigned int tunable_upload_max_rate; //最大上传速度
extern unsigned int tunable_download_max_rate; //最大下载速度
extern const char *tunable_listen_address; //服务器ip地址
可以将配置项信息要跟所对应的变量相对应的关系设计表,通过查询表中的字符串,找到相对应的配置项,就可以将数据保存到配置项中,如下:
//找到表中相对应的配置名称,然后将配置信息保存到相对应的变量中
//字符串 布尔 unsigned int 三个表格
static struct parseconf_bool_setting {
const char *p_setting_name;
int *p_variable;
}
parseconf_bool_array[] = {
{
"pasv_enable", &tunable_pasv_enable },
{
"port_enable", &tunable_port_enable },
{
NULL, NULL }
}