PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmessage/lliohttpserver.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 139 lines | 48 code | 18 blank | 73 comment | 0 complexity | 5c452daf6a88efe33b4370f6cd70f6bd MD5 | raw file
  1/** 
  2 * @file lliohttpserver.h
  3 * @brief Declaration of function for creating an HTTP wire server
  4 * @see LLIOServerSocket, LLPumpIO
  5 *
  6 * $LicenseInfo:firstyear=2005&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#ifndef LL_LLIOHTTPSERVER_H
 29#define LL_LLIOHTTPSERVER_H
 30
 31#include "llchainio.h"
 32#include "llhttpnode.h"
 33
 34class LLPumpIO;
 35
 36// common strings use for populating the context. bascally 'request',
 37// 'wildcard', and 'headers'.
 38extern const std::string CONTEXT_REQUEST;
 39extern const std::string CONTEXT_RESPONSE;
 40extern const std::string CONTEXT_VERB;
 41extern const std::string CONTEXT_HEADERS;
 42extern const std::string HTTP_VERB_GET;
 43extern const std::string HTTP_VERB_PUT;
 44extern const std::string HTTP_VERB_POST;
 45extern const std::string HTTP_VERB_DELETE;
 46extern const std::string HTTP_VERB_OPTIONS;
 47
 48class LLIOHTTPServer
 49{
 50public:
 51	typedef void (*timing_callback_t)(const char* hashed_name, F32 time, void* data);
 52
 53	static LLHTTPNode& create(apr_pool_t* pool, LLPumpIO& pump, U16 port);
 54	/**< Creates an HTTP wire server on the pump for the given TCP port.
 55	 *
 56	 *   Returns the root node of the new server.  Add LLHTTPNode instances
 57	 *   to this root.
 58	 *
 59	 *   Nodes that return NULL for getProtocolHandler(), will use the
 60	 *   default handler that interprets HTTP on the wire and converts
 61	 *   it into calls to get(), put(), post(), del() with appropriate
 62	 *   LLSD arguments and results.
 63	 *
 64	 *   To have nodes that implement some other wire protocol (XML-RPC
 65	 *   for example), use the helper templates below.
 66	 */
 67 
 68	static void createPipe(LLPumpIO::chain_t& chain, 
 69            const LLHTTPNode& root, const LLSD& ctx);
 70	/**< Create a pipe on the chain that handles HTTP requests.
 71	 *   The requests are served by the node tree given at root.
 72	 *
 73	 *   This is primarily useful for unit testing.
 74	 */
 75
 76	static void setTimingCallback(timing_callback_t callback, void* data);
 77	/**< Register a callback function that will be called every time
 78	*    a GET, PUT, POST, or DELETE is handled.
 79	*
 80	* This is used to time the LLHTTPNode handler code, which often hits
 81	* the database or does other, slow operations. JC
 82	*/
 83};
 84
 85/* @name Helper Templates
 86 *
 87 * These templates make it easy to create nodes that use thier own protocol
 88 * handlers rather than the default.  Typically, you subclass LLIOPipe to
 89 * implement the protocol, and then add a node using the templates:
 90 *
 91 * rootNode->addNode("thing", new LLHTTPNodeForPipe<LLThingPipe>);
 92 *
 93 * The templates are:
 94 *
 95 * 	LLChainIOFactoryForPipe
 96 * 		- a simple factory that builds instances of a pipe
 97 *
 98 * 	LLHTTPNodeForFacotry
 99 * 		- a HTTP node that uses a factory as the protocol handler
100 *
101 * 	LLHTTPNodeForPipe
102 * 		- a HTTP node that uses a simple factory based on a pipe
103 */
104//@{
105
106template<class Pipe>
107class LLChainIOFactoryForPipe : public LLChainIOFactory
108{
109public:
110	virtual bool build(LLPumpIO::chain_t& chain, LLSD context) const
111	{   
112		chain.push_back(LLIOPipe::ptr_t(new Pipe));
113		return true;
114	}
115};
116
117template<class Factory>
118class LLHTTPNodeForFactory : public LLHTTPNode
119{
120public:
121	const LLChainIOFactory* getProtocolHandler() const
122		{ return &mProtocolHandler; }
123
124private:
125	Factory mProtocolHandler;
126};
127
128//@}
129
130
131template<class Pipe>
132class LLHTTPNodeForPipe : public LLHTTPNodeForFactory<
133						  			LLChainIOFactoryForPipe<Pipe> >
134{
135};
136
137
138#endif // LL_LLIOHTTPSERVER_H
139