aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/hippoRestRequest.h
blob: 727dbf7338e700d1798c19a91750677df334c9f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef __HIPPO_REST_REQUEST_H__
#define __HIPPO_REST_REQUEST_H__


#include <map>
#include <string>

#include <boost/shared_ptr.hpp>

class LLBufferArray;
class LLChannelDescriptors;
class LLXmlTree;


#define HIPPO_REST_TIMEOUT 60.f


// ********************************************************************
 

class HippoRestHandler
{
	public:
		virtual ~HippoRestHandler() { }
 
		virtual const char *getAcceptMimeType() const = 0;

		bool hasHeader(const std::string &header) const;
		const std::string &getHeader(const std::string &header) const;

	private:
		// These functions are called by the request engine
		void addHeader(const std::string &header, const std::string &content);
		virtual void handle(int status, const std::string &reason,
							const LLChannelDescriptors &channels,
							const boost::shared_ptr<LLBufferArray> &body) = 0;

		std::map<std::string, std::string> mHeaders;
		
		friend class HippoRestComplete;
};

 
class HippoRestHandlerRaw : public HippoRestHandler
{
	public:
		virtual ~HippoRestHandlerRaw() { }

		const char *getAcceptMimeType() const { return "application/octet-stream"; }

	private:
		// This function must be implemented to receive the content
		// it is executed on (status == 200) only
		virtual void result(const std::string &content) = 0;

		// This function is called by the request engine
		void handle(int status, const std::string &reason,
					const LLChannelDescriptors &channels,
					const boost::shared_ptr<LLBufferArray> &body);
};


class HippoRestHandlerXml : public HippoRestHandler
{
	public:
		virtual ~HippoRestHandlerXml() { }

		const char *getAcceptMimeType() const { return "application/xml"; }
		
	private:
		// This function must be implemented to receive the content
		virtual void result(LLXmlTree *content) = 0;

		// This function is called by the request engine
		void handle(int status, const std::string &reason,
					const LLChannelDescriptors &channels,
					const boost::shared_ptr<LLBufferArray> &body);
};


// ********************************************************************


class HippoRestRequest
{
	public:
		// asynchronous interface
		static void get(const std::string &url,
						HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT);
		static void put(const std::string &url, const std::string &body,
						HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT);
		static void put(const std::string &url, const LLXmlTree *body,
						HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT);
		static void post(const std::string &url, const std::string &body,
						 HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT);
		static void post(const std::string &url, const LLXmlTree *body,
						 HippoRestHandler *handler, float timeout=HIPPO_REST_TIMEOUT);
 
		// synchronous interface
		static int getBlocking(const std::string &url, std::string *result);
};


#endif