bool PrePostProcessor::HistoryEdit(IDList* pIDList, EEditAction eAction, int iOffset, const char* szText) { bool bOK = false; DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue(); for (IDList::iterator itID = pIDList->begin(); itID != pIDList->end(); itID++) { int iID = *itID; for (HistoryList::iterator itHistory = pDownloadQueue->GetHistoryList()->begin(); itHistory != pDownloadQueue->GetHistoryList()->end(); itHistory++) { HistoryInfo* pHistoryInfo = *itHistory; if (pHistoryInfo->GetID() == iID) { switch (eAction) { case eaHistoryDelete: HistoryDelete(pDownloadQueue, itHistory, pHistoryInfo); break; case eaHistoryReturn: case eaHistoryProcess: HistoryReturn(pDownloadQueue, itHistory, pHistoryInfo, eAction == eaHistoryProcess); break; case eaHistorySetParameter: HistorySetParameter(pHistoryInfo, szText); break; default: // nothing, just to avoid compiler warning break; } bOK = true; break; } } } if (bOK) { SaveQueue(pDownloadQueue); } g_pQueueCoordinator->UnlockQueue(); return bOK; }
bool HistoryCoordinator::EditList(DownloadQueue* pDownloadQueue, IDList* pIDList, DownloadQueue::EEditAction eAction, int iOffset, const char* szText) { bool bOK = false; PrepareEdit(pDownloadQueue, pIDList, eAction); for (IDList::iterator itID = pIDList->begin(); itID != pIDList->end(); itID++) { int iID = *itID; for (HistoryList::iterator itHistory = pDownloadQueue->GetHistory()->begin(); itHistory != pDownloadQueue->GetHistory()->end(); itHistory++) { HistoryInfo* pHistoryInfo = *itHistory; if (pHistoryInfo->GetID() == iID) { bOK = true; switch (eAction) { case DownloadQueue::eaHistoryDelete: case DownloadQueue::eaHistoryFinalDelete: HistoryDelete(pDownloadQueue, itHistory, pHistoryInfo, eAction == DownloadQueue::eaHistoryFinalDelete); break; case DownloadQueue::eaHistoryReturn: case DownloadQueue::eaHistoryProcess: HistoryReturn(pDownloadQueue, itHistory, pHistoryInfo, eAction == DownloadQueue::eaHistoryProcess); break; case DownloadQueue::eaHistoryRedownload: HistoryRedownload(pDownloadQueue, itHistory, pHistoryInfo, false); break; case DownloadQueue::eaHistorySetParameter: bOK = HistorySetParameter(pHistoryInfo, szText); break; case DownloadQueue::eaHistorySetCategory: bOK = HistorySetCategory(pHistoryInfo, szText); break; case DownloadQueue::eaHistorySetName: bOK = HistorySetName(pHistoryInfo, szText); break; case DownloadQueue::eaHistorySetDupeKey: case DownloadQueue::eaHistorySetDupeScore: case DownloadQueue::eaHistorySetDupeMode: case DownloadQueue::eaHistorySetDupeBackup: HistorySetDupeParam(pHistoryInfo, eAction, szText); break; case DownloadQueue::eaHistoryMarkBad: g_pDupeCoordinator->HistoryMark(pDownloadQueue, pHistoryInfo, NZBInfo::ksBad); break; case DownloadQueue::eaHistoryMarkGood: g_pDupeCoordinator->HistoryMark(pDownloadQueue, pHistoryInfo, NZBInfo::ksGood); break; case DownloadQueue::eaHistoryMarkSuccess: g_pDupeCoordinator->HistoryMark(pDownloadQueue, pHistoryInfo, NZBInfo::ksSuccess); break; default: // nothing, just to avoid compiler warning break; } break; } } } if (bOK) { pDownloadQueue->Save(); } return bOK; }
void HistoryBinCommand::Execute() { SNZBHistoryRequest HistoryRequest; if (!ReceiveRequest(&HistoryRequest, sizeof(HistoryRequest))) { return; } SNZBHistoryResponse HistoryResponse; memset(&HistoryResponse, 0, sizeof(HistoryResponse)); HistoryResponse.m_MessageBase.m_iSignature = htonl(NZBMESSAGE_SIGNATURE); HistoryResponse.m_MessageBase.m_iStructSize = htonl(sizeof(HistoryResponse)); HistoryResponse.m_iEntrySize = htonl(sizeof(SNZBHistoryResponseEntry)); char* buf = NULL; int bufsize = 0; // Make a data structure and copy all the elements of the list into it DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue(); // calculate required buffer size for nzbs int iNrEntries = pDownloadQueue->GetHistoryList()->size(); bufsize += iNrEntries * sizeof(SNZBHistoryResponseEntry); for (HistoryList::iterator it = pDownloadQueue->GetHistoryList()->begin(); it != pDownloadQueue->GetHistoryList()->end(); it++) { HistoryInfo* pHistoryInfo = *it; char szNicename[1024]; pHistoryInfo->GetName(szNicename, sizeof(szNicename)); bufsize += strlen(szNicename) + 1; // align struct to 4-bytes, needed by ARM-processor (and may be others) bufsize += bufsize % 4 > 0 ? 4 - bufsize % 4 : 0; } buf = (char*) malloc(bufsize); char* bufptr = buf; // write nzb entries for (HistoryList::iterator it = pDownloadQueue->GetHistoryList()->begin(); it != pDownloadQueue->GetHistoryList()->end(); it++) { HistoryInfo* pHistoryInfo = *it; SNZBHistoryResponseEntry* pListAnswer = (SNZBHistoryResponseEntry*) bufptr; pListAnswer->m_iID = htonl(pHistoryInfo->GetID()); pListAnswer->m_iKind = htonl((int)pHistoryInfo->GetKind()); pListAnswer->m_tTime = htonl((int)pHistoryInfo->GetTime()); char szNicename[1024]; pHistoryInfo->GetName(szNicename, sizeof(szNicename)); pListAnswer->m_iNicenameLen = htonl(strlen(szNicename) + 1); if (pHistoryInfo->GetKind() == HistoryInfo::hkNZBInfo) { NZBInfo* pNZBInfo = pHistoryInfo->GetNZBInfo(); unsigned long iSizeHi, iSizeLo; Util::SplitInt64(pNZBInfo->GetSize(), &iSizeHi, &iSizeLo); pListAnswer->m_iSizeLo = htonl(iSizeLo); pListAnswer->m_iSizeHi = htonl(iSizeHi); pListAnswer->m_iFileCount = htonl(pNZBInfo->GetFileCount()); pListAnswer->m_iParStatus = htonl(pNZBInfo->GetParStatus()); pListAnswer->m_iScriptStatus = htonl(pNZBInfo->GetScriptStatus()); } else if (pHistoryInfo->GetKind() == HistoryInfo::hkUrlInfo) { UrlInfo* pUrlInfo = pHistoryInfo->GetUrlInfo(); pListAnswer->m_iUrlStatus = htonl(pUrlInfo->GetStatus()); } bufptr += sizeof(SNZBHistoryResponseEntry); strcpy(bufptr, szNicename); bufptr += ntohl(pListAnswer->m_iNicenameLen); // align struct to 4-bytes, needed by ARM-processor (and may be others) if ((size_t)bufptr % 4 > 0) { pListAnswer->m_iNicenameLen = htonl(ntohl(pListAnswer->m_iNicenameLen) + 4 - (size_t)bufptr % 4); memset(bufptr, 0, 4 - (size_t)bufptr % 4); //suppress valgrind warning "uninitialized data" bufptr += 4 - (size_t)bufptr % 4; } } g_pQueueCoordinator->UnlockQueue(); HistoryResponse.m_iNrTrailingEntries = htonl(iNrEntries); HistoryResponse.m_iTrailingDataLength = htonl(bufsize); // Send the request answer send(m_iSocket, (char*) &HistoryResponse, sizeof(HistoryResponse), 0); // Send the data if (bufsize > 0) { send(m_iSocket, buf, bufsize, 0); } free(buf); }