SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HTTPConnection.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20
21 #include "NativeFeatureIncludes.h"
22 #if _RAKNET_SUPPORT_HTTPConnection==1 && _RAKNET_SUPPORT_TCPInterface==1
23
24 #ifndef __HTTP_CONNECTION
25 #define __HTTP_CONNECTION
26
27 #include "Export.h"
28 #include "string.h"
29 #include "memoryoverride.h"
30 #include "types.h"
31 #include "DS_Queue.h"
32
33 namespace SLNet
34 {
36 class TCPInterface;
37 struct SystemAddress;
38
47 class RAK_DLL_EXPORT HTTPConnection
48 {
49 public:
50 // GetInstance() and DestroyInstance(instance*)
51 STATIC_FACTORY_DECLARATIONS(HTTPConnection)
52
53
54 HTTPConnection();
55 virtual ~HTTPConnection();
56
58 void Init(TCPInterface *_tcp, const char *host, unsigned short port=80);
59
67 void Post(const char *path, const char *data, const char *_contentType="application/x-www-form-urlencoded");
68
71 void Get(const char *path);
72
74 bool HasRead(void) const;
75
78 SLNet::RakString Read(void);
79
81 void Update(void);
82
84 SystemAddress GetServerAddress(void) const;
85
91 void ProcessTCPPacket(Packet *packet);
92
95 enum ResponseCodes { NoBody=1001, OK=200, Deleted=1002 };
96
97 HTTPConnection& operator=(const HTTPConnection& rhs){(void) rhs; return *this;}
98
100 struct BadResponse
101 {
102 public:
103 BadResponse() {code=0;}
104
105 BadResponse(const unsigned char *_data, int _code)
106 : data((const char *)_data), code(_code) {}
107
108 BadResponse(const char *_data, int _code)
109 : data(_data), code(_code) {}
110
111 operator int () const { return code; }
112
113 SLNet::RakString data;
114 int code; // ResponseCodes
115 };
116
118 bool HasBadResponse(int *code, SLNet::RakString *data);
119
121 bool IsBusy(void) const;
122
124 int GetState(void) const;
125
126 struct OutgoingCommand
127 {
128 SLNet::RakString remotePath;
129 SLNet::RakString data;
130 SLNet::RakString contentType;
131 bool isPost;
132 };
133
134 DataStructures::Queue<OutgoingCommand> outgoingCommand;
135 OutgoingCommand currentProcessingCommand;
136
137 private:
138 SystemAddress server;
139 TCPInterface *tcp;
140 SLNet::RakString host;
141 unsigned short port;
142 DataStructures::Queue<BadResponse> badResponses;
143
144 enum ConnectionState
145 {
146 CS_NONE,
147 CS_DISCONNECTING,
148 CS_CONNECTING,
149 CS_CONNECTED,
150 CS_PROCESSING,
151 } connectionState;
152
153 SLNet::RakString incomingData;
154 DataStructures::Queue<SLNet::RakString> results;
155
156 void CloseConnection();
157
158 /*
159 enum { RAK_HTTP_INITIAL,
160 RAK_HTTP_STARTING,
161 RAK_HTTP_CONNECTING,
162 RAK_HTTP_ESTABLISHED,
163 RAK_HTTP_REQUEST_SENT,
164 RAK_HTTP_IDLE } state;
165
166 SLNet::RakString outgoing, incoming, path, contentType;
167 void Process(Packet *packet); // the workhorse
168
169 // this helps check the various status lists in TCPInterface
170 typedef SystemAddress (TCPInterface::*StatusCheckFunction)(void);
171 bool InList(StatusCheckFunction func);
172 */
173
174 };
175
176 } // namespace SLNet
177
178 #endif
179
180 #endif // _RAKNET_SUPPORT_*