git subrepo clone https://github.com/libretro/libretro-common.git deps/libretro-common
[pcsx_rearmed.git] / deps / libretro-common / include / net / net_http.h
CommitLineData
3719602c
PC
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
32RETRO_BEGIN_DECLS
33
34struct http_t;
35struct http_connection_t;
36
37struct http_connection_t *net_http_connection_new(const char *url, const char *method, const char *data);
38
39/**
40 * net_http_connection_iterate:
41 *
42 * Leaf function.
43 **/
44bool net_http_connection_iterate(struct http_connection_t *conn);
45
46bool net_http_connection_done(struct http_connection_t *conn);
47
48void net_http_connection_free(struct http_connection_t *conn);
49
50void net_http_connection_set_user_agent(struct http_connection_t *conn, const char *user_agent);
51
52void net_http_connection_set_headers(struct http_connection_t *conn, const char *headers);
53
54const char *net_http_connection_url(struct http_connection_t *conn);
55
56const char* net_http_connection_method(struct http_connection_t* conn);
57
58struct http_t *net_http_new(struct http_connection_t *conn);
59
60/**
61 * net_http_fd:
62 *
63 * Leaf function.
64 *
65 * You can use this to call net_http_update
66 * only when something will happen; select() it for reading.
67 **/
68int net_http_fd(struct http_t *state);
69
70/**
71 * net_http_update:
72 *
73 * @return true if it's done, or if something broke.
74 * @total will be 0 if it's not known.
75 **/
76bool net_http_update(struct http_t *state, size_t* progress, size_t* total);
77
78/**
79 * net_http_status:
80 *
81 * Report HTTP status. 200, 404, or whatever.
82 *
83 * Leaf function.
84 *
85 * @return HTTP status code.
86 **/
87int net_http_status(struct http_t *state);
88
89/**
90 * net_http_error:
91 *
92 * Leaf function
93 **/
94bool net_http_error(struct http_t *state);
95
96/**
97 * net_http_data:
98 *
99 * Leaf function.
100 *
101 * @return the downloaded data. The returned buffer is owned by the
102 * HTTP handler; it's freed by net_http_delete.
103 * If the status is not 20x and accept_error is false, it returns NULL.
104 **/
105uint8_t* net_http_data(struct http_t *state, size_t* len, bool accept_error);
106
107/**
108 * net_http_delete:
109 *
110 * Cleans up all memory.
111 **/
112void net_http_delete(struct http_t *state);
113
114/**
115 * net_http_urlencode:
116 *
117 * URL Encode a string
118 * caller is responsible for deleting the destination buffer
119 **/
120void net_http_urlencode(char **dest, const char *source);
121
122/**
123 * net_http_urlencode_full:
124 *
125 * Re-encode a full URL
126 **/
127void net_http_urlencode_full(char *dest, const char *source, size_t size);
128
129RETRO_END_DECLS
130
131#endif