kodi
Http.h
1 /*****************************************************************
2 |
3 | Platinum - Managed Http
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 |
21 | This program is distributed in the hope that it will be useful,
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | GNU General Public License for more details.
25 |
26 | You should have received a copy of the GNU General Public License
27 | along with this program; see the file LICENSE.txt. If not, write to
28 | the Free Software Foundation, Inc.,
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 | http://www.gnu.org/licenses/gpl-2.0.html
31 |
32 ****************************************************************/
33 #pragma once
34 
35 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 
39 namespace Platinum
40 {
41 
42 /*----------------------------------------------------------------------
43 | HttpRequest
44 +---------------------------------------------------------------------*/
45 public ref class HttpRequest
46 {
47 protected:
48 
49  NPT_HttpRequest* m_pHandle;
50 
51 internal:
52 
53  property NPT_HttpRequest& Handle
54  {
55  NPT_HttpRequest& get()
56  {
57  return *m_pHandle;
58  }
59  }
60 
61 public:
62 
63  virtual Boolean Equals(Object^ obj) override
64  {
65  if (obj == nullptr)
66  return false;
67 
68  if (!this->GetType()->IsInstanceOfType(obj))
69  return false;
70 
71  return (m_pHandle == ((HttpRequest^)obj)->m_pHandle);
72  }
73 
74 public:
75 
76  // properties
77  virtual property Uri^ URI
78  {
79  Uri^ get()
80  {
81  return marshal_as<Uri^>(m_pHandle->GetUrl());
82  }
83  }
84 
85 internal:
86 
87  // Note: Because a NPT_HttpRequest cannot do a deep copy,
88  // this only refers to the original native object
89  HttpRequest(NPT_HttpRequest& native) :
90  m_pHandle(&native)
91  {
92  }
93 
94 public:
95 
96  ~HttpRequest()
97  {
98  // clean-up managed
99 
100  // clean-up unmanaged
101  this->!HttpRequest();
102  }
103 
104  !HttpRequest()
105  {
106  // clean-up unmanaged
107  }
108 };
109 
110 }
111 
112 // marshal wrapper
113 PLATINUM_MANAGED_MARSHAL_AS(Platinum::HttpRequest, NPT_HttpRequest);
114 
115 namespace Platinum
116 {
117 
118 /*----------------------------------------------------------------------
119 | HttpRequest
120 +---------------------------------------------------------------------*/
121 public ref class HttpResponse
122 {
123 protected:
124 
125  NPT_HttpResponse* m_pHandle;
126 
127 internal:
128 
129  property NPT_HttpResponse& Handle
130  {
131  NPT_HttpResponse& get()
132  {
133  return *m_pHandle;
134  }
135  }
136 
137 public:
138 
139  virtual Boolean Equals(Object^ obj) override
140  {
141  if (obj == nullptr)
142  return false;
143 
144  if (!this->GetType()->IsInstanceOfType(obj))
145  return false;
146 
147  return (m_pHandle == ((HttpResponse^)obj)->m_pHandle);
148  }
149 
150 internal:
151 
152  // Note: Because a NPT_HttpResponse cannot do a deep copy,
153  // this only refers to the original native object
154  HttpResponse(NPT_HttpResponse& native) :
155  m_pHandle(&native)
156  {
157  }
158 
159 public:
160 
161  ~HttpResponse()
162  {
163  // clean-up managed
164 
165  // clean-up unmanaged
166  this->!HttpResponse();
167  }
168 
169  !HttpResponse()
170  {
171  // clean-up unmanaged
172  }
173 };
174 
175 }
176 
177 // marshal wrapper
178 PLATINUM_MANAGED_MARSHAL_AS(Platinum::HttpResponse, NPT_HttpResponse);
179 
180 namespace Platinum
181 {
182 
183 /*----------------------------------------------------------------------
184 | DeviceSignature
185 +---------------------------------------------------------------------*/
186 public enum class DeviceSignature
187 {
188  Unknown,
189  XBox,
190  PS3,
191  WMP
192 };
193 
194 /*----------------------------------------------------------------------
195 | HttpRequestContext
196 +---------------------------------------------------------------------*/
197 public ref class HttpRequestContext : ManagedWrapper<PLT_HttpRequestContext>
198 {
199 
200 public:
201 
202  ref struct SocketAddress {
203  String^ ip;
204  UInt32 port;
205  };
206 
207  virtual property SocketAddress^ LocalAddress
208  {
209  SocketAddress^ get()
210  {
211  SocketAddress^ local = gcnew SocketAddress;
212  local->ip = marshal_as<String^>(Handle.GetLocalAddress().GetIpAddress().ToString());
213  local->port = Handle.GetLocalAddress().GetPort();
214  return local;
215  }
216  }
217 
218  virtual property SocketAddress^ RemoteAddress
219  {
220  SocketAddress^ get()
221  {
222  SocketAddress^ local = gcnew SocketAddress;
223  local->ip = marshal_as<String^>(Handle.GetRemoteAddress().GetIpAddress().ToString());
224  local->port = Handle.GetRemoteAddress().GetPort();
225  return local;
226  }
227  }
228 
229  virtual property HttpRequest^ Request
230  {
231  HttpRequest^ get()
232  {
233  return marshal_as<HttpRequest^>(m_pHandle->GetRequest());
234  }
235  }
236 
237  virtual property DeviceSignature Signature
238  {
239  DeviceSignature get()
240  {
241  return ParseDeviceSignature(m_pHandle->GetDeviceSignature());
242  }
243  }
244 private:
245 
246  static DeviceSignature ParseDeviceSignature(PLT_DeviceSignature signature)
247  {
248  switch (signature)
249  {
250  case PLT_DEVICE_XBOX:
251  return DeviceSignature::XBox;
252  case PLT_DEVICE_PS3:
253  return DeviceSignature::PS3;
254  case PLT_DEVICE_WMP:
255  return DeviceSignature::WMP;
256  default:
257  return DeviceSignature::Unknown;
258  }
259  }
260 
261 
262 internal:
263 
266  {
267  }
268 
270  {
271  // clean-up managed
272 
273  // clean-up unmanaged
274  this->!HttpRequestContext();
275  }
276 
278  {
279  // clean-up unmanaged
280  }
281 };
282 
283 }
284 
285 // marshal wrapper
286 PLATINUM_MANAGED_MARSHAL_AS(Platinum::HttpRequestContext, PLT_HttpRequestContext);
Definition: Http.h:45
Definition: Http.h:121
Definition: NptHttp.h:315
Definition: NptHttp.h:282
Definition: Http.h:197
The PLT_HttpRequestContext class holds information about the request sent, the local & remote ip addr...
Definition: PltHttp.h:111
Definition: Helpers.h:274