Example #1
0
//读取连接信息
int read_connect_cfg(ndxml *xmlroot, int base_port, struct connect_config *ccfg)
{
	ndxml *xml_sub ;
	//read port
	XML_READ_SUB_INT(xmlroot,"remote_port",ccfg->port) ;
	ccfg->port += base_port ;

	XML_READ_SUB_INT(xmlroot,"connected_tmout",ccfg->tmout) ;
	
	//read remote host
	XML_READ_SUB_BUF(xmlroot,"host",ccfg->host) ;

	//read listen_mod
	XML_READ_SUB_BUF(xmlroot,"connect_protocol",ccfg->protocol_name) ;




	//read proxy info 
	xml_sub = ndxml_refsub(xmlroot,"proxy") ;
	if(xml_sub) {
		XML_READ_SUB_INT(xml_sub,"proxy_type",ccfg->proxy_info.proxy_type) ;
		if (ccfg->proxy_info.proxy_type==0)
			return 0;
		XML_READ_SUB_INT(xml_sub,"proxy_port",ccfg->proxy_info.proxy_port) ;
		XML_READ_SUB_BUF(xml_sub,"proxy_host",ccfg->proxy_info.proxy_host) ;
		XML_READ_SUB_BUF(xml_sub,"proxy_user",ccfg->proxy_info.user) ;
		XML_READ_SUB_BUF(xml_sub,"proxy_password",ccfg->proxy_info.password) ;
		
	}
	return 0 ;
}
Example #2
0
int read_base_port(ndxml *xmlroot)
{
	ndxml *xml_sub = ndxml_refsub(xmlroot,"base_port") ;
	if (!xml_sub){
		T_ERROR("read base port error") ;
	}
	return ndxml_getval_int(xml_sub) ;
};
Example #3
0
//get save db list
int get_saveDB_sort(ndxml_root *xmlfile,name_list_t &res_list,name_list_t &save_list)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	name_list_t save_input ;
	
	
	int add_new = 1 ;
	while (add_new > 0) {
		add_new = 0 ;
		for (name_list_t::iterator it= res_list.begin(); it!=res_list.end(); ++it) {
			if (it->is_saveDB && it->is_used==0) {
				it->is_used = 1;
				++add_new ;
			}
			if (!it->is_used) {
				continue ;
			}
			
			ndxml *subNode1 = ndxml_refsub(xnode,it->name.c_str()) ;
			int sub_num = ndxml_getsub_num(subNode1) ;
			
			for (int i=0; i<sub_num; ++i) {
				ndxml *subNode2 = ndxml_refsubi(subNode1,i) ;
				const char *myName = ndxml_getattr_val(subNode2, "type") ;
				
				const char *ret = get_type_from_alias(myName,alias_type, sizeof(alias_type)/sizeof(alias_type[0]) ) ;
				if (ret) {
					continue ;
				}
				
				for (name_list_t::iterator it_sub= res_list.begin(); it_sub!=res_list.end(); ++it_sub) {
					if (it_sub->is_used) {
						continue;
					}
					if (0== strcmp(myName, it_sub->name.c_str()) ) {
						if (it_sub->is_used==0) {
							it_sub->is_used = 1 ;
							++add_new;
							break ;
						}
					}
				}
			}
			
		}
	}
	
	for (name_list_t::iterator it= res_list.begin(); it!=res_list.end(); ++it) {
		if (it->is_used) {
			save_list.push_back(*it) ;
		}
	}
	return 0;
}
Example #4
0
int build_dataTypeForUE4(ndxml_root *xmlfile, const char *out_file)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	ndxml *xInfo = ndxml_getnode(xmlfile, "DataDesc") ;
	if (!xInfo) {
		return -1;
	}
	
	name_list_t res_list ;
	get_name_sort(xmlfile, res_list);
	
	char buf[128] ;
	snprintf(buf, sizeof(buf), "%s.h",out_file );
	FILE *pf = fopen(buf, "w") ;
	if (!pf){
		fprintf(stderr, " open out put file %s error \n", buf ) ;
		return -1 ;
	}
	snprintf(buf, sizeof(buf), "%s.cpp",out_file );
	FILE *pfCpp = fopen(buf, "w") ;
	if (!pf){
		fprintf(stderr, " open out put file %s error \n", buf ) ;
		return -1 ;
	}
	
	_OUT_PUT_TIME(pfCpp) ;
	fprintf(pfCpp, "\n\n#include \"netMessage/dataStream.h\"\n" );
	fprintf(pfCpp, "#include \"netMessage/netStreamAutoDefine.h\"\n\n\n" );
	//fprintf(pfCpp, "namespace NetMessage \n{\n" );
	
	_OUT_PUT_TIME(pf) ;
	fprintf(pf, "#ifndef _NET_STREAM_AUTO_DEFINE_H_\n" );
	fprintf(pf, "#define _NET_STREAM_AUTO_DEFINE_H_\n" );;
	fprintf(pf, "#include \"Object.h\" \n\nclass NDIStreamMsg;\nclass  NDOStreamMsg;\n\n") ;
	//fprintf(pf, "#include \"dataStream.h\"\n\n") ;
	//fprintf(pf, "#define DATA_IN_DB_VERSION %s \n\n", version );
	//fprintf(pf, "namespace NetMessage \n{\n" );
	
	int total =(int) res_list.size(); //ndxml_getsub_num(xnode) ;
	for (int i=0; i<total; ++i) {
		ndxml *sub = ndxml_refsub(xnode,res_list[i].name.c_str()) ;
		_out_data_forUE(sub,  pf,pfCpp) ;
		fprintf(pf, "\n") ;
	}
	
	fprintf(pf,"\n#endif\n\n") ;
	fclose(pf) ;
	
	//fprintf(pfCpp,"};\n\n") ;
	fclose(pfCpp) ;

	return 0 ;
}
Example #5
0
int read_dbconfig(const char *fileName, const char *dbCfgname ,struct nd_db_config *db_cfg)
{
	//ND_TRACE_FUNC() ;
	
	int ret = -1;
	ndxml *xmlroot, *xmlsub, *xmlnode ;
	ndxml_root xmlfile;
	
#define GET_VAL(name)                       \
	xmlnode = ndxml_refsub(xmlsub, #name) ; \
	if (!xmlnode){                          \
		ret = -1;                               \
		goto READ_EXIT ;                        \
	}                                       \
	strncpy(db_cfg->db_##name, ndxml_getval(xmlnode), sizeof(db_cfg->db_##name) )
	
	
	if ( 0 != ndxml_load(fileName , &xmlfile ) ){
		nd_logfatal("read file %s error %s\n", fileName, nd_last_error() ) ;
		return -1;
	}
	
	xmlroot = ndxml_getnode( &xmlfile, "root" ) ;
	if ( !xmlroot )   {
		goto READ_EXIT;
	}
	//read connect config
	xmlsub = ndxml_refsub( xmlroot, dbCfgname ) ;
	if ( !xmlsub )   {
		goto READ_EXIT;
	}
	
	GET_VAL( host ) ;
	GET_VAL( database ) ;
	GET_VAL( user ) ;
	GET_VAL( password) ;
	ret = 0 ;
	
	
READ_EXIT:
	ndxml_destroy( &xmlfile );
	return ret ;
}
Example #6
0
int read_remote_proxy(char *file, struct nd_proxy_info *proxy_info )
{
	int ret;
	ndxml  *xml_node, *xml_read ;
	ndxml_root xmlroot;

	nd_assert(file) ;
	ret = ndxml_load(file, &xmlroot) ;
	if(0!=ret) {
		return -1;
	}
	xml_node = ndxml_getnode(&xmlroot,"server_config") ;
	if(!xml_node) {		
		ndxml_destroy(&xmlroot);
		return -1;
	}

	//read proxy
	xml_read = ndxml_refsub(xml_node, "proxy") ;
	if(xml_read) {

		ndxml *xmltmp = ndxml_refsub(xml_read, "proxy_type") ;
		if (!xmltmp) 	goto CFG_EXIT ;		
		proxy_info->proxy_type = ndxml_getval_int(xmltmp);
		if(0==proxy_info->proxy_type )goto CFG_EXIT ;

		xmltmp = ndxml_refsub(xml_read, "proxy_host") ;
		if (!xmltmp) 	goto CFG_EXIT ;		
		ndxml_getval_buf(xmltmp, proxy_info->proxy_host, sizeof(proxy_info->proxy_host)) ;


		xmltmp = ndxml_refsub(xml_read, "proxy_port") ;
		if (!xmltmp) 	goto CFG_EXIT ;		
		proxy_info->proxy_port = ndxml_getval_int(xmltmp) ;

		xmltmp = ndxml_refsub(xml_read, "proxy_user") ;
		if (xmltmp)
			ndxml_getval_buf(xmltmp, proxy_info->user, sizeof(proxy_info->user)) ;

		xmltmp = ndxml_refsub(xml_read, "proxy_password") ;
		if (xmltmp) 
			ndxml_getval_buf(xmltmp, proxy_info->password, sizeof(proxy_info->password)) ;
	}

CFG_EXIT:
	ndxml_destroy(&xmlroot);
	return 0;

}
Example #7
0
int read_config(ndxml *xmlroot, const char *name, struct server_config *scfg) 
{
	ndxml *xml_sub,*xml_listen ;
	
	int base_port = read_base_port(xmlroot) ;

	memset(scfg, 0, sizeof(scfg)) ;
	if (0==base_port) {
		return -1;
	}
	
	xml_sub = ndxml_refsub(xmlroot,name) ;
	if (!xml_sub){
		T_ERROR("read base port error") ;
	}

	if(-1== read_instance_info(xml_sub, &scfg->i_cfg)) {
		return -1 ;
	}


	xml_listen = ndxml_refsub(xml_sub,"listen") ;
	if (!xml_listen){
		T_ERROR("read base port error") ;
	}	
	if(-1== read_listen_cfg(xml_listen,  base_port,&scfg->l_cfg) ) {
		return -1 ;
	}
	//

	scfg->reliable_num = 0;
	xml_listen = ndxml_refsub(xml_sub,"reliable_host") ;
	if (xml_listen){
		read_iplist(xml_listen, scfg->reliable_hosts, MAX_RELIABLE_HOST ) ;
		for(int i=0; i<MAX_RELIABLE_HOST; i++) {
			union {
				ndip_t ip ;
				NDUINT8 buf[4] ;
			}readip,ipmask;

			readip.ip = scfg->reliable_hosts[i] ;
			if (readip.ip ==0){
				break ;
			}
			ipmask.ip = 0xffffffff;
			for (int x=0; x<4; x++)	{
				if (0xff== readip.buf[x]){
					ipmask.buf[x] = 0 ;
				}
			}
			scfg->reliable_ipmask[i] = ipmask.ip;
			scfg->reliable_num++;
		}
		//get netmask
	}
	//read connectors
	
	xml_listen = ndxml_refsub(xml_sub,"connectors") ;
	if (xml_listen){
		for (int i=0; i< ND_CONNECT_OTHER_HOSTR_NUM && i<ndxml_num(xml_listen); i++) {
			ndxml *pnode = ndxml_getnodei(xml_listen, i) ;
			
			if(0== read_connect_cfg(pnode,  base_port, &scfg->i_cfg.connectors[i]) ) {
				const char *pname = ndxml_getattr_val(pnode, "name") ;
				if (pname && pname[0]) {
					strncpy(scfg->i_cfg.connectors[i].connector_name, pname,sizeof(scfg->i_cfg.connectors[i].connector_name)) ;
				}
				else {
					pname = ndxml_getname(pnode) ;
					strncpy(scfg->i_cfg.connectors[i].connector_name, pname,sizeof(scfg->i_cfg.connectors[i].connector_name)) ;
				}
			}
		}
	}
	
	return 0 ;
}
Example #8
0
int set_xml_value(char *file, char *node_name_list, char *attr_name, char*attr_val, char *node_val)
{
    int ret;
    ndxml_root xmlfile;
    
    ndxml *xnode = 0 ;
    
    char *p = node_name_list;
    char name[128] ;
    
    ret = ndxml_load(file, &xmlfile) ;
    if(0!=ret) {
        fprintf(stderr,"load xml from %s\n", file) ;
        return -1;
    }
    
    p = (char*)ndstr_nstr_end(p, name, '.', sizeof(name)) ;
    
    if (IS_NUMERALS(name[0])) {
		xnode = ndxml_getnodei(&xmlfile, ndstr_atoi_hex(name));
    }
    else {
        xnode = ndxml_getnode(&xmlfile, name) ;
    }
    if (!xnode) {
        fprintf(stderr,"read xml-node %s error \n", name) ;
    }
    
    bool success = true ;
    while (p && *p) {
        
        if (*p == '.') {
            ++p ;
            if (!*p) {
                break ;
            }
        }
        
        p = (char*) ndstr_nstr_end(p, name, '.', sizeof(name)) ;
        
        if (IS_NUMERALS(name[0])) {
			xnode = ndxml_refsubi(xnode, ndstr_atoi_hex(name));
        }
        else {
            xnode = ndxml_refsub(xnode, name) ;
        }
        if (!xnode) {
            fprintf(stderr,"read xml-node %s error \n", name) ;
            success = false ;
            break ;
        }
        
        
    }
    if (success) {
        success = false;
        if (attr_name && attr_name[0] && attr_val && attr_val[0]) {
            ndxml_setattrval(xnode,attr_name, attr_val ) ;
            success = true ;
        }
        if (node_val && node_val[0]) {
            ndxml_setval(xnode, node_val) ;
            success = true ;
        }
        if (success) {
            ndxml_save(&xmlfile,file) ;
        }
    }
    
    ndxml_destroy(&xmlfile);
    return success ? 0: -1 ;
}
Example #9
0
//build datatype
int build_dataType(ndxml_root *xmlfile, const char *out_file,bool saveDB)
{
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	ndxml *xInfo = ndxml_getnode(xmlfile, "DataDesc") ;
	if (!xInfo) {
		return -1;
	}
	const char *version = ndxml_getattr_val(xInfo, "version");
	if (!version) {
		return -1;
	}
	const char *comm_version = ndxml_getattr_val(xInfo, "comm_version");
	
	const char *nameSpace = ndxml_getattr_val(xnode, "namespace"); 

	name_list_t res_list ;
	get_name_sort(xmlfile, res_list);
	
	NDUINT64 nowTime = (NDUINT64) time(NULL);
	if (saveDB) {
		
		char buf[128] ;
		snprintf(buf, sizeof(buf), "%s_v%s.h",out_file, version );
		FILE *pf = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error \n", buf ) ;
			return -1 ;
		}
		snprintf(buf, sizeof(buf), "%s_v%s.cpp",out_file, version  );
		FILE *pfCpp = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error \n", buf ) ;
			return -1 ;
		}
		
		_OUT_PUT_TIME(pfCpp) ;
		fprintf(pfCpp, "\n\n#include \"netMessage/dataStream.h\"\n");
		fprintf(pfCpp, "\n\n#include \"netMessage/auto_dataTypeDb_v%s.h\"\n", version );
		//fprintf(pfCpp, "namespace NetMessage \n{\n" );
		if (nameSpace) {
			fprintf(pfCpp, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pfCpp, "/* undefined namespace*/\n{\n");
		}


		
		_OUT_PUT_TIME(pf) ;
		fprintf(pf, "#ifndef _AUTO_DATA_TYPE_DEFINE_DB_%s_H_\n",version );
		fprintf(pf, "#define _AUTO_DATA_TYPE_DEFINE_DB_%s_H_\n",version );
		fprintf(pf, "#include \"netMessage/auto_macroDefine.h\"\n\n") ;
		fprintf(pf, "#include \"netMessage/dataStream.h\"\n\n");
		fprintf(pf, "#include \"netMessage/dataBinary.h\"\n\n");

		if (nameSpace) {
			fprintf(pf, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pf, "/* undefined namespace*/\n{\n");
		}
		
		
		name_list_t save_list;
		get_saveDB_sort(xmlfile,res_list,save_list);
		
		int total =(int) save_list.size(); //ndxml_getsub_num(xnode) ;
		for (int i=0; i<total; ++i) {
			ndxml *sub = ndxml_refsub(xnode,save_list[i].name.c_str()) ;
			_save_dataTypeNode(sub,  pf,pfCpp ,version, true) ;
			fprintf(pf, "\n\n") ;
		}
		fprintf(pf,"};\n\n#endif\n\n") ;
		fclose(pf) ;
		
		fprintf(pfCpp,"};\n\n") ;
		fclose(pfCpp) ;
		
	}
	else {
		
		char buf[128] ;
		snprintf(buf, sizeof(buf), "%s.h",out_file );
		FILE *pf = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error: %s \n", buf , nd_last_error() ) ;
			return -1 ;
		}
		snprintf(buf, sizeof(buf), "%s.cpp",out_file );
		FILE *pfCpp = fopen(buf, "w") ;
		if (!pf){
			fprintf(stderr, " open out put file %s error: %s \n", buf, nd_last_error());
			return -1 ;
		}

		_OUT_PUT_TIME(pfCpp) ;
		fprintf(pfCpp, "\n\n#include \"netMessage/auto_dataType.h\"\n" );
		//fprintf(pfCpp, "namespace NetMessage \n{\n" );

		if (nameSpace) {
			fprintf(pfCpp, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pfCpp, "/* undefined namespace*/\n{\n");
		}

		
		_OUT_PUT_TIME(pf) ;
		fprintf(pf, "#ifndef _AUTO_DATA_TYPE_DEFINE_H_\n" );
		fprintf(pf, "#define _AUTO_DATA_TYPE_DEFINE_H_\n" );;
		fprintf(pf, "#include \"netMessage/auto_macroDefine.h\"\n\n") ;
		fprintf(pf, "#include \"netMessage/dataStream.h\"\n\n") ;
		fprintf(pf, "#include \"netMessage/dataBinary.h\"\n\n");

		fprintf(pf, "#define DATA_IN_DB_VERSION %s \n\n", version);
		fprintf(pf, "#define NET_COMMUNATION_VERSION %s \n\n", comm_version);
		fprintf(pf, "#define NET_MESSAGE_EXPORT_TM %lld \n", nowTime);
		

		if (nameSpace) {
			fprintf(pf, "namespace %s \n{\n", nameSpace);
		}
		else {
			fprintf(pf, "/* undefined namespace*/\n{\n");
		}

		int total =(int) res_list.size(); //ndxml_getsub_num(xnode) ;
		for (int i=0; i<total; ++i) {
			ndxml *sub = ndxml_refsub(xnode,res_list[i].name.c_str()) ;
// 			if (0 == ndstricmp(sub->name, "CityBase")) {
// 				ND_DebugBreak();
// 			}
			_save_dataTypeNode(sub,  pf,pfCpp, NULL, false) ;
			fprintf(pf, "\n") ;
		}
		
		fprintf(pf,"};\n\n#endif\n\n") ;
		fclose(pf) ;
		
		fprintf(pfCpp,"};\n\n") ;
		fclose(pfCpp) ;
	}

	return 0 ;
}
Example #10
0
int get_name_sort(ndxml_root *xmlfile,name_list_t &res_list)
{
	name_list_t org_list ;
	ndxml *xnode = ndxml_getnode(xmlfile, "DataType") ;
	if (!xnode) {
		fprintf(stderr, " build marco error MarcoDefine node unexist\n" ) ;
		return -1 ;
	}
	
	int total = ndxml_getsub_num(xnode) ;
	
	//get original list
	for (int i=0; i<total; ++i) {
		ndxml *sub = ndxml_refsubi(xnode,i) ;
		ref_order_t node ;
		node.name = ndxml_getname(sub) ;
		node.is_used = 0 ;
		const char *saveDB = ndxml_getattr_val(sub, "saveDB") ;
		if (saveDB) {
			node.is_saveDB = atoi(saveDB) ;
		}
		else {
			node.is_saveDB = 0 ;
		}
		org_list.push_back(node) ;
	}
	//check name 
	for (name_list_t::iterator it= org_list.begin(); it!=org_list.end();++it ) {
		for (name_list_t::iterator it_sub= it + 1; it_sub!=org_list.end();++it_sub ) {
			if (it->name == it_sub->name) {
				fprintf(stderr, "%s name duplicate\n", it->name.c_str());
				exit(1) ;
			}
			
		}
	}
	
	//check  is ref not after this
	int free_numb =(int) org_list.size() ;
	while (free_numb > 0) {
		free_numb = 0 ;
		
		for (name_list_t::iterator it= org_list.begin(); it!=org_list.end();++it ) {
			//cheng reference by other
			if (it->is_used) {
				continue ;
			}
			ndxml *subNode1 = ndxml_refsub(xnode,it->name.c_str()) ;
			int sub_num = ndxml_getsub_num(subNode1) ;
			
			bool is_ref = false ;
			
			for (int i=0; i<sub_num; ++i) {
				ndxml *subNode2 = ndxml_refsubi(subNode1,i) ;
				const char *myName = ndxml_getattr_val(subNode2, "type") ;
				
				for (name_list_t::iterator it_sub= org_list.begin(); it_sub!=org_list.end(); ++it_sub) {
					if (it_sub->is_used || it==it_sub) {
						continue ;
					}
					if (0== strcmp(myName, it_sub->name.c_str()) ) {
						is_ref = true ;
						break ;
					}
				}
			}
			
			if (is_ref==false) {
				res_list.push_back(*it) ;
				it->is_used = 1;
			}
			else {
				++free_numb ;
			}
		}
	}
	return 0;
	
}