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(); }
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)); } }
/* * 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; }
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; }
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&) { // ... } }
bool VideoPreview::IsAvailableData(int64_t pos, int64_t size) const { CFlyLock(csRoadMap); if (_fileRoadMap.get() != NULL) return _fileRoadMap->IsAvaiable(pos, size); return false; }
void VideoPreview::addSegment(int64_t start, int64_t size) { CFlyLock(csRoadMap); _fileRoadMap->AddSegment(start, size); if (!_viewStarted && ::IsWindow(_callWnd)) _ServerStartedReportNoWait(_callWnd); _viewStarted = true; }
void VideoPreview::_AddLogInfo(const std::string& loginfo) { CFlyLock(csInfo); if (_logInfoData.size() >= MAX_INFO_STACK_COUNT) _logInfoData.pop(); _logInfoData.push(loginfo); _SendLogInfo(); }
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()); } }
bool VideoPreview::GetNextLogItem(string& outString) { CFlyLock(csInfo); if (!_logInfoData.empty()) { outString = _logInfoData.front(); _logInfoData.pop(); } else outString.clear(); return !outString.empty(); }
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(); }
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); } } }
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; }
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; } } }
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); } }
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(); }
/* * 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; }
void VideoPreview::setFileAlreadyDownloaded() { CFlyLock(csRoadMap); _fileRoadMap->AddSegment(0, _previewFileSize); }
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; }