UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
httpreadwrite.hpp
Go to the documentation of this file.
1#ifndef UPNPLIB_HTTPREADWRITE_HPP
2#define UPNPLIB_HTTPREADWRITE_HPP
3// Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
4// Redistribution only with this Copyright remark. Last modified: 2025-06-11
10#include <string>
11
12namespace UPnPsdk {
13
14// ######################################
15// Interface for the httpreadwrite module
16// ######################################
17// clang-format off
18// Only these functions are called exclusively by the upnpapi module.
19//
20// `http_CancelHttpGet(void*)'
21// `http_CloseHttpConnection(void*)'
22// `http_Download(char const*, int, char**, unsigned long*, char*)'
23// `http_EndHttpRequest(void*, int)'
24// `http_GetHttpResponse(void*, s_UpnpString*, char**, int*, int*, int)'
25// `http_HttpGetProgress(void*, unsigned long*, unsigned long*)'
26// `http_MakeHttpRequest(Upnp_HttpMethod_e, char const*, void*, s_UpnpString*, char const*, int, int)'
27// `http_OpenHttpConnection(char const*, void**, int)'
28// `http_OpenHttpGetEx(char const*, void**, char**, int*, int*, int, int, int)'
29// `http_ReadHttpResponse(void*, char*, unsigned long*, int)'
30
31#if 0
35class Ihttpreadwrite {
36 public:
37 virtual ~Ihttpreadwrite() {}
38
40 virtual struct tm* http_gmtime_r(
41 const time_t* clock, struct tm* result) = 0;
43 virtual int http_FixUrl(
44 uri_type* url, uri_type* fixed_url) = 0;
46 virtual int http_FixStrUrl(
47 const char* urlstr, size_t urlstrlen, uri_type* fixed_url) = 0;
49 virtual SOCKET http_Connect(
50 uri_type* destination_url, uri_type* url) = 0;
52 virtual int http_RecvMessage(
53 SOCKINFO* info, http_parser_t* parser, http_method_t request_method,
54 int* timeout_secs, int* http_error_code) = 0;
55 // virtual int http_SendMessage(
56 // SOCKINFO* info, int* TimeOut, const char* fmt, ...) = 0;
58 virtual int http_RequestAndResponse(
59 uri_type* destination, const char* request, size_t request_length,
60 http_method_t req_method, int timeout_secs, http_parser_t* response) = 0;
62 virtual int http_Download(
63 const char* url_str, int timeout_secs, char** document,
64 size_t* doc_length, char* content_type) = 0;
66 virtual int MakeGenericMessage(
67 http_method_t method, const char* url_str, membuffer* request, uri_type* url,
68 int contentLength, const char* contentType, const UpnpString* headers) = 0;
70 virtual int http_HttpGetProgress(
71 void* Handle, size_t* length, size_t* total) = 0;
73 virtual int http_CancelHttpGet(
74 void* Handle) = 0;
76 virtual int http_OpenHttpConnection(
77 const char* url_str, void** Handle, int timeout) = 0;
79 virtual int http_MakeHttpRequest(
80 Upnp_HttpMethod method, const char* url_str, void* Handle, UpnpString* headers,
81 const char* contentType, int contentLength, int timeout) = 0;
83 virtual int http_WriteHttpRequest(
84 void* Handle, char* buf, size_t* size, int timeout) = 0;
86 virtual int http_EndHttpRequest(
87 void* Handle, int timeout) = 0;
89 virtual int http_GetHttpResponse(
90 void* Handle, UpnpString* headers, char** contentType, int* contentLength,
91 int* httpStatus, int timeout) = 0;
93 virtual int http_ReadHttpResponse(
94 void* Handle, char* buf, size_t* size, int timeout) = 0;
96 virtual int http_CloseHttpConnection(
97 void* Handle) = 0;
99 virtual int http_SendStatusResponse(
100 SOCKINFO* info, int http_status_code, int request_major_version,
101 int request_minor_version) = 0;
102 // virtual int http_MakeMessage(
103 // membuffer* buf, int http_major_version, int http_minor_version,
104 // const char* fmt, ...) = 0;
106 virtual void http_CalcResponseVersion(
107 int request_major_vers, int request_minor_vers, int* response_major_vers,
108 int* response_minor_vers) = 0;
110 virtual int MakeGetMessageEx(
111 const char* url_str, membuffer* request, uri_type* url,
112 struct SendInstruction* pRangeSpecifier) = 0;
114 virtual int http_OpenHttpGetEx(
115 const char* url_str, void** Handle, char** contentType, int* contentLength,
116 int* httpStatus, int lowRange, int highRange, int timeout) = 0;
118 virtual void get_sdk_info(
119 char* info, size_t infoSize) = 0;
120};
121
125class Chttpreadwrite_old : Ihttpreadwrite {
126 public:
127 virtual ~Chttpreadwrite_old() override {}
128
129 struct tm* http_gmtime_r(const time_t* clock, struct tm* result) override {
130 return ::http_gmtime_r(clock, result); }
131 int http_FixUrl(uri_type* url, uri_type* fixed_url) override {
132 return ::http_FixUrl(url, fixed_url); }
133 int http_FixStrUrl(const char* urlstr, size_t urlstrlen, uri_type* fixed_url) override {
134 return ::http_FixStrUrl(urlstr, urlstrlen, fixed_url); }
135 SOCKET http_Connect(uri_type* destination_url, uri_type* url) override {
136 return ::http_Connect(destination_url, url); }
137 int http_RecvMessage(SOCKINFO* info, http_parser_t* parser, http_method_t request_method, int* timeout_secs, int* http_error_code) override {
138 return ::http_RecvMessage(info, parser, request_method, timeout_secs, http_error_code); }
139 // int http_SendMessage(SOCKINFO* info, int* TimeOut, const char* fmt, ...) override {
140 // return ::http_SendMessage(info, TimeOut, fmt, ...); }
141 // return UPNP_E_OUTOF_MEMORY; }
142 int http_RequestAndResponse(uri_type* destination, const char* request, size_t request_length, http_method_t req_method, int timeout_secs, http_parser_t* response) override {
143 return ::http_RequestAndResponse(destination, request, request_length, req_method, timeout_secs, response); }
144 int http_Download(const char* url_str, int timeout_secs, char** document, size_t* doc_length, char* content_type) override {
145 return ::http_Download(url_str, timeout_secs, document, doc_length, content_type); }
146 int MakeGenericMessage(http_method_t method, const char* url_str, membuffer* request, uri_type* url, int contentLength, const char* contentType, const UpnpString* headers) override {
147 return ::MakeGenericMessage(method, url_str, request, url, contentLength, contentType, headers); }
148 int http_HttpGetProgress(void* Handle, size_t* length, size_t* total) override {
149 return ::http_HttpGetProgress(Handle, length, total); }
150 int http_CancelHttpGet(void* Handle) override {
151 return ::http_CancelHttpGet(Handle); }
152 int http_OpenHttpConnection(const char* url_str, void** Handle, int timeout) override {
153 return ::http_OpenHttpConnection(url_str, Handle, timeout); }
154 int http_MakeHttpRequest(Upnp_HttpMethod method, const char* url_str, void* Handle, UpnpString* headers, const char* contentType, int contentLength, int timeout) override {
155 return ::http_MakeHttpRequest(method, url_str, Handle, headers, contentType, contentLength, timeout); }
156 int http_WriteHttpRequest(void* Handle, char* buf, size_t* size, int timeout) override {
157 return ::http_WriteHttpRequest(Handle, buf, size, timeout); }
158 int http_EndHttpRequest(void* Handle, int timeout) override {
159 return ::http_EndHttpRequest(Handle, timeout); }
160 int http_GetHttpResponse(void* Handle, UpnpString* headers, char** contentType, int* contentLength, int* httpStatus, int timeout) override {
161 return ::http_GetHttpResponse(Handle, headers, contentType, contentLength, httpStatus, timeout); }
162 int http_ReadHttpResponse(void* Handle, char* buf, size_t* size, int timeout) override {
163 return ::http_ReadHttpResponse(Handle, buf, size, timeout); }
164 int http_CloseHttpConnection(void* Handle) override {
165 return ::http_CloseHttpConnection(Handle); }
166 int http_SendStatusResponse(SOCKINFO* info, int http_status_code, int request_major_version, int request_minor_version) override {
167 return ::http_SendStatusResponse(info, http_status_code, request_major_version, request_minor_version); }
168 // int http_MakeMessage(membuffer* buf, int http_major_version, int http_minor_version, const char* fmt, ...) override {
169 // return ::http_MakeMessage(buf, http_major_version, http_minor_version, fmt, ...); }
170 // return UPNP_E_OUTOF_MEMORY; }
171 void http_CalcResponseVersion(int request_major_vers, int request_minor_vers, int* response_major_vers, int* response_minor_vers) override {
172 return ::http_CalcResponseVersion(request_major_vers, request_minor_vers, response_major_vers, response_minor_vers); }
173 int MakeGetMessageEx(const char* url_str, membuffer* request, uri_type* url, struct SendInstruction* pRangeSpecifier) override {
174 return ::MakeGetMessageEx(url_str, request, url, pRangeSpecifier); }
175 int http_OpenHttpGetEx(const char* url_str, void** Handle, char** contentType, int* contentLength, int* httpStatus, int lowRange, int highRange, int timeout) override {
176 return ::http_OpenHttpGetEx(url_str, Handle, contentType, contentLength, httpStatus, lowRange, highRange, timeout); }
177 void get_sdk_info(char* info, size_t infoSize) override {
178 return ::get_sdk_info(info, infoSize); }
179};
180#endif
181
182#if 0
183class Chttpreadwrite: Chttpreadwrite_old {
184 public:
185 virtual ~Chttpreadwrite() override {}
186
187 // int http_OpenHttpConnection(const char* url_str, void** Handle, int timeout) override {
188 // This is only prepaired so far and will be enabled if needed.
189 // return UPnPsdk::http_OpenHttpConnection(url_str, Handle, timeout); }
190 // return UPNP_E_INVALID_PARAM; }
191};
192// clang-format on
193
220 const char* url,
224 void** handle,
228 int timeout);
229#endif
230
231
235class CUri {
236 public:
238 const std::string url_str;
240 std::string hostport;
241
243 CUri(std::string a_url_str);
244};
245
246} // namespace UPnPsdk
247
248#endif // UPNPLIB_HTTPREADWRITE_HPP
249// vim: nowrap
int http_ReadHttpResponse(void *Handle, char *buf, size_t *size, int timeout)
Reads the content of a response using a connection previously created by UpnpOpenHttpConnection().
int http_OpenHttpConnection(const char *url_str, void **Handle, int timeout)
Opens a connection to the server.
int http_RequestAndResponse(uri_type *destination, const char *request, size_t request_length, http_method_t req_method, int timeout_secs, http_parser_t *response)
Initiates socket, connects to the remote host, sends a request and waits for the response from the re...
int http_CloseHttpConnection(void *Handle)
Closes the connection created with UpnpOpenHttpConnection() and frees any memory associated with the ...
int http_FixStrUrl(const char *urlstr, size_t urlstrlen, uri_type *fixed_url)
Parses URL and then validates URL.
SOCKET http_Connect(uri_type *destination_url, uri_type *url)
Gets destination address from URL and then connects to the remote end.
void get_sdk_info(char *info, size_t infoSize)
Returns the server information for the operating system.
int http_Download(const char *url_str, int timeout_secs, char **document, size_t *doc_length, char *content_type)
Download the document message and extract the document from the message.
int http_FixUrl(uri_type *url, uri_type *fixed_url)
Validates URL.
int http_CancelHttpGet(void *Handle)
Set the cancel flag of the HttpGet handle.
int http_WriteHttpRequest(void *Handle, char *buf, size_t *size, int timeout)
Writes the content of a HTTP request initiated by a UpnpMakeHttpRequest() call. The end of the conten...
void http_CalcResponseVersion(int request_major_vers, int request_minor_vers, int *response_major_vers, int *response_minor_vers)
Calculate HTTP response versions based on the request versions.
tm * http_gmtime_r(const time_t *clock, tm *result)
Portable gmtime_r for Microsoft Windows.
int http_EndHttpRequest(void *Handle, int timeout)
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest().
int http_SendStatusResponse(SOCKINFO *info, int http_status_code, int request_major_version, int request_minor_version)
Generate a response message for the status query and send the status response.
int http_OpenHttpGetEx(const char *url_str, void **Handle, char **contentType, int *contentLength, int *httpStatus, int lowRange, int highRange, int timeout)
Makes the HTTP GET message, connects to the peer, sends the HTTP GET request, gets the response and p...
int http_GetHttpResponse(void *Handle, UpnpString *headers, char **contentType, int *contentLength, int *httpStatus, int timeout)
Gets the response from the server using a connection previously created by UpnpOpenHttpConnection().
int http_MakeHttpRequest(Upnp_HttpMethod method, const char *url_str, void *Handle, UpnpString *headers, const char *contentType, int contentLength, int timeout)
Makes a HTTP request using a connection previously created by UpnpOpenHttpConnection().
int http_RecvMessage(SOCKINFO *info, http_parser_t *parser, http_method_t request_method, int *timeout_secs, int *http_error_code)
Get the data on the socket and take actions based on the read data to modify the parser objects buffe...
int http_HttpGetProgress(void *Handle, size_t *length, size_t *total)
Extracts information from the Handle to the HTTP get object.
http_method_t
Method in a HTTP request.
Structure of an HTTP parser object.
Represents a URI used in parse_uri and elsewhere.
Definition uri.hpp:92
Send instruction.
Definition webserver.hpp:50
Stores a URL and provides its host with port part.
const std::string url_str
URL.
std::string hostport
Host with port part from the URL.
Internal implementation of the class UpnpString.
Upnp_HttpMethod
Different HTTP methods.
Definition API.hpp:1945
Maintains a block of dynamically allocated memory.
Definition membuffer.hpp:61
Reengineered Object Oriented UPnP+ program code.
int MakeGetMessageEx(const char *url_str, membuffer *request, uri_type *url, SendInstruction *pRangeSpecifier)
Make extended GetMessage.
int MakeGenericMessage(http_method_t method, const char *url_str, membuffer *request, uri_type *url, int contentLength, const char *contentType, const UpnpString *headers)
Make a generic message, what ever this mean.
Additional socket information for connections and ssl.
Definition sock.hpp:65
#define UPnPsdk_VIS
Prefix to export symbol for external use.