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 f26f1205 2022-02-09 op TAILQ_ENTRY(vline) vlines;
122 f26f1205 2022-02-09 op struct parser;
124 d54dd816 2022-04-13 op typedef int (*printfn)(void *, const char *, ...);
126 f63b8f73 2022-04-24 op typedef void (*parserinit)(struct parser *);
128 d54dd816 2022-04-13 op typedef int (*parsechunkfn)(struct parser *, const char *, size_t);
129 d54dd816 2022-04-13 op typedef int (*parserfreefn)(struct parser *);
130 0110411e 2022-04-13 op typedef int (*parserserial)(struct parser *, FILE *);
132 f26f1205 2022-02-09 op typedef void (imsg_handlerfn)(struct imsg*, size_t);
134 f26f1205 2022-02-09 op struct parser {
135 f26f1205 2022-02-09 op const char *name;
136 f26f1205 2022-02-09 op char title[128+1];
141 f26f1205 2022-02-09 op #define PARSER_IN_BODY 1
142 f26f1205 2022-02-09 op #define PARSER_IN_PRE 2
143 f26f1205 2022-02-09 op #define PARSER_IN_PATCH_HDR 4
145 f63b8f73 2022-04-24 op parserinit init;
146 f26f1205 2022-02-09 op parsechunkfn parse;
147 f26f1205 2022-02-09 op parserfreefn free;
148 f26f1205 2022-02-09 op parserserial serialize;
150 f26f1205 2022-02-09 op TAILQ_HEAD(, line) head;
154 f26f1205 2022-02-09 op * differnt types of trust for a certificate. Following
155 f26f1205 2022-02-09 op * gemini://thfr.info/gemini/modified-trust-verify.gmi
157 f26f1205 2022-02-09 op enum trust_state {
159 f26f1205 2022-02-09 op TS_UNTRUSTED,
160 f26f1205 2022-02-09 op TS_TEMP_TRUSTED,
165 f26f1205 2022-02-09 op struct tofu_entry {
166 f26f1205 2022-02-09 op char domain[GEMINI_URL_LEN];
169 f26f1205 2022-02-09 op * enough space for ``PROTO:HASH''. probably isn't a good
172 f26f1205 2022-02-09 op char hash[128+1];
173 f26f1205 2022-02-09 op int verified;
176 f26f1205 2022-02-09 op struct histhead {
177 f26f1205 2022-02-09 op TAILQ_HEAD(mhisthead, hist) head;
180 f26f1205 2022-02-09 op struct hist {
181 f26f1205 2022-02-09 op char h[1025];
182 f26f1205 2022-02-09 op size_t line_off;
183 f26f1205 2022-02-09 op size_t current_off;
184 f26f1205 2022-02-09 op TAILQ_ENTRY(hist) entries;
187 f26f1205 2022-02-09 op struct buffer {
188 f26f1205 2022-02-09 op struct parser page;
190 f26f1205 2022-02-09 op size_t last_line_off;
191 f26f1205 2022-02-09 op int force_redraw;
195 f26f1205 2022-02-09 op size_t line_off;
196 f26f1205 2022-02-09 op size_t line_max;
197 f26f1205 2022-02-09 op struct vline *top_line;
198 f26f1205 2022-02-09 op struct vline *current_line;
199 f26f1205 2022-02-09 op size_t cpoff;
200 f26f1205 2022-02-09 op TAILQ_HEAD(vhead, vline) head;
203 f26f1205 2022-02-09 op #define TAB_CURRENT 0x1 /* only for save_session */
204 f26f1205 2022-02-09 op #define TAB_KILLED 0x2 /* only for save_session */
205 f26f1205 2022-02-09 op #define TAB_URGENT 0x4
206 f26f1205 2022-02-09 op #define TAB_LAZY 0x8 /* to lazy load tabs */
208 f26f1205 2022-02-09 op #define NEW_TAB_URL "about:new"
210 f26f1205 2022-02-09 op TAILQ_HEAD(tabshead, tab);
211 f26f1205 2022-02-09 op extern struct tabshead tabshead;
212 f26f1205 2022-02-09 op extern struct tabshead ktabshead;
214 f26f1205 2022-02-09 op TAILQ_ENTRY(tab) tabs;
216 f26f1205 2022-02-09 op uint32_t flags;
219 f26f1205 2022-02-09 op enum trust_state trust;
220 f26f1205 2022-02-09 op struct proxy *proxy;
221 f26f1205 2022-02-09 op struct phos_uri uri;
222 f26f1205 2022-02-09 op struct histhead hist;
223 f26f1205 2022-02-09 op struct hist *hist_cur;
224 f26f1205 2022-02-09 op size_t hist_off;
225 f26f1205 2022-02-09 op char *last_input_url;
228 f26f1205 2022-02-09 op char meta[GEMINI_URL_LEN];
229 f26f1205 2022-02-09 op int redirect_count;
231 f26f1205 2022-02-09 op struct buffer buffer;
233 f26f1205 2022-02-09 op short loading_anim;
234 f26f1205 2022-02-09 op short loading_anim_step;
235 f26f1205 2022-02-09 op struct event loadingev;
238 f26f1205 2022-02-09 op extern TAILQ_HEAD(proxylist, proxy) proxies;
239 f26f1205 2022-02-09 op struct proxy {
240 f26f1205 2022-02-09 op char *match_proto;
246 f26f1205 2022-02-09 op TAILQ_ENTRY(proxy) proxies;
250 f26f1205 2022-02-09 op PROTO_FINGER,
251 f26f1205 2022-02-09 op PROTO_GEMINI,
252 f26f1205 2022-02-09 op PROTO_GOPHER,
256 f26f1205 2022-02-09 op struct get_req {
258 f26f1205 2022-02-09 op char host[254];
259 f26f1205 2022-02-09 op char port[16];
260 f26f1205 2022-02-09 op char req[1027];
264 f26f1205 2022-02-09 op const char *cmd;
265 f26f1205 2022-02-09 op void (*fn)(struct buffer *);
266 f26f1205 2022-02-09 op const char *descr;
268 f26f1205 2022-02-09 op extern struct cmd cmds[];
270 f26f1205 2022-02-09 op /* defaults.c */
271 f26f1205 2022-02-09 op void config_init(void);
272 f26f1205 2022-02-09 op int config_setprfx(const char *, const char *, const char *);
273 f26f1205 2022-02-09 op int config_setvari(const char *, int);
274 f26f1205 2022-02-09 op int config_setvars(const char *, char *);
275 f26f1205 2022-02-09 op int config_setcolor(int, const char *, int, int, int);
276 f26f1205 2022-02-09 op int config_setattr(const char *, int, int, int);
277 f26f1205 2022-02-09 op void config_apply_style(void);
279 f26f1205 2022-02-09 op /* downloads.c */
280 f26f1205 2022-02-09 op extern STAILQ_HEAD(downloads, download) downloads;
281 f26f1205 2022-02-09 op struct download {
284 f26f1205 2022-02-09 op size_t bytes;
286 f26f1205 2022-02-09 op STAILQ_ENTRY(download) entries;
289 f26f1205 2022-02-09 op void recompute_downloads(void);
290 fd984e76 2022-05-05 op struct download *enqueue_download(uint32_t, const char *);
291 f26f1205 2022-02-09 op struct download *download_by_id(uint32_t);
294 f26f1205 2022-02-09 op void recompute_help(void);
297 f26f1205 2022-02-09 op void hist_clear(struct histhead *);
298 f26f1205 2022-02-09 op void hist_clear_forward(struct histhead*, struct hist*);
299 f26f1205 2022-02-09 op void hist_push(struct histhead*, struct hist*);
300 f26f1205 2022-02-09 op void hist_add_before(struct histhead *, struct hist *, struct hist *);
301 f26f1205 2022-02-09 op struct hist *hist_pop(struct histhead *);
304 f26f1205 2022-02-09 op int setup_parser_for(struct tab*);
307 f26f1205 2022-02-09 op int net_main(void);
309 f26f1205 2022-02-09 op /* parse.y */
310 f26f1205 2022-02-09 op void parseconfig(const char *, int);
312 f26f1205 2022-02-09 op /* sandbox.c */
313 f26f1205 2022-02-09 op void sandbox_net_process(void);
314 f26f1205 2022-02-09 op void sandbox_ui_process(void);
316 f26f1205 2022-02-09 op /* telescope.c */
317 f26f1205 2022-02-09 op extern int operating;
318 f26f1205 2022-02-09 op extern int safe_mode;
320 f26f1205 2022-02-09 op #define LU_MODE_NONE 0x0
321 f26f1205 2022-02-09 op #define LU_MODE_NOHIST 0x1
322 f26f1205 2022-02-09 op #define LU_MODE_NOCACHE 0x2
324 f26f1205 2022-02-09 op void gopher_send_search_req(struct tab *, const char *);
325 f26f1205 2022-02-09 op int load_page_from_str(struct tab *, const char *);
326 f26f1205 2022-02-09 op void load_url(struct tab *, const char *, const char *, int);
327 f26f1205 2022-02-09 op void load_url_in_tab(struct tab *, const char *, const char *, int);
328 f26f1205 2022-02-09 op int load_previous_page(struct tab*);
329 f26f1205 2022-02-09 op int load_next_page(struct tab*);
330 868b3a8f 2022-04-13 op void write_buffer(const char *, struct tab *);
331 f26f1205 2022-02-09 op void humanify_url(const char *, char *, size_t);
332 486bde7d 2022-04-24 op int bookmark_page(const char *);
333 f26f1205 2022-02-09 op int ui_send_net(int, uint32_t, const void *, uint16_t);
336 f26f1205 2022-02-09 op void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
337 f26f1205 2022-02-09 op struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
338 f26f1205 2022-02-09 op void tofu_add(struct ohash*, struct tofu_entry*);
339 4fa88f57 2022-04-24 op int tofu_save(struct ohash *, struct tofu_entry *);
340 f26f1205 2022-02-09 op void tofu_update(struct ohash*, struct tofu_entry*);
341 3078e1bc 2022-04-24 op int tofu_update_persist(struct ohash *, struct tofu_entry *);
342 f26f1205 2022-02-09 op void tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
345 f26f1205 2022-02-09 op void erase_buffer(struct buffer *);
346 f26f1205 2022-02-09 op void empty_linelist(struct buffer*);
347 f26f1205 2022-02-09 op void empty_vlist(struct buffer*);
348 f26f1205 2022-02-09 op int wrap_one(struct buffer *, const char *, struct line *, size_t);
349 f26f1205 2022-02-09 op int wrap_text(struct buffer*, const char*, struct line*, size_t);
350 f26f1205 2022-02-09 op int hardwrap_text(struct buffer*, struct line*, size_t);
351 f26f1205 2022-02-09 op int wrap_page(struct buffer *, int width);
353 f26f1205 2022-02-09 op #endif /* TELESCOPE_H */