Пример #1
0
void CommandScriptController::ExecuteScript(ScriptConfig::Script* script)
{
	PrintMessage(Message::mkInfo, "Executing script %s with command %s", script->GetName(), *m_command);

	SetArgs({script->GetLocation()});

	BString<1024> infoName("script %s with command %s", script->GetName(), *m_command);
	SetInfoName(infoName);

	SetLogPrefix(script->GetDisplayName());
	PrepareParams(script->GetName());

	int exitCode = Execute();

	infoName[0] = 'S'; // uppercase
	SetLogPrefix(nullptr);

	switch (exitCode)
	{
		case COMMANDPROCESS_SUCCESS:
			PrintMessage(Message::mkInfo, "%s successful", *infoName);
			break;

		case COMMANDPROCESS_ERROR:
		case -1: // Execute() returns -1 if the process could not be started (file not found or other problem)
			PrintMessage(Message::mkError, "%s failed", *infoName);
			break;

		default:
			PrintMessage(Message::mkError, "%s failed (terminated with unknown status)", *infoName);
			break;
	}
}
Пример #2
0
void ScanScriptController::ExecuteScript(Options::Script* pScript)
{
	if (!pScript->GetScanScript() || !Util::FileExists(m_szNZBFilename))
	{
		return;
	}

	PrintMessage(Message::mkInfo, "Executing scan-script %s for %s", pScript->GetName(), Util::BaseFileName(m_szNZBFilename));

	SetScript(pScript->GetLocation());
	SetArgs(NULL, false);

	char szInfoName[1024];
	snprintf(szInfoName, 1024, "scan-script %s for %s", pScript->GetName(), Util::BaseFileName(m_szNZBFilename));
	szInfoName[1024-1] = '\0';
	SetInfoName(szInfoName);

	SetLogPrefix(pScript->GetDisplayName());
	m_iPrefixLen = strlen(pScript->GetDisplayName()) + 2; // 2 = strlen(": ");
	PrepareParams(pScript->GetName());

	Execute();

	SetLogPrefix(NULL);
}
Пример #3
0
void QueueScriptController::AddMessage(Message::EKind eKind, const char* szText)
{
	const char* szMsgText = szText + m_iPrefixLen;

	if (!strncmp(szMsgText, "[NZB] ", 6))
	{
		debug("Command %s detected", szMsgText + 6);
		if (!strncmp(szMsgText + 6, "NZBPR_", 6))
		{
			char* szParam = strdup(szMsgText + 6 + 6);
			char* szValue = strchr(szParam, '=');
			if (szValue)
			{
				*szValue = '\0';
				DownloadQueue* pDownloadQueue = DownloadQueue::Lock();
				NZBInfo* pNZBInfo = pDownloadQueue->GetQueue()->Find(m_iID);
				if (pNZBInfo)
				{
					pNZBInfo->GetParameters()->SetParameter(szParam, szValue + 1);
				}
				DownloadQueue::Unlock();
			}
			else
			{
				error("Invalid command \"%s\" received from %s", szMsgText, GetInfoName());
			}
			free(szParam);
		}
		else if (!strncmp(szMsgText + 6, "MARK=BAD", 8))
		{
			m_bMarkBad = true;
			DownloadQueue* pDownloadQueue = DownloadQueue::Lock();
			NZBInfo* pNZBInfo = pDownloadQueue->GetQueue()->Find(m_iID);
			if (pNZBInfo)
			{
				SetLogPrefix(NULL);
				PrintMessage(Message::mkWarning, "Marking %s as bad", m_szNZBName);
				SetLogPrefix(m_pScript->GetDisplayName());
				pNZBInfo->SetMarkStatus(NZBInfo::ksBad);
			}
			DownloadQueue::Unlock();
		}
		else
		{
			error("Invalid command \"%s\" received from %s", szMsgText, GetInfoName());
		}
	}
	else
	{
		ScriptController::AddMessage(eKind, szText);
	}
}
Пример #4
0
void QueueScriptController::ExecuteScript(ScriptConfig::Script* script)
{
	PrintMessage(m_event == QueueScriptCoordinator::qeFileDownloaded ? Message::mkDetail : Message::mkInfo,
		"Executing queue-script %s for %s", script->GetName(), FileSystem::BaseFileName(m_nzbName));

	SetArgs({script->GetLocation()});

	BString<1024> infoName("queue-script %s for %s", script->GetName(), FileSystem::BaseFileName(m_nzbName));
	SetInfoName(infoName);

	SetLogPrefix(script->GetDisplayName());
	m_prefixLen = strlen(script->GetDisplayName()) + 2; // 2 = strlen(": ");
	PrepareParams(script->GetName());

	Execute();

	SetLogPrefix(nullptr);
}
Пример #5
0
void QueueScriptController::ExecuteScript(ScriptConfig::Script* pScript)
{
	PrintMessage(m_eEvent == QueueScriptCoordinator::qeFileDownloaded ? Message::mkDetail : Message::mkInfo,
		"Executing queue-script %s for %s", pScript->GetName(), Util::BaseFileName(m_szNZBName));

	SetScript(pScript->GetLocation());
	SetArgs(NULL, false);

	char szInfoName[1024];
	snprintf(szInfoName, 1024, "queue-script %s for %s", pScript->GetName(), Util::BaseFileName(m_szNZBName));
	szInfoName[1024-1] = '\0';
	SetInfoName(szInfoName);

	SetLogPrefix(pScript->GetDisplayName());
	m_iPrefixLen = strlen(pScript->GetDisplayName()) + 2; // 2 = strlen(": ");
	PrepareParams(pScript->GetName());

	Execute();

	SetLogPrefix(NULL);
}
Пример #6
0
void FeedScriptController::ExecuteScript(ScriptConfig::Script* pScript)
{
	if (!pScript->GetFeedScript())
	{
		return;
	}

	PrintMessage(Message::mkInfo, "Executing feed-script %s for Feed%i", pScript->GetName(), m_iFeedID);

	SetScript(pScript->GetLocation());
	SetArgs(NULL, false);

	char szInfoName[1024];
	snprintf(szInfoName, 1024, "feed-script %s for Feed%i", pScript->GetName(), m_iFeedID);
	szInfoName[1024-1] = '\0';
	SetInfoName(szInfoName);

	SetLogPrefix(pScript->GetDisplayName());
	PrepareParams(pScript->GetName());

	Execute();

	SetLogPrefix(NULL);
}
Пример #7
0
void QueueScriptController::Run()
{
	ExecuteScript(m_script);

	SetLogPrefix(nullptr);

	if (m_markBad)
	{
		GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
		NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(m_id);
		if (nzbInfo)
		{
			PrintMessage(Message::mkWarning, "Cancelling download and deleting %s", *m_nzbName);
			nzbInfo->SetDeleteStatus(NzbInfo::dsBad);
			downloadQueue->EditEntry(m_id, DownloadQueue::eaGroupDelete, 0, nullptr);
		}
	}

	g_QueueScriptCoordinator->CheckQueue();
}
Пример #8
0
void QueueScriptController::Run()
{
	ExecuteScript(m_pScript);

	SetLogPrefix(NULL);

	if (m_bMarkBad)
	{
		DownloadQueue* pDownloadQueue = DownloadQueue::Lock();
		NZBInfo* pNZBInfo = pDownloadQueue->GetQueue()->Find(m_iID);
		if (pNZBInfo)
		{
			PrintMessage(Message::mkWarning, "Cancelling download and deleting %s", m_szNZBName);
			pNZBInfo->SetDeleteStatus(NZBInfo::dsBad);
			pDownloadQueue->EditEntry(m_iID, DownloadQueue::eaGroupDelete, 0, NULL);
		}
		DownloadQueue::Unlock();
	}

	g_pQueueScriptCoordinator->CheckQueue();
}
Пример #9
0
void QueueScriptController::AddMessage(Message::EKind kind, const char* text)
{
	const char* msgText = text + m_prefixLen;

	if (!strncmp(msgText, "[NZB] ", 6))
	{
		debug("Command %s detected", msgText + 6);
		if (!strncmp(msgText + 6, "NZBPR_", 6))
		{
			CString param = msgText + 6 + 6;
			char* value = strchr(param, '=');
			if (value)
			{
				*value = '\0';
				GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
				NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id);
				if (nzbInfo)
				{
					nzbInfo->GetParameters()->SetParameter(param, value + 1);
				}
			}
			else
			{
				error("Invalid command \"%s\" received from %s", msgText, GetInfoName());
			}
		}
		else if (!strncmp(msgText + 6, "DIRECTORY=", 10) &&
			m_event == QueueScriptCoordinator::qeNzbDownloaded)
		{
			GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
			NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id);
			if (nzbInfo)
			{
				nzbInfo->SetFinalDir(msgText + 6 + 10);
			}
		}
		else if (!strncmp(msgText + 6, "MARK=BAD", 8))
		{
			m_markBad = true;
			GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
			NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id);
			if (nzbInfo)
			{
				SetLogPrefix(nullptr);
				PrintMessage(Message::mkWarning, "Marking %s as bad", *m_nzbName);
				SetLogPrefix(m_script->GetDisplayName());
				nzbInfo->SetMarkStatus(NzbInfo::ksBad);
			}
		}
		else
		{
			error("Invalid command \"%s\" received from %s", msgText, GetInfoName());
		}
	}
	else
	{
		NzbInfo* nzbInfo = nullptr;
		{
			GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
			nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id);
			if (nzbInfo)
			{
				nzbInfo->AddMessage(kind, text);
			}
		}

		if (!nzbInfo)
		{
			ScriptController::AddMessage(kind, text);
		}
	}
}
Пример #10
0
bool EosUdpIn_Win::Initialize(EosLog &log, const char *ip, unsigned short port)
{
	if(	!IsInitialized() )
	{
		SetLogPrefix("udp in", ip, port, m_LogPrefix);

		if( ip )
		{
			WSADATA wsaData;
			int result = WSAStartup(MAKEWORD(2,2), &wsaData);
			if(result == 0)
			{
				m_Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
				if(m_Socket != INVALID_SOCKET)
				{
					int optval = 1;
					if(setsockopt(m_Socket,SOL_SOCKET,SO_REUSEADDR,(const char*)&optval,sizeof(optval)) == SOCKET_ERROR)
					{
						char text[256];
						sprintf(text, "%s setsockopt(SO_REUSEADDR) failed with error %d", GetLogPrefix(m_LogPrefix), WSAGetLastError());
						log.AddWarning(text);
					}

					sockaddr_in addr;
					memset(&addr, 0, sizeof(addr));
					addr.sin_family = AF_INET;
					addr.sin_addr.S_un.S_addr = inet_addr(ip);
					addr.sin_port = htons(port);
					result = bind(m_Socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
					if(result != SOCKET_ERROR)
					{
						char text[256];
						sprintf(text, "%s socket intialized", GetLogPrefix(m_LogPrefix));
						log.AddInfo(text);
					}
					else
					{
						char text[256];
						sprintf(text, "%s bind failed with error %d", GetLogPrefix(m_LogPrefix), WSAGetLastError());
						log.AddError(text);
						closesocket(m_Socket);
						m_Socket = INVALID_SOCKET;
						WSACleanup();
					}
				}
				else
				{
					char text[256];
					sprintf(text, "%s socket failed with error %d", GetLogPrefix(m_LogPrefix), WSAGetLastError());
					log.AddError(text);
					WSACleanup();
				}
			}
			else
			{
				char text[256];
				sprintf(text, "%s WSAStartup failed with error %d", GetLogPrefix(m_LogPrefix), result);
				log.AddError(text);
				WSACleanup();
			}
		}
		else
		{
			char text[256];
			sprintf(text, "%s initialize failed, invalid arguments", GetLogPrefix(m_LogPrefix));
			log.AddError(text);
		}
	}
	else
	{
		char text[256];
		sprintf(text, "%s initialize failed, already initialized", GetLogPrefix(m_LogPrefix));
		log.AddWarning(text);
	}

	return IsInitialized();
}
Пример #11
0
bool EosUdpIn_Mac::Initialize(EosLog &log, const char *ip, unsigned short port)
{
	if(	!IsInitialized() )
	{
		SetLogPrefix("udp input", ip, port, m_LogPrefix);
	
		if( ip )
		{
			m_Socket = socket(AF_INET, SOCK_DGRAM, 0);
			if(m_Socket != -1)
			{
				int optval = 1;
				if(setsockopt(m_Socket,SOL_SOCKET,SO_REUSEADDR,(const char*)&optval,sizeof(optval)) == -1)
				{
					char text[256];
					sprintf(text, "%s setsockopt(SO_REUSEADDR) failed with error %d", GetLogPrefix(m_LogPrefix), errno);
					log.AddWarning(text);
				}
				
				sockaddr_in addr;
				memset(&addr, 0, sizeof(addr));
				addr.sin_family = AF_INET;
				addr.sin_addr.s_addr = inet_addr(ip);
				addr.sin_port = htons(port);
				int result = bind(m_Socket, reinterpret_cast<sockaddr*>(&addr), static_cast<socklen_t>(sizeof(addr)));
				if(result != -1)
				{
					char text[256];
					sprintf(text, "%s socket intialized", GetLogPrefix(m_LogPrefix));
					log.AddInfo(text);
				}
				else
				{
					char text[256];
					sprintf(text, "%s bind failed with error %d", GetLogPrefix(m_LogPrefix), errno);
					log.AddError(text);
					close(m_Socket);
					m_Socket = -1;
				}
			}
			else
			{
				char text[256];
				sprintf(text, "%s socket failed with error %d", GetLogPrefix(m_LogPrefix), errno);
				log.AddError(text);
			}
		}
		else
		{
			char text[256];
			sprintf(text, "%s initialize failed, invalid arguments", GetLogPrefix(m_LogPrefix));
			log.AddError(text);
		}
	}
	else
	{
		char text[256];
		sprintf(text, "%s initialize failed, already initialized", GetLogPrefix(m_LogPrefix));
		log.AddWarning(text);
	}

	return IsInitialized();
}