Download
jcs
/wikipedia
/http.h
(View History)
jcs *: Fix lots of bugs, add progress in fetch dialog | Latest amendment: 44 on 2023-08-30 |
1 | /* |
2 | * Copyright (c) 2020-2022 joshua stein <jcs@jcs.org> |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above |
6 | * copyright notice and this permission notice appear in all copies. |
7 | * |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ |
16 | |
17 | #ifndef __HTTP_H__ |
18 | #define __HTTP_H__ |
19 | |
20 | #include "util.h" |
21 | #include "tcp.h" |
22 | |
23 | struct url { |
24 | char *scheme; |
25 | char *host; |
26 | unsigned short port; |
27 | char *path; |
28 | }; |
29 | |
30 | struct http_request { |
31 | struct url *url; |
32 | ip_addr host_ip; |
33 | |
34 | TCPiopb tcp_iopb; |
35 | StreamPtr tcp_stream; |
36 | unsigned char *tcp_buf; |
37 | size_t tcp_buf_size; |
38 | wdsEntry tcp_wds[2]; |
39 | TCPStatusPB tcp_status_pb; |
40 | |
41 | char *message; |
42 | |
43 | size_t content_len; |
44 | |
45 | char chunk[2048]; |
46 | ssize_t chunk_len; |
47 | ssize_t chunk_off; |
48 | }; |
49 | |
50 | struct url * url_parse(const char *str); |
51 | char * url_encode(unsigned char *str); |
52 | |
53 | struct http_request * http_get(const char *url); |
54 | ssize_t http_req_read(struct http_request *req, char *data, size_t len); |
55 | bool http_req_skip_header(struct http_request *req); |
56 | short http_req_chunk_peek(void *req); |
57 | short http_req_chunk_read(void *req); |
58 | void http_req_free(void *reqptr); |
59 | |
60 | #endif |