예제 #1
0
void RSSManager::load(SimpleXML& aXml)
{
	{
		CFlyLock(g_csFeed);
		aXml.resetCurrentChild();
		if (aXml.findChild("Rss"))
		{
			aXml.stepIn();
			while (aXml.findChild("Feed"))
			{
				const string& realURL = aXml.getChildData();
				if (realURL.empty())
				{
					continue;
				}
				const string& sourceName = aXml.getChildAttrib("Name");
				const string& codeingType = aXml.getChildAttrib("Codeing");
				
				const size_t iCodeingType = Util::toInt(codeingType);
				
				// add only unique RSS feeds
				addNewFeed(realURL, sourceName, getCodeing(iCodeingType));
			}
			aXml.stepOut();
		}
	}
	updateFeeds();
}
예제 #2
0
void VideoPreview::SetDownloadSegment(int64_t pos, int64_t size)
{
	CFlyLock(csDownloadItems);
	
	
	int64_t posNew = pos;
	int64_t sizeNew = size;
	if (!_fileRoadMap->GetInsertableSizeAndPos(posNew, sizeNew))
	{
		bool iFound = false;
		MapVItems::const_iterator i = _ask2Download.cbegin();
		while (i != _ask2Download.cend()) // Это цикл должен убить все скачанные из заказа не зависимо от найденных
		{
			if (IsAvailableData(i->getPosition(), i->getSize()))
				i = _ask2Download.erase(i);
			else
			{
				if (i->getPosition() == posNew)
					iFound = true;
				++i;
			}
		}
		if (iFound)
			return;
			
		LocalArray<CHAR, 256>buff;
		_snprintf(buff.data(), buff.size(), "ask segment: %s / %s", Util::toString(posNew).c_str(), Util::toString(sizeNew).c_str());
		string loginfo = buff.data();
		VideoPreview::getInstance()->AddLogInfo(loginfo);
		_ask2Download.push_back(FileRoadMapItem(posNew, sizeNew));
	}
}
예제 #3
0
/*
 * 1) Pass through labels w/o "xn--" prefix unaltered.
 * 2) Strip "xn--" prefix and pass to punycode_decode()
 * 3) Repeat for all labels with "xn--" prefix.
 * 4) Collect Unicode strings and convert to original codepage.
 */
