libUPnP  1.14.30
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 "httpparser.h"
42 #include "sock.h"
43 #include "upnputil.h"
44 
46 #define HTTP_DEFAULT_TIMEOUT 30
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 #ifdef _WIN32
53  #define http_gmtime_r(clock, result) \
54  (gmtime_s(result, clock) ? NULL : result)
55 #else
56  #define http_gmtime_r gmtime_r
57 #endif
58 
59 int http_CancelHttpGet(/* IN */ void *Handle);
60 
68 int http_FixUrl(
70  uri_type *url,
72  uri_type *fixed_url);
73 
81 int http_FixStrUrl(
83  const char *urlstr,
85  size_t urlstrlen,
87  uri_type *fixed_url);
88 
99  uri_type *destination_url,
101  uri_type *url);
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  ************************************************************************/
123 int http_RecvMessage(SOCKINFO *info,
124  http_parser_t *parser,
125  http_method_t request_method,
126  int *timeout_secs,
127  int *http_error_code);
128 
151 int http_SendMessage(
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  ************************************************************************/
183 int http_RequestAndResponse(uri_type *destination,
184  const char *request,
185  size_t request_length,
186  http_method_t req_method,
187  int timeout_secs,
188  http_parser_t *response);
189 
190 /************************************************************************
191  * return codes:
192  * 0 -- success
193  * UPNP_E_OUTOF_MEMORY
194  * UPNP_E_TIMEDOUT
195  * UPNP_E_BAD_REQUEST
196  * UPNP_E_BAD_RESPONSE
197  * UPNP_E_INVALID_URL
198  * UPNP_E_SOCKET_READ
199  * UPNP_E_SOCKET_WRITE
200  ************************************************************************/
201 
202 /************************************************************************
203  * Function: http_Download
204  *
205  * Parameters:
206  * IN const char* url_str; String as a URL
207  * IN int timeout_secs; time out value
208  * OUT char** document; buffer to store the document extracted
209  * from the donloaded message.
210  * OUT size_t* doc_length; length of the extracted document
211  * OUT char* content_type; Type of content
212  *
213  * Description:
214  * Download the document message and extract the document
215  * from the message.
216  *
217  * Return: int
218  * UPNP_E_SUCCESS
219  * UPNP_E_INVALID_URL
220  ************************************************************************/
221 int http_Download(const char *url,
222  int timeout_secs,
223  char **document,
224  size_t *doc_length,
225  char *content_type);
226 
227 /************************************************************************
228  * Function: http_HttpGetProgress
229  *
230  * Parameters:
231  * IN void *Handle; Handle to the HTTP get object
232  * OUT size_t *length; Buffer to get the read and parsed data
233  * OUT size_t *total; Size of tge buffer passed
234  *
235  * Description:
236  * Extracts information from the Handle to the HTTP get object.
237  *
238  * Return: int
239  * UPNP_E_SUCCESS - On Sucess
240  * UPNP_E_INVALID_PARAM - Invalid Parameter
241  ************************************************************************/
242 int http_HttpGetProgress(void *Handle, size_t *length, size_t *total);
243 
270  const char *url,
274  void **handle,
278  int timeout);
279 
306  /* ![in] The method to use to make the request. */
307  Upnp_HttpMethod method,
310  const char *url,
312  void *handle,
317  UpnpString *headers,
319  const char *contentType,
324  int contentLength,
328  int timeout);
329 
347  void *handle,
349  char *buf,
351  size_t *size,
355  int timeout);
356 
377  void *handle,
381  int timeout);
382 
415  void *handle,
418  UpnpString *headers,
420  char **contentType,
422  int *contentLength,
424  int *httpStatus,
429  int timeout);
430 
452  void *handle,
454  char *buf,
456  size_t *size,
461  int timeout);
462 
478  void *handle);
479 
480 /************************************************************************
481  * Function: http_SendStatusResponse
482  *
483  * Parameters:
484  * IN SOCKINFO *info; Socket information object
485  * IN int http_status_code; error code returned while making
486  * or sending the response message
487  * IN int request_major_version; request major version
488  * IN int request_minor_version; request minor version
489  *
490  * Description:
491  * Generate a response message for the status query and send the
492  * status response.
493  *
494  * Return: int
495  * 0 -- success
496  * UPNP_E_OUTOF_MEMORY
497  * UPNP_E_SOCKET_WRITE
498  * UPNP_E_TIMEDOUT
499  ************************************************************************/
500 int http_SendStatusResponse(SOCKINFO *info,
501  int http_status_code,
502  int request_major_version,
503  int request_minor_version);
504 
545 int http_MakeMessage(
546  /* [in,out] Buffer with the contents of the message. */
547  membuffer *buf,
548  /* [in] HTTP major version. */
549  int http_major_version,
550  /* [in] HTTP minor version. */
551  int http_minor_version,
552  /* [in] Pattern format. */
553  const char *fmt,
554  /* [in] Format arguments. */
555  ...);
556 
557 /************************************************************************
558  * Function: http_CalcResponseVersion
559  *
560  * Parameters:
561  * IN int request_major_vers; Request major version
562  * IN int request_minor_vers; Request minor version
563  * OUT int* response_major_vers; Response mojor version
564  * OUT int* response_minor_vers; Response minor version
565  *
566  * Description:
567  * Calculate HTTP response versions based on the request versions.
568  *
569  * Return: void
570  ************************************************************************/
571 void http_CalcResponseVersion(int request_major_vers,
572  int request_minor_vers,
573  int *response_major_vers,
574  int *response_minor_vers);
575 
576 /************************************************************************
577  * Function: http_OpenHttpGetEx
578  *
579  * Parameters:
580  * IN const char *url_str; String as a URL
581  * IN OUT void **Handle; Pointer to buffer to store HTTP
582  * post handle
583  * IN OUT char **contentType; Type of content
584  * OUT int *contentLength; length of content
585  * OUT int *httpStatus; HTTP status returned on receiving a
586  * response message
587  * IN int timeout; time out value
588  *
589  * Description:
590  * Makes the HTTP GET message, connects to the peer,
591  * sends the HTTP GET request, gets the response and parses the
592  * response.
593  *
594  * Return: int
595  * UPNP_E_SUCCESS - On Success
596  * UPNP_E_INVALID_PARAM - Invalid Paramters
597  * UPNP_E_OUTOF_MEMORY
598  * UPNP_E_SOCKET_ERROR
599  * UPNP_E_BAD_RESPONSE
600  ************************************************************************/
601 int http_OpenHttpGetEx(const char *url_str,
602  void **Handle,
603  char **contentType,
604  int *contentLength,
605  int *httpStatus,
606  int lowRange,
607  int highRange,
608  int timeout);
609 
610 /************************************************************************
611  * Function: get_sdk_info
612  *
613  * Parameters:
614  * OUT char *info; buffer to store the operating system information
615  * IN size_t infoSize; size of buffer
616  *
617  * Description:
618  * Returns the server information for the operating system
619  *
620  * Return:
621  * UPNP_INLINE void
622  ************************************************************************/
623 void get_sdk_info(char *info, size_t infoSize);
624 
625 #ifdef __cplusplus
626 } /* #extern "C" */
627 #endif
628 
629 #endif /* GENLIB_NET_HTTP_HTTPREADWRITE_H */
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:1482
int http_OpenHttpConnection(const char *url_str, void **Handle, int timeout)
Opens a connection to the server.
Definition: httpreadwrite.c:1254
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...
Definition: httpreadwrite.c:350
Represents a URI used in parse_uri and elsewhere.
Definition: uri.h:133
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:1419
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:1314
int http_EndHttpRequest(void *Handle, int timeout)
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest.
Definition: httpreadwrite.c:1398
Definition: sock.h:59
int http_CloseHttpConnection(void *Handle)
Closes the connection created with UpnpOpenHttpConnection and frees any memory associated with the co...
Definition: httpreadwrite.c:1587
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:1652
int SOCKET
Definition: UpnpInet.h:50
int http_FixUrl(uri_type *url, uri_type *fixed_url)
Validates URL.
Definition: httpreadwrite.c:234
SOCKET http_Connect(uri_type *destination_url, uri_type *url)
Gets destination address from URL and then connects to the remote end.
Definition: httpreadwrite.c:287
int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt,...)
Sends a message to the destination based on the format parameter.
Definition: httpreadwrite.c:478
Definition: httpparser.h:215
#define UPNP_EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition: UpnpGlobal.h:105
struct s_UpnpString UpnpString
Type of the string objects inside libupnp.
Definition: UpnpString.h:33
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:1352
Definition: membuffer.h:57
int http_FixStrUrl(const char *url_str, size_t url_str_len, uri_type *fixed_url)
Parses URL and then validates URL.
Definition: httpreadwrite.c:261