~ubuntu-branches/ubuntu/oneiric/inspircd/oneiric-security

« back to all changes in this revision

Viewing changes to src/modules/httpclient.h

  • Committer: Bazaar Package Importer
  • Author(s): Darren Blaber
  • Date: 2008-04-21 12:51:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080421125101-m6lqhtn1wna8u2go
Tags: 1.1.19+dfsg-1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*       +------------------------------------+
2
 
 *       | Inspire Internet Relay Chat Daemon |
3
 
 *       +------------------------------------+
4
 
 *
5
 
 *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6
 
 * See: http://www.inspircd.org/wiki/index.php/Credits
7
 
 *
8
 
 * This program is free but copyrighted software; see
9
 
 *            the file COPYING for details.
10
 
 *
11
 
 * ---------------------------------------------------
12
 
 */
13
 
 
14
 
#include "base.h"
15
 
 
16
 
#ifndef HTTPCLIENT_H__
17
 
#define HTTPCLIENT_H__
18
 
 
19
 
#include <string>
20
 
#include <map>
21
 
 
22
 
typedef std::map<std::string,std::string> HeaderMap;
23
 
 
24
 
const char* HTTP_CLIENT_RESPONSE = "HTTPCLIENT_RESPONSE";
25
 
const char* HTTP_CLIENT_REQUEST = "HTTPCLIENT_REQUEST";
26
 
 
27
 
/** This class represents an outgoing HTTP request
28
 
 */
29
 
class HTTPClientRequest : public Request
30
 
{
31
 
 protected:
32
 
        std::string url;
33
 
        InspIRCd *Instance;
34
 
        Module *src;
35
 
        HeaderMap Headers;
36
 
 public:
37
 
        HTTPClientRequest(InspIRCd *Instance, Module *src, Module* target, const std::string &url)
38
 
                : Request(src, target, HTTP_CLIENT_REQUEST), url(url), Instance(Instance), src(src)
39
 
        {
40
 
                Headers["User-Agent"] = "InspIRCd (m_http_client.so)";
41
 
                Headers["Connection"] = "Close";
42
 
                Headers["Accept"] = "*/*";
43
 
        }
44
 
 
45
 
        HTTPClientRequest() : Request(NULL, NULL, HTTP_CLIENT_REQUEST)
46
 
        {
47
 
        }
48
 
 
49
 
        const std::string &GetURL()
50
 
        {
51
 
                return url;
52
 
        }
53
 
 
54
 
        void AddHeader(std::string &header, std::string &data)
55
 
        {
56
 
                Headers[header] = data;
57
 
        }
58
 
        
59
 
        void DeleteHeader(std::string &header)
60
 
        {
61
 
                Headers.erase(header);
62
 
        }
63
 
 
64
 
        HeaderMap GetHeaders()
65
 
        {
66
 
                return Headers;
67
 
        }
68
 
};
69
 
 
70
 
class HTTPClientResponse : public Request
71
 
{
72
 
 protected:
73
 
        friend class HTTPSocket;
74
 
        
75
 
        std::string url;
76
 
        std::string data;
77
 
        int response;
78
 
        std::string responsestr;
79
 
        HeaderMap Headers;
80
 
 public:
81
 
        HTTPClientResponse(Module* src, Module* target, std::string &url, int response, std::string responsestr)
82
 
                : Request(src, target, HTTP_CLIENT_RESPONSE), url(url), response(response), responsestr(responsestr)
83
 
        {
84
 
        }
85
 
 
86
 
        HTTPClientResponse() : Request(NULL, NULL, HTTP_CLIENT_RESPONSE)
87
 
        {
88
 
        }
89
 
 
90
 
        void SetData(const std::string &ndata)
91
 
        {
92
 
                data = ndata;
93
 
        }
94
 
        
95
 
        void AddHeader(const std::string &header, const std::string &data)
96
 
        {
97
 
                Headers[header] = data;
98
 
        }
99
 
        
100
 
        const std::string &GetURL()
101
 
        {
102
 
                return url;
103
 
        }
104
 
        
105
 
        const std::string &GetData()
106
 
        {
107
 
                return data;
108
 
        }
109
 
        
110
 
        int GetResponse(std::string &str)
111
 
        {
112
 
                str = responsestr;
113
 
                return response;
114
 
        }
115
 
        
116
 
        std::string GetHeader(const std::string &header)
117
 
        {
118
 
                HeaderMap::iterator i = Headers.find(header);
119
 
                
120
 
                if (i != Headers.end())
121
 
                        return i->second;
122
 
                else
123
 
                        return "";
124
 
        }
125
 
};
126
 
 
127
 
#endif