BOOL IDNA_convert_from_ACE (
          char   *name,    /* IN/OUT: ACE/native ASCII name */
          size_t *size)    /* IN:     ACE raw string length */
{                          /* OUT:    ASCII decoded length */
  char  *in_name = name;
  char **labels;
  int    i;
  BOOL   rc = FALSE;

  CFlyLock(g_critSection);

  labels  = split_labels (name);

  for (i = 0; labels[i]; i++)
  {
    const char *ascii = NULL;
    const char *label = labels[i];

    if (!strncmp(label,"xn--",4) && label[4])
    {
      ascii = convert_from_ACE (label+4);
      if (!ascii)
         goto quit;
    }
    name += sprintf_s (name, MAX_COPY_SIZE, "%s.", ascii ? ascii : label);
  }
  if (name > in_name)
     name--;
  *name = '\0';
  *size = name - in_name;
  rc = TRUE;

quit:
  return rc;
}
예제 #4
0
bool
RSSManager::removeFeedAt(size_t pos)
{
	bool bRes = false;
	CFlyLock(g_csFeed); // [+] IRainman fix.
	if (pos < g_feeds.size())
	{
		RSSFeed* feed = g_feeds.at(pos);
		if (feed)
		{
			auto i = g_feeds.cbegin();
			for (; i != g_feeds.cend(); ++i)
			{
				if (*i == feed)
				{
					break;
				}
			}
			if (i != g_feeds.cend())
			{
				g_feeds.erase(i);
				bRes = true;
			}
		}
	}
	return bRes;
}
예제 #5
0
void  TraceManager::print(const string& msg)
{
	DWORD tid;
	char buf[21];
	
	time_t now = time(NULL);
//+BugMaster: fix
	if (!strftime(buf, 21, "%Y-%m-%d %H:%M:%S ", localtime(&now)))
	{
		strcpy(buf, "xxxx-xx-xx xx:xx:xx ");
	}
//-BugMaster: fix

	tid = GetCurrentThreadId();
	
	CFlyLock(cs);
	
	try
	{
		f->write(buf + string(indents[tid], ' ') + msg + "\r\n");
	}
	catch (const FileException&)
	{
		// ...
	}
	
}
예제 #6
0
bool VideoPreview::IsAvailableData(int64_t pos, int64_t size) const
{
	CFlyLock(csRoadMap);
	if (_fileRoadMap.get() != NULL)
		return _fileRoadMap->IsAvaiable(pos, size);
		
	return false;
}
예제 #7
0
void VideoPreview::addSegment(int64_t start, int64_t size)
{
	CFlyLock(csRoadMap);
	_fileRoadMap->AddSegment(start, size);
	if (!_viewStarted && ::IsWindow(_callWnd))
		_ServerStartedReportNoWait(_callWnd);
	_viewStarted = true;
}
예제 #8
0
void VideoPreview::_AddLogInfo(const std::string& loginfo)
{
	CFlyLock(csInfo);
	if (_logInfoData.size() >= MAX_INFO_STACK_COUNT)
		_logInfoData.pop();
		
	_logInfoData.push(loginfo);
	_SendLogInfo();
}
예제 #9
0
void VideoPreview::on(QueueManagerListener::FileMoved, const string& n) noexcept
{
	if (n.compare(_currentFilePreview) == 0)
	{
		CFlyLock(csRoadMap);
		m_tempFilename = n;
		_canUseFile = true;
		LocalArray<CHAR, 256>buff;
		_snprintf(buff.data(), buff.size(), "All file %s now available", n.c_str());
		VideoPreview::getInstance()->AddLogInfo(buff.data());
		
	}
}
예제 #10
0
bool VideoPreview::GetNextLogItem(string& outString)
{
	CFlyLock(csInfo);
	if (!_logInfoData.empty())
	{
		outString = _logInfoData.front();
		_logInfoData.pop();
	}
	else
		outString.clear();
		
	return !outString.empty();
}
예제 #11
0
void RSSManager::save(SimpleXML& aXml)
{
	CFlyLock(g_csFeed);
	aXml.addTag("Rss");
	aXml.stepIn();
	for (auto i = g_feeds.cbegin(); i != g_feeds.cend(); ++i)
	{
		aXml.addTag("Feed", (*i)->getFeedURL());
		aXml.addChildAttrib("Name", (*i)->getSource());
		const size_t codeingT = GetCodeingByString((*i)->getCodeing());
		aXml.addChildAttrib("Codeing", Util::toString(codeingT));
	}
	aXml.stepOut();
}
예제 #12
0
void RSSManager::updateFeeds()
{
	dcassert(!ClientManager::isShutdown());
	if (!ClientManager::isShutdown())
	{
		{
			CFlyLock(g_csFeed);
			if (g_feeds.empty()) // [+] IRainman fix.
				return;
		}
		if (RSSManager::isValidInstance())
		{
			RSSManager::getInstance()->addTask(CHECK_NEWS);
		}
	}
}
예제 #13
0
RSSFeed*
RSSManager::addNewFeed(const string& url, const string& name, const string& codeing, bool bUpdateFeeds/* = false */)
{
	CFlyLock(g_csFeed); // [+] IRainman fix.
	if (!hasRSSFeed(url, name))
	{
		RSSFeed* rFeed = new RSSFeed(url, name, codeing);
		g_feeds.push_back(rFeed);
		if (bUpdateFeeds)
		{
			updateFeeds();
		}
		
		return rFeed;
	}
	return nullptr;
}
예제 #14
0
RSSManager::~RSSManager(void)
{
	TimerManager::getInstance()->removeListener(this);
	waitShutdown();
	{
		CFlyFastLock(g_csNews);
		for (auto j = g_newsList.cbegin(); j != g_newsList.cend(); ++j)
		{
			delete *j;
		}
	}
	{
		CFlyLock(g_csFeed);
		for (auto i = g_feeds.cbegin(); i != g_feeds.cend(); ++i)
		{
			delete *i;
		}
	}
}
예제 #15
0
void
RSSManager::updateAllFeeds()
{
	unsigned int iNewNews = 0;
	NewsList l_fire_added_array;
	{
		CFlyLock(g_csFeed); // [+] IRainman fix.
		for (auto i = g_feeds.cbegin(); i != g_feeds.cend(); ++i)
		{
			if ((*i)->UpdateFeedNewXML())
			{
				const RSSFeed::RSSItemList& list = (*i)->getNewsList();
				for (auto j = list.cbegin(); j != list.cend(); ++j)
				{
					const RSSItem *l_item = new RSSItem(*j);
					CFlyFastLock(g_csNews);
					if (canAdd(l_item))
					{
						g_newsList.push_back(l_item);
						l_fire_added_array.push_back(l_item);
					}
					else
					{
						safe_delete(l_item);
					}
				}
				iNewNews += list.size();
			}
		}
	}
	for (auto i = l_fire_added_array.begin(); i !=  l_fire_added_array.end(); ++i)
	{
		fly_fire1(RSSListener::Added(), *i);
	}
	
	if (iNewNews)
	{
		fly_fire1(RSSListener::NewRSS(), iNewNews);
	}
}
예제 #16
0
size_t VideoPreview::getDownloadItems(int64_t blockSize, vector<int64_t>& ItemsArray)
{
	CFlyLock(csDownloadItems);
	MapVItems::const_iterator i = _ask2Download.cbegin();
	while (i != _ask2Download.cend())
	{
		if (IsAvailableData(i->getPosition(), i->getSize()))
			i = _ask2Download.erase(i);
		else
		{
			int64_t startPos = ((i->getPosition()) / blockSize) * blockSize;
			const int64_t endPos = ((i->getPosition() + i->getSize()) / blockSize) * blockSize;
			for (; startPos <= endPos; startPos += blockSize)
				ItemsArray.push_back(startPos);
				
			++i;
		}
		
	}
	
	_ask2Download.clear();
	return ItemsArray.size();
}
예제 #17
0
/*
 * E.g. convert "www.tromsø.no" to ACE:
 *
 * 1) Convert each label separately. "www", "tromsø" and "no"
 * 2) "tromsø" -> u+0074 u+0072 u+006F u+006D u+0073 u+00F8
 * 3) Pass this through 'punycode_encode()' which gives "troms-zua".
 * 4) Repeat for all labels with non-ASCII letters.
 * 5) Prepending "xn--" for each converted label gives "www.xn--troms-zua.no".
 *
 * E.g. 2:
 *   "www.blåbærsyltetøy.no" -> "www.xn--blbrsyltety-y8aO3x.no"
 *
 * Ref. http://www.imc.org/idna/do-idna.cgi
 *      http://www.norid.no/domenenavnbaser/ace/ace_technical.en.html
 */
