5555555555

#include "Initialize.h"  
#include "tinyxml.h"  
#include "TinyXmlFunction.h"
#include <stdlib.h>  
  
struct ConfigValue configvalues;  

bool GetNodePointerByName(TiXmlElement* pRootEle, const char *strNodeName,TiXmlElement* &destNode)  
{  
	// 假如等于根节点名,就退出  
	if (!(strcmp(strNodeName, pRootEle->Value())))  
	{  
		destNode = pRootEle;  
		//printf("目标节点是根节点\r\n");
		return 0;  
	}    
	TiXmlElement *pEle = pRootEle;    
	for (pEle = pRootEle->FirstChildElement(); pEle; pEle = pEle->NextSiblingElement())    
	{    
		if (0 != strcmp(pEle->Value(), strNodeName))  
		{  
			GetNodePointerByName(pEle,strNodeName,destNode);  
		}  
		else  
		{  
			destNode = pEle;  
			//printf("目标节点名: %s\n", pEle->Value());  
			return 0;  
		}   
	}    
	return 1;  
}   

char *InquireNodeText(const char *XmlFile,const char *strNodeName)  
{  
	TiXmlElement *pNode = NULL; 

	TiXmlDocument doc(XmlFile);
	bool loadOkay = doc.LoadFile();
	if (loadOkay == 1)
	{
		printf("filename: %s\n", XmlFile);
	}
	else
	{
		printf("Failed to load file \n");
		return NULL;
	}
	TiXmlElement *pRootEle = doc.RootElement();  
	if (NULL==pRootEle)  
	{  
		printf("Have No RootNode, SomeThing Wrong!\r\n");
		return NULL;  
	}
	GetNodePointerByName(pRootEle,strNodeName,pNode);  
	if (NULL != pNode)  
	{  
		if(NULL != pNode->GetText())
		{
			char *strText = (char *)malloc(strlen(pNode->GetText())+1);
			if(NULL == strText)
			{
				printf("Malloc strText Error!!\r\n");
				return NULL;
			}
			strcpy(strText, pNode->GetText());
			return strText; 
		}
		else
		{
			printf("The Node Have No Text!!\r\n");
			return NULL;
		}
	}  
	else  
	{  
		return NULL;  
	} 
}

///读取配置文件  
bool ReadInitConfig(const char *path)  
{   
    configvalues.DefaultUrl = InquireNodeText(path,"server_ip");  
    printf("DefaultUrl = %s\r\n",configvalues.DefaultUrl);  
  
    configvalues.Interval = atoi(InquireNodeText(path,"interval"));  
    printf("Interval = %d\r\n",configvalues.Interval);  
  
    configvalues.Defaultport = atoi(InquireNodeText(path,"server_port"));  
    printf("Defaultport = %d\r\n",configvalues.Defaultport);  
  
    configvalues.MaxThread = atoi(InquireNodeText(path,"thread"));  
    printf("MaxThread = %d\r\n",configvalues.MaxThread);  

	configvalues.SendCount = atoi(InquireNodeText(path,"send_count"));  
    printf("SendCount = %d\r\n",configvalues.SendCount);  
  
	configvalues.TaskSleep = atoi(InquireNodeText(path,"tasksleep"));  
    printf("TaskSleep = %d\r\n",configvalues.TaskSleep);

    configvalues.HopeData = InquireNodeText(path,"hope_data");  
    printf("HopeData = %s\r\n",configvalues.HopeData);  

	configvalues.HttpDebug = atoi(InquireNodeText(path,"httpdebug"));
	printf("httpdebug = %d\r\n",configvalues.HttpDebug);
      
    return 0;   
}  

 

你可能感兴趣的:(thread,server,struct,null,Path,include)