Platinum UPnP SDK  1.0.5.13
PltHttp.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - HTTP Helper
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 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
39 #ifndef _PLT_HTTP_H_
40 #define _PLT_HTTP_H_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltVersion.h"
47 
48 /*----------------------------------------------------------------------
49 | constants
50 +---------------------------------------------------------------------*/
51 #if !defined(PLT_HTTP_DEFAULT_USER_AGENT)
52 #define PLT_HTTP_DEFAULT_USER_AGENT "UPnP/1.0 DLNADOC/1.50 Platinum/" PLT_PLATINUM_SDK_VERSION_STRING
53 #endif
54 
55 #if !defined(PLT_HTTP_DEFAULT_SERVER)
56 #define PLT_HTTP_DEFAULT_SERVER "UPnP/1.0 DLNADOC/1.50 Platinum/" PLT_PLATINUM_SDK_VERSION_STRING
57 #endif
58 
59 /*----------------------------------------------------------------------
60 | types
61 +---------------------------------------------------------------------*/
62 typedef enum {
63  PLT_DEVICE_UNKNOWN,
64  PLT_DEVICE_XBOX,
65  PLT_DEVICE_PS3,
66  PLT_DEVICE_WMP,
67  PLT_DEVICE_SONOS,
68  PLT_DEVICE_MAC,
69  PLT_DEVICE_WINDOWS,
70  PLT_DEVICE_VLC
71 } PLT_DeviceSignature;
72 
73 /*----------------------------------------------------------------------
74 | PLT_HttpHelper
75 +---------------------------------------------------------------------*/
81 public:
82  static bool IsConnectionKeepAlive(NPT_HttpMessage& message);
83  static bool IsBodyStreamSeekable(NPT_HttpMessage& message);
84 
85  static NPT_Result ToLog(NPT_LoggerReference logger, int level, const char* prefix, NPT_HttpRequest* request);
86  static NPT_Result ToLog(NPT_LoggerReference logger, int level, const char* prefix, const NPT_HttpRequest& request);
87  static NPT_Result ToLog(NPT_LoggerReference logger, int level, const char* prefix, NPT_HttpResponse* response);
88  static NPT_Result ToLog(NPT_LoggerReference logger, int level, const char* prefix, const NPT_HttpResponse& response);
89 
90  static NPT_Result GetContentType(const NPT_HttpMessage& message, NPT_String& type);
91  static NPT_Result GetContentLength(const NPT_HttpMessage& message, NPT_LargeSize& len);
92 
93  static NPT_Result GetHost(const NPT_HttpRequest& request, NPT_String& value);
94  static void SetHost(NPT_HttpRequest& request, const char* host);
95  static PLT_DeviceSignature GetDeviceSignature(const NPT_HttpRequest& request);
96 
97  static NPT_Result SetBody(NPT_HttpMessage& message, NPT_String& text, NPT_HttpEntity** entity = NULL);
98  static NPT_Result SetBody(NPT_HttpMessage& message, const char* text, NPT_HttpEntity** entity = NULL);
99  static NPT_Result SetBody(NPT_HttpMessage& message, const void* body, NPT_LargeSize len, NPT_HttpEntity** entity = NULL);
100  static NPT_Result SetBody(NPT_HttpMessage& message, NPT_InputStreamReference stream, NPT_HttpEntity** entity = NULL);
101  static NPT_Result GetBody(const NPT_HttpMessage& message, NPT_String& body);
102  static NPT_Result ParseBody(const NPT_HttpMessage& message, NPT_XmlElementNode*& xml);
103 
104  static void SetBasicAuthorization(NPT_HttpRequest& request, const char* username, const char* password);
105 };
106 
107 /*----------------------------------------------------------------------
108 | PLT_HttpRequestContext
109 +---------------------------------------------------------------------*/
115 class PLT_HttpRequestContext : public NPT_HttpRequestContext {
116 public:
117  // constructors and destructor
118  PLT_HttpRequestContext(const NPT_HttpRequest& request) :
119  m_Request(request) {}
120  PLT_HttpRequestContext(const NPT_HttpRequest& request, const NPT_HttpRequestContext& context) :
121  NPT_HttpRequestContext(&context.GetLocalAddress(), &context.GetRemoteAddress()),
122  m_Request(request) {}
123  virtual ~PLT_HttpRequestContext() {}
124 
125  const NPT_HttpRequest& GetRequest() const { return m_Request; }
126  PLT_DeviceSignature GetDeviceSignature() { return PLT_HttpHelper::GetDeviceSignature(m_Request); }
127 
128 private:
129  const NPT_HttpRequest& m_Request;
130 };
131 
132 /*----------------------------------------------------------------------
133 | macros
134 +---------------------------------------------------------------------*/
135 #if defined(NPT_CONFIG_ENABLE_LOGGING)
136 #define PLT_LOG_HTTP_MESSAGE_L(_logger, _level, _prefix, _msg) \
137  PLT_HttpHelper::ToLog((_logger), (_level), (_prefix), (_msg))
138 #define PLT_LOG_HTTP_MESSAGE(_level, _prefix, _msg) \
139  PLT_HttpHelper::ToLog((_NPT_LocalLogger), (_level), (_prefix), (_msg))
140 
141 #else /* NPT_CONFIG_ENABLE_LOGGING */
142 #define PLT_LOG_HTTP_MESSAGE_L(_logger, _level, _prefix, _msg)
143 #define PLT_LOG_HTTP_MESSAGE(_level, _prefix, _msg)
144 #endif /* NPT_CONFIG_ENABLE_LOGGING */
145 
146 /*----------------------------------------------------------------------
147 | PLT_HttpRequestHandler
148 +---------------------------------------------------------------------*/
153 class PLT_HttpRequestHandler : public NPT_HttpRequestHandler
154 {
155 public:
156  PLT_HttpRequestHandler(NPT_HttpRequestHandler* delegate) :
157  m_Delegate(delegate) {}
158  virtual ~PLT_HttpRequestHandler() {}
159 
160  // NPT_HttpRequestHandler methods
161  NPT_Result SetupResponse(NPT_HttpRequest& request,
162  const NPT_HttpRequestContext& context,
163  NPT_HttpResponse& response) {
164  return m_Delegate->SetupResponse(request, context, response);
165  }
166 
167 private:
168  NPT_HttpRequestHandler* m_Delegate;
169 };
170 
171 #endif /* _PLT_HTTP_H_ */
The PLT_HttpHelper class is a set of utility functions for manipulating HTTP headers, entities and messages.
Definition: PltHttp.h:80
The PLT_HttpRequestContext class holds information about the request sent, the local & remote ip addr...
Definition: PltHttp.h:115
The PLT_HttpRequestHandler class delegates the handling of the response of a received HTTP request by...
Definition: PltHttp.h:153