diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmessage/llmessageconfig.cpp | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llmessageconfig.cpp b/linden/indra/llmessage/llmessageconfig.cpp new file mode 100644 index 0000000..a0566ea --- /dev/null +++ b/linden/indra/llmessage/llmessageconfig.cpp | |||
@@ -0,0 +1,230 @@ | |||
1 | /** | ||
2 | * @file llmessageconfig.cpp | ||
3 | * @brief Live file handling for messaging | ||
4 | * | ||
5 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * Second Life Viewer Source Code | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
29 | #include "linden_common.h" | ||
30 | |||
31 | #include "llmessageconfig.h" | ||
32 | #include "llfile.h" | ||
33 | #include "lllivefile.h" | ||
34 | #include "llsd.h" | ||
35 | #include "llsdserialize.h" | ||
36 | |||
37 | static const char messageConfigFileName[] = "message.xml"; | ||
38 | static const F32 messageConfigRefreshRate = 5.0; // seconds | ||
39 | static std::string sServerName = ""; | ||
40 | static std::string sConfigDir = ""; | ||
41 | |||
42 | class LLMessageConfigFile : public LLLiveFile | ||
43 | { | ||
44 | private: | ||
45 | LLMessageConfigFile() | ||
46 | : LLLiveFile(fileName(), messageConfigRefreshRate), | ||
47 | mChanged(false) | ||
48 | { } | ||
49 | |||
50 | static std::string fileName(); | ||
51 | |||
52 | public: | ||
53 | static LLMessageConfigFile& instance(); | ||
54 | // return the singleton configuration file | ||
55 | |||
56 | protected: | ||
57 | /* virtual */ void loadFile(); | ||
58 | void loadServerDefaults(const LLSD& data); | ||
59 | void loadMessages(const LLSD& data); | ||
60 | |||
61 | public: | ||
62 | bool mChanged; | ||
63 | |||
64 | std::string mServerDefault; | ||
65 | LLSD mMessages; | ||
66 | }; | ||
67 | |||
68 | std::string LLMessageConfigFile::fileName() | ||
69 | { | ||
70 | std::ostringstream ostr; | ||
71 | ostr << sConfigDir//gAppSimp->getOption("configdir").asString() | ||
72 | << "/" << messageConfigFileName; | ||
73 | return ostr.str(); | ||
74 | } | ||
75 | |||
76 | LLMessageConfigFile& LLMessageConfigFile::instance() | ||
77 | { | ||
78 | static LLMessageConfigFile the_file; | ||
79 | the_file.checkAndReload(); | ||
80 | return the_file; | ||
81 | } | ||
82 | |||
83 | // virtual | ||
84 | void LLMessageConfigFile::loadFile() | ||
85 | { | ||
86 | LLSD data; | ||
87 | { | ||
88 | llifstream file(filename().c_str()); | ||
89 | if (file.is_open()) | ||
90 | { | ||
91 | llinfos << "Loading message.xml file at " << fileName() << llendl; | ||
92 | LLSDSerialize::fromXML(data, file); | ||
93 | } | ||
94 | |||
95 | if (data.isUndefined()) | ||
96 | { | ||
97 | llinfos << "LLMessageConfigFile::loadFile: file missing," | ||
98 | " ill-formed, or simply undefined; not changing the" | ||
99 | " file" << llendl; | ||
100 | return; | ||
101 | } | ||
102 | } | ||
103 | loadServerDefaults(data); | ||
104 | loadMessages(data); | ||
105 | } | ||
106 | |||
107 | void LLMessageConfigFile::loadServerDefaults(const LLSD& data) | ||
108 | { | ||
109 | mServerDefault = data["serverDefaults"][sServerName].asString(); | ||
110 | lldebugs << "loading default " << mServerDefault << llendl; | ||
111 | } | ||
112 | |||
113 | void LLMessageConfigFile::loadMessages(const LLSD& data) | ||
114 | { | ||
115 | mMessages = data["messages"]; | ||
116 | std::ostringstream out; | ||
117 | LLSDXMLFormatter *formatter = new LLSDXMLFormatter; | ||
118 | formatter->format(mMessages, out); | ||
119 | lldebugs << "loading ... " << out.str() | ||
120 | << " LLMessageConfigFile::loadMessages loaded " | ||
121 | << mMessages.size() << " messages" << llendl; | ||
122 | } | ||
123 | |||
124 | |||
125 | //--------------------------------------------------------------- | ||
126 | // LLMessageConfig | ||
127 | //--------------------------------------------------------------- | ||
128 | |||
129 | //static | ||
130 | void LLMessageConfig::initClass(const std::string& server_name, | ||
131 | const std::string& config_dir) | ||
132 | { | ||
133 | sServerName = server_name; | ||
134 | sConfigDir = config_dir; | ||
135 | (void) LLMessageConfigFile::instance(); | ||
136 | llinfos << "LLMessageConfig::intiClass config file " | ||
137 | << config_dir << "/" << messageConfigFileName << llendl; | ||
138 | } | ||
139 | |||
140 | //static | ||
141 | bool LLMessageConfig::isServerDefaultBuilderLLSD() | ||
142 | { | ||
143 | if (sServerName.empty()) | ||
144 | { | ||
145 | llerrs << "LLMessageConfig::isServerDefaultBuilderLLSD() before" | ||
146 | << " LLMessageConfig::initClass()" << llendl; | ||
147 | } | ||
148 | LLMessageConfigFile& file = LLMessageConfigFile::instance(); | ||
149 | return (file.mServerDefault == "llsd"); | ||
150 | } | ||
151 | |||
152 | //static | ||
153 | bool LLMessageConfig::isServerDefaultBuilderTemplate() | ||
154 | { | ||
155 | if (sServerName.empty()) | ||
156 | { | ||
157 | llerrs << "LLMessageConfig::isServerDefaultBuilderTemplate() before" | ||
158 | << " LLMessageConfig::initClass()" << llendl; | ||
159 | } | ||
160 | LLMessageConfigFile& file = LLMessageConfigFile::instance(); | ||
161 | return (file.mServerDefault == "template"); | ||
162 | } | ||
163 | |||
164 | //static | ||
165 | bool LLMessageConfig::isMessageBuiltLLSD(const std::string& msg_name) | ||
166 | { | ||
167 | if (sServerName.empty()) | ||
168 | { | ||
169 | llerrs << "LLMessageConfig::isMessageBuiltLLSD(name) before" | ||
170 | << " LLMessageConfig::initClass()" << llendl; | ||
171 | } | ||
172 | LLMessageConfigFile& file = LLMessageConfigFile::instance(); | ||
173 | LLSD config = file.mMessages[msg_name]; | ||
174 | if (!config.has("builder")) | ||
175 | { | ||
176 | return isServerDefaultBuilderLLSD(); | ||
177 | } | ||
178 | return (config["builder"].asString() == "llsd"); | ||
179 | } | ||
180 | |||
181 | //static | ||
182 | bool LLMessageConfig::isMessageBuiltTemplate(const std::string& msg_name) | ||
183 | { | ||
184 | if (sServerName.empty()) | ||
185 | { | ||
186 | llerrs << "LLMessageConfig::isMessageBuiltTemplate(name) before" | ||
187 | << " LLMessageConfig::initClass()" << llendl; | ||
188 | } | ||
189 | LLMessageConfigFile& file = LLMessageConfigFile::instance(); | ||
190 | LLSD config = file.mMessages[msg_name]; | ||
191 | if (!config.has("builder")) | ||
192 | { | ||
193 | return isServerDefaultBuilderTemplate(); | ||
194 | } | ||
195 | return (config["builder"].asString() == "template"); | ||
196 | } | ||
197 | |||
198 | //static | ||
199 | bool LLMessageConfig::isMessageTrusted(const std::string& msg_name) | ||
200 | { | ||
201 | if (sServerName.empty()) | ||
202 | { | ||
203 | llerrs << "LLMessageConfig::isMessageTrusted(name) before" | ||
204 | << " LLMessageConfig::initClass()" << llendl; | ||
205 | } | ||
206 | LLMessageConfigFile& file = LLMessageConfigFile::instance(); | ||
207 | LLSD config = file.mMessages[msg_name]; | ||
208 | if (!config.has("trusted-sender")) | ||
209 | { | ||
210 | return false; | ||
211 | } | ||
212 | return config["trusted-sender"].asBoolean(); | ||
213 | } | ||
214 | |||
215 | //static | ||
216 | bool LLMessageConfig::isValidUntrustedMessage(const std::string& msg_name) | ||
217 | { | ||
218 | if (sServerName.empty()) | ||
219 | { | ||
220 | llerrs << "LLMessageConfig::isMessageTrusted(name) before" | ||
221 | << " LLMessageConfig::initClass()" << llendl; | ||
222 | } | ||
223 | LLMessageConfigFile& file = LLMessageConfigFile::instance(); | ||
224 | LLSD config = file.mMessages[msg_name]; | ||
225 | if (!config.has("trusted-sender")) | ||
226 | { | ||
227 | return false; | ||
228 | } | ||
229 | return !(config["trusted-sender"].asBoolean()); | ||
230 | } | ||