AmendHub

Download

jcs

/

wikipedia

/

http.h

 

(View History)

jcs   browser+wikipedia: Support UTF8, article redirections, "View Source" mode Latest amendment: 32 on 2022-09-07

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 char chunk[2048];
44 ssize_t chunk_len;
45 ssize_t chunk_off;
46 };
47
48 struct url * url_parse(const char *str);
49 char * url_encode(unsigned char *str);
50
51 struct http_request * http_get(const char *url);
52 ssize_t http_req_read(struct http_request *req, char *data, size_t len);
53 bool http_req_skip_header(struct http_request *req);
54 short http_req_chunk_peek(void *req);
55 short http_req_chunk_read(void *req);
56 void http_req_free(void *reqptr);
57
58 #endif