aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llsdhttpserver.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/llsdhttpserver.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmessage/llsdhttpserver.cpp')
-rw-r--r--linden/indra/llmessage/llsdhttpserver.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llsdhttpserver.cpp b/linden/indra/llmessage/llsdhttpserver.cpp
new file mode 100644
index 0000000..4054680
--- /dev/null
+++ b/linden/indra/llmessage/llsdhttpserver.cpp
@@ -0,0 +1,151 @@
1/**
2 * @file llsdhttpserver.cpp
3 * @brief Standard LLSD services
4 *
5 * Copyright (c) 2006-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "linden_common.h"
29#include "llsdhttpserver.h"
30
31#include "llhttpnode.h"
32
33/**
34 * This module implements common services that should be included
35 * in all server URL trees. These services facilitate debugging and
36 * introsepction.
37 */
38
39void LLHTTPStandardServices::useServices()
40{
41 /*
42 Having this function body here, causes the classes and globals in this
43 file to be linked into any program that uses the llmessage library.
44 */
45}
46
47
48
49class LLHTTPHelloService : public LLHTTPNode
50{
51public:
52 virtual void describe(Description& desc) const
53 {
54 desc.shortInfo("says hello");
55 desc.getAPI();
56 desc.output("\"hello\"");
57 desc.source(__FILE__, __LINE__);
58 }
59
60 virtual LLSD get() const
61 {
62 LLSD result = "hello";
63 return result;
64 }
65};
66
67LLHTTPRegistration<LLHTTPHelloService>
68 gHTTPRegistrationWebHello("/web/hello");
69
70
71
72class LLHTTPEchoService : public LLHTTPNode
73{
74public:
75 virtual void describe(Description& desc) const
76 {
77 desc.shortInfo("echo input");
78 desc.postAPI();
79 desc.input("<any>");
80 desc.output("<the input>");
81 desc.source(__FILE__, __LINE__);
82 }
83
84 virtual LLSD post(const LLSD& params) const
85 {
86 return params;
87 }
88};
89
90LLHTTPRegistration<LLHTTPEchoService>
91 gHTTPRegistrationWebEcho("/web/echo");
92
93
94
95class LLAPIService : public LLHTTPNode
96{
97public:
98 virtual void describe(Description& desc) const
99 {
100 desc.shortInfo("information about the URLs this server supports");
101 desc.getAPI();
102 desc.output("a list of URLs supported");
103 desc.source(__FILE__, __LINE__);
104 }
105
106 virtual bool handles(const LLSD& remainder, LLSD& context) const
107 {
108 return followRemainder(remainder) != NULL;
109 }
110
111 virtual void get(ResponsePtr response, const LLSD& context) const
112 {
113 const LLSD& remainder = context["request"]["remainder"];
114
115 if (remainder.size() > 0)
116 {
117 const LLHTTPNode* node = followRemainder(remainder);
118 if (!node)
119 {
120 response->notFound();
121 return;
122 }
123
124 Description desc;
125 node->describe(desc);
126 response->result(desc.getInfo());
127 return;
128 }
129
130 response->result(rootNode()->allNodePaths());
131 }
132
133private:
134 const LLHTTPNode* followRemainder(const LLSD& remainder) const
135 {
136 const LLHTTPNode* node = rootNode();
137
138 LLSD::array_const_iterator i = remainder.beginArray();
139 LLSD::array_const_iterator end = remainder.endArray();
140 for (; node && i != end; ++i)
141 {
142 node = node->findNode(*i);
143 }
144
145 return node;
146 }
147};
148
149LLHTTPRegistration<LLAPIService>
150 gHTTPRegistrationWebServerApi("/web/server/api");
151