libUPnP 1.8.4
httpreadwrite.h
1/*******************************************************************************
2 *
3 * Copyright (c) 2000-2003 Intel Corporation
4 * All rights reserved.
5 * Copyright (c) 2012 France Telecom All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * - Neither name of Intel Corporation nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 ******************************************************************************/
32
33#ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H
34#define GENLIB_NET_HTTP_HTTPREADWRITE_H
35
36/*
37 * \file
38 */
39
40#include "config.h"
41#include "upnputil.h"
42#include "sock.h"
43#include "httpparser.h"
44
46#define HTTP_DEFAULT_TIMEOUT 30
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#ifdef _WIN32
53struct tm *http_gmtime_r(const time_t *clock, struct tm *result);
54#else
55#define http_gmtime_r gmtime_r
56#endif
57
58int http_CancelHttpGet(IN void *Handle);
59
67int http_FixUrl(
69 uri_type *url,
71 uri_type *fixed_url);
72
80int http_FixStrUrl(
82 const char *urlstr,
84 size_t urlstrlen,
86 uri_type *fixed_url);
87
96SOCKET http_Connect(
98 uri_type *destination_url,
100 uri_type *url);
101
102
103/************************************************************************
104 * Function: http_RecvMessage
105 *
106 * Parameters:
107 * IN SOCKINFO *info; Socket information object
108 * OUT http_parser_t* parser; HTTP parser object
109 * IN http_method_t request_method; HTTP request method
110 * IN OUT int* timeout_secs; time out
111 * OUT int* http_error_code; HTTP error code returned
112 *
113 * Description:
114 * Get the data on the socket and take actions based on the read data
115 * to modify the parser objects buffer. If an error is reported while
116 * parsing the data, the error code is passed in the http_errr_code
117 * parameter
118 *
119 * Returns:
120 * UPNP_E_BAD_HTTPMSG
121 * UPNP_E_SUCCESS
122 ************************************************************************/
123int http_RecvMessage( IN SOCKINFO *info, OUT http_parser_t* parser,
124 IN http_method_t request_method,
125 IN OUT int* timeout_secs,
126 OUT int* http_error_code );
127
128
152 /* [in] Socket information object. */
153 SOCKINFO *info,
154 /* [in,out] Time out value. */
155 int* timeout_secs,
156 /* [in] Pattern format to take actions upon. */
157 const char* fmt,
158 /* [in] Variable parameter list. */
159 ...);
160
161/************************************************************************
162 * Function: http_RequestAndResponse
163 *
164 * Parameters:
165 * IN uri_type* destination; Destination URI object which contains
166 * remote IP address among other elements
167 * IN const char* request; Request to be sent
168 * IN size_t request_length; Length of the request
169 * IN http_method_t req_method; HTTP Request method
170 * IN int timeout_secs; time out value
171 * OUT http_parser_t* response; Parser object to receive the repsonse
172 *
173 * Description:
174 * Initiates socket, connects to the destination, sends a
175 * request and waits for the response from the remote end
176 *
177 * Returns:
178 * UPNP_E_SOCKET_ERROR
179 * UPNP_E_SOCKET_CONNECT
180 * Error Codes returned by http_SendMessage
181 * Error Codes returned by http_RecvMessage
182 ************************************************************************/
183int http_RequestAndResponse(
184 IN uri_type* destination,
185 IN const char* request,
186 IN size_t request_length,
187 IN http_method_t req_method,
188 IN int timeout_secs,
189 OUT http_parser_t* response );
190
191
192/************************************************************************
193 * return codes:
194 * 0 -- success
195 * UPNP_E_OUTOF_MEMORY
196 * UPNP_E_TIMEDOUT
197 * UPNP_E_BAD_REQUEST
198 * UPNP_E_BAD_RESPONSE
199 * UPNP_E_INVALID_URL
200 * UPNP_E_SOCKET_READ
201 * UPNP_E_SOCKET_WRITE
202 ************************************************************************/
203
204
205/************************************************************************
206 * Function: http_Download
207 *
208 * Parameters:
209 * IN const char* url_str; String as a URL
210 * IN int timeout_secs; time out value
211 * OUT char** document; buffer to store the document extracted
212 * from the donloaded message.
213 * OUT size_t* doc_length; length of the extracted document
214 * OUT char* content_type; Type of content
215 *
216 * Description:
217 * Download the document message and extract the document
218 * from the message.
219 *
220 * Return: int
221 * UPNP_E_SUCCESS
222 * UPNP_E_INVALID_URL
223 ************************************************************************/
224int http_Download(
225 IN const char* url,
226 IN int timeout_secs,
227 OUT char** document,
228 OUT size_t *doc_length,
229 OUT char* content_type );
230
231
232/************************************************************************
233 * Function: http_HttpGetProgress
234 *
235 * Parameters:
236 * IN void *Handle; Handle to the HTTP get object
237 * OUT size_t *length; Buffer to get the read and parsed data
238 * OUT size_t *total; Size of tge buffer passed
239 *
240 * Description:
241 * Extracts information from the Handle to the HTTP get object.
242 *
243 * Return: int
244 * UPNP_E_SUCCESS - On Sucess
245 * UPNP_E_INVALID_PARAM - Invalid Parameter
246 ************************************************************************/
247int http_HttpGetProgress(
248 IN void *Handle,
249 OUT size_t *length,
250 OUT size_t *total);
251
252
278 const char *url,
281 void **handle,
285 int timeout);
286
287
314 /* ![in] The method to use to make the request. */
315 Upnp_HttpMethod method,
318 const char *url,
320 void *handle,
323 UpnpString *headers,
325 const char *contentType,
329 int contentLength,
333 int timeout);
334
335
352 void *handle,
354 char *buf,
356 size_t *size,
360 int timeout);
361
362
383 void *handle,
387 int timeout);
388
389
422 void *handle,
425 UpnpString *headers,
427 char **contentType,
429 int *contentLength,
431 int *httpStatus,
435 int timeout);
436
437
459 void *handle,
461 char *buf,
463 size_t *size,
467 int timeout);
468
469
485 void *handle);
486
487
488/************************************************************************
489 * Function: http_SendStatusResponse
490 *
491 * Parameters:
492 * IN SOCKINFO *info; Socket information object
493 * IN int http_status_code; error code returned while making
494 * or sending the response message
495 * IN int request_major_version; request major version
496 * IN int request_minor_version; request minor version
497 *
498 * Description:
499 * Generate a response message for the status query and send the
500 * status response.
501 *
502 * Return: int
503 * 0 -- success
504 * UPNP_E_OUTOF_MEMORY
505 * UPNP_E_SOCKET_WRITE
506 * UPNP_E_TIMEDOUT
507 ************************************************************************/
508int http_SendStatusResponse(
509 IN SOCKINFO *info,
510 IN int http_status_code,
511 IN int request_major_version,
512 IN int request_minor_version );
513
553 /* [in,out] Buffer with the contents of the message. */
554 INOUT membuffer* buf,
555 /* [in] HTTP major version. */
556 IN int http_major_version,
557 /* [in] HTTP minor version. */
558 IN int http_minor_version,
559 /* [in] Pattern format. */
560 IN const char* fmt,
561 /* [in] Format arguments. */
562 ... );
563
564
565/************************************************************************
566 * Function: http_CalcResponseVersion
567 *
568 * Parameters:
569 * IN int request_major_vers; Request major version
570 * IN int request_minor_vers; Request minor version
571 * OUT int* response_major_vers; Response mojor version
572 * OUT int* response_minor_vers; Response minor version
573 *
574 * Description:
575 * Calculate HTTP response versions based on the request versions.
576 *
577 * Return: void
578 ************************************************************************/
579void http_CalcResponseVersion(
580 IN int request_major_vers,
581 IN int request_minor_vers,
582 OUT int* response_major_vers,
583 OUT int* response_minor_vers );
584
585
586/************************************************************************
587 * Function: http_OpenHttpGetEx
588 *
589 * Parameters:
590 * IN const char *url_str; String as a URL
591 * IN OUT void **Handle; Pointer to buffer to store HTTP
592 * post handle
593 * IN OUT char **contentType; Type of content
594 * OUT int *contentLength; length of content
595 * OUT int *httpStatus; HTTP status returned on receiving a
596 * response message
597 * IN int timeout; time out value
598 *
599 * Description:
600 * Makes the HTTP GET message, connects to the peer,
601 * sends the HTTP GET request, gets the response and parses the
602 * response.
603 *
604 * Return: int
605 * UPNP_E_SUCCESS - On Success
606 * UPNP_E_INVALID_PARAM - Invalid Paramters
607 * UPNP_E_OUTOF_MEMORY
608 * UPNP_E_SOCKET_ERROR
609 * UPNP_E_BAD_RESPONSE
610 ************************************************************************/
611int http_OpenHttpGetEx(IN const char *url_str,
612 IN OUT void **Handle,
613 IN OUT char **contentType,
614 OUT int *contentLength,
615 OUT int *httpStatus,
616 IN int lowRange,
617 IN int highRange,
618 IN int timeout);
619
620
621/************************************************************************
622 * Function: get_sdk_info
623 *
624 * Parameters:
625 * OUT char *info; buffer to store the operating system information
626 * IN size_t infoSize; size of buffer
627 *
628 * Description:
629 * Returns the server information for the operating system
630 *
631 * Return:
632 * UPNP_INLINE void
633 ************************************************************************/
634void get_sdk_info( OUT char *info, IN size_t infoSize );
635
636#ifdef __cplusplus
637} /* #extern "C" */
638#endif
639
640
641#endif /* GENLIB_NET_HTTP_HTTPREADWRITE_H */
642
#define EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition: UpnpGlobal.h:87
int SOCKET
Definition: UpnpInet.h:48
struct s_UpnpString UpnpString
Type of the string objects inside libupnp.
Definition: UpnpString.h:38
int http_RecvMessage(IN SOCKINFO *info, OUT http_parser_t *parser, IN http_method_t request_method, IN OUT int *timeout_secs, OUT int *http_error_code)
Get the data on the socket and take actions based on the read data to modify the parser objects buffe...
Definition: httpreadwrite.c:344
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.
Definition: httpreadwrite.c:1315
int http_OpenHttpConnection(const char *url_str, void **Handle, int timeout)
Opens a connection to the server.
Definition: httpreadwrite.c:1103
int http_CloseHttpConnection(void *Handle)
Closes the connection created with UpnpOpenHttpConnection and frees any memory associated with the co...
Definition: httpreadwrite.c:1413
int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt,...)
Sends a message to the destination based on the format parameter.
Definition: httpreadwrite.c:437
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 content ...
Definition: httpreadwrite.c:1191
int http_EndHttpRequest(void *Handle, int timeout)
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest.
Definition: httpreadwrite.c:1238
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.
Definition: httpreadwrite.c:1256
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.
Definition: httpreadwrite.c:1162
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.
Definition: httpreadwrite.c:1470
Definition: sock.h:60
Represents a URI used in parse_uri and elsewhere.
Definition: uri.h:136
Definition: httpparser.h:213
Definition: membuffer.h:56