1 /* Copyright  (C) 2010-2020 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (net_http.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef _LIBRETRO_SDK_NET_HTTP_H
24 #define _LIBRETRO_SDK_NET_HTTP_H
25 
26 #include <stdint.h>
27 #include <boolean.h>
28 #include <string.h>
29 
30 #include <retro_common_api.h>
31 
32 RETRO_BEGIN_DECLS
33 
34 struct http_t;
35 struct http_connection_t;
36 
37 struct http_connection_t *net_http_connection_new(const char *url, const char *method, const char *data);
38 
39 bool net_http_connection_iterate(struct http_connection_t *conn);
40 
41 bool net_http_connection_done(struct http_connection_t *conn);
42 
43 void net_http_connection_free(struct http_connection_t *conn);
44 
45 void net_http_connection_set_user_agent(struct http_connection_t* conn, const char* user_agent);
46 
47 const char *net_http_connection_url(struct http_connection_t *conn);
48 
49 struct http_t *net_http_new(struct http_connection_t *conn);
50 
51 /* You can use this to call net_http_update
52  * only when something will happen; select() it for reading. */
53 int net_http_fd(struct http_t *state);
54 
55 /* Returns true if it's done, or if something broke.
56  * 'total' will be 0 if it's not known. */
57 bool net_http_update(struct http_t *state, size_t* progress, size_t* total);
58 
59 /* 200, 404, or whatever.  */
60 int net_http_status(struct http_t *state);
61 
62 bool net_http_error(struct http_t *state);
63 
64 /* Returns the downloaded data. The returned buffer is owned by the
65  * HTTP handler; it's freed by net_http_delete.
66  *
67  * If the status is not 20x and accept_error is false, it returns NULL. */
68 uint8_t* net_http_data(struct http_t *state, size_t* len, bool accept_error);
69 
70 /* Cleans up all memory. */
71 void net_http_delete(struct http_t *state);
72 
73 /* URL Encode a string */
74 void net_http_urlencode(char **dest, const char *source);
75 
76 /* Re-encode a full URL */
77 void net_http_urlencode_full(char *dest, const char *source, size_t size);
78 
79 RETRO_END_DECLS
80 
81 #endif
82