BOOL IDNA_convert_to_ACE (
          char  *name,   /* IN/OUT: native ASCII/ACE name */
          size_t *size)   /* IN:     length of name buf */
{                         /* OUT:    ACE encoded length */
  const  BYTE *p;
  const  char *ace;
  char  *in_name = name;
  char **labels;
  int    i;
  size_t len = 0;
  BOOL   rc = FALSE;
  CFlyLock(g_critSection);
  labels = split_labels (name);

  for (i = 0; labels[i]; i++)
  {
    ace = NULL;
    for (p = (const BYTE*)labels[i]; *p; p++)
        if (*p >= 0x80)  /* !! this may not be true for all codepages */
        {
          ace = convert_to_ACE (labels[i]);
          if (!ace)
             goto quit;
          break;
        }

    if (ace)
    {
      if (len + 5 + strlen(ace) > *size)
      {
#ifdef IDNA_DEBUG_ENABLED
        IDNA_DEBUG ("input length exceeded\n");
#endif
		dcassert(0);
        goto quit;
      }
	  name += sprintf (name, "xn--%s.", ace);
    }
    else  /* pass through unchanged */
    {
      if (len + 1 + strlen(labels[i]) > *size)
      {
#ifdef IDNA_DEBUG_ENABLED
        IDNA_DEBUG ("input length exceeded\n");
#endif
		dcassert(0);
        goto quit;
      }
      name += sprintf (name, "%s.", labels[i]);
    }
  }
  if (in_name > name)   /* drop trailing '.' */
     name--;
  len = name - in_name;
  *name = '\0';
  *size = len;
#ifdef IDNA_DEBUG_ENABLED
  IDNA_DEBUG ("IDNA_convert_to_ACE: '%s', %d bytes\n", in_name, int(len));
#endif
  rc = TRUE;
quit:
  return rc;
}
예제 #18
0
void VideoPreview::setFileAlreadyDownloaded()
{
	CFlyLock(csRoadMap);
	_fileRoadMap->AddSegment(0, _previewFileSize);
}
예제 #19
0
bool VideoPreview::checkEvents()
{
	while (m_video_task_semaphore.wait())
	{
		pair<Tasks, TaskData*> p;
		p.second = 0;
		{
			CFlyLock(cs);
			dcassert(!m_tasks.empty());
			if (m_tasks.empty())
				return false;
			p = m_tasks.front();
			m_tasks.pop_front();
		}
		try
		{
			if (failed && p.first != SHUTDOWN)
			{
				dcdebug("VideoPreview: New command when already failed: %d\n", p.first);
				fail(STRING(DISCONNECTED));
				goto check_events_clean_task_data; // [+] IRainman fix.
				// delete p.second; continue; [-] IRainman fix.
			}
			
			switch (p.first)
			{
				case START_PREVIEW_SERVER:
				{
					if (!IsServerStarted())
					{
						_StartServer();
					}
				}
				break;
				case STOP_PREVIEW_SERVER:
				{
					if (IsServerStarted())
						_StopServer();
				}
				break;
				case ADD_LOG_INFO:
				{
					_AddLogInfo(p.second->m_logInfo);
				}
				break;
				case SHUTDOWN:
				{
					if (IsServerStarted())
						_StopServer();
				}
				return false;
			}
			// delete p.second; [-] IRainman fix.
		}
		catch (const Exception& e)
		{
			// delete p.second; [-] IRainman fix.
			fail(e.getError());
		}
		// [+] IRainman fix.
check_events_clean_task_data:
		delete p.second;
		// [~] IRainman fix.
	}
	return true;
}