/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_GeckoArgs_h #define mozilla_GeckoArgs_h #include "mozilla/CmdLineAndEnvUtils.h" #include "mozilla/Maybe.h" #include #include #include #include #include namespace mozilla { namespace geckoargs { template struct CommandLineArg { Maybe Get(int& aArgc, char** aArgv, const CheckArgFlag aFlags = CheckArgFlag::RemoveArg); const char* Name() { return sName; }; void Put(std::vector& aArgs); void Put(T aValue, std::vector& aArgs); const char* sName; const char* sMatch; }; /// Get() template <> inline Maybe CommandLineArg::Get( int& aArgc, char** aArgv, const CheckArgFlag aFlags) { MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()"); const char* rv = nullptr; if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, &rv, aFlags)) { return Some(rv); } return Nothing(); } template <> inline Maybe CommandLineArg::Get(int& aArgc, char** aArgv, const CheckArgFlag aFlags) { MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()"); if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, (const char**)nullptr, aFlags)) { return Some(true); } return Nothing(); } template <> inline Maybe CommandLineArg::Get( int& aArgc, char** aArgv, const CheckArgFlag aFlags) { MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()"); const char* rv = nullptr; if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, &rv, aFlags)) { errno = 0; char* endptr = nullptr; uint64_t conv = std::strtoull(rv, &endptr, 10); if (errno == 0 && endptr && *endptr == '\0') { return Some(conv); } } return Nothing(); } /// Put() template <> inline void CommandLineArg::Put(const char* aValue, std::vector& aArgs) { aArgs.push_back(Name()); aArgs.push_back(aValue); } template <> inline void CommandLineArg::Put(bool aValue, std::vector& aArgs) { if (aValue) { aArgs.push_back(Name()); } } template <> inline void CommandLineArg::Put(std::vector& aArgs) { Put(true, aArgs); } template <> inline void CommandLineArg::Put(uint64_t aValue, std::vector& aArgs) { aArgs.push_back(Name()); aArgs.push_back(std::to_string(aValue)); } #if defined(__GNUC__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-variable" #endif static CommandLineArg sParentBuildID{"-parentBuildID", "parentbuildid"}; static CommandLineArg sAppDir{"-appDir", "appdir"}; static CommandLineArg sProfile{"-profile", "profile"}; static CommandLineArg sJsInitHandle{"-jsInitHandle", "jsinithandle"}; static CommandLineArg sJsInitLen{"-jsInitLen", "jsinitlen"}; static CommandLineArg sPrefsHandle{"-prefsHandle", "prefshandle"}; static CommandLineArg sPrefsLen{"-prefsLen", "prefslen"}; static CommandLineArg sPrefMapHandle{"-prefMapHandle", "prefmaphandle"}; static CommandLineArg sPrefMapSize{"-prefMapSize", "prefmapsize"}; static CommandLineArg sChildID{"-childID", "childid"}; static CommandLineArg sSandboxingKind{"-sandboxingKind", "sandboxingkind"}; static CommandLineArg sSafeMode{"-safeMode", "safemode"}; static CommandLineArg sIsForBrowser{"-isForBrowser", "isforbrowser"}; static CommandLineArg sNotForBrowser{"-notForBrowser", "notforbrowser"}; #if defined(XP_WIN) # if defined(MOZ_SANDBOX) static CommandLineArg sWin32kLockedDown{"-win32kLockedDown", "win32klockeddown"}; # endif // defined(MOZ_SANDBOX) # if defined(ACCESSIBILITY) static CommandLineArg sA11yResourceId{"-a11yResourceId", "a11yresourceid"}; # endif // defined(ACCESSIBILITY) static CommandLineArg sDisableDynamicDllBlocklist{ "-disableDynamicBlocklist", "disabledynamicblocklist"}; #endif // defined(XP_WIN) #if defined(__GNUC__) # pragma GCC diagnostic pop #endif } // namespace geckoargs } // namespace mozilla #endif // mozilla_GeckoArgs_h