void ScriptController::SetEnvVarSpecial(const char* szPrefix, const char* szName, const char* szValue) { char szVarname[1024]; snprintf(szVarname, sizeof(szVarname), "%s_%s", szPrefix, szName); szVarname[1024-1] = '\0'; // Original name SetEnvVar(szVarname, szValue); char szNormVarname[1024]; strncpy(szNormVarname, szVarname, sizeof(szVarname)); szNormVarname[1024-1] = '\0'; // Replace special characters with "_" and convert to upper case for (char* szPtr = szNormVarname; *szPtr; szPtr++) { if (strchr(".:*!\"$%&/()=`+~#'{}[]@- ", *szPtr)) *szPtr = '_'; *szPtr = toupper(*szPtr); } // Another env var with normalized name (replaced special chars and converted to upper case) if (strcmp(szVarname, szNormVarname)) { SetEnvVar(szNormVarname, szValue); } }
void ScriptController::SetIntEnvVar(const char* szName, int iValue) { char szValue[1024]; snprintf(szValue, 10, "%i", iValue); szValue[1024-1] = '\0'; SetEnvVar(szName, szValue); }
void CommandScriptController::PrepareParams(const char* scriptName) { ResetEnv(); SetEnvVar("NZBCP_COMMAND", m_command); PrepareEnvScript(nullptr, scriptName); }
void ScanScriptController::PrepareParams(const char* szScriptName) { ResetEnv(); SetEnvVar("NZBNP_FILENAME", m_szNZBFilename); SetEnvVar("NZBNP_URL", m_szUrl); SetEnvVar("NZBNP_NZBNAME", strlen(*m_pNZBName) > 0 ? *m_pNZBName : Util::BaseFileName(m_szNZBFilename)); SetEnvVar("NZBNP_CATEGORY", *m_pCategory); SetIntEnvVar("NZBNP_PRIORITY", *m_iPriority); SetIntEnvVar("NZBNP_TOP", *m_bAddTop ? 1 : 0); SetIntEnvVar("NZBNP_PAUSED", *m_bAddPaused ? 1 : 0); SetEnvVar("NZBNP_DUPEKEY", *m_pDupeKey); SetIntEnvVar("NZBNP_DUPESCORE", *m_iDupeScore); const char* szDupeModeName[] = { "SCORE", "ALL", "FORCE" }; SetEnvVar("NZBNP_DUPEMODE", szDupeModeName[*m_eDupeMode]); // remove trailing slash char szDir[1024]; strncpy(szDir, m_szDirectory, 1024); szDir[1024-1] = '\0'; int iLen = strlen(szDir); if (szDir[iLen-1] == PATH_SEPARATOR) { szDir[iLen-1] = '\0'; } SetEnvVar("NZBNP_DIRECTORY", szDir); PrepareEnvScript(m_pParameters, szScriptName); }
void FeedScriptController::PrepareParams(const char* szScriptName) { ResetEnv(); SetEnvVar("NZBFP_FILENAME", m_szFeedFile); SetIntEnvVar("NZBFP_FEEDID", m_iFeedID); PrepareEnvScript(NULL, szScriptName); }
void ScriptController::SetEnvVarSpecial(const char* prefix, const char* name, const char* value) { BString<1024> varname("%s_%s", prefix, name); // Original name SetEnvVar(varname, value); BString<1024> normVarname = *varname; // Replace special characters with "_" and convert to upper case for (char* ptr = normVarname; *ptr; ptr++) { if (strchr(".:*!\"$%&/()=`+~#'{}[]@- ", *ptr)) *ptr = '_'; *ptr = toupper(*ptr); } // Another env var with normalized name (replaced special chars and converted to upper case) if (strcmp(varname, normVarname)) { SetEnvVar(normVarname, value); } }
void QueueScriptController::PrepareParams(const char* szScriptName) { ResetEnv(); SetEnvVar("NZBNA_NZBNAME", m_szNZBName); SetIntEnvVar("NZBNA_NZBID", m_iID); SetEnvVar("NZBNA_FILENAME", m_szNZBFilename); SetEnvVar("NZBNA_DIRECTORY", m_szDestDir); SetEnvVar("NZBNA_URL", m_szUrl); SetEnvVar("NZBNA_CATEGORY", m_szCategory); SetIntEnvVar("NZBNA_PRIORITY", m_iPriority); SetIntEnvVar("NZBNA_LASTID", m_iID); // deprecated SetEnvVar("NZBNA_EVENT", QUEUE_EVENT_NAMES[m_eEvent]); PrepareEnvScript(&m_Parameters, szScriptName); }
void QueueScriptController::PrepareParams(const char* scriptName) { ResetEnv(); SetEnvVar("NZBNA_NZBNAME", m_nzbName); SetIntEnvVar("NZBNA_NZBID", m_id); SetEnvVar("NZBNA_FILENAME", m_nzbFilename); SetEnvVar("NZBNA_DIRECTORY", m_destDir); SetEnvVar("NZBNA_QUEUEDFILE", m_queuedFilename); SetEnvVar("NZBNA_URL", m_url); SetEnvVar("NZBNA_CATEGORY", m_category); SetIntEnvVar("NZBNA_PRIORITY", m_priority); SetIntEnvVar("NZBNA_LASTID", m_id); // deprecated SetEnvVar("NZBNA_DUPEKEY", m_dupeKey); SetIntEnvVar("NZBNA_DUPESCORE", m_dupeScore); const char* dupeModeName[] = { "SCORE", "ALL", "FORCE" }; SetEnvVar("NZBNA_DUPEMODE", dupeModeName[m_dupeMode]); SetEnvVar("NZBNA_EVENT", QUEUE_EVENT_NAMES[m_event]); const char* deleteStatusName[] = { "NONE", "MANUAL", "HEALTH", "DUPE", "BAD", "GOOD", "COPY", "SCAN" }; SetEnvVar("NZBNA_DELETESTATUS", deleteStatusName[m_deleteStatus]); const char* urlStatusName[] = { "NONE", "UNKNOWN", "SUCCESS", "FAILURE", "UNKNOWN", "SCAN_SKIPPED", "SCAN_FAILURE" }; SetEnvVar("NZBNA_URLSTATUS", urlStatusName[m_urlStatus]); const char* markStatusName[] = { "NONE", "BAD", "GOOD", "SUCCESS" }; SetEnvVar("NZBNA_MARKSTATUS", markStatusName[m_markStatus]); PrepareEnvScript(&m_parameters, scriptName); }
int __cdecl main(int argc, char *argv[]) { DWORD dwBuffLength = _MAX_DIR; WCHAR wPath[_MAX_DIR]; WCHAR tmpValue[] = {'T','M','P','\0'}; WCHAR tempValue[] = {'T','E','M','P','\0'}; #if WIN32 WCHAR tempPath[] = {'C',':','\\','t','e','m','p','\\','\0'}; WCHAR tmpPath[] = {'C',':','\\','t','m','p','\\','\0'}; #else WCHAR tempPath[] = {'.','\\','t','e','m','p','\\','\0'}; WCHAR tmpPath[] = {'.','\\','t','m','p','\\','\0'}; #endif if (0 != PAL_Initialize(argc,argv)) { return FAIL; } if (GetTempPathW(dwBuffLength, wPath) == 0) { Fail("GetTempPathW: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } else { // CreateDirectory should fail on an existing directory if (CreateDirectoryW(wPath, NULL) != 0) { Fail("GetTempPathW: ERROR -> The path returned is apparently " "invalid since CreateDirectory succeeded whereas it should " "have failed.\n"); } } /* set both tmp and temp to null and check that gettemppathw returns a non zero value*/ SetEnvVar(tmpValue, NULL); /* create the environment variable */ SetEnvVar(tempValue, tempPath); /* set the environment variable to NULL */ SetEnvVar(tempValue, NULL); if(GetTempPathW(dwBuffLength, wPath) == 0) { Fail("GetTempPathW: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } /* set temp, and gettemppathw should return value of temp */ SetEnvVar(tempValue, tempPath); if(GetTempPathW(dwBuffLength, wPath) == 0) { Fail("GetTempPathW: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } if(wcscmp(wPath, tempPath) != 0) { Fail("GetTempPathW: ERROR -> Failed to return correct temporary path. " "Expected path %s but got %s.\n", tempPath, wPath); } /* set temp to null, and set temp to a proper value, gettemppathw should return value stored in tmp */ SetEnvVar(tempValue, NULL); SetEnvVar(tmpValue, tmpPath); if(GetTempPathW(dwBuffLength, wPath) == 0) { Fail("GetTempPathW: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } if(wcscmp(wPath, tmpPath) != 0) { Fail("GetTempPathW: ERROR -> Failed to return correct temporary path. " "Expected path %s but got %s.\n", tmpPath, wPath); } /* set temp and gettemppathw should return value stored in tmp */ SetEnvVar(tempValue, tempPath); if(GetTempPathW(dwBuffLength, wPath) == 0) { Fail("GetTempPathW: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } if(wcscmp(wPath, tmpPath) != 0) { Fail("GetTempPathW: ERROR -> Failed to return correct temporary path. " "Expected path %s but got %s.\n", tmpPath, wPath); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { DWORD dwBuffLength = _MAX_DIR; CHAR path[_MAX_DIR]; char* tmpValue = "TMP"; char* tempValue = "TEMP"; #if WIN32 char tempPath[] = "C:\\temp\\"; char tmpPath[] = "C:\\tmp\\"; #else char tempPath[] = ".\\temp\\"; char tmpPath[] = ".\\tmp\\"; #endif if (0 != PAL_Initialize(argc,argv)) { return FAIL; } if (GetTempPathA(dwBuffLength, path) == 0) { Fail("GetTempPathA: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } else { // CreateDirectory should fail on an existing directory if (CreateDirectoryA(path, NULL) != 0) { Fail("GetTempPathA: ERROR -> The path returned is apparently " "invalid since CreateDirectory succeeded whereas it should " "have failed.\n"); } } /* set both tmp and temp to null and check that gettemppath returns a non zero value*/ SetEnvVar(tmpValue, NULL); /* create the variable tempValue */ SetEnvVar(tempValue, ""); /* set tempValue to null initially */ SetEnvironmentVariable(tempValue, NULL); /* get the temp path */ if(GetTempPathA(dwBuffLength, path) == 0) { Fail("GetTempPathA: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } /* set temp, and gettemppatha should return value of temp */ SetEnvVar(tempValue, tempPath); if(GetTempPathA(dwBuffLength, path) == 0) { Fail("GetTempPathA: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } if(strcmp(path,tempPath) != 0) { Fail("GetTempPathA: ERROR -> Failed to return correct temporary path. " "Expected path %s but got %s.\n", tempPath, path); } /* set temp to null, and set temp to a proper value, gettemppatha should return value stored in tmp */ SetEnvVar(tempValue, NULL); SetEnvVar(tmpValue, tmpPath); if(GetTempPathA(dwBuffLength, path) == 0) { Fail("GetTempPathA: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } if(strcmp(path,tmpPath) != 0) { Fail("GetTempPathA: ERROR -> Failed to return correct temporary path. " "Expected path %s but got %s.\n", tmpPath, path); } /* set temp and gettemppatha should return value stored in tmp */ SetEnvVar(tempValue, tempPath); if(GetTempPathA(dwBuffLength, path) == 0) { Fail("GetTempPathA: ERROR -> Failed to return a temporary path. " "error code: %ld\n", GetLastError()); } if(strcmp(path,tmpPath) != 0) { Fail("GetTempPathA: ERROR -> Failed to return correct temporary path. " "Expected path %s but got %s.\n", tmpPath, path); } PAL_Terminate(); return PASS; }
void ScriptController::SetIntEnvVar(const char* name, int value) { BString<1024> strValue("%i", value); SetEnvVar(name, strValue); }