blob: a2b0bc5efaa9aab4303d3e77e565297bac51a987 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/**
* @file llmessageconfig.cpp
* @brief Live file handling for messaging
*
* Copyright (c) 2000-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#include "linden_common.h"
#include "llmessageconfig.h"
#include "llfile.h"
#include "lllivefile.h"
#include "llsd.h"
#include "llsdserialize.h"
static const char messageConfigFileName[] = "message.xml";
static const F32 messageConfigRefreshRate = 5.0; // seconds
static std::string sServerName = "";
static std::string sConfigDir = "";
class LLMessageConfigFile : public LLLiveFile
{
private:
LLMessageConfigFile()
: LLLiveFile(fileName(), messageConfigRefreshRate),
mChanged(false)
{ }
static std::string fileName();
public:
static LLMessageConfigFile& instance();
// return the singleton configuration file
protected:
/* virtual */ void loadFile();
void loadServerDefaults(const LLSD& data);
void loadMessages(const LLSD& data);
public:
bool mChanged;
std::string mServerDefault;
LLSD mMessages;
};
std::string LLMessageConfigFile::fileName()
{
std::ostringstream ostr;
ostr << sConfigDir//gAppSimp->getOption("configdir").asString()
<< "/" << messageConfigFileName;
return ostr.str();
}
LLMessageConfigFile& LLMessageConfigFile::instance()
{
static LLMessageConfigFile the_file;
the_file.checkAndReload();
return the_file;
}
// virtual
void LLMessageConfigFile::loadFile()
{
LLSD data;
{
llifstream file(filename().c_str());
if (file.is_open())
{
llinfos << "Loading message.xml file at " << fileName() << llendl;
LLSDSerialize::fromXML(data, file);
}
if (data.isUndefined())
{
llinfos << "LLMessageConfigFile::loadFile: file missing,"
" ill-formed, or simply undefined; not changing the"
" file" << llendl;
return;
}
}
loadServerDefaults(data);
loadMessages(data);
}
void LLMessageConfigFile::loadServerDefaults(const LLSD& data)
{
mServerDefault = data["serverDefaults"][sServerName].asString();
lldebugs << "loading default " << mServerDefault << llendl;
}
void LLMessageConfigFile::loadMessages(const LLSD& data)
{
mMessages = data["messages"];
std::ostringstream out;
LLSDXMLFormatter *formatter = new LLSDXMLFormatter;
formatter->format(mMessages, out);
lldebugs << "loading ... " << out.str()
<< " LLMessageConfigFile::loadMessages loaded "
<< mMessages.size() << " messages" << llendl;
}
//---------------------------------------------------------------
// LLMessageConfig
//---------------------------------------------------------------
//static
void LLMessageConfig::initClass(const std::string& server_name,
const std::string& config_dir)
{
sServerName = server_name;
sConfigDir = config_dir;
(void) LLMessageConfigFile::instance();
llinfos << "LLMessageConfig::intiClass config file "
<< config_dir << "/" << messageConfigFileName << llendl;
}
//static
bool LLMessageConfig::isServerDefaultBuilderLLSD()
{
if (sServerName.empty())
{
llerrs << "LLMessageConfig::isServerDefaultBuilderLLSD() before"
<< " LLMessageConfig::initClass()" << llendl;
}
LLMessageConfigFile& file = LLMessageConfigFile::instance();
return (file.mServerDefault == "llsd");
}
//static
bool LLMessageConfig::isServerDefaultBuilderTemplate()
{
if (sServerName.empty())
{
llerrs << "LLMessageConfig::isServerDefaultBuilderTemplate() before"
<< " LLMessageConfig::initClass()" << llendl;
}
LLMessageConfigFile& file = LLMessageConfigFile::instance();
return (file.mServerDefault == "template");
}
//static
bool LLMessageConfig::isMessageBuiltLLSD(const std::string& msg_name)
{
if (sServerName.empty())
{
llerrs << "LLMessageConfig::isMessageBuiltLLSD(name) before"
<< " LLMessageConfig::initClass()" << llendl;
}
LLMessageConfigFile& file = LLMessageConfigFile::instance();
LLSD config = file.mMessages[msg_name];
if (!config.has("builder"))
{
return isServerDefaultBuilderLLSD();
}
return (config["builder"].asString() == "llsd");
}
//static
bool LLMessageConfig::isMessageBuiltTemplate(const std::string& msg_name)
{
if (sServerName.empty())
{
llerrs << "LLMessageConfig::isMessageBuiltTemplate(name) before"
<< " LLMessageConfig::initClass()" << llendl;
}
LLMessageConfigFile& file = LLMessageConfigFile::instance();
LLSD config = file.mMessages[msg_name];
if (!config.has("builder"))
{
return isServerDefaultBuilderTemplate();
}
return (config["builder"].asString() == "template");
}
//static
bool LLMessageConfig::isMessageTrusted(const std::string& msg_name)
{
if (sServerName.empty())
{
llerrs << "LLMessageConfig::isMessageTrusted(name) before"
<< " LLMessageConfig::initClass()" << llendl;
}
LLMessageConfigFile& file = LLMessageConfigFile::instance();
LLSD config = file.mMessages[msg_name];
if (!config.has("trusted-sender"))
{
return false;
}
return config["trusted-sender"].asBoolean();
}
//static
bool LLMessageConfig::isValidUntrustedMessage(const std::string& msg_name)
{
if (sServerName.empty())
{
llerrs << "LLMessageConfig::isMessageTrusted(name) before"
<< " LLMessageConfig::initClass()" << llendl;
}
LLMessageConfigFile& file = LLMessageConfigFile::instance();
LLSD config = file.mMessages[msg_name];
if (!config.has("trusted-sender"))
{
return false;
}
return !(config["trusted-sender"].asBoolean());
}
|