Ejemplo n.º 1
0
void CHttpReader::parseCookies()
{
	string::size_type pos1 = 0;
	string::size_type pos2 = 0;
	string::size_type equalPos = 0;
	string sTmp;

	MAP_HEAD_INFO::const_iterator it = m_mapHeadInfo.find("cookie");
	if (it != m_mapHeadInfo.end())
	{
		m_sCookies = it->second;
	}

	if (m_sCookies.empty())
		return ;
	while ( pos2 != string::npos )
	{
		pos2 = m_sCookies.find(';',pos1);

		sTmp = m_sCookies.substr(pos1, pos2-pos1);
		pos1 = pos2+1;
		equalPos = sTmp.find('=');
		if (equalPos == string::npos)
			continue;

		std::string::size_type wscount = 0;
		std::string::const_iterator data_iter;
		for(data_iter = sTmp.begin(); data_iter != sTmp.end(); ++data_iter,++wscount)
			if(isspace(*data_iter) == 0)
				break;

		m_mapCookieList[sTmp.substr(wscount, equalPos - wscount)] = formUrlDecode(sTmp.substr(1+equalPos));
	}
}
Ejemplo n.º 2
0
void CHttpReader::parseValues()
{
	string::size_type pos1 = 0;
	string::size_type pos2 = 0;
	string::size_type equalPos = 0;
	string sTmp;

	if (m_sValues.empty())
		return ;
	while ( pos2 != string::npos )
	{
		pos2 = m_sValues.find('&',pos1);
		sTmp = m_sValues.substr(pos1, pos2-pos1);
		pos1 = pos2+1;
		equalPos = sTmp.find('=');
		if (equalPos == string::npos)
			continue;
		m_mapValueList[sTmp.substr(0, equalPos)] = formUrlDecode(sTmp.substr(1+equalPos));
	}
}
Ejemplo n.º 3
0
void CHttpParser::parsePostFormData(const string &sBoundary, const string::size_type headEndPos)
{
	string sValue;
	string sName;
	string::size_type pos1 = headEndPos+4;

	while ( string::npos != pos1 && pos1 < m_sHttpContent.size())
	{
		string::size_type pos = 0;
		string sNV = getStrBetween(m_sHttpContent, pos1, sBoundary, sBoundary, pos);

		if(pos == string::npos || sNV.empty())
		{
			break;
		}

		pos1 = pos + sNV.size() ;

		static const string FORM_DATA("Content-Disposition: form-data; ");
		if(sNV.substr(2, FORM_DATA.size()) != FORM_DATA)
		{
			break;
		}

		sName = getStrBetween(sNV, 2, "name=\"", "\"", pos);
		if(pos == string::npos || sName.empty())
		{
			break;
		}

		pos = sNV.find("\r\n\r\n", pos+1);
		if(pos == string::npos)
		{
			break;
		}
		sValue = sNV.substr(pos+4);
		if(sValue.size() > 2)
		{
			sValue.erase(sValue.size() -2);
		}
		m_mapValueList[sName] = formUrlDecode(sValue);
		m_sFileName = getStrBetween(sNV, 0, "filename=\"", "\"", pos);
		if(pos == string::npos || m_sFileName.empty())
		{
			continue;
		}

		string sFileType = getStrBetween(sNV, pos, "Content-Type: ", "\r\n", pos);
		if(pos == string::npos || sFileType.empty())
		{
			continue;
		}
		SFile stFile;
		m_mapFiles[sName] = stFile;

		MAP_FILE::iterator it = m_mapFiles.find(sName);

		it->second.sData = sNV.substr(pos+sFileType.size()+4);

		if(it->second.sData.size() > 2)
		{
			it->second.sData.erase(it->second.sData.size()-2);
		}

		it->second.sContentType =sFileType;
		it->second.sName = m_sFileName;
	}

}