Beispiel #1
0
int WebPDemuxPrevChunk(WebPChunkIterator* iter) {
  if (iter != NULL && iter->chunk_num > 1) {
    const char* const fourcc =
        (const char*)iter->chunk.bytes - CHUNK_HEADER_SIZE;
    return SetChunk(fourcc, iter->chunk_num - 1, iter);
  }
  return 0;
}
Beispiel #2
0
int WebPDemuxNextChunk(WebPChunkIterator* iter) {
  if (iter != NULL) {
    const char* const fourcc =
        (const char*)iter->chunk_.bytes_ - CHUNK_HEADER_SIZE;
    return SetChunk(fourcc, iter->chunk_num_ + 1, iter);
  }
  return 0;
}
Beispiel #3
0
int WebPDemuxGetChunk(const WebPDemuxer* dmux,
                      const char fourcc[4], int chunk_num,
                      WebPChunkIterator* iter) {
  if (iter == NULL) return 0;

  memset(iter, 0, sizeof(*iter));
  iter->private_ = (void*)dmux;
  return SetChunk(fourcc, chunk_num, iter);
}
Beispiel #4
0
// Overrides SNM_ChunkParserPatcher::Commit() in order to remove the fake "TAKE" line, see
// GetChunk() comments. Also see important comments for SNM_ChunkParserPatcher::Commit()
bool SNM_TakeParserPatcher::Commit(bool _force)
{
	if (m_reaObject && (m_updates || _force) && m_chunk->GetLength() && !(GetPlayStateEx(NULL) & 4))
	{
// SNM_ChunkParserPatcher::Commit() mod ----->
		if (m_fakeTake)
		{
			m_fakeTake = false;
			const char* p = strstr(m_chunk->Get(), "\nNAME ");
			// empty item (i.e. no take at all) or NULL takes only
			if (!p) 
			{
				p = strstr(m_chunk->Get(), "\nTAKE");
				if (p)
				{
					const char* p2 = p+5;
					while (*p2 && p2 < (m_chunk->Get()+m_chunk->GetLength()) && *p2 != '\n') p2++;
					if (*p2 == '\n')
						m_chunk->DeleteSub((int)(p-m_chunk->Get()), (int)(p2-p));
				}
			}
			// "normal" item
			else
			{
				char* p2 = (char*)(p-1);
				while (*p2 && p2 > m_chunk->Get() && *p2 != '\n') p2--;
				if (*p2 == '\n' && !strncmp(p2, "\nTAKE", 5))
				{
					m_chunk->DeleteSub((int)(p2-m_chunk->Get()), (int)(p-p2));
					p -= (int)(p-p2);
				}

				// if there's a "TAKE" before "NAME" it must not be "TAKE NULL"
				p--; // we assume it's safe (serious other issues otherwise)
				while (*p && p > m_chunk->Get() && *p != '\n') p--;
				if (!strncmp(p, "\nTAKE NULL", 10))
					m_chunk->DeleteSub((int)(p+5-m_chunk->Get()), 5); // removes " NULL"
			}
		}
// SNM_ChunkParserPatcher::Commit() mod <-----

		if (!SNM_GetSetObjectState(m_reaObject, m_chunk)) {
			SetChunk("", 0);
			return true;
		}
	}
	return false;
}
Beispiel #5
0
	void SetDestination(MacAddress mac) {
		SetChunk(0, ConstBuf(&mac.m_n64, 6));
	}
