POSTFILE_KEY CWorkerThread::ParseMultipartData(const std::string &data, const std::string &boundary)
{
	std::string rboundary="--"+boundary;
	int state=0;
	std::string key;
	std::string value;
	std::string filename;
	std::string name;
	std::string filedata;
	std::string contenttype;
	size_t start;
	POSTFILE_KEY pfilekey=Server->getPostFileKey();
	for(size_t i=0;i<data.size();++i)
	{
	    switch(state)
	    {
		case 0:
		    if(next(data,i,rboundary))
		    {
				i+=rboundary.size()+1;
				state=2;
		    }
		    break;
		case 1:
		    if(data[i]=='\n' || data[i]=='\r' )
			{
				if(data[i]=='\n')
				{
					state=4;
					rboundary+="--";
					start=i+1;
				}
				else
					break;
			}
		    else
				state=1;
		case 2:
			if(data[i]!=':')
				key+=toupper(data[i]);
		    else
				state=3;
		    break;
		case 3:
		    if(data[i]!='\n' && data[i]!='\r' )
				value+=data[i];
		    else if(data[i]=='\n')
			{
				if(key=="CONTENT-DISPOSITION")
				{
					name=getbetween("name=\"","\"", value);
					filename=getbetween("filename=\"","\"", value);
				}
				else if(key=="CONTENT-TYPE")
				{
					contenttype=value;
				}
				value.clear();
				key.clear();
				state=1;
			}
		    break;
		case 4:
			if(next(data,i,rboundary)==true)
			{
            	IFile *memfile=Server->openMemoryFile();
				memfile->Write(data.substr(start,i-start-2) );
				memfile->Seek(0);
				Server->addPostFile(pfilekey, name, SPostfile(memfile, widen(filename), widen(contenttype)) );
				state=0;
				rboundary.erase(rboundary.size()-2,2);
				i+=rboundary.size()+2;
				state=0;
			}
	    }
	}
    return pfilekey;
}
Exemple #2
0
	bool	ColorCfgLoad::Parsing(const string& section, const string& var, const string& val)
	{
		int		fcol = 0, bcol = 0;
		string::size_type p = val.find(',');

		LOG_WRITE("Parsing sSection [%s] var [%s] val [%s]", section.c_str(), var.c_str(), val.c_str());

		try
		{
			if (p != string::npos)
			{
				fcol = strtoint(val.substr(0, p).c_str());
				bcol = strtoint(val.substr(p+1).c_str());
			}
			else 
			{
				fcol = strtoint(val.c_str());
				bcol = GetColorEntry("Default").back;
			}
		}
		catch(Exception& ex)
		{
			LOG_WRITE("Color File Loading Exception : %s", (char*)ex);
			return false;
		}
		
		ColorEntry cur(fcol, bcol);
	
		if (var.substr(0, 4) == "mask")		
		{
			int num = strtol(getbetween(var, '[', ']').c_str(), NULL, 8);
			_mapMask[num] = cur;
		}
		else if(var.substr(0, 4) == "name")
		{
			StringToken st(getbetween(var, '[', ']'), ";");
			while(st.Next())
			{
				if (st.Get().empty()) continue;
				_mapName[Tolower(st.Get())] = cur;
				LOG_WRITE("_mapName [%s [%d:%d]]", Tolower(st.Get()).c_str(), cur.font, cur.back);	
			}
		}
		else if (var.substr(0, 3) == "ext")
		{
			StringToken st(getbetween(var, '[', ']'), ";");
		
			while(st.Next())
			{
				if (st.Get().empty()) continue;
				_mapExt[st.Get()] = cur;
				LOG_WRITE("_mapExt [%s [%d:%d]]", st.Get().c_str(), cur.font, cur.back);
			}
		}	
		else
		{
			_mapColor[Tolower(var)] = cur;
			LOG_WRITE("_mapColor [%s [%d:%d]]", var.c_str(), cur.font, cur.back);
			if (Tolower(var) == "default") 
				_DefaultColor = cur;
		}
		return false;
	}