void CJabberProto::OnIqResultGetCollection(HXML iqNode, CJabberIqInfo*) { if ( mir_tstrcmp( xmlGetAttrValue(iqNode, _T("type")), _T("result"))) return; HXML chatNode = xmlGetChild(iqNode, "chat"); if (!chatNode || mir_tstrcmp( xmlGetAttrValue(chatNode, _T("xmlns")), JABBER_FEAT_ARCHIVE)) return; const TCHAR* start = xmlGetAttrValue(chatNode, _T("start")); const TCHAR* with = xmlGetAttrValue(chatNode, _T("with")); if (!start || !with) return; MCONTACT hContact = HContactFromJID(with); time_t tmStart = str2time(start); if (hContact == 0 || tmStart == 0) return; _tzset(); for (int nodeIdx = 0; ; nodeIdx++) { HXML itemNode = xmlGetChild(chatNode, nodeIdx); if (!itemNode) break; int from; const TCHAR *itemName = xmlGetName(itemNode); if (!mir_tstrcmp(itemName, _T("to"))) from = DBEF_SENT; else if (!mir_tstrcmp(itemName, _T("from"))) from = 0; else continue; HXML body = xmlGetChild(itemNode, "body"); if (!body) continue; const TCHAR *tszBody = xmlGetText(body); const TCHAR *tszSecs = xmlGetAttrValue(itemNode, _T("secs")); if (!tszBody || !tszSecs) continue; ptrA szEventText( mir_utf8encodeT(tszBody)); DBEVENTINFO dbei = { sizeof(DBEVENTINFO) }; dbei.eventType = EVENTTYPE_MESSAGE; dbei.szModule = m_szModuleName; dbei.cbBlob = (DWORD)strlen(szEventText); dbei.flags = DBEF_READ + DBEF_UTF + from; dbei.pBlob = (PBYTE)(char*)szEventText; dbei.timestamp = tmStart + _ttol(tszSecs) - timezone; if (!IsDuplicateEvent(hContact, dbei)) db_event_add(hContact, &dbei); } }
void CVNSITimers::Action() { #if VDRVERSNUM >= 20301 bool modified; cStateKey timerState; // set thread priority (nice level) SetPriority(1); while (Running()) { if (!m_doScan) { usleep(1000*1000); continue; } m_doScan = false; std::vector<CVNSITimer> timers; { cMutexLock lock(&m_timerLock); timers = m_timers; } cTimers *Timers = cTimers::GetTimersWrite(timerState); if (!Timers) continue; Timers->SetExplicitModify(); modified = false; cStateKey SchedulesStateKey(true); const cSchedules *schedules = cSchedules::GetSchedulesRead(SchedulesStateKey); if (schedules) { for (const cSchedule *schedule = schedules->First(); schedule; schedule = schedules->Next(schedule)) { for (auto &searchTimer : timers) { if (!searchTimer.m_enabled) continue; if (!(searchTimer.m_channelID == schedule->ChannelID())) continue; for (const cEvent *event = schedule->Events()->First(); event; event = schedule->Events()->Next(event)) { std::string title(event->Title()); std::smatch m; std::regex e(Convert(searchTimer.m_search)); if (std::regex_search(title, m, e, std::regex_constants::match_not_null)) { bool duplicate = false; LOCK_RECORDINGS_READ; for (const cRecording *recording = Recordings->First(); recording; recording = Recordings->Next(recording)) { if (recording->Info() != nullptr) { if (strcmp(recording->Info()->Title(), event->Title()) == 0) { if (recording->Info()->ShortText() != nullptr && event->ShortText() != nullptr && strcmp(recording->Info()->ShortText(), event->ShortText()) == 0) { duplicate = true; break; } } } if (abs(difftime(event->StartTime(), recording->Start())) < 300) { duplicate = true; break; } } if (duplicate) continue; if (IsDuplicateEvent(Timers, event)) continue; std::unique_ptr<cTimer> newTimer(new cTimer(event)); Timers->Add(newTimer.release()); modified = true; } } } } } if (modified) Timers->SetModified(); timerState.Remove(modified); SchedulesStateKey.Remove(modified); } #endif }
static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoCount) { // Is it contats history import? MCONTACT hDst = (protoCount == 0) ? convertContact(hContact) : NULL; //system history import // OK to import this chain? if (hDst == INVALID_CONTACT_ID) { nSkippedContacts++; return; } int i = 0, skipAll = 0; DWORD cbAlloc = 4096; BYTE* eventBuf = (PBYTE)mir_alloc(cbAlloc); // Get the start of the event chain HANDLE hEvent = srcDb->FindFirstEvent(hContact); while (hEvent) { int skip = 0; // Copy the event and import it DBEVENTINFO dbei = { sizeof(DBEVENTINFO) }; dbei.cbBlob = srcDb->GetBlobSize(hEvent); if (dbei.cbBlob > cbAlloc) { cbAlloc = dbei.cbBlob + 4096 - dbei.cbBlob % 4096; eventBuf = (PBYTE)mir_realloc(eventBuf, cbAlloc); } dbei.pBlob = eventBuf; if (!srcDb->GetEvent(hEvent, &dbei)) { // check protocols during system history import if (hDst == NULL) { skipAll = 1; for (int i = 0; i < protoCount; i++) if (!strcmp(dbei.szModule, protocol[i]->szModuleName)) { skipAll = 0; break; } skip = skipAll; } // custom filtering if (!skip && nImportOption == IMPORT_CUSTOM) { BOOL sent = (dbei.flags & DBEF_SENT); if (dbei.timestamp < (DWORD)dwSinceDate) skip = 1; if (!skip) { if (hDst) { skip = 1; switch (dbei.eventType) { case EVENTTYPE_MESSAGE: if ((sent ? IOPT_MSGSENT : IOPT_MSGRECV) & nCustomOptions) skip = 0; break; case EVENTTYPE_FILE: if ((sent ? IOPT_FILESENT : IOPT_FILERECV) & nCustomOptions) skip = 0; break; case EVENTTYPE_URL: if ((sent ? IOPT_URLSENT : IOPT_URLRECV) & nCustomOptions) skip = 0; break; default: if ((sent ? IOPT_OTHERSENT : IOPT_OTHERRECV) & nCustomOptions) skip = 0; break; } } else if (!(nCustomOptions & IOPT_SYSTEM)) skip = 1; } if (skip) nSkippedEvents++; } if (!skip) { // Check for duplicate entries if (!IsDuplicateEvent((MCONTACT)hDst, dbei)) { // Add dbevent if (dstDb->AddEvent(hDst, &dbei) != NULL) nMessagesCount++; else AddMessage(LPGENT("Failed to add message")); } else nDupes++; } } if (!(i % 10)) { MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } // skip this chain if needed if (skipAll) break; // Get next event hEvent = srcDb->FindNextEvent(hContact, hEvent); i++; } mir_free(eventBuf); }