2 f26f1205 2022-02-09 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 f26f1205 2022-02-09 op * Permission to use, copy, modify, and distribute this software for any
5 f26f1205 2022-02-09 op * purpose with or without fee is hereby granted, provided that the above
6 f26f1205 2022-02-09 op * copyright notice and this permission notice appear in all copies.
8 f26f1205 2022-02-09 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 f26f1205 2022-02-09 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 f26f1205 2022-02-09 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 f26f1205 2022-02-09 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 f26f1205 2022-02-09 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 f26f1205 2022-02-09 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 f26f1205 2022-02-09 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 f26f1205 2022-02-09 op #ifndef TELESCOPE_H
18 f26f1205 2022-02-09 op #define TELESCOPE_H
20 f26f1205 2022-02-09 op #include "compat.h"
22 f26f1205 2022-02-09 op #include <limits.h>
23 0110411e 2022-04-13 op #include <stdio.h> /* XXX: for parsers.h */
25 f26f1205 2022-02-09 op #include "cmd.h"
26 f26f1205 2022-02-09 op #include "phos.h"
28 f26f1205 2022-02-09 op #define MIN(a, b) ((a) < (b) ? (a) : (b))
29 f26f1205 2022-02-09 op #define MAX(a, b) ((a) > (b) ? (a) : (b))
31 f26f1205 2022-02-09 op #define GEMINI_URL_LEN 1024
32 f26f1205 2022-02-09 op #define TITLE_MAX 128+1 /* account for NUL too */
34 f26f1205 2022-02-09 op #define SIDE_WINDOW_LEFT 0x1
35 f26f1205 2022-02-09 op #define SIDE_WINDOW_BOTTOM 0x2
37 f26f1205 2022-02-09 op struct imsgev {
38 f26f1205 2022-02-09 op struct imsgbuf ibuf;
39 f26f1205 2022-02-09 op void (*handler)(int, short, void *);
40 f26f1205 2022-02-09 op struct event ev;
44 7018345e 2022-02-11 op #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
46 f26f1205 2022-02-09 op enum imsg_type {
47 2534e4d5 2022-05-27 op /* ui <-> net */
48 c6e37ffd 2022-05-27 op IMSG_GET, /* struct get_req, peerid is the tab id */
50 f26f1205 2022-02-09 op IMSG_CHECK_CERT,
51 f26f1205 2022-02-09 op IMSG_CERT_STATUS,
52 f26f1205 2022-02-09 op IMSG_GOT_CODE,
53 f26f1205 2022-02-09 op IMSG_GOT_META,
60 2534e4d5 2022-05-27 op /* ui <-> ctl */
61 4cf6ba13 2022-02-11 op IMSG_CTL_OPEN_URL,
64 f26f1205 2022-02-09 op enum line_type {
65 f26f1205 2022-02-09 op /* text/gemini */
73 f26f1205 2022-02-09 op LINE_PRE_START,
74 f26f1205 2022-02-09 op LINE_PRE_CONTENT,
77 f26f1205 2022-02-09 op /* text/x-patch */
79 f26f1205 2022-02-09 op LINE_PATCH_HDR,
80 f26f1205 2022-02-09 op LINE_PATCH_HUNK_HDR,
81 f26f1205 2022-02-09 op LINE_PATCH_ADD,
82 f26f1205 2022-02-09 op LINE_PATCH_DEL,
84 f26f1205 2022-02-09 op /* minibuffer */
86 f26f1205 2022-02-09 op LINE_COMPL_CURRENT,
91 f26f1205 2022-02-09 op /* download */
92 f26f1205 2022-02-09 op LINE_DOWNLOAD,
93 f26f1205 2022-02-09 op LINE_DOWNLOAD_DONE,
94 f26f1205 2022-02-09 op LINE_DOWNLOAD_INFO,
100 f26f1205 2022-02-09 op /* for lines: mark as hidden */
101 f26f1205 2022-02-09 op #define L_HIDDEN 1
103 f26f1205 2022-02-09 op /* for vlines: mark as continuation */
104 f26f1205 2022-02-09 op #define L_CONTINUATION 2
106 f26f1205 2022-02-09 op struct line {
107 f26f1205 2022-02-09 op enum line_type type;
112 f26f1205 2022-02-09 op TAILQ_ENTRY(line) lines;
115 f26f1205 2022-02-09 op struct vline {
116 f26f1205 2022-02-09 op struct line *parent;
119 bd4a08a7 2022-11-07 op size_t cplen;
121 f26f1205 2022-02-09 op TAILQ_ENTRY(vline) vlines;
124 f26f1205 2022-02-09 op struct parser;
126 d54dd816 2022-04-13 op typedef int (*printfn)(void *, const char *, ...);
128 f63b8f73 2022-04-24 op typedef void (*parserinit)(struct parser *);
130 d54dd816 2022-04-13 op typedef int (*parsechunkfn)(struct parser *, const char *, size_t);
131 d54dd816 2022-04-13 op typedef int (*parserfreefn)(struct parser *);
132 0110411e 2022-04-13 op typedef int (*parserserial)(struct parser *, FILE *);
134 f26f1205 2022-02-09 op typedef void (imsg_handlerfn)(struct imsg*, size_t);
136 f26f1205 2022-02-09 op struct parser {
137 f26f1205 2022-02-09 op const char *name;
138 f26f1205 2022-02-09 op char title[128+1];
143 f26f1205 2022-02-09 op #define PARSER_IN_BODY 1
144 f26f1205 2022-02-09 op #define PARSER_IN_PRE 2
145 f26f1205 2022-02-09 op #define PARSER_IN_PATCH_HDR 4
147 f63b8f73 2022-04-24 op parserinit init;
148 f26f1205 2022-02-09 op parsechunkfn parse;
149 f26f1205 2022-02-09 op parserfreefn free;
150 f26f1205 2022-02-09 op parserserial serialize;
152 f26f1205 2022-02-09 op TAILQ_HEAD(, line) head;
156 f26f1205 2022-02-09 op * differnt types of trust for a certificate. Following
157 f26f1205 2022-02-09 op * gemini://thfr.info/gemini/modified-trust-verify.gmi
159 f26f1205 2022-02-09 op enum trust_state {
161 f26f1205 2022-02-09 op TS_UNTRUSTED,
162 f26f1205 2022-02-09 op TS_TEMP_TRUSTED,
167 f26f1205 2022-02-09 op struct tofu_entry {
168 f26f1205 2022-02-09 op char domain[GEMINI_URL_LEN];
171 f26f1205 2022-02-09 op * enough space for ``PROTO:HASH''. probably isn't a good
174 f26f1205 2022-02-09 op char hash[128+1];
175 f26f1205 2022-02-09 op int verified;
178 f26f1205 2022-02-09 op struct histhead {
179 f26f1205 2022-02-09 op TAILQ_HEAD(mhisthead, hist) head;
182 f26f1205 2022-02-09 op struct hist {
183 f26f1205 2022-02-09 op char h[1025];
184 f26f1205 2022-02-09 op size_t line_off;
185 f26f1205 2022-02-09 op size_t current_off;
186 f26f1205 2022-02-09 op TAILQ_ENTRY(hist) entries;
189 f26f1205 2022-02-09 op struct buffer {
190 f26f1205 2022-02-09 op struct parser page;
192 f26f1205 2022-02-09 op size_t last_line_off;
193 f26f1205 2022-02-09 op int force_redraw;
197 f26f1205 2022-02-09 op size_t line_off;
198 f26f1205 2022-02-09 op size_t line_max;
199 f26f1205 2022-02-09 op struct vline *top_line;
200 f26f1205 2022-02-09 op struct vline *current_line;
201 f26f1205 2022-02-09 op size_t cpoff;
202 f26f1205 2022-02-09 op TAILQ_HEAD(vhead, vline) head;
205 f26f1205 2022-02-09 op #define TAB_CURRENT 0x1 /* only for save_session */
206 f26f1205 2022-02-09 op #define TAB_KILLED 0x2 /* only for save_session */
207 f26f1205 2022-02-09 op #define TAB_URGENT 0x4
208 f26f1205 2022-02-09 op #define TAB_LAZY 0x8 /* to lazy load tabs */
210 f26f1205 2022-02-09 op #define NEW_TAB_URL "about:new"
212 f26f1205 2022-02-09 op TAILQ_HEAD(tabshead, tab);
213 f26f1205 2022-02-09 op extern struct tabshead tabshead;
214 f26f1205 2022-02-09 op extern struct tabshead ktabshead;
216 f26f1205 2022-02-09 op TAILQ_ENTRY(tab) tabs;
218 f26f1205 2022-02-09 op uint32_t flags;
221 f26f1205 2022-02-09 op enum trust_state trust;
222 f26f1205 2022-02-09 op struct proxy *proxy;
223 f26f1205 2022-02-09 op struct phos_uri uri;
224 f26f1205 2022-02-09 op struct histhead hist;
225 f26f1205 2022-02-09 op struct hist *hist_cur;
226 f26f1205 2022-02-09 op size_t hist_off;
227 f26f1205 2022-02-09 op char *last_input_url;
230 f26f1205 2022-02-09 op char meta[GEMINI_URL_LEN];
231 f26f1205 2022-02-09 op int redirect_count;
233 f26f1205 2022-02-09 op struct buffer buffer;
235 f26f1205 2022-02-09 op short loading_anim;
236 f26f1205 2022-02-09 op short loading_anim_step;
237 f26f1205 2022-02-09 op struct event loadingev;
240 f26f1205 2022-02-09 op extern TAILQ_HEAD(proxylist, proxy) proxies;
241 f26f1205 2022-02-09 op struct proxy {
242 f26f1205 2022-02-09 op char *match_proto;
248 f26f1205 2022-02-09 op TAILQ_ENTRY(proxy) proxies;
252 f26f1205 2022-02-09 op PROTO_FINGER,
253 f26f1205 2022-02-09 op PROTO_GEMINI,
254 f26f1205 2022-02-09 op PROTO_GOPHER,
258 f26f1205 2022-02-09 op struct get_req {
260 f26f1205 2022-02-09 op char host[254];
261 f26f1205 2022-02-09 op char port[16];
262 f26f1205 2022-02-09 op char req[1027];
266 f26f1205 2022-02-09 op const char *cmd;
267 f26f1205 2022-02-09 op void (*fn)(struct buffer *);
268 f26f1205 2022-02-09 op const char *descr;
270 f26f1205 2022-02-09 op extern struct cmd cmds[];
272 f26f1205 2022-02-09 op /* defaults.c */
273 f26f1205 2022-02-09 op void config_init(void);
274 f26f1205 2022-02-09 op int config_setprfx(const char *, const char *, const char *);
275 f26f1205 2022-02-09 op int config_setvari(const char *, int);
276 f26f1205 2022-02-09 op int config_setvars(const char *, char *);
277 f26f1205 2022-02-09 op int config_setcolor(int, const char *, int, int, int);
278 f26f1205 2022-02-09 op int config_setattr(const char *, int, int, int);
279 f26f1205 2022-02-09 op void config_apply_style(void);
281 f26f1205 2022-02-09 op /* downloads.c */
282 f26f1205 2022-02-09 op extern STAILQ_HEAD(downloads, download) downloads;
283 f26f1205 2022-02-09 op struct download {
286 f26f1205 2022-02-09 op size_t bytes;
288 f26f1205 2022-02-09 op STAILQ_ENTRY(download) entries;
291 f26f1205 2022-02-09 op void recompute_downloads(void);
292 fd984e76 2022-05-05 op struct download *enqueue_download(uint32_t, const char *);
293 f26f1205 2022-02-09 op struct download *download_by_id(uint32_t);
296 f26f1205 2022-02-09 op void recompute_help(void);
299 f26f1205 2022-02-09 op void hist_clear(struct histhead *);
300 f26f1205 2022-02-09 op void hist_clear_forward(struct histhead*, struct hist*);
301 f26f1205 2022-02-09 op void hist_push(struct histhead*, struct hist*);
302 f26f1205 2022-02-09 op void hist_add_before(struct histhead *, struct hist *, struct hist *);
303 f26f1205 2022-02-09 op struct hist *hist_pop(struct histhead *);
306 f26f1205 2022-02-09 op int setup_parser_for(struct tab*);
309 f26f1205 2022-02-09 op int net_main(void);
311 f26f1205 2022-02-09 op /* parse.y */
312 f26f1205 2022-02-09 op void parseconfig(const char *, int);
314 f26f1205 2022-02-09 op /* sandbox.c */
315 f26f1205 2022-02-09 op void sandbox_net_process(void);
316 f26f1205 2022-02-09 op void sandbox_ui_process(void);
318 f26f1205 2022-02-09 op /* telescope.c */
319 f26f1205 2022-02-09 op extern int operating;
320 f26f1205 2022-02-09 op extern int safe_mode;
322 f26f1205 2022-02-09 op #define LU_MODE_NONE 0x0
323 f26f1205 2022-02-09 op #define LU_MODE_NOHIST 0x1
324 f26f1205 2022-02-09 op #define LU_MODE_NOCACHE 0x2
326 f26f1205 2022-02-09 op void gopher_send_search_req(struct tab *, const char *);
327 f26f1205 2022-02-09 op int load_page_from_str(struct tab *, const char *);
328 f26f1205 2022-02-09 op void load_url(struct tab *, const char *, const char *, int);
329 f26f1205 2022-02-09 op void load_url_in_tab(struct tab *, const char *, const char *, int);
330 f26f1205 2022-02-09 op int load_previous_page(struct tab*);
331 f26f1205 2022-02-09 op int load_next_page(struct tab*);
332 868b3a8f 2022-04-13 op void write_buffer(const char *, struct tab *);
333 f26f1205 2022-02-09 op void humanify_url(const char *, char *, size_t);
334 486bde7d 2022-04-24 op int bookmark_page(const char *);
335 f26f1205 2022-02-09 op int ui_send_net(int, uint32_t, const void *, uint16_t);
338 f26f1205 2022-02-09 op void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
339 f26f1205 2022-02-09 op struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
340 f26f1205 2022-02-09 op void tofu_add(struct ohash*, struct tofu_entry*);
341 4fa88f57 2022-04-24 op int tofu_save(struct ohash *, struct tofu_entry *);
342 f26f1205 2022-02-09 op void tofu_update(struct ohash*, struct tofu_entry*);
343 3078e1bc 2022-04-24 op int tofu_update_persist(struct ohash *, struct tofu_entry *);
344 f26f1205 2022-02-09 op void tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
347 f26f1205 2022-02-09 op void erase_buffer(struct buffer *);
348 f26f1205 2022-02-09 op void empty_linelist(struct buffer*);
349 f26f1205 2022-02-09 op void empty_vlist(struct buffer*);
350 6b91e104 2022-10-09 op int wrap_text(struct buffer*, const char*, struct line*, size_t, int);
351 f26f1205 2022-02-09 op int wrap_page(struct buffer *, int width);
353 f26f1205 2022-02-09 op #endif /* TELESCOPE_H */