Example #1
0
static void GetIPAndPort(astring &str, astring & ip, astring & port, astring & onvifAddr)
{
       astring strItem = "http://";
	size_t pos = 0;
	while (1)
	{
	       strItem = "http://";
		size_t p1 = str.find(strItem, pos);
		if (p1 == string::npos) return;
		size_t posIP = p1 + strItem.length();
		strItem = "/";
		size_t p2 = str.find(strItem,posIP);
		if (p2 == string::npos) return;
		string strGetIP = str.substr(posIP, p2 - posIP);
		if (strGetIP.find(".") == string::npos || 
			strGetIP.find("169") == 0)
		{
			/* IPV6 address */
			pos = p2;
			continue;
		}
		string strGetOnvifAddr;
		strItem = "http://";
		if (str.find(strItem, p2) == string::npos)
		{
			strGetOnvifAddr = str .substr(p2);
		}else
		{
			strItem = " ";
			size_t p3 = str.find(strItem, p2);
			if (p3 == string::npos) return;
			strGetOnvifAddr = str.substr(p2, p3 - p2);
		}

	       string strPort = "80";
		size_t posPort = strGetIP.find_first_of(":");
		if (posPort != std::string::npos) 
		{
			strPort = strGetIP.substr(posPort + 1);
			string strIPTemp = strGetIP.substr(0, posPort);
			strGetIP = strIPTemp;
		}
		ip = strGetIP;
		port = strPort;
		onvifAddr = strGetOnvifAddr;
		strItem = "http://";
		if (str.find(strItem, p2) == string::npos)
		{
			break;
		}else
		{
			pos = p2;
			continue;			
		}
	}
	
}
Example #2
0
	/**
	@brief	文字列分割
	@note
	http://shnya.jp/blog/?p=195 のコードを改造
	*/
	static std::vector<astring> split(const astring &str, const astring &delim)
	{
		std::vector<astring> res;
		size_t current = 0, found, delimlen = delim.size();
		while ((found = str.find(delim, current)) != astring::npos)
		{
			res.push_back(astring(str, current, found - current));
			current = found + delimlen;
		}
		res.push_back(astring(str, current, str.size() - current));
		return res;
	}
Example #3
0
static void GetHardwareModel(astring &str, astring & hdModel)
{
	size_t pos1= 0;
	size_t pos2 = 0;	
	std::string strItem;
	strItem = "hardware/";
	pos2 = str.find(strItem);

	string sHardware = "unknown";
	if (pos2 != string::npos)
	{
		size_t posHardware =  pos2 + strItem.length();
		strItem = "onvif";
		pos1 = str.find(strItem,pos2);
		
		if (pos1 != string::npos)
		{
			sHardware =  str.substr(posHardware,pos1 - posHardware);
			transform(sHardware.begin(), sHardware.end(),sHardware.begin(),(int(*)(int))toupper);
		}
		
	}
	hdModel = sHardware;
}