Exemplo n.º 1
0
/*
*  解析配置文件参数
*/
void Config::Para_FileParse(std::string file)
{
#define LINELENGTH 256
	char line[LINELENGTH];
	char *name = NULL, *value = NULL;
	int fd = -1;
	int n = 0;

	fd = open(file.c_str(), O_RDONLY);
	if(fd == -1)
	{
		goto EXITPara_FileParse;
	}

        //插件列表以配置文件为准
        PluginList.clear();
	/*
	*命令格式如下:
	*[#注释|[空格]关键字[空格]=[空格]value]
	*/
	while( (n = conf_readline(fd, line, LINELENGTH)) !=0)
	{
		char *pos = line;	
		/* 跳过一行开头部分的空格 */
		while(isspace(*pos)){
			pos++;
		}
		/*注释?*/
		if(*pos == '#'){
			continue;
		}
		
		/*关键字开始部分*/
		name = pos;
		/*关键字的末尾*/
		while(!isspace(*pos) && *pos != '=')
		{
			pos++;
		}
		*pos = '\0';/*生成关键字字符串*/
                pos++;

		/*value部分前面空格*/
		while(isspace(*pos) || (*pos) == '=')
		{
			pos++;
		}
		/*value开始*/
		value = pos;
		/*到结束*/
		while(!isspace(*pos) && *pos != '\r' && *pos != '\n' && *pos != '\0')
		{
			pos++;
		}
		*pos = '\0';/*生成值的字符串*/
                //std::cout<< name <<std::endl;
		/*根据关键字部分,获得value部分的值*/
		int ivalue;
		/*"CGIRoot","DefaultFile","DocumentRoot","ListenIP","ListenPort","MaxClient","InitConPool","TimeOut"*/
		if(0 == strncmp("CGIRoot", name, 7))	{/*CGIRoot部分*/
                        CGIRoot = value;
		}else if(0 == strncmp("DefaultFile", name, 11)){/*DefaultFile部分*/
                        DefaultFile = value;
		}else if(0 == strncmp("DocumentRoot", name, 12)){/*DocumentRoot部分*/
                        DocumentRoot = value;
		}else if(0 == strncmp("Plugin", name, 6)){/*Plugin部分*/
                        PluginList.push_back(value);
		}else if(0 == strncmp("ListenIP", name, 8)){/*ListenIP部分*/
                        ListenIP = value;
		}else if(0 == strncmp("ListenPort", name, 10)){/*ListenPort部分*/
			ivalue = strtol(value, NULL, 10);
			ListenPort = ivalue;
		}else if(0 == strncmp("MaxWorker", name, 9)){/*MaxClient部分*/
			ivalue = strtol(value, NULL, 10);
			MaxWorker = ivalue;
		}else if(0 == strncmp("InitConPool", name, 11)){/*InitConPool部分*/
			ivalue = strtol(value, NULL, 10);
			InitConPool = ivalue;
		}else if(0 == strncmp("TimeOut", name, 7)){/*TimeOut部分*/
			ivalue = strtol(value, NULL, 10);
			TimeOut = ivalue;
		}		
	}
	close(fd);

EXITPara_FileParse:
	return;	
}
Exemplo n.º 2
0
/*
*  para file 
*/
void Para_FileParse(char *file)
{
#define LINELENGTH 256
	char line[LINELENGTH];
	char *name = NULL, *value = NULL;
	int fd = -1;
	int n = 0;

	fd = open(file, O_RDONLY);
	if(fd == -1)
	{
		goto EXITPara_FileParse;
	}
	
	/*
	*命令格式如下:
	*[#注释|[空格]关键字[空格]=[空格]value]
	*/
	while( (n = conf_readline(fd, line, LINELENGTH)) !=0)
	{
		char *pos = line;	
		/*jump the tab*/
		while(isspace(*pos)){
			pos++;
		}
		/*explant*/
		if(*pos == '#'){
			continue;
		}
		
		/*key begin*/
		name = pos;
		/*key end*/
		while(!isspace(*pos) && *pos != '=')
		{
			pos++;
		}
		*pos = '\0';

		/*value tab*/
		while(isspace(*pos))
		{
			pos++;
		}
		/*value begin*/
		value = pos;
		/*until end*/
		while(!isspace(*pos) && *pos != '\r' && *pos != '\n')
		{
			pos++;
		}
		*pos = '\0';/*生成值的字符串*/


		/*根据关键字部分,获得value部分的值*/
		int ivalue;
		/*"CGIRoot","DefaultFile","DocumentRoot","ListenPort","MaxClient","TimeOut"*/
		if(strncmp("CGIRoot", name, 7))	{/*CGIRoot部分*/
			memcpy(conf_para.CGIRoot, value, strlen(value)+1);
		}else if(strncmp("DefaultFile", name, 11)){/*DefaultFile部分*/
			memcpy(conf_para.DefaultFile, value, strlen(value)+1);
		}else if(strncmp("DocumentRoot", name, 12)){/*DocumentRoot部分*/
			memcpy(conf_para.DocumentRoot, value, strlen(value)+1);
		}else if(strncmp("ListenPort", name, 10)){/*ListenPort部分*/
			ivalue = strtol(value, NULL, 10);
			conf_para.ListenPort = ivalue;
		}else if(strncmp("MaxClient", name, 9)){/*MaxClient部分*/
			ivalue = strtol(value, NULL, 10);
			conf_para.MaxClient = ivalue;
		}else if(strncmp("TimeOut", name, 7)){/*TimeOut部分*/
			ivalue = strtol(value, NULL, 10);
			conf_para.TimeOut = ivalue;
		}		
	}
	close(fd);

EXITPara_FileParse:
	return;	
}
Exemplo n.º 3
0
//
// 解析配置文件参数
//
void Para_FileParse(char *file)
{
#define LINELENGTH 256
	char line[LINELENGTH];
	char *name = NULL, *value = NULL;
	int fd = -1;
	int n = 0;

	fd = open(file, O_RDONLY);
	if(fd == -1)
	{
		goto EXITPara_FileParse;
	}
	
	/*
	*命令格式如下:
	*[#注释|[空格]关键字[空格]=[空格]value]
	*/
	while( (n = conf_readline(fd, line, LINELENGTH)) !=0)
	{
		char *pos = line;	
		/* 跳过一行开头部分的空格 */
		while(isspace(*pos)){
			pos++;
		}
		/*注释?*/
		if(*pos == '#'){
			continue;
		}
		
		/*关键字开始部分*/
		name = pos;
		/*关键字的末尾*/
		while(!isspace(*pos) && *pos != '=')
		{
			pos++;
		}
		*pos = '\0';/*生成关键字字符串*/

		/*value部分前面空格*/
		while(isspace(*pos))
		{
			pos++;
		}
		/*value开始*/
		value = pos;
		/*到结束*/
		while(!isspace(*pos) && *pos != '\r' && *pos != '\n')
		{
			pos++;
		}
		*pos = '\0';/*生成值的字符串*/


		/*根据关键字部分,获得value部分的值*/
		int ivalue;
		/*"CGIRoot","default_file","DocumentRoot","listen_port","max_client","time_out"*/
		if(strncmp("CGIRoot", name, 7))	{/*CGIRoot部分*/
			memcpy(conf_para.CGIRoot, value, strlen(value)+1);
		}else if(strncmp("default_file", name, 11)){/*DefaultFile部分*/
			memcpy(conf_para.default_file, value, strlen(value)+1);
		}else if(strncmp("DocumentRoot", name, 12)){/*DocumentRoot部分*/
			memcpy(conf_para.DocumentRoot, value, strlen(value)+1);
		}else if(strncmp("listen_port", name, 10)){/*ListenPort部分*/
			ivalue = strtol(value, NULL, 10);
			conf_para.listen_port = ivalue;
		}else if(strncmp("max_client", name, 9)){/*MaxClient部分*/
			ivalue = strtol(value, NULL, 10);
			conf_para.max_client = ivalue;
		}else if(strncmp("time_out", name, 7)){/*TimeOut部分*/
			ivalue = strtol(value, NULL, 10);
			conf_para.time_out = ivalue;
		}		
	}
	close(fd);

EXIT:
	return;	
}