llsdhttpserver.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 #include "llsdhttpserver.h"
00034 
00035 #include "llhttpnode.h"
00036 
00043 void LLHTTPStandardServices::useServices()
00044 {
00045         /*
00046                 Having this function body here, causes the classes and globals in this
00047                 file to be linked into any program that uses the llmessage library.
00048         */
00049 }
00050 
00051 
00052 
00053 class LLHTTPHelloService : public LLHTTPNode
00054 {
00055 public:
00056         virtual void describe(Description& desc) const
00057         {
00058                 desc.shortInfo("says hello");
00059                 desc.getAPI();
00060                 desc.output("\"hello\"");
00061                 desc.source(__FILE__, __LINE__);
00062         }
00063     
00064         virtual LLSD get() const
00065         {
00066                 LLSD result = "hello";
00067                 return result;
00068         }
00069 };
00070 
00071 LLHTTPRegistration<LLHTTPHelloService>
00072         gHTTPRegistrationWebHello("/web/hello");
00073 
00074 
00075 
00076 class LLHTTPEchoService : public LLHTTPNode
00077 {
00078 public:
00079         virtual void describe(Description& desc) const
00080         {
00081                 desc.shortInfo("echo input");
00082                 desc.postAPI();
00083                 desc.input("<any>");
00084                 desc.output("<the input>");
00085                 desc.source(__FILE__, __LINE__);
00086         }
00087         
00088     virtual LLSD post(const LLSD& params) const
00089         {
00090                 return params;
00091         }
00092 };
00093 
00094 LLHTTPRegistration<LLHTTPEchoService>
00095         gHTTPRegistrationWebEcho("/web/echo");
00096 
00097 
00098 
00099 class LLAPIService : public LLHTTPNode
00100 {
00101 public:
00102         virtual void describe(Description& desc) const
00103         {
00104                 desc.shortInfo("information about the URLs this server supports");
00105                 desc.getAPI();
00106                 desc.output("a list of URLs supported");
00107                 desc.source(__FILE__, __LINE__);
00108         }
00109 
00110         virtual bool handles(const LLSD& remainder, LLSD& context) const
00111         {
00112                 return followRemainder(remainder) != NULL;
00113         }
00114 
00115     virtual void get(ResponsePtr response, const LLSD& context) const
00116         {
00117                 const LLSD& remainder = context["request"]["remainder"];
00118                 
00119                 if (remainder.size() > 0)
00120                 {
00121                         const LLHTTPNode* node = followRemainder(remainder);
00122                         if (!node)
00123                         {
00124                                 response->notFound();
00125                                 return;
00126                         }
00127                         
00128                         Description desc;
00129                         node->describe(desc);
00130                         response->result(desc.getInfo());
00131                         return;
00132                 }
00133 
00134                 response->result(rootNode()->allNodePaths());
00135         }
00136 
00137 private:
00138         const LLHTTPNode* followRemainder(const LLSD& remainder) const
00139         {
00140                 const LLHTTPNode* node = rootNode();
00141                 
00142                 LLSD::array_const_iterator i = remainder.beginArray();
00143                 LLSD::array_const_iterator end = remainder.endArray();
00144                 for (; node  &&  i != end; ++i)
00145                 {
00146                         node = node->findNode(*i);
00147                 }
00148                 
00149                 return node;
00150         }
00151 };
00152 
00153 LLHTTPRegistration<LLAPIService>
00154         gHTTPRegistrationWebServerApi("/web/server/api");
00155 

Generated on Fri May 16 08:32:30 2008 for SecondLife by  doxygen 1.5.5