libUPnP  1.14.22
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 struct tm *http_gmtime_r(const time_t *clock, struct tm *result);
54 #else
55  #define http_gmtime_r gmtime_r
56 #endif
57 
58 int http_CancelHttpGet(/* IN */ void *Handle);
59 
67 int http_FixUrl(
69  uri_type *url,
71  uri_type *fixed_url);
72 
80 int http_FixStrUrl(
82  const char *urlstr,
84  size_t urlstrlen,
86  uri_type *fixed_url);
87 
98  uri_type *destination_url,
100  uri_type *url);
101 
102 /************************************************************************
103  * Function: http_RecvMessage
104  *
105  * Parameters:
106  * IN SOCKINFO *info; Socket information object
107  * OUT http_parser_t* parser; HTTP parser object
108  * IN http_method_t request_method; HTTP request method
109  * IN OUT int* timeout_secs; time out
110  * OUT int* http_error_code; HTTP error code returned
111  *
112  * Description:
113  * Get the data on the socket and take actions based on the read data
114  * to modify the parser objects buffer. If an error is reported while
115  * parsing the data, the error code is passed in the http_errr_code
116  * parameter
117  *
118  * Returns:
119  * UPNP_E_BAD_HTTPMSG
120  * UPNP_E_SUCCESS
121  ************************************************************************/
122 int http_RecvMessage(SOCKINFO *info,
123  http_parser_t *parser,
124  http_method_t request_method,
125  int *timeout_secs,
126  int *http_error_code);
127 
150 int http_SendMessage(
151  /* [in] Socket information object. */
152  SOCKINFO *info,
153  /* [in,out] Time out value. */
154  int *timeout_secs,
155  /* [in] Pattern format to take actions upon. */
156  const char *fmt,
157  /* [in] Variable parameter list. */
158  ...);
159 
160 /************************************************************************
161  * Function: http_RequestAndResponse
162  *
163  * Parameters:
164  * IN uri_type* destination; Destination URI object which contains
165  * remote IP address among other elements
166  * IN const char* request; Request to be sent
167  * IN size_t request_length; Length of the request
168  * IN http_method_t req_method; HTTP Request method
169  * IN int timeout_secs; time out value
170  * OUT http_parser_t* response; Parser object to receive the repsonse
171  *
172  * Description:
173  * Initiates socket, connects to the destination, sends a
174  * request and waits for the response from the remote end
175  *
176  * Returns:
177  * UPNP_E_SOCKET_ERROR
178  * UPNP_E_SOCKET_CONNECT
179  * Error Codes returned by http_SendMessage
180  * Error Codes returned by http_RecvMessage
181  ************************************************************************/
182 int http_RequestAndResponse(uri_type *destination,
183  const char *request,
184  size_t request_length,
185  http_method_t req_method,
186  int timeout_secs,
187  http_parser_t *response);
188 
189 /************************************************************************
190  * return codes:
191  * 0 -- success
192  * UPNP_E_OUTOF_MEMORY
193  * UPNP_E_TIMEDOUT
194  * UPNP_E_BAD_REQUEST
195  * UPNP_E_BAD_RESPONSE
196  * UPNP_E_INVALID_URL
197  * UPNP_E_SOCKET_READ
198  * UPNP_E_SOCKET_WRITE
199  ************************************************************************/
200 
201 /************************************************************************
202  * Function: http_Download
203  *
204  * Parameters:
205  * IN const char* url_str; String as a URL
206  * IN int timeout_secs; time out value
207  * OUT char** document; buffer to store the document extracted
208  * from the donloaded message.
209  * OUT size_t* doc_length; length of the extracted document
210  * OUT char* content_type; Type of content
211  *
212  * Description:
213  * Download the document message and extract the document
214  * from the message.
215  *
216  * Return: int
217  * UPNP_E_SUCCESS
218  * UPNP_E_INVALID_URL
219  ************************************************************************/
220 int http_Download(const char *url,
221  int timeout_secs,
222  char **document,
223  size_t *doc_length,
224  char *content_type);
225 
226 /************************************************************************
227  * Function: http_HttpGetProgress
228  *
229  * Parameters:
230  * IN void *Handle; Handle to the HTTP get object
231  * OUT size_t *length; Buffer to get the read and parsed data
232  * OUT size_t *total; Size of tge buffer passed
233  *
234  * Description:
235  * Extracts information from the Handle to the HTTP get object.
236  *
237  * Return: int
238  * UPNP_E_SUCCESS - On Sucess
239  * UPNP_E_INVALID_PARAM - Invalid Parameter
240  ************************************************************************/
241 int http_HttpGetProgress(void *Handle, size_t *length, size_t *total);
242 
269  const char *url,
273  void **handle,
277  int timeout);
278 
305  /* ![in] The method to use to make the request. */
306  Upnp_HttpMethod method,
309  const char *url,
311  void *handle,
316  UpnpString *headers,
318  const char *contentType,
323  int contentLength,
327  int timeout);
328 
346  void *handle,
348  char *buf,
350  size_t *size,
354  int timeout);
355 
376  void *handle,
380  int timeout);
381 
414  void *handle,
417  UpnpString *headers,
419  char **contentType,
421  int *contentLength,
423  int *httpStatus,
428  int timeout);
429 
451  void *handle,
453  char *buf,
455  size_t *size,
460  int timeout);
461 
477  void *handle);
478 
479 /************************************************************************
480  * Function: http_SendStatusResponse
481  *
482  * Parameters:
483  * IN SOCKINFO *info; Socket information object
484  * IN int http_status_code; error code returned while making
485  * or sending the response message
486  * IN int request_major_version; request major version
487  * IN int request_minor_version; request minor version
488  *
489  * Description:
490  * Generate a response message for the status query and send the
491  * status response.
492  *
493  * Return: int
494  * 0 -- success
495  * UPNP_E_OUTOF_MEMORY
496  * UPNP_E_SOCKET_WRITE
497  * UPNP_E_TIMEDOUT
498  ************************************************************************/
499 int http_SendStatusResponse(SOCKINFO *info,
500  int http_status_code,
501  int request_major_version,
502  int request_minor_version);
503 
544 int http_MakeMessage(
545  /* [in,out] Buffer with the contents of the message. */
546  membuffer *buf,
547  /* [in] HTTP major version. */
548  int http_major_version,
549  /* [in] HTTP minor version. */
550  int http_minor_version,
551  /* [in] Pattern format. */
552  const char *fmt,
553  /* [in] Format arguments. */
554  ...);
555 
556 /************************************************************************
557  * Function: http_CalcResponseVersion
558  *
559  * Parameters:
560  * IN int request_major_vers; Request major version
561  * IN int request_minor_vers; Request minor version
562  * OUT int* response_major_vers; Response mojor version
563  * OUT int* response_minor_vers; Response minor version
564  *
565  * Description:
566  * Calculate HTTP response versions based on the request versions.
567  *
568  * Return: void
569  ************************************************************************/
570 void http_CalcResponseVersion(int request_major_vers,
571  int request_minor_vers,
572  int *response_major_vers,
573  int *response_minor_vers);
574 
575 /************************************************************************
576  * Function: http_OpenHttpGetEx
577  *
578  * Parameters:
579  * IN const char *url_str; String as a URL
580  * IN OUT void **Handle; Pointer to buffer to store HTTP
581  * post handle
582  * IN OUT char **contentType; Type of content
583  * OUT int *contentLength; length of content
584  * OUT int *httpStatus; HTTP status returned on receiving a
585  * response message
586  * IN int timeout; time out value
587  *
588  * Description:
589  * Makes the HTTP GET message, connects to the peer,
590  * sends the HTTP GET request, gets the response and parses the
591  * response.
592  *
593  * Return: int
594  * UPNP_E_SUCCESS - On Success
595  * UPNP_E_INVALID_PARAM - Invalid Paramters
596  * UPNP_E_OUTOF_MEMORY
597  * UPNP_E_SOCKET_ERROR
598  * UPNP_E_BAD_RESPONSE
599  ************************************************************************/
600 int http_OpenHttpGetEx(const char *url_str,
601  void **Handle,
602  char **contentType,
603  int *contentLength,
604  int *httpStatus,
605  int lowRange,
606  int highRange,
607  int timeout);
608 
609 /************************************************************************
610  * Function: get_sdk_info
611  *
612  * Parameters:
613  * OUT char *info; buffer to store the operating system information
614  * IN size_t infoSize; size of buffer
615  *
616  * Description:
617  * Returns the server information for the operating system
618  *
619  * Return:
620  * UPNP_INLINE void
621  ************************************************************************/
622 void get_sdk_info(char *info, size_t infoSize);
623 
624 #ifdef __cplusplus
625 } /* #extern "C" */
626 #endif
627 
628 #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:1492
int http_OpenHttpConnection(const char *url_str, void **Handle, int timeout)
Opens a connection to the server.
Definition: httpreadwrite.c:1266
int http_FixStrUrl(const char *urlstr, size_t urlstrlen, uri_type *fixed_url)
Parses URL and then validates URL.
Definition: httpreadwrite.c:276
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:364
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:1429
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:1326
int http_EndHttpRequest(void *Handle, int timeout)
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest.
Definition: httpreadwrite.c:1410
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:1597
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:1662
int SOCKET
Definition: UpnpInet.h:48
int http_FixUrl(uri_type *url, uri_type *fixed_url)
Validates URL.
Definition: httpreadwrite.c:249
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:302
int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt,...)
Sends a message to the destination based on the format parameter.
Definition: httpreadwrite.c:492
Definition: httpparser.h:216
#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:1364
Definition: membuffer.h:57