aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llcommandhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llcommandhandler.cpp')
-rw-r--r--linden/indra/newview/llcommandhandler.cpp49
1 files changed, 34 insertions, 15 deletions
diff --git a/linden/indra/newview/llcommandhandler.cpp b/linden/indra/newview/llcommandhandler.cpp
index 5c44937..6e7014c 100644
--- a/linden/indra/newview/llcommandhandler.cpp
+++ b/linden/indra/newview/llcommandhandler.cpp
@@ -14,12 +14,12 @@
14 * ("GPL"), unless you have obtained a separate licensing agreement 14 * ("GPL"), unless you have obtained a separate licensing agreement
15 * ("Other License"), formally executed by you and Linden Lab. Terms of 15 * ("Other License"), formally executed by you and Linden Lab. Terms of
16 * the GPL can be found in doc/GPL-license.txt in this distribution, or 16 * the GPL can be found in doc/GPL-license.txt in this distribution, or
17 * online at http://secondlife.com/developers/opensource/gplv2 17 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
18 * 18 *
19 * There are special exceptions to the terms and conditions of the GPL as 19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception 20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or 21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlife.com/developers/opensource/flossexception 22 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
23 * 23 *
24 * By copying, modifying or distributing this software, you acknowledge 24 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above, 25 * that you have read and understood your obligations described above,
@@ -40,16 +40,21 @@
40//--------------------------------------------------------------------------- 40//---------------------------------------------------------------------------
41// Underlying registry for command handlers, not directly accessible. 41// Underlying registry for command handlers, not directly accessible.
42//--------------------------------------------------------------------------- 42//---------------------------------------------------------------------------
43struct LLCommandHandlerInfo
44{
45 bool mAllowFromExternalBrowser;
46 LLCommandHandler* mHandler; // safe, all of these are static objects
47};
43 48
44class LLCommandHandlerRegistry 49class LLCommandHandlerRegistry
45{ 50{
46public: 51public:
47 static LLCommandHandlerRegistry& instance(); 52 static LLCommandHandlerRegistry& instance();
48 void add(const char* cmd, LLCommandHandler* handler); 53 void add(const char* cmd, bool allow_from_external_browser, LLCommandHandler* handler);
49 bool dispatch(const std::string& cmd, const LLSD& params, const LLSD& queryMap); 54 bool dispatch(const std::string& cmd, bool from_external_browser, const LLSD& params, const LLSD& queryMap);
50 55
51private: 56private:
52 std::map<std::string, LLCommandHandler*> mMap; 57 std::map<std::string, LLCommandHandlerInfo> mMap;
53}; 58};
54 59
55// static 60// static
@@ -62,29 +67,40 @@ LLCommandHandlerRegistry& LLCommandHandlerRegistry::instance()
62 return instance; 67 return instance;
63} 68}
64 69
65void LLCommandHandlerRegistry::add(const char* cmd, LLCommandHandler* handler) 70void LLCommandHandlerRegistry::add(const char* cmd, bool allow_from_external_browser, LLCommandHandler* handler)
66{ 71{
67 mMap[cmd] = handler; 72 LLCommandHandlerInfo info;
73 info.mAllowFromExternalBrowser = allow_from_external_browser;
74 info.mHandler = handler;
75
76 mMap[cmd] = info;
68} 77}
69 78
70bool LLCommandHandlerRegistry::dispatch(const std::string& cmd, 79bool LLCommandHandlerRegistry::dispatch(const std::string& cmd,
80 bool from_external_browser,
71 const LLSD& params, 81 const LLSD& params,
72 const LLSD& queryMap) 82 const LLSD& queryMap)
73{ 83{
74 std::map<std::string, LLCommandHandler*>::iterator it = mMap.find(cmd); 84 std::map<std::string, LLCommandHandlerInfo>::iterator it = mMap.find(cmd);
75 if (it == mMap.end()) return false; 85 if (it == mMap.end()) return false;
76 LLCommandHandler* handler = it->second; 86 const LLCommandHandlerInfo& info = it->second;
77 if (!handler) return false; 87 if (from_external_browser && !info.mAllowFromExternalBrowser)
78 return handler->handle(params, queryMap); 88 {
89 // block request from external browser, but report as
90 // "handled" because it was well formatted.
91 return true;
92 }
93 if (!info.mHandler) return false;
94 return info.mHandler->handle(params, queryMap);
79} 95}
80 96
81//--------------------------------------------------------------------------- 97//---------------------------------------------------------------------------
82// Automatic registration of commands, runs before main() 98// Automatic registration of commands, runs before main()
83//--------------------------------------------------------------------------- 99//---------------------------------------------------------------------------
84 100
85LLCommandHandler::LLCommandHandler(const char* cmd) 101LLCommandHandler::LLCommandHandler(const char* cmd, bool allow_from_external_browser)
86{ 102{
87 LLCommandHandlerRegistry::instance().add(cmd, this); 103 LLCommandHandlerRegistry::instance().add(cmd, allow_from_external_browser, this);
88} 104}
89 105
90LLCommandHandler::~LLCommandHandler() 106LLCommandHandler::~LLCommandHandler()
@@ -98,7 +114,10 @@ LLCommandHandler::~LLCommandHandler()
98//--------------------------------------------------------------------------- 114//---------------------------------------------------------------------------
99 115
100// static 116// static
101bool LLCommandDispatcher::dispatch(const std::string& cmd, const LLSD& params, const LLSD& queryMap) 117bool LLCommandDispatcher::dispatch(const std::string& cmd,
118 bool from_external_browser,
119 const LLSD& params, const LLSD& queryMap)
102{ 120{
103 return LLCommandHandlerRegistry::instance().dispatch(cmd, params, queryMap); 121 return LLCommandHandlerRegistry::instance().dispatch(
122 cmd, from_external_browser, params, queryMap);
104} 123}