/*! \brief Counts images in a list of subtrees \param paths List of dirs */ void ImageScanThread::CountFiles(QStringList paths) { // Get exclusions as comma-seperated list using glob chars * and ? QString excPattern = gCoreContext->GetSetting("GalleryIgnoreFilter", ""); // Combine into a single regexp excPattern.replace(".", "\\."); // Preserve "." excPattern.replace("*", ".*"); // Convert glob wildcard "*" excPattern.replace("?", "."); // Convert glob wildcard "?" excPattern.replace(",", "|"); // Convert list to OR's QString pattern = QString("^(%1)$").arg(excPattern); m_exclusions = QRegExp(pattern); LOG(VB_FILE, LOG_DEBUG, QString("%1: Exclude regexp is \"%2\"") .arg(objectName(), pattern)); QMutexLocker locker(&m_mutexProgress); m_progressCount = 0; m_progressTotalCount = 0; // Release lock to broadcast locker.unlock(); BroadcastStatus("SCANNING"); locker.relock(); // Use global image filters QDir dir = m_dir; foreach(const QString &sgDir, paths) { dir.cd(sgDir); CountTree(dir); }
DWORD CNdasIXBcast::ThreadStart(HANDLE hStopEvent) { if (0 == m_NDFSVersion.wMajor && 0 == m_NDFSVersion.wMinor) { return 1; } HANDLE waitHandles[] = { hStopEvent, m_sockAddrChangeNotifier.GetChangeEvent()}; const DWORD nWaitHandles = RTL_NUMBER_OF(waitHandles); // CTask::Initialized called? XTLASSERT(NULL != waitHandles[0]); // m_sockAddrChangeNotifier is initialized? XTLASSERT(NULL != waitHandles[1]); // // Initial bind // ResetBind(hStopEvent); // // initial LPX socket address list is attained // DWORD dwTimeout = 1000; // broadcast interval while (TRUE) { DWORD waitResult = ::WaitForMultipleObjects( nWaitHandles, waitHandles, FALSE, dwTimeout); if (WAIT_OBJECT_0 == waitResult) { return 0; } else if (WAIT_OBJECT_0 + 1 == waitResult) { // reset bind ResetBind(hStopEvent); } else if (WAIT_TIMEOUT == waitResult) { BroadcastStatus(); } else { XTLTRACE2(NDASSVC_IX, TRACE_LEVEL_ERROR, "WaitForMultipleObject failed, waitResult=%d.\n", waitResult); XTLASSERT(FALSE); } } }
int __cdecl CYahooProto::SetAwayMsg(int status, const PROTOCHAR* msg) { char *c = msg && msg[0] ? mir_utf8encodeT(msg) : NULL; debugLogA("[YahooSetAwayMessage] Status: %S, Msg: %s", pcli->pfnGetStatusModeDescription(status, 0), (char*)c); if (!m_bLoggedIn) { if (m_iStatus == ID_STATUS_OFFLINE) { debugLogA("[YahooSetAwayMessage] WARNING: WE ARE OFFLINE!"); mir_free(c); return 1; } else { if (m_startMsg) free(m_startMsg); m_startMsg = c ? strdup(c) : NULL; mir_free(c); return 0; } } /* need to tell ALL plugins that we are changing status */ BroadcastStatus(status); if (m_startMsg) free(m_startMsg); /* now decide what we tell the server */ if (c != 0) { m_startMsg = strdup(c); if (status == ID_STATUS_ONLINE) { set_status(YAHOO_CUSTOM_STATUS, c, 0); } else if (status != ID_STATUS_INVISIBLE) { set_status(YAHOO_CUSTOM_STATUS, c, 1); } } else { set_status(status, NULL, 0); m_startMsg = NULL; } mir_free(c); return 0; }
DWORD CNdasIXBcast::OnTaskStart() { if (0 == m_NDFSVersion.wMajor && 0 == m_NDFSVersion.wMinor) { return 0; } HANDLE hEvents[2]; hEvents[0] = m_hTaskTerminateEvent; hEvents[1] = m_sockAddrChangeNotifier.GetChangeEvent(); // CTask::Initialized called? _ASSERTE(NULL != hEvents[0]); // m_sockAddrChangeNotifier is initialized? _ASSERTE(NULL != hEvents[1]); // // Initial bind // ResetBind(); // // initial LPX socket address list is attained // DWORD dwTimeout = 1000; // broadcast interval while (1) { DWORD dwWaitResult = ::WaitForMultipleObjects( 2, hEvents, FALSE, dwTimeout); if (WAIT_OBJECT_0 == dwWaitResult) { return 0; } else if (WAIT_OBJECT_0 + 1 == dwWaitResult) { // reset bind ResetBind(); } else if (WAIT_TIMEOUT == dwWaitResult) { BroadcastStatus(); } else { DPErrorEx(_FT("Unexpected wait result %d: "), dwWaitResult); _ASSERTE(FALSE); } } }
int __cdecl CYahooProto::SetStatus(int iNewStatus) { LOG(("[SetStatus] New status %S", pcli->pfnGetStatusModeDescription(iNewStatus, 0))); if (iNewStatus == ID_STATUS_OFFLINE) { logout(); } else if (!m_bLoggedIn) { DBVARIANT dbv; int err = 0; char errmsg[80]; if (m_iStatus == ID_STATUS_CONNECTING) return 0; YAHOO_utils_logversion(); /* * Load Yahoo ID from the database. */ if (!getString(YAHOO_LOGINID, &dbv)) { if (lstrlenA(dbv.pszVal) > 0) lstrcpynA(m_yahoo_id, dbv.pszVal, 255); else err++; db_free(&dbv); } else { ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); err++; } if (err) lstrcpynA(errmsg, Translate("Please enter your Yahoo ID in Options/Network/Yahoo"), 80); else { if (!getString(YAHOO_PASSWORD, &dbv)) { if (lstrlenA(dbv.pszVal) > 0) lstrcpynA(m_password, dbv.pszVal, 255); else err++; db_free(&dbv); } else { ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); err++; } if (err) lstrcpynA(errmsg, Translate("Please enter your Yahoo password in Options/Network/Yahoo"), 80); } if (err != 0) { BroadcastStatus(ID_STATUS_OFFLINE); ShowError(TranslateT("Yahoo Login Error"), _A2T(errmsg)); return 0; } if (iNewStatus == ID_STATUS_OFFLINE) iNewStatus = ID_STATUS_ONLINE; FREE(m_pw_token); // No Token yet. if (!getString(YAHOO_PWTOKEN, &dbv)) { if (lstrlenA(dbv.pszVal) > 0) m_pw_token = strdup(dbv.pszVal); db_free(&dbv); } m_startStatus = iNewStatus; //reset the unread email count. We'll get a new packet since we are connecting. m_unreadMessages = 0; BroadcastStatus(ID_STATUS_CONNECTING); iNewStatus = (iNewStatus == ID_STATUS_INVISIBLE) ? YAHOO_STATUS_INVISIBLE : YAHOO_STATUS_AVAILABLE; ForkThread(&CYahooProto::server_main, (void *)iNewStatus); } else if (iNewStatus == ID_STATUS_INVISIBLE) { /* other normal away statuses are set via setaway */ BroadcastStatus(iNewStatus); set_status(m_iStatus, NULL, (m_iStatus != ID_STATUS_ONLINE) ? 1 : 0); } else { /* clear out our message just in case, STUPID AA! */ FREE(m_startMsg); /* now tell miranda that we are Online, don't tell Yahoo server yet though! */ BroadcastStatus(iNewStatus); } return 0; }
void __cdecl CYahooProto::server_main(void *empty) { enum yahoo_status status = (enum yahoo_status) (int)empty; time_t lLastPing, lLastKeepAlive, t; YList *l; NETLIBSELECTEX nls = { 0 }; int recvResult, ridx = 0, widx = 0, i; debugLogA("Server Thread Starting status: %d", status); do_yahoo_debug = YAHOO_LOG_DEBUG; yahoo_set_log_level((yahoo_log_level)do_yahoo_debug); poll_loop = 1; /* set this so we start looping */ ext_login(status); lLastKeepAlive = lLastPing = time(NULL); while (poll_loop) { nls.cbSize = sizeof(nls); nls.dwTimeout = 1000; // 1000 millis = 1 sec FD_ZERO(&nls.hReadStatus); FD_ZERO(&nls.hWriteStatus); FD_ZERO(&nls.hExceptStatus); nls.hExceptConns[0] = NULL; ridx = 0; widx = 0; for (l = m_connections; l;) { struct _conn *c = (_conn *)l->data; //LOG(("Connection tag:%d id:%d fd:%d remove:%d", c->tag, c->id, c->fd, c->remove)); if (c->remove) { YList *n = y_list_next(l); //LOG(("Removing id:%d fd:%d tag:%d", c->id, c->fd, c->tag)); m_connections = y_list_remove_link(m_connections, l); y_list_free_1(l); FREE(c); l = n; } else { if (c->cond & YAHOO_INPUT_READ) { //LOG(("[YAHOO_INPUT_READ] Waiting on read. Tag: %d fd: %d", c->tag, c->fd )); nls.hReadConns[ridx++] = (HANDLE)c->fd; } if (c->cond & YAHOO_INPUT_WRITE) { //LOG(("[YAHOO_INPUT_WRITE] Waiting on write. Tag: %d fd: %d", c->tag, c->fd )); nls.hWriteConns[widx++] = (HANDLE)c->fd; } l = y_list_next(l); } } //debugLogA("[Yahoo_Server] ridx:%d widx:%d", ridx, widx); nls.hReadConns[ridx] = NULL; nls.hWriteConns[widx] = NULL; if (m_connections == NULL) { debugLogA("Last connection closed."); break; } recvResult = CallService(MS_NETLIB_SELECTEX, 0, (LPARAM)&nls); /* do the timer check */ if (m_id > 0) { #ifdef HTTP_GATEWAY //debugLogA("HTTPGateway: %d", iHTTPGateway); if (!iHTTPGateway) { #endif t = time(NULL); if (m_bLoggedIn && t - lLastKeepAlive >= 60) { LOG(("[TIMER] Sending a keep alive message")); yahoo_keepalive(m_id); lLastKeepAlive = t; } if (m_bLoggedIn && t - lLastPing >= 3600) { LOG(("[TIMER] Sending ping")); yahoo_send_ping(m_id); lLastPing = t; } #ifdef HTTP_GATEWAY } else { debugLogA("[SERVER] Got packets: %d", ylad->rpkts); if ( m_bLoggedIn && ( (ylad->rpkts > 0 && (time(NULL) - lLastSend) >=3) || ( (time(NULL) - lLastSend) >= 13)) ) { LOG(("[TIMER] Sending an idle message...")); yahoo_send_idle_packet(m_id); } // // need to sleep, cause netlibselectex is too fast? // SleepEx(500, TRUE); } #endif } /* do the timer check ends */ for (l = m_connections; l; l = y_list_next(l)) { struct _conn *c = (_conn *)l->data; if (c->remove) continue; /* are we waiting for a Read request? */ if (c->cond & YAHOO_INPUT_READ) { for (i = 0; i < ridx; i++) { if ((HANDLE)c->fd == nls.hReadConns[i]) { if (nls.hReadStatus[i]) { //LOG(("[YAHOO_INPUT_READ] Read Ready. Tag: %d fd: %d", c->tag, c->fd )); yahoo_callback(c, YAHOO_INPUT_READ); } }//if c->fd= }//for i = 0 } /* are we waiting for a Write request? */ if (c->cond & YAHOO_INPUT_WRITE) { for (i = 0; i < widx; i++) { if ((HANDLE)c->fd == nls.hWriteConns[i]) { if (nls.hWriteStatus[i]) { //LOG(("[YAHOO_INPUT_WRITE] Write ready. Tag: %d fd: %d", c->tag, c->fd )); yahoo_callback(c, YAHOO_INPUT_WRITE); } } // if c->fd == nls }// for i = 0 } }// for l=connections /* Check for Miranda Exit Status */ if (Miranda_Terminated()) { debugLogA("Miranda Exiting... stopping the loop."); break; } } debugLogA("Exited loop"); /* cleanup the data stuff and close our connection handles */ while (m_connections) { YList *tmp = m_connections; struct _conn * c = (_conn *)m_connections->data; Netlib_CloseHandle((HANDLE)c->fd); FREE(c); m_connections = y_list_remove_link(m_connections, m_connections); y_list_free_1(tmp); } yahoo_close(m_id); m_bLoggedIn = FALSE; m_status = YAHOO_STATUS_OFFLINE; m_id = 0; /* now set ourselves to offline */ BroadcastStatus(ID_STATUS_OFFLINE); logoff_buddies(); debugLogA("Server thread ending"); }