ReactOS 0.4.16-dev-297-gc569aee
http_client.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2018 Simon Goldschmidt <goldsimon@gmx.de>
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * This file is part of the lwIP TCP/IP stack.
33 *
34 * Author: Simon Goldschmidt <goldsimon@gmx.de>
35 *
36 */
37
38#ifndef LWIP_HDR_APPS_HTTP_CLIENT_H
39#define LWIP_HDR_APPS_HTTP_CLIENT_H
40
41#include "lwip/opt.h"
42#include "lwip/ip_addr.h"
43#include "lwip/err.h"
44#include "lwip/altcp.h"
45#include "lwip/prot/iana.h"
46#include "lwip/pbuf.h"
47
48#if LWIP_TCP && LWIP_CALLBACK_API
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
60#ifndef LWIP_HTTPC_HAVE_FILE_IO
61#define LWIP_HTTPC_HAVE_FILE_IO 0
62#endif
63
68#define HTTP_DEFAULT_PORT LWIP_IANA_PORT_HTTP
69
74typedef enum ehttpc_result {
76 HTTPC_RESULT_OK = 0,
78 HTTPC_RESULT_ERR_UNKNOWN = 1,
80 HTTPC_RESULT_ERR_CONNECT = 2,
82 HTTPC_RESULT_ERR_HOSTNAME = 3,
84 HTTPC_RESULT_ERR_CLOSED = 4,
86 HTTPC_RESULT_ERR_TIMEOUT = 5,
88 HTTPC_RESULT_ERR_SVR_RESP = 6,
90 HTTPC_RESULT_ERR_MEM = 7,
92 HTTPC_RESULT_LOCAL_ABORT = 8,
94 HTTPC_RESULT_ERR_CONTENT_LEN = 9
95} httpc_result_t;
96
97typedef struct _httpc_state httpc_state_t;
98
110typedef void (*httpc_result_fn)(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err);
111
123typedef err_t (*httpc_headers_done_fn)(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len);
124
125typedef struct _httpc_connection {
126 ip_addr_t proxy_addr;
127 u16_t proxy_port;
128 u8_t use_proxy;
129 /* @todo: add username:pass? */
130
131#if LWIP_ALTCP
132 altcp_allocator_t *altcp_allocator;
133#endif
134
135 /* this callback is called when the transfer is finished (or aborted) */
136 httpc_result_fn result_fn;
137 /* this callback is called after receiving the http headers
138 It can abort the connection by returning != ERR_OK */
139 httpc_headers_done_fn headers_done_fn;
140} httpc_connection_t;
141
142err_t httpc_get_file(const ip_addr_t* server_addr, u16_t port, const char* uri, const httpc_connection_t *settings,
143 altcp_recv_fn recv_fn, void* callback_arg, httpc_state_t **connection);
144err_t httpc_get_file_dns(const char* server_name, u16_t port, const char* uri, const httpc_connection_t *settings,
145 altcp_recv_fn recv_fn, void* callback_arg, httpc_state_t **connection);
146
147#if LWIP_HTTPC_HAVE_FILE_IO
148err_t httpc_get_file_to_disk(const ip_addr_t* server_addr, u16_t port, const char* uri, const httpc_connection_t *settings,
149 void* callback_arg, const char* local_file_name, httpc_state_t **connection);
150err_t httpc_get_file_dns_to_disk(const char* server_name, u16_t port, const char* uri, const httpc_connection_t *settings,
151 void* callback_arg, const char* local_file_name, httpc_state_t **connection);
152#endif /* LWIP_HTTPC_HAVE_FILE_IO */
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif /* LWIP_TCP && LWIP_CALLBACK_API */
159
160#endif /* LWIP_HDR_APPS_HTTP_CLIENT_H */
struct mke2fs_defaults settings[]
#define altcp_recv_fn
Definition: altcp.h:154
USHORT port
Definition: uri.c:228
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
s8_t err_t
Definition: err.h:96
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
char hdr[14]
Definition: iptest.cpp:33
const char * uri
Definition: sec_mgr.c:1588
#define err(...)
Definition: pbuf.h:186
char * server_name
Definition: widl.c:145
void * arg
Definition: msvc.h:10