/** splits message to it's important parts and stores their info in the chunkset mChunks */
bool cMessageDC::SplitChunks()
{
 	SetChunk(0, 0, mStr.length()); // the zeroth chunk is everywhere the same

	switch (mType) { // now try to find chunks one by one
		case eDC_SUPPORTS: // single parameter
		case eDC_MYHUBURL:
		case eDC_KEY:
		case eDC_VALIDATENICK:
		case eDC_MYPASS:
		case eDC_VERSION:
		case eDCO_KICK:
		case eDC_QUIT:
		case eDCO_USERIP:
		case eDCO_UNBAN:
		case eDCO_WHOIP:
		case eDCO_SETTOPIC:
		case eDCB_BOTINFO:
		case eDCC_MYNICK:
		case eDCC_LOCK:
			if (mLen < mKWSize)
				mError = true;
			else
				SetChunk(eCH_1_PARAM, mKWSize, mLen - mKWSize);

			break;

		case eDC_GETINFO:
			if (!SplitOnTwo(mKWSize, ' ', eCH_GI_OTHER , eCH_GI_NICK))
				mError = true;

			break;

		case eDC_RCONNECTTOME:
			if (!SplitOnTwo(mKWSize, ' ', eCH_RC_NICK, eCH_RC_OTHER))
				mError = true;

			break;

		case eDC_CHAT:
			if (!SplitOnTwo(mKWSize, "> ", eCH_CH_NICK, eCH_CH_MSG))
				mError = true;

			break;

		case eDC_CONNECTTOME:
		case eDC_MCONNECTTOME:
			if (!SplitOnTwo(mKWSize, ' ', eCH_CM_NICK, eCH_CM_ACTIVE))
				mError = true;

			if (!SplitOnTwo(':', eCH_CM_ACTIVE, eCH_CM_IP, eCH_CM_PORT))
				mError = true;

			break;

		case eDC_TO:
			/*
				$To: <othernick> From: <mynick> $<<mynick>> <message>
				eCH_PM_ALL, eCH_PM_TO, eCH_PM_FROM, eCH_PM_CHMSG, eCH_PM_NICK, eCH_PM_MSG
			*/

			if (!SplitOnTwo(mKWSize, " From: ", eCH_PM_TO, eCH_PM_FROM))
				mError = true;

			if (!SplitOnTwo(" $<", eCH_PM_FROM, eCH_PM_FROM, eCH_PM_CHMSG))
				mError = true;

			if (!SplitOnTwo("> ", eCH_PM_CHMSG, eCH_PM_NICK, eCH_PM_MSG))
				mError = true;

			break;

		case eDC_MCTO:
			/*
				$MCTo: <othernick> From: <mynick> $<<mynick>> <message>
				eCH_MCTO_ALL, eCH_MCTO_TO, eCH_MCTO_FROM, eCH_MCTO_CHMSG, eCH_MCTO_NICK, eCH_MCTO_MSG
			*/

			if (!SplitOnTwo(mKWSize, " From: ", eCH_MCTO_TO, eCH_MCTO_FROM))
				mError = true;

			if (!SplitOnTwo(" $<", eCH_MCTO_FROM, eCH_MCTO_FROM, eCH_MCTO_CHMSG))
				mError = true;

			if (!SplitOnTwo("> ", eCH_MCTO_CHMSG, eCH_MCTO_NICK, eCH_MCTO_MSG))
				mError = true;

			break;

		case eDC_MYINFO:
			/*
				$MyINFO $ALL <nick> <interest>$ $<speed>$<e-mail>$<sharesize>$
				eCH_MI_ALL, eCH_MI_DEST, eCH_MI_NICK, eCH_MI_INFO, eCH_MI_DESC, eCH_MI_SPEED, eCH_MI_MAIL, eCH_MI_SIZE
			*/

			if (!SplitOnTwo(mKWSize, ' ', eCH_MI_DEST, eCH_MI_NICK))
				mError = true;

			if (!SplitOnTwo(' ', eCH_MI_NICK, eCH_MI_NICK, eCH_MI_INFO))
				mError = true;

			if (!SplitOnTwo('$', eCH_MI_INFO, eCH_MI_DESC, eCH_MI_SPEED))
				mError = true;

			if (!ChunkRedLeft(eCH_MI_SPEED, 2))
				mError = true;

			if (!SplitOnTwo('$', eCH_MI_SPEED, eCH_MI_SPEED, eCH_MI_MAIL))
				mError = true;

			if (!SplitOnTwo('$', eCH_MI_MAIL, eCH_MI_MAIL, eCH_MI_SIZE))
				mError = true;

			if (!ChunkRedRight(eCH_MI_SIZE, 1))
				mError = true;

			break;

		case eDC_IN:
			/*
				$IN <nick>$<data>[$<data>]
				eCH_IN_ALL, eCH_IN_NICK, eCH_IN_DATA
			*/

			if (!SplitOnTwo(mKWSize, '$', eCH_IN_NICK, eCH_IN_DATA))
				mError = true;

			break;

		case eDC_EXTJSON:
			/*
				$ExtJSON <nick> {parameters with values}
				eCH_EJ_ALL, eCH_EJ_NICK, eCH_EJ_PARS
			*/

			if (!SplitOnTwo(mKWSize, ' ', eCH_EJ_NICK, eCH_EJ_PARS))
				mError = true;

			break;

		case eDCO_OPFORCEMOVE:
			/*
				$OpForceMove $Who:<victimNick>$Where:<newIp>$Msg:<reasonMsg>
				eCH_FM_NICK eCH_FM_DEST eCH_FM_REASON
			*/

			if (!SplitOnTwo(mKWSize, '$', eCH_FM_NICK, eCH_FM_DEST))
				mError = true;

			if (!ChunkRedLeft(eCH_FM_DEST, 6)) // skip the "Where:" part
				mError = true;

			if (!SplitOnTwo('$', eCH_FM_DEST, eCH_FM_DEST, eCH_FM_REASON))
				mError = true;

			if (!ChunkRedLeft(eCH_FM_REASON, 4)) // skip the "Msg:" part
				mError = true;

			break;

		case eDC_MSEARCH_PAS: // not implemented, but should be same as passive search
		case eDC_SEARCH_PAS:
			/*
				$Search Hub:<nick> <limits><pattern>
				eCH_PS_ALL, eCH_PS_NICK, eCH_PS_QUERY, eCH_PS_SEARCHLIMITS, eCH_PS_SEARCHPATTERN
			*/

			if (!SplitOnTwo(mKWSize, ' ', eCH_PS_NICK, eCH_PS_QUERY))
				mError = true;

			if (!SplitOnTwo('?', eCH_PS_QUERY, eCH_PS_SEARCHLIMITS, eCH_PS_SEARCHPATTERN, false))
				mError = true;

			if (!ChunkIncLeft(eCH_PS_SEARCHLIMITS, 1)) // get back last question mark
				mError = true;

			break;

		case eDC_MSEARCH: // not implemented, but should be same as active search
		case eDC_SEARCH:
			/*
				$Search <ip>:<port> <limits><pattern>
				eCH_AS_ALL, eCH_AS_ADDR, eCH_AS_IP, eCH_AS_PORT, eCH_AS_QUERY, eCH_AS_SEARCHLIMITS, eCH_AS_SEARCHPATTERN
			*/

			if (!SplitOnTwo(mKWSize, ' ', eCH_AS_ADDR, eCH_AS_QUERY))
				mError = true;

			if (!SplitOnTwo(':', eCH_AS_ADDR, eCH_AS_IP, eCH_AS_PORT))
				mError = true;

			if (!SplitOnTwo(' ', eCH_AS_PORT, eCH_AS_PORT, eCH_AS_QUERY))
				mError = true;

			if (!SplitOnTwo('?', eCH_AS_QUERY, eCH_AS_SEARCHLIMITS, eCH_AS_SEARCHPATTERN, false))
				mError = true;

			if (!ChunkIncLeft(eCH_AS_SEARCHLIMITS, 1)) // get back last question mark
				mError = true;

			break;

		case eDC_SR:
			/*
				$SR <senderNick> <filepath>^E<filesize> <freeslots>/<totalslots>^E<hubname> (<hubhost>[:<hubport>])^E<searchingNick>
				$SR <senderNick> <filepath>^E<filesize> <freeslots>/<totalslots>^ETTH:<TTH-ROOT> (<hub_ip>[:<hubport>])^E<searchingNick>
				$SR <senderNick> <filepath>^E<freeslots>/<totalslots>^ETTH:<TTH-ROOT> (<hub_ip>:[hubport]>)^E<searchingNick>
					1)      ----FROM----|-----------------------------------(PATH)--------------------------------------------------------------
					2)                  |-------PATH-----------|----------------------(SLOTS)---------------------------------------------------
					3)                                         |-----------SLOTS---------|-------------(HUBINFO)--------------------------------
					4)                                                                   |-------------(HUBINFO)---------------|----TO----------
					5)
				eCH_SR_FROM, eCH_SR_PATH, eCH_SR_SIZE, eCH_SR_SLOTS, eCH_SR_SL_FR, eCH_SR_SL_TO, eCH_SR_HUBINFO, eCH_SR_TO
			*/

			if (!SplitOnTwo(mKWSize, ' ', eCH_SR_FROM, eCH_SR_PATH))
				mError = true;

			/*
			if (!SplitOnTwo(' ', eCH_SR_PATH, eCH_SR_PATH, eCH_SR_SLOTS))
				mError = true;

			if (!SplitOnTwo(' ', eCH_SR_SLOTS, eCH_SR_SLOTS, eCH_SR_HUBINFO)
				mError = true;

			if (!SplitOnTwo(' ', eCH_SR_HUBINFO, eCH_SR_HUBINFO, eSR_TO)
				mError = true;
			*/

			if (!SplitOnTwo(0x05, eCH_SR_PATH, eCH_SR_PATH, eCH_SR_SIZE))
				mError = true;

			if (!SplitOnTwo(0x05, eCH_SR_SIZE, eCH_SR_HUBINFO, eCH_SR_TO, false))
				mError = true;

			if (SplitOnTwo(0x05, eCH_SR_HUBINFO, eCH_SR_SIZE, eCH_SR_HUBINFO)) {
				if (!SplitOnTwo(' ', eCH_SR_SIZE, eCH_SR_SIZE, eCH_SR_SLOTS))
					mError = true;

				if (!SplitOnTwo('/', eCH_SR_SLOTS, eCH_SR_SL_FR, eCH_SR_SL_TO))
					mError = true;
			} else {
				SetChunk(eCH_SR_SIZE, 0, 0);
			}

			break;

		case eDCO_BAN:
			if (!SplitOnTwo(mKWSize, '$', eCH_NB_NICK, eCH_NB_REASON))
				mError = true;

			break;

		case eDCO_TBAN:
			if (!SplitOnTwo(mKWSize, '$', eCH_NB_NICK, eCH_NB_TIME))
				mError = true;

			if (!SplitOnTwo('$', eCH_NB_TIME, eCH_NB_TIME, eCH_NB_REASON))
				mError = true;

			break;

		default:
			break;
	}

	mModified = false; // reset modified flag
	return mError;
}