VSF Documented
vsf_http_client.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_HTTP_CLIENT_H__
19#define __VSF_HTTP_CLIENT_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_MBEDTLS == ENABLED
26// DO NOT include mbedtls_tls_session.h here, because it will undefine _WIN32 for VSF,
27// but some windows based environment will need this
28//# include "component/3rd-party/mbedtls/extension/tls_session/mbedtls_tls_session.h"
29#endif
30
31#if defined(__VSF_HTTP_CLIENT_CLASS_IMPLEMENT)
32# define __VSF_CLASS_IMPLEMENT__
33#elif defined(__VSF_HTTP_CLIENT_CLASS_INHERIT__)
34# define __VSF_CLASS_INHERIT__
35#endif
36
37#include "utilities/ooc_class.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*============================ MACROS ========================================*/
44
45#ifndef VSF_HTTP_CLIENT_CFG_BUFFER_SIZE
46# define VSF_HTTP_CLIENT_CFG_BUFFER_SIZE 4096
47#endif
48
49#ifndef VSF_HTTP_CLIENT_CFG_USER_AGENT
50// for some website, not all user agent are accepted, so use fake curl here
51# define VSF_HTTP_CLIENT_CFG_USER_AGENT "curl/8.5.0"
52#endif
53
54/*============================ MACROFIED FUNCTIONS ===========================*/
55/*============================ TYPES =========================================*/
56
58
59vsf_class(vsf_http_op_t) {
60 protected_member(
61 int (*fn_connect)(void *param, const char *host, const char *port);
62 void (*fn_close)(void *param);
63 int (*fn_write)(void *param, uint8_t *buf, uint16_t len);
64 int (*fn_read)(void *param, uint8_t *buf, uint16_t len);
65 )
66};
67
70 const char *host;
71 const char *port;
72 const char *verb;
73 const char *connect_mode;
74
75 char *header;
76 char *path;
77
79 size_t txdata_len;
80
81 // IMPORTANT: line is NULL terminated string ending with \r
83};
84
86 public_member(
87 const vsf_http_op_t *op;
88 void *param;
89 int resp_status;
90 int content_length;
91 char *redirect_path;
92 )
93 private_member(
94 uint16_t cur_size;
95 bool is_chunked;
96 int cur_chunk_size;
97 uint8_t *cur_buffer;
99 )
100};
101
102/*============================ GLOBAL VARIABLES ==============================*/
103
104#if VSF_USE_MBEDTLS == ENABLED
105// to use mbedtls_http_op, user source code(.c) MUST include
106// "component/3rd-party/mbedtls/extension/tls_session/mbedtls_tls_session.h",
107// and set mbedtls_session_t instance to param of vsf_http_client_t.
108extern const vsf_http_op_t vsf_mbedtls_http_op;
109#endif
110
111/*============================ PROTOTYPES ====================================*/
112
114extern void vsf_http_client_init(vsf_http_client_t *http);
116extern int vsf_http_client_read(vsf_http_client_t *http, uint8_t *buf, uint16_t len);
117extern int vsf_http_client_write(vsf_http_client_t *http, uint8_t *buf, uint16_t len);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif // __VSF_HTTP_CLIENT_H__
Definition vsf_http_client.h:85
#define vsf_class(__name)
Definition ooc_class.h:48
#define vsf_declare_class(__name)
Definition ooc_class.h:45
unsigned short uint16_t
Definition stdint.h:7
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_http_client.h:69
const char * verb
Definition vsf_http_client.h:72
uint8_t * txdata
Definition vsf_http_client.h:78
char * header
Definition vsf_http_client.h:75
const char * host
Definition vsf_http_client.h:70
size_t txdata_len
Definition vsf_http_client.h:79
const char * port
Definition vsf_http_client.h:71
void(* on_response_header)(vsf_http_client_t *http, vsf_http_client_req_t *req, char *line)
Definition vsf_http_client.h:82
char * path
Definition vsf_http_client.h:76
const char * connect_mode
Definition vsf_http_client.h:73
void vsf_http_client_close(vsf_http_client_t *http)
Definition vsf_http_client.c:74
#define VSF_HTTP_CLIENT_CFG_BUFFER_SIZE
Definition vsf_http_client.h:46
int vsf_http_client_write(vsf_http_client_t *http, uint8_t *buf, uint16_t len)
Definition vsf_http_client.c:266
const vsf_http_op_t vsf_mbedtls_http_op
Definition vsf_http_client.c:47
void vsf_http_client_init(vsf_http_client_t *http)
Definition vsf_http_client.c:69
int vsf_http_client_request(vsf_http_client_t *http, vsf_http_client_req_t *req)
Definition vsf_http_client.c:79
int vsf_http_client_read(vsf_http_client_t *http, uint8_t *buf, uint16_t len)
Definition vsf_http_client.c:202
Generated from commit: vsfteam/vsf@2b286be