Example #1
0
bool
connection_base::print_message(message const &msg, std::streambuf &buf) {

	formatter const *fmt_ptr = NULL;
	if (NULL != fmt_data_.get()) {
		fmt_ptr = fmt_data_->find_formatter(msg);
	}

	std::string const &content = msg.content();
	if (NULL != fmt_ptr) {
		if (!print_message_content(fmt_ptr->wrap_message(content), buf)) {
			return false;
		}
	}
	else if (!print_message_content(content, buf)) {
		return false;
	}

	if (NULL != fmt_data_.get()) {
		fmt_data_->update(msg);
	}
	return true;
}
Example #2
0
	void dcc_send_connection::incoming_message(irc::connection& aConnection, const message& aMessage)
	{
		if (&aConnection != iConnection)
			return;
		if (aMessage.command() != message::PRIVMSG)
			return;
		typedef std::vector<std::pair<std::string::const_iterator, std::string::const_iterator> > bits_t;
		bits_t bits;
		neolib::tokens(aMessage.content(), std::string("\001 "), bits);
		if (neolib::to_upper(neolib::to_string(bits[0])) != "DCC")
			return;
		if (iSendType == Download && neolib::to_upper(neolib::to_string(bits[1])) == "ACCEPT" && bits.size() >= 5)
		{
			if (*bits[2].first == '\"')
			{
				for (bits_t::size_type i = 3; i < bits.size(); ++i)
					if (*(bits[i].second - 1) == '\"')
					{
						bits[2].second = bits[i].second;
						bits.erase(bits.begin() + 3, bits.begin() + i + 1);
						break;
					}
			}
			std::string fileName = neolib::to_string(bits[2]);
			if (fileName == iResumeData->iFileName && 
				neolib::string_to_unsigned_integer(neolib::to_string(bits[3])) == iResumeData->iPort &&
				neolib::string_to_unsigned_integer(neolib::to_string(bits[4])) == iResumeData->iResumeFileSize)
			{
				u_long address = iResumeData->iAddress;
				u_short port = iResumeData->iPort;
				iBytesTransferred = iResumeData->iResumeFileSize;
				iLastBytesTransferred = iBytesTransferred;
				if (!connect(address, port))
				{
					close();
					return;
				}
				neolib::observable<dcc_send_connection_observer>::notify_observers(dcc_send_connection_observer::NotifyTransferStarted);
				if (!open_file())
					return;
			}
		}
		else if (iSendType == Listen && neolib::to_upper(neolib::to_string(bits[1])) == "RESUME" && bits.size() >= 5)
		{
			if (*bits[2].first == '\"')
			{
				for (bits_t::size_type i = 3; i < bits.size(); ++i)
					if (*(bits[i].second - 1) == '\"')
					{
						bits[2].second = bits[i].second;
						bits.erase(bits.begin() + 3, bits.begin() + i + 1);
						break;
					}
			}
			std::string fileName = neolib::to_string(bits[2]);
			if (fileName == iName && 
				neolib::string_to_unsigned_integer(neolib::to_string(bits[3])) == stream_server().local_port())
			{
				iResumeData = resume_data_t(0, stream_server().local_port(), name(), neolib::string_to_unsigned_integer(neolib::to_string(bits[4])));
				message newMessage(*iConnection, message::OUTGOING);
				newMessage.set_command(message::PRIVMSG);
				newMessage.parameters().push_back(iRemoteUser.nick_name());
				newMessage.parameters().push_back("\001DCC ACCEPT "); 
				newMessage.parameters().back() += iResumeData->iFileName + " ";
				newMessage.parameters().back() += neolib::unsigned_integer_to_string<char>(iResumeData->iPort) + " ";
				newMessage.parameters().back() += neolib::unsigned_integer_to_string<char>(iResumeData->iResumeFileSize) + "\001";
				iConnection->send_message(newMessage);
			}
		}
	}