PageRenderTime 24ms CodeModel.GetById 1ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmessage/llsdappservices.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 277 lines | 218 code | 26 blank | 33 comment | 13 complexity | af21c065f4e696ca5b0c7bce5e253188 MD5 | raw file
  1/** 
  2 * @file llsdappservices.cpp
  3 * @author Phoenix
  4 * @date 2006-09-12
  5 *
  6 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "linden_common.h"
 29#include "llsdappservices.h"
 30
 31#include "llapp.h"
 32#include "llhttpnode.h"
 33#include "llsdserialize.h"
 34
 35void LLSDAppServices::useServices()
 36{
 37	/*
 38		Having this function body here, causes the classes and globals in this
 39		file to be linked into any program that uses the llmessage library.
 40	*/
 41}
 42
 43class LLHTTPConfigService : public LLHTTPNode
 44{
 45public:
 46	virtual void describe(Description& desc) const
 47	{
 48		desc.shortInfo("GET an array of all the options in priority order.");
 49		desc.getAPI();
 50		desc.source(__FILE__, __LINE__);
 51	}
 52    
 53	virtual LLSD simpleGet() const
 54	{
 55		LLSD result;
 56		LLApp* app = LLApp::instance();
 57		for(int ii = 0; ii < LLApp::PRIORITY_COUNT; ++ii)
 58		{
 59			result.append(app->getOptionData((LLApp::OptionPriority)ii));
 60		}
 61		return result;
 62	}
 63};
 64
 65LLHTTPRegistration<LLHTTPConfigService>
 66	gHTTPRegistratiAppConfig("/app/config");
 67
 68class LLHTTPConfigRuntimeService : public LLHTTPNode
 69{
 70public:
 71	virtual void describe(Description& desc) const
 72	{
 73		desc.shortInfo("Manipulate a map of runtime-override options.");
 74		desc.getAPI();
 75		desc.postAPI();
 76		desc.source(__FILE__, __LINE__);
 77	}
 78    
 79	virtual LLSD simpleGet() const
 80	{
 81		return LLApp::instance()->getOptionData(
 82			LLApp::PRIORITY_RUNTIME_OVERRIDE);
 83	}
 84
 85	virtual void post(
 86		LLHTTPNode::ResponsePtr response,
 87		const LLSD& context,
 88		const LLSD& input) const
 89	{
 90		LLSD result = LLApp::instance()->getOptionData(
 91			LLApp::PRIORITY_RUNTIME_OVERRIDE);
 92		LLSD::map_const_iterator iter = input.beginMap();
 93		LLSD::map_const_iterator end = input.endMap();
 94		for(; iter != end; ++iter)
 95		{
 96			result[(*iter).first] = (*iter).second;
 97		}
 98		LLApp::instance()->setOptionData(
 99			LLApp::PRIORITY_RUNTIME_OVERRIDE,
100			result);
101		response->result(result);
102	}
103};
104
105LLHTTPRegistration<LLHTTPConfigRuntimeService>
106	gHTTPRegistrationRuntimeConfig("/app/config/runtime-override");
107
108class LLHTTPConfigRuntimeSingleService : public LLHTTPNode
109{
110public:
111	virtual void describe(Description& desc) const
112	{
113		desc.shortInfo("Manipulate a single runtime-override option.");
114		desc.getAPI();
115		desc.putAPI();
116		desc.delAPI();
117		desc.source(__FILE__, __LINE__);
118	}
119    
120	virtual bool validate(const std::string& name, LLSD& context) const
121	{
122		//llinfos << "validate: " << name << ", "
123		//	<< LLSDOStreamer<LLSDNotationFormatter>(context) << llendl;
124		if((std::string("PUT") == context["request"]["verb"].asString()) && !name.empty())
125		{
126			return true;
127		}
128		else
129		{
130			// This is for GET and DELETE
131			LLSD options = LLApp::instance()->getOptionData(
132				LLApp::PRIORITY_RUNTIME_OVERRIDE);
133			if(options.has(name)) return true;
134			else return false;
135		}
136	}
137
138	virtual void get(
139		LLHTTPNode::ResponsePtr response,
140		const LLSD& context) const
141	{
142		std::string name = context["request"]["wildcard"]["option-name"];
143		LLSD options = LLApp::instance()->getOptionData(
144			LLApp::PRIORITY_RUNTIME_OVERRIDE);
145		response->result(options[name]);
146	}
147
148	virtual void put(
149		LLHTTPNode::ResponsePtr response,
150		const LLSD& context,
151		const LLSD& input) const
152	{
153		std::string name = context["request"]["wildcard"]["option-name"];
154		LLSD options = LLApp::instance()->getOptionData(
155			LLApp::PRIORITY_RUNTIME_OVERRIDE);
156		options[name] = input;
157		LLApp::instance()->setOptionData(
158			LLApp::PRIORITY_RUNTIME_OVERRIDE,
159			options);
160		response->result(input);
161	}
162
163	virtual void del(
164		LLHTTPNode::ResponsePtr response,
165		const LLSD& context) const
166	{
167		std::string name = context["request"]["wildcard"]["option-name"];
168		LLSD options = LLApp::instance()->getOptionData(
169			LLApp::PRIORITY_RUNTIME_OVERRIDE);
170		options.erase(name);
171		LLApp::instance()->setOptionData(
172			LLApp::PRIORITY_RUNTIME_OVERRIDE,
173			options);
174		response->result(LLSD());
175	}
176};
177
178LLHTTPRegistration<LLHTTPConfigRuntimeSingleService>
179	gHTTPRegistrationRuntimeSingleConfig(
180		"/app/config/runtime-override/<option-name>");
181
182template<int PRIORITY>
183class LLHTTPConfigPriorityService : public LLHTTPNode
184{
185public:
186	virtual void describe(Description& desc) const
187	{
188		desc.shortInfo("Get a map of the options at this priority.");
189		desc.getAPI();
190		desc.source(__FILE__, __LINE__);
191	}
192
193	virtual void get(
194		LLHTTPNode::ResponsePtr response,
195		const LLSD& context) const
196	{
197		response->result(LLApp::instance()->getOptionData(
198			(LLApp::OptionPriority)PRIORITY));
199	}
200};
201
202LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_COMMAND_LINE> >
203	gHTTPRegistrationCommandLineConfig("/app/config/command-line");
204LLHTTPRegistration<
205	LLHTTPConfigPriorityService<LLApp::PRIORITY_SPECIFIC_CONFIGURATION> >
206	gHTTPRegistrationSpecificConfig("/app/config/specific");
207LLHTTPRegistration<
208	LLHTTPConfigPriorityService<LLApp::PRIORITY_GENERAL_CONFIGURATION> >
209	gHTTPRegistrationGeneralConfig("/app/config/general");
210LLHTTPRegistration< LLHTTPConfigPriorityService<LLApp::PRIORITY_DEFAULT> >
211	gHTTPRegistrationDefaultConfig("/app/config/default");
212
213class LLHTTPLiveConfigService : public LLHTTPNode
214{
215public:
216	virtual void describe(Description& desc) const
217	{
218		desc.shortInfo("Get a map of the currently live options.");
219		desc.getAPI();
220		desc.source(__FILE__, __LINE__);
221	}
222
223	virtual void get(
224		LLHTTPNode::ResponsePtr response,
225		const LLSD& context) const
226	{
227		LLSD result;
228		LLApp* app = LLApp::instance();
229		LLSD::map_const_iterator iter;
230		LLSD::map_const_iterator end;
231		for(int ii = LLApp::PRIORITY_COUNT - 1; ii >= 0; --ii)
232		{
233			LLSD options = app->getOptionData((LLApp::OptionPriority)ii);
234			iter = options.beginMap();
235			end = options.endMap();
236			for(; iter != end; ++iter)
237			{
238				result[(*iter).first] = (*iter).second;
239			}
240		}
241		response->result(result);
242	}
243};
244
245LLHTTPRegistration<LLHTTPLiveConfigService>
246	gHTTPRegistrationLiveConfig("/app/config/live");
247
248class LLHTTPLiveConfigSingleService : public LLHTTPNode
249{
250public:
251	virtual void describe(Description& desc) const
252	{
253		desc.shortInfo("Get the named live option.");
254		desc.getAPI();
255		desc.source(__FILE__, __LINE__);
256	}
257
258	virtual bool validate(const std::string& name, LLSD& context) const
259	{
260		llinfos << "LLHTTPLiveConfigSingleService::validate(" << name
261			<< ")" << llendl;
262		LLSD option = LLApp::instance()->getOption(name);
263		if(option.isDefined()) return true;
264		else return false;
265	}
266
267	virtual void get(
268		LLHTTPNode::ResponsePtr response,
269		const LLSD& context) const
270	{
271		std::string name = context["request"]["wildcard"]["option-name"];
272		response->result(LLApp::instance()->getOption(name));
273	}
274};
275
276LLHTTPRegistration<LLHTTPLiveConfigSingleService>
277	gHTTPRegistrationLiveSingleConfig("/app/config/live/<option-name>");