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

