aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llmessageconfig.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llmessageconfig.cpp165
1 files changed, 94 insertions, 71 deletions
diff --git a/linden/indra/llmessage/llmessageconfig.cpp b/linden/indra/llmessage/llmessageconfig.cpp
index 687896b..8d114a9 100644
--- a/linden/indra/llmessage/llmessageconfig.cpp
+++ b/linden/indra/llmessage/llmessageconfig.cpp
@@ -32,37 +32,44 @@
32#include "llfile.h" 32#include "llfile.h"
33#include "lllivefile.h" 33#include "lllivefile.h"
34#include "llsd.h" 34#include "llsd.h"
35#include "llsdutil.h"
35#include "llsdserialize.h" 36#include "llsdserialize.h"
37#include "message.h"
36 38
37static const char messageConfigFileName[] = "message.xml"; 39static const char messageConfigFileName[] = "message.xml";
38static const F32 messageConfigRefreshRate = 5.0; // seconds 40static const F32 messageConfigRefreshRate = 5.0; // seconds
41
39static std::string sServerName = ""; 42static std::string sServerName = "";
40static std::string sConfigDir = ""; 43static std::string sConfigDir = "";
41 44
45static std::string sServerDefault;
46static LLSD sMessages;
47
48
42class LLMessageConfigFile : public LLLiveFile 49class LLMessageConfigFile : public LLLiveFile
43{ 50{
44private: 51public:
45 LLMessageConfigFile() 52 LLMessageConfigFile()
46 : LLLiveFile(fileName(), messageConfigRefreshRate), 53 : LLLiveFile(fileName(), messageConfigRefreshRate)
47 mChanged(false)
48 { } 54 { }
49 55
50 static std::string fileName(); 56 static std::string fileName();
51 57
52public: 58 LLSD mMessages;
59 std::string mServerDefault;
60
53 static LLMessageConfigFile& instance(); 61 static LLMessageConfigFile& instance();
54 // return the singleton configuration file 62 // return the singleton configuration file
55 63
56protected:
57 /* virtual */ void loadFile(); 64 /* virtual */ void loadFile();
58 void loadServerDefaults(const LLSD& data); 65 void loadServerDefaults(const LLSD& data);
59 void loadMessages(const LLSD& data); 66 void loadMessages(const LLSD& data);
67 void loadCapBans(const LLSD& blacklist);
68 void loadMessageBans(const LLSD& blacklist);
69 bool isCapBanned(const std::string& cap_name) const;
60 70
61public: 71public:
62 bool mChanged; 72 LLSD mCapBans;
63
64 std::string mServerDefault;
65 LLSD mMessages;
66}; 73};
67 74
68std::string LLMessageConfigFile::fileName() 75std::string LLMessageConfigFile::fileName()
@@ -102,26 +109,63 @@ void LLMessageConfigFile::loadFile()
102 } 109 }
103 loadServerDefaults(data); 110 loadServerDefaults(data);
104 loadMessages(data); 111 loadMessages(data);
112 loadCapBans(data);
113 loadMessageBans(data);
105} 114}
106 115
107void LLMessageConfigFile::loadServerDefaults(const LLSD& data) 116void LLMessageConfigFile::loadServerDefaults(const LLSD& data)
108{ 117{
109 mServerDefault = data["serverDefaults"][sServerName].asString(); 118 mServerDefault = data["serverDefaults"][sServerName].asString();
110 lldebugs << "loading default " << mServerDefault << llendl;
111} 119}
112 120
113void LLMessageConfigFile::loadMessages(const LLSD& data) 121void LLMessageConfigFile::loadMessages(const LLSD& data)
114{ 122{
115 LLPointer<LLSDXMLFormatter> formatter = new LLSDXMLFormatter;
116 std::ostringstream out;
117
118 mMessages = data["messages"]; 123 mMessages = data["messages"];
124
125#ifdef DEBUG
126 std::ostringstream out;
127 LLSDXMLFormatter *formatter = new LLSDXMLFormatter;
119 formatter->format(mMessages, out); 128 formatter->format(mMessages, out);
120 lldebugs << "loading ... " << out.str() 129 llinfos << "loading ... " << out.str()
121 << " LLMessageConfigFile::loadMessages loaded " 130 << " LLMessageConfigFile::loadMessages loaded "
122 << mMessages.size() << " messages" << llendl; 131 << mMessages.size() << " messages" << llendl;
132#endif
123} 133}
124 134
135void LLMessageConfigFile::loadCapBans(const LLSD& data)
136{
137 LLSD bans = data["capBans"];
138 if (!bans.isMap())
139 {
140 llinfos << "LLMessageConfigFile::loadCapBans: missing capBans section"
141 << llendl;
142 return;
143 }
144
145 mCapBans = bans;
146
147 llinfos << "LLMessageConfigFile::loadCapBans: "
148 << bans.size() << " ban tests" << llendl;
149}
150
151void LLMessageConfigFile::loadMessageBans(const LLSD& data)
152{
153 LLSD bans = data["messageBans"];
154 if (!bans.isMap())
155 {
156 llinfos << "LLMessageConfigFile::loadMessageBans: missing messageBans section"
157 << llendl;
158 return;
159 }
160
161 gMessageSystem->setMessageBans(bans["trusted"], bans["untrusted"]);
162}
163
164bool LLMessageConfigFile::isCapBanned(const std::string& cap_name) const
165{
166 llinfos << "mCapBans is " << LLSDXMLStreamer(mCapBans) << llendl;
167 return mCapBans[cap_name];
168}
125 169
126//--------------------------------------------------------------- 170//---------------------------------------------------------------
127// LLMessageConfig 171// LLMessageConfig
@@ -134,98 +178,77 @@ void LLMessageConfig::initClass(const std::string& server_name,
134 sServerName = server_name; 178 sServerName = server_name;
135 sConfigDir = config_dir; 179 sConfigDir = config_dir;
136 (void) LLMessageConfigFile::instance(); 180 (void) LLMessageConfigFile::instance();
137 llinfos << "LLMessageConfig::intiClass config file " 181 llinfos << "LLMessageConfig::initClass config file "
138 << config_dir << "/" << messageConfigFileName << llendl; 182 << config_dir << "/" << messageConfigFileName << llendl;
139} 183}
140 184
141//static 185//static
142bool LLMessageConfig::isServerDefaultBuilderLLSD() 186void LLMessageConfig::useConfig(const LLSD& config)
143{ 187{
144 if (sServerName.empty()) 188 LLMessageConfigFile &the_file = LLMessageConfigFile::instance();
145 { 189 the_file.loadServerDefaults(config);
146 llerrs << "LLMessageConfig::isServerDefaultBuilderLLSD() before" 190 the_file.loadMessages(config);
147 << " LLMessageConfig::initClass()" << llendl; 191 the_file.loadCapBans(config);
148 } 192 the_file.loadMessageBans(config);
149 LLMessageConfigFile& file = LLMessageConfigFile::instance();
150 return (file.mServerDefault == "llsd");
151}
152 193
153//static
154bool LLMessageConfig::isServerDefaultBuilderTemplate()
155{
156 if (sServerName.empty())
157 {
158 llerrs << "LLMessageConfig::isServerDefaultBuilderTemplate() before"
159 << " LLMessageConfig::initClass()" << llendl;
160 }
161 LLMessageConfigFile& file = LLMessageConfigFile::instance();
162 return (file.mServerDefault == "template");
163} 194}
164 195
165//static 196//static
166bool LLMessageConfig::isMessageBuiltLLSD(const std::string& msg_name) 197LLMessageConfig::Flavor LLMessageConfig::getServerDefaultFlavor()
167{ 198{
168 if (sServerName.empty()) 199 LLMessageConfigFile& file = LLMessageConfigFile::instance();
200 if (file.mServerDefault == "llsd")
169 { 201 {
170 llerrs << "LLMessageConfig::isMessageBuiltLLSD(name) before" 202 return LLSD_FLAVOR;
171 << " LLMessageConfig::initClass()" << llendl;
172 } 203 }
173 LLMessageConfigFile& file = LLMessageConfigFile::instance(); 204 if (file.mServerDefault == "template")
174 LLSD config = file.mMessages[msg_name];
175 if (!config.has("builder"))
176 { 205 {
177 return isServerDefaultBuilderLLSD(); 206 return TEMPLATE_FLAVOR;
178 } 207 }
179 return (config["builder"].asString() == "llsd"); 208 return NO_FLAVOR;
180} 209}
181 210
182//static 211//static
183bool LLMessageConfig::isMessageBuiltTemplate(const std::string& msg_name) 212LLMessageConfig::Flavor LLMessageConfig::getMessageFlavor(const std::string& msg_name)
184{ 213{
185 if (sServerName.empty())
186 {
187 llerrs << "LLMessageConfig::isMessageBuiltTemplate(name) before"
188 << " LLMessageConfig::initClass()" << llendl;
189 }
190 LLMessageConfigFile& file = LLMessageConfigFile::instance(); 214 LLMessageConfigFile& file = LLMessageConfigFile::instance();
191 LLSD config = file.mMessages[msg_name]; 215 LLSD config = file.mMessages[msg_name];
192 if (!config.has("builder")) 216 if (config["flavor"].asString() == "llsd")
193 { 217 {
194 return isServerDefaultBuilderTemplate(); 218 return LLSD_FLAVOR;
195 } 219 }
196 return (config["builder"].asString() == "template"); 220 if (config["flavor"].asString() == "template")
221 {
222 return TEMPLATE_FLAVOR;
223 }
224 return NO_FLAVOR;
197} 225}
198 226
199//static 227//static
200bool LLMessageConfig::isMessageTrusted(const std::string& msg_name) 228LLMessageConfig::SenderTrust LLMessageConfig::getSenderTrustedness(
229 const std::string& msg_name)
201{ 230{
202 if (sServerName.empty())
203 {
204 llerrs << "LLMessageConfig::isMessageTrusted(name) before"
205 << " LLMessageConfig::initClass()" << llendl;
206 }
207 LLMessageConfigFile& file = LLMessageConfigFile::instance(); 231 LLMessageConfigFile& file = LLMessageConfigFile::instance();
208 LLSD config = file.mMessages[msg_name]; 232 LLSD config = file.mMessages[msg_name];
209 if (!config.has("trusted-sender")) 233 if (config.has("trusted-sender"))
210 { 234 {
211 return false; 235 return config["trusted-sender"].asBoolean() ? TRUSTED : UNTRUSTED;
212 } 236 }
213 return config["trusted-sender"].asBoolean(); 237 return NOT_SET;
214} 238}
215 239
216//static 240//static
217bool LLMessageConfig::isValidUntrustedMessage(const std::string& msg_name) 241bool LLMessageConfig::isValidMessage(const std::string& msg_name)
218{ 242{
219 if (sServerName.empty()) 243 if (sServerName.empty())
220 { 244 {
221 llerrs << "LLMessageConfig::isMessageTrusted(name) before" 245 llerrs << "LLMessageConfig::initClass() not called" << llendl;
222 << " LLMessageConfig::initClass()" << llendl;
223 } 246 }
224 LLMessageConfigFile& file = LLMessageConfigFile::instance(); 247 LLMessageConfigFile& file = LLMessageConfigFile::instance();
225 LLSD config = file.mMessages[msg_name]; 248 return file.mMessages.has(msg_name);
226 if (!config.has("trusted-sender")) 249}
227 { 250
228 return false; 251bool LLMessageConfig::isCapBanned(const std::string& cap_name)
229 } 252{
230 return !(config["trusted-sender"].asBoolean()); 253 return LLMessageConfigFile::instance().isCapBanned(cap_name);
231} 254}