Exemplo n.º 1
0
CStrings split(const string Splitter,const string Str,const int maxCount=std::numeric_limits<int>::max(),int *rest=NULL) {
	CStrings Result;
	size_t oldpos,pos=-Splitter.size();
	oldpos=pos;
	if (rest!=NULL) *rest=0;

	while( (pos=Str.find(Splitter,pos+Splitter.size())) != string::npos ) {
		if (Result.size() >= maxCount) {
			if (rest!=NULL) *rest=2;
			break;
		} else { 
			if (pos-oldpos-Splitter.size()) {
				Result.push_back(Str.substr(oldpos+Splitter.size(),pos-oldpos-Splitter.size()));
			}
			oldpos=pos;
		}
	}

	if (oldpos+Splitter.size()<Str.length()) {
		Result.push_back(Str.substr(oldpos+Splitter.size(),string::npos));
		if (rest!=NULL && *rest==0) *rest=1;
	}

	return Result;
}
Exemplo n.º 2
0
void processControls (string &msgsStr,const socket_t &sock) {
	int msgsStrEnd;
	const CStrings msgs=split("\n",msgsStr,std::numeric_limits<int>::max(),&msgsStrEnd);

	for (CStringsIterator msgsItem=msgs.begin();msgsItem!=msgs.end();msgsItem++) {
	    if (!msgsItem->empty()) {
		string resp=processControl(*msgsItem,sock);
		if (!resp.empty()) {
//			makeLog(LOG_DEBUG,"Sending control {%s}",resp.c_str());
			sendControl(resp);//socket,resp.c_str(),resp.length(),0,(const sockaddr*)&control.peer,sizeof(control.peer));
		}
	    }
	}
	
	
	msgsStr=msgsStrEnd?msgs.back():"";
}
Exemplo n.º 3
0
void CDownload::SetDownloadInfo( LPCTSTR szUrl, LPCTSTR szFilePath )
{
	//m_strUrl = szUrl;
	LPCTSTR szMagic = _T("http://download.");
	LPCTSTR szReplace = _T("http://qh.dlservice.");
	
	CStrings mirrors;
	if(_tcsnicmp(szUrl, szMagic, _tcslen(szMagic)) == 0)
	{
		CString sm;
		sm = szReplace;
		sm.Append(szUrl + _tcslen(szMagic));
		mirrors.push_back( sm );
	}
	m_locationPool.SetLocation(szUrl, mirrors);
	m_strFilePath = szFilePath;
}
Exemplo n.º 4
0
string processControl (const string Msg,const socket_t &sock) {
	const CStrings data=split(" ",Msg);
	const CStringsIterator name=data.begin();
	string result="";
	makeLog(LOG_DEBUG,"Control: Processing {%s}",Msg.c_str());

	if (name->compare("SEND")==0) {
		uint16_t resendNumber = (data.size()>1)?atoi(data[1].c_str()):0;
		uint16_t cnt = (data.size()>2)?atoi(data[2].c_str()):0;
		if (cnt<1) cnt=1;
		
//		makeLog(LOG_DEBUG,"RESEND request: %d:%d",resendNumber,cnt);

		bool wasMissing=false;
		for (int i=0;i<cnt;i++) {
			int missing = getDatagramLength(resendNumber);
			
			if (missing<=0) {
				wasMissing=true;
				makeLog(LOG_INFO,"Streamer: Datagram lost: %d",resendNumber);
				sendControl(stringprintf("SEND_OOB %d",resendNumber));
			} else {
				ictDatagram_t ictDatagram;
				getDatagram(ictDatagram,resendNumber);
				
				outQueue.push_front	( resendNumber );
				
//				sendto(sender.socket,ictDatagram,ictDatagram.size(),0,(const sockaddr*)&sender.peer,sizeof(sender.peer));
			}
			
			resendNumber++;
		}

		if (wasMissing) {
			makeLog(LOG_WARNING,"Streamer: Packet(s) is out of buffer");
		}
	}
	else if (name->compare("STARTED")==0) {
		makeLog (LOG_INFO,"Control: method STARTED");
	}
	else if (name->compare("KEPT")==0) {
		keptLastTime=getMNow();
	}
	else if (name->compare("SETBUF")==0) {
		//makelog ("Control message: {$msg1}");
		int newBufferTime=(data.size()>1)?atoi(data[1].c_str()):-1;

		if (newBufferTime!=-1 && cleaningArgs.bufferSize!=newBufferTime) {
			cleaningArgs.bufferSize=newBufferTime;
			makeLog (LOG_INFO,"Buffer is set to new value: %d",cleaningArgs.bufferSize);
		}
		return stringprintf("BUFSET %d",cleaningArgs.bufferSize);
	}
	else if (name->compare("RESETSTREAM")==0) {
		FD_CLR(sender.getHandle(),&master);
		sender.reinit();
		FD_SET(sender.getHandle(),&master);
		
		makeLog (LOG_INFO,"Streamer: Restart on receiver requested");
		result+=stringprintf("STREAMRESET %d",0);
	}
	else if (name->compare("SUSPEND")==0) {
		if (!sendingSuspended) {
			sendingSuspended=true;
			makeLog(LOG_INFO,"Streamer: Supended on receiver request");
		}
		
		return stringprintf("SUSPENDED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane
	}
	else if (name->compare("RESUME")==0) {
		sendingSuspended=false;
	
		return stringprintf("RESUMED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane
	}
	else if (name->compare("CINIT")==0) {
		int newBufferTime=data.size()>1?atoi(data[1].c_str()):-1;
		sendingSuspended=false;
		makeLog(LOG_INFO,"Clinet initialization request from receiver");

		if (newBufferTime!=-1 && cleaningArgs.bufferSize!=newBufferTime) {
			cleaningArgs.bufferSize=newBufferTime;
			makeLog (LOG_INFO,"Buffer is set to new value: %d",cleaningArgs.bufferSize);
			result+=stringprintf("BUFSET %d",cleaningArgs.bufferSize);
		}

		result+=stringprintf("CINITED %d",0);//getSocketLocalPort(sender.socket)); //TODO O by malo byt cislo noveho portu na vysielacej strane
	}

	else if (name->compare("CUNINIT")==0) {
		clearBuffer();
		sendingInitialized=false;
		result+=stringprintf("CUNINITED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane
	}
	else if (name->compare("CONNECTCONTROL")==0) {
		return "CONTROLCONNECT\n";
	} else {
		makeLog(LOG_ERR,"Control: unknown command: %s",name->c_str());
	}

	return result;
}