UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
httpreadwrite.hpp
Go to the documentation of this file.
1#ifdef COMPA_HAVE_WEBSERVER
2
3#ifndef COMPA_GENLIB_NET_HTTP_HTTPREADWRITE_HPP
4#define COMPA_GENLIB_NET_HTTP_HTTPREADWRITE_HPP
5/*******************************************************************************
6 *
7 * Copyright (c) 2000-2003 Intel Corporation
8 * All rights reserved.
9 * Copyright (c) 2012 France Telecom All rights reserved.
10 * Copyright (C) 2022+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
11 * Redistribution only with this Copyright remark. Last modified: 2025-06-12
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *
16 * - Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * - Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * - Neither name of Intel Corporation nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
33 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38// Last compare with ./pupnp source file on 2023-08-20, ver 1.14.17
44#include <httpparser.hpp>
45#include <sock.hpp>
46
48#define HTTP_DEFAULT_TIMEOUT 30
49
50#if defined(_WIN32) || defined(DOXYGEN_RUN)
52tm* http_gmtime_r(const time_t* clock, tm* result);
53#else
54#define http_gmtime_r gmtime_r
55#endif
56
65 void* Handle
66);
67
75int http_FixUrl( //
76 uri_type* url,
77 uri_type* fixed_url
78);
79
87int http_FixStrUrl( //
88 const char* urlstr,
89 size_t urlstrlen,
90 uri_type* fixed_url
91);
92
103SOCKET http_Connect( //
104 uri_type* destination_url,
105 uri_type* url
106);
107
119int http_RecvMessage( //
120 SOCKINFO* info,
121 http_parser_t* parser,
122 http_method_t request_method,
123 int* timeout_secs,
124 int* http_error_code
125);
126
162int http_SendMessage(SOCKINFO* info,
163 int* TimeOut,
164 const char* fmt,
166 ...
167);
168
185 uri_type* destination,
187 const char* request,
188 size_t request_length,
189 http_method_t req_method,
190 int timeout_secs,
191 http_parser_t* response
192);
193
194/************************************************************************
195 * return codes:
196 * 0 -- success
197 * UPNP_E_OUTOF_MEMORY
198 * UPNP_E_TIMEDOUT
199 * UPNP_E_BAD_REQUEST
200 * UPNP_E_BAD_RESPONSE
201 * UPNP_E_INVALID_URL
202 * UPNP_E_SOCKET_READ
203 * UPNP_E_SOCKET_WRITE
204 ************************************************************************/
205
215int http_Download( //
216 const char* url_str,
217 int timeout_secs,
218 char** document,
220 size_t* doc_length,
221 char* content_type
222);
223
233 void* Handle,
234 size_t* length,
235 size_t* total
236);
237
261 const char* url_str,
264 void** Handle,
267 int timeout);
268
292 Upnp_HttpMethod method,
295 const char* url_str,
297 void* Handle,
301 UpnpString* headers,
303 const char* contentType,
308 int contentLength,
312 int timeout);
313
330 void* Handle,
332 char* buf,
334 size_t* size,
338 int timeout);
339
356 void* Handle,
360 int timeout);
361
388 void* Handle,
391 UpnpString* headers,
393 char** contentType,
395 int* contentLength,
397 int* httpStatus,
401 int timeout);
402
424 void* Handle,
426 char* buf,
428 size_t* size,
432 int timeout);
433
448 void* Handle);
449
462 SOCKINFO* info,
463 int http_status_code,
465 int request_major_version,
466 int request_minor_version
467);
468
469// clang-format off
514// clang-format on
516 membuffer* buf,
517 int http_major_version,
518 int http_minor_version,
519 const char* fmt,
520 ...
521);
522
527 int request_major_vers,
528 int request_minor_vers,
529 int* response_major_vers,
530 int* response_minor_vers
531);
532
546 const char* url_str,
547 void** Handle,
548 char** contentType,
549 int* contentLength,
550 int* httpStatus,
552 int lowRange,
553 int highRange,
554 int timeout
555);
556
560void get_sdk_info(
561 char* info,
562 size_t infoSize
563);
564
565#endif /* COMPA_GENLIB_NET_HTTP_HTTPREADWRITE_HPP */
566#endif // COMPA_HAVE_WEBSERVER
http_method_t
Method in a HTTP request.
Structure of an HTTP parser object.
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.
int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt,...)
Sends a message to the destination based on the format parameter.
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.
int http_MakeMessage(membuffer *buf, int http_major_version, int http_minor_version, const char *fmt,...)
Generate an HTTP message based on the format that is specified in the input parameters.
Represents a URI used in parse_uri and elsewhere.
Definition uri.hpp:92
Functions to parse UPnP messages like requests and responses.
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
Manage network sockets and connections.
Additional socket information for connections and ssl.
Definition sock.hpp:65