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 f26f1205 2022-02-09 op /* ui <-> client/fs */
48 f26f1205 2022-02-09 op IMSG_GET, /* data is URL, peerid the tab id */
49 f26f1205 2022-02-09 op IMSG_GET_FILE, /* data is path, without \r\n or such */
50 f26f1205 2022-02-09 op IMSG_GET_RAW, /* get but with an explicit req str */
52 f26f1205 2022-02-09 op IMSG_CHECK_CERT,
53 f26f1205 2022-02-09 op IMSG_CERT_STATUS,
54 f26f1205 2022-02-09 op IMSG_GOT_CODE,
55 f26f1205 2022-02-09 op IMSG_GOT_META,
62 f26f1205 2022-02-09 op /* ui <-> fs */
65 f26f1205 2022-02-09 op IMSG_BOOKMARK_PAGE,
66 f26f1205 2022-02-09 op IMSG_BOOKMARK_OK,
67 f26f1205 2022-02-09 op IMSG_SAVE_CERT,
68 f26f1205 2022-02-09 op IMSG_SAVE_CERT_OK,
69 f26f1205 2022-02-09 op IMSG_UPDATE_CERT,
70 f26f1205 2022-02-09 op IMSG_UPDATE_CERT_OK,
72 f26f1205 2022-02-09 op IMSG_FILE_OPEN,
73 f26f1205 2022-02-09 op IMSG_FILE_OPENED,
75 f26f1205 2022-02-09 op IMSG_SESSION_START,
76 f26f1205 2022-02-09 op IMSG_SESSION_TAB,
77 f26f1205 2022-02-09 op IMSG_SESSION_TAB_HIST,
78 f26f1205 2022-02-09 op IMSG_SESSION_END,
80 9e97090d 2022-02-26 op IMSG_HIST_ITEM, /* struct histitem */
81 9e97090d 2022-02-26 op IMSG_HIST_END, /* empty */
83 4cf6ba13 2022-02-11 op IMSG_CTL_OPEN_URL,
86 f26f1205 2022-02-09 op enum line_type {
87 f26f1205 2022-02-09 op /* text/gemini */
95 f26f1205 2022-02-09 op LINE_PRE_START,
96 f26f1205 2022-02-09 op LINE_PRE_CONTENT,
99 f26f1205 2022-02-09 op /* text/x-patch */
101 f26f1205 2022-02-09 op LINE_PATCH_HDR,
102 f26f1205 2022-02-09 op LINE_PATCH_HUNK_HDR,
103 f26f1205 2022-02-09 op LINE_PATCH_ADD,
104 f26f1205 2022-02-09 op LINE_PATCH_DEL,
106 f26f1205 2022-02-09 op /* minibuffer */
108 f26f1205 2022-02-09 op LINE_COMPL_CURRENT,
113 f26f1205 2022-02-09 op /* download */
114 f26f1205 2022-02-09 op LINE_DOWNLOAD,
115 f26f1205 2022-02-09 op LINE_DOWNLOAD_DONE,
116 f26f1205 2022-02-09 op LINE_DOWNLOAD_INFO,
118 f26f1205 2022-02-09 op /* misc ui */
122 f26f1205 2022-02-09 op /* for lines: mark as hidden */
123 f26f1205 2022-02-09 op #define L_HIDDEN 1
125 f26f1205 2022-02-09 op /* for vlines: mark as continuation */
126 f26f1205 2022-02-09 op #define L_CONTINUATION 2
128 f26f1205 2022-02-09 op struct line {
129 f26f1205 2022-02-09 op enum line_type type;
134 f26f1205 2022-02-09 op TAILQ_ENTRY(line) lines;
137 f26f1205 2022-02-09 op struct vline {
138 f26f1205 2022-02-09 op struct line *parent;
141 f26f1205 2022-02-09 op TAILQ_ENTRY(vline) vlines;
144 f26f1205 2022-02-09 op struct parser;
146 d54dd816 2022-04-13 op typedef int (*printfn)(void *, const char *, ...);
148 d54dd816 2022-04-13 op typedef int (*parsechunkfn)(struct parser *, const char *, size_t);
149 d54dd816 2022-04-13 op typedef int (*parserfreefn)(struct parser *);
150 0110411e 2022-04-13 op typedef int (*parserserial)(struct parser *, FILE *);
152 f26f1205 2022-02-09 op typedef void (imsg_handlerfn)(struct imsg*, size_t);
154 f26f1205 2022-02-09 op struct parser {
155 f26f1205 2022-02-09 op const char *name;
156 f26f1205 2022-02-09 op char title[128+1];
161 f26f1205 2022-02-09 op #define PARSER_IN_BODY 1
162 f26f1205 2022-02-09 op #define PARSER_IN_PRE 2
163 f26f1205 2022-02-09 op #define PARSER_IN_PATCH_HDR 4
165 f26f1205 2022-02-09 op void (*init)(struct parser *);
166 f26f1205 2022-02-09 op parsechunkfn parse;
167 f26f1205 2022-02-09 op parserfreefn free;
168 f26f1205 2022-02-09 op parserserial serialize;
170 f26f1205 2022-02-09 op TAILQ_HEAD(, line) head;
174 f26f1205 2022-02-09 op * differnt types of trust for a certificate. Following
175 f26f1205 2022-02-09 op * gemini://thfr.info/gemini/modified-trust-verify.gmi
177 f26f1205 2022-02-09 op enum trust_state {
179 f26f1205 2022-02-09 op TS_UNTRUSTED,
180 f26f1205 2022-02-09 op TS_TEMP_TRUSTED,
185 f26f1205 2022-02-09 op struct tofu_entry {
186 f26f1205 2022-02-09 op char domain[GEMINI_URL_LEN];
189 f26f1205 2022-02-09 op * enough space for ``PROTO:HASH''. probably isn't a good
192 f26f1205 2022-02-09 op char hash[128+1];
193 f26f1205 2022-02-09 op int verified;
196 f26f1205 2022-02-09 op struct histhead {
197 f26f1205 2022-02-09 op TAILQ_HEAD(mhisthead, hist) head;
200 f26f1205 2022-02-09 op struct hist {
201 f26f1205 2022-02-09 op char h[1025];
202 f26f1205 2022-02-09 op size_t line_off;
203 f26f1205 2022-02-09 op size_t current_off;
204 f26f1205 2022-02-09 op TAILQ_ENTRY(hist) entries;
207 f26f1205 2022-02-09 op struct buffer {
208 f26f1205 2022-02-09 op struct parser page;
210 f26f1205 2022-02-09 op size_t last_line_off;
211 f26f1205 2022-02-09 op int force_redraw;
215 f26f1205 2022-02-09 op size_t line_off;
216 f26f1205 2022-02-09 op size_t line_max;
217 f26f1205 2022-02-09 op struct vline *top_line;
218 f26f1205 2022-02-09 op struct vline *current_line;
219 f26f1205 2022-02-09 op size_t cpoff;
220 f26f1205 2022-02-09 op TAILQ_HEAD(vhead, vline) head;
223 f26f1205 2022-02-09 op #define TAB_CURRENT 0x1 /* only for save_session */
224 f26f1205 2022-02-09 op #define TAB_KILLED 0x2 /* only for save_session */
225 f26f1205 2022-02-09 op #define TAB_URGENT 0x4
226 f26f1205 2022-02-09 op #define TAB_LAZY 0x8 /* to lazy load tabs */
228 f26f1205 2022-02-09 op #define NEW_TAB_URL "about:new"
230 f26f1205 2022-02-09 op TAILQ_HEAD(tabshead, tab);
231 f26f1205 2022-02-09 op extern struct tabshead tabshead;
232 f26f1205 2022-02-09 op extern struct tabshead ktabshead;
234 f26f1205 2022-02-09 op TAILQ_ENTRY(tab) tabs;
236 f26f1205 2022-02-09 op uint32_t flags;
239 f26f1205 2022-02-09 op enum trust_state trust;
240 f26f1205 2022-02-09 op struct proxy *proxy;
241 f26f1205 2022-02-09 op struct phos_uri uri;
242 f26f1205 2022-02-09 op struct histhead hist;
243 f26f1205 2022-02-09 op struct hist *hist_cur;
244 f26f1205 2022-02-09 op size_t hist_off;
245 f26f1205 2022-02-09 op char *last_input_url;
248 f26f1205 2022-02-09 op char meta[GEMINI_URL_LEN];
249 f26f1205 2022-02-09 op int redirect_count;
251 f26f1205 2022-02-09 op struct buffer buffer;
253 f26f1205 2022-02-09 op short loading_anim;
254 f26f1205 2022-02-09 op short loading_anim_step;
255 f26f1205 2022-02-09 op struct event loadingev;
258 f26f1205 2022-02-09 op extern TAILQ_HEAD(proxylist, proxy) proxies;
259 f26f1205 2022-02-09 op struct proxy {
260 f26f1205 2022-02-09 op char *match_proto;
266 f26f1205 2022-02-09 op TAILQ_ENTRY(proxy) proxies;
270 f26f1205 2022-02-09 op PROTO_FINGER,
271 f26f1205 2022-02-09 op PROTO_GEMINI,
272 f26f1205 2022-02-09 op PROTO_GOPHER,
276 f26f1205 2022-02-09 op struct get_req {
278 f26f1205 2022-02-09 op char host[254];
279 f26f1205 2022-02-09 op char port[16];
280 f26f1205 2022-02-09 op char req[1027];
284 f26f1205 2022-02-09 op const char *cmd;
285 f26f1205 2022-02-09 op void (*fn)(struct buffer *);
286 f26f1205 2022-02-09 op const char *descr;
288 f26f1205 2022-02-09 op extern struct cmd cmds[];
290 f26f1205 2022-02-09 op /* defaults.c */
291 f26f1205 2022-02-09 op void config_init(void);
292 f26f1205 2022-02-09 op int config_setprfx(const char *, const char *, const char *);
293 f26f1205 2022-02-09 op int config_setvari(const char *, int);
294 f26f1205 2022-02-09 op int config_setvars(const char *, char *);
295 f26f1205 2022-02-09 op int config_setcolor(int, const char *, int, int, int);
296 f26f1205 2022-02-09 op int config_setattr(const char *, int, int, int);
297 f26f1205 2022-02-09 op void config_apply_style(void);
299 f26f1205 2022-02-09 op /* downloads.c */
300 f26f1205 2022-02-09 op extern STAILQ_HEAD(downloads, download) downloads;
301 f26f1205 2022-02-09 op struct download {
304 f26f1205 2022-02-09 op size_t bytes;
307 f26f1205 2022-02-09 op STAILQ_ENTRY(download) entries;
310 f26f1205 2022-02-09 op void recompute_downloads(void);
311 868b3a8f 2022-04-13 op void enqueue_download(uint32_t, const char *, int);
312 868b3a8f 2022-04-13 op void dequeue_first_download(void);
313 f26f1205 2022-02-09 op struct download *download_by_id(uint32_t);
316 f26f1205 2022-02-09 op void recompute_help(void);
319 f26f1205 2022-02-09 op void hist_clear(struct histhead *);
320 f26f1205 2022-02-09 op void hist_clear_forward(struct histhead*, struct hist*);
321 f26f1205 2022-02-09 op void hist_push(struct histhead*, struct hist*);
322 f26f1205 2022-02-09 op void hist_add_before(struct histhead *, struct hist *, struct hist *);
323 f26f1205 2022-02-09 op struct hist *hist_pop(struct histhead *);
326 f26f1205 2022-02-09 op int setup_parser_for(struct tab*);
329 f26f1205 2022-02-09 op int net_main(void);
331 f26f1205 2022-02-09 op /* parse.y */
332 f26f1205 2022-02-09 op void parseconfig(const char *, int);
334 f26f1205 2022-02-09 op /* sandbox.c */
335 f26f1205 2022-02-09 op void sandbox_net_process(void);
336 f26f1205 2022-02-09 op void sandbox_ui_process(void);
337 f26f1205 2022-02-09 op void sandbox_fs_process(void);
339 f26f1205 2022-02-09 op /* telescope.c */
340 f26f1205 2022-02-09 op extern int operating;
341 f26f1205 2022-02-09 op extern int safe_mode;
343 f26f1205 2022-02-09 op #define LU_MODE_NONE 0x0
344 f26f1205 2022-02-09 op #define LU_MODE_NOHIST 0x1
345 f26f1205 2022-02-09 op #define LU_MODE_NOCACHE 0x2
347 f26f1205 2022-02-09 op void gopher_send_search_req(struct tab *, const char *);
348 f26f1205 2022-02-09 op int load_page_from_str(struct tab *, const char *);
349 f26f1205 2022-02-09 op void load_url(struct tab *, const char *, const char *, int);
350 f26f1205 2022-02-09 op void load_url_in_tab(struct tab *, const char *, const char *, int);
351 f26f1205 2022-02-09 op int load_previous_page(struct tab*);
352 f26f1205 2022-02-09 op int load_next_page(struct tab*);
353 f26f1205 2022-02-09 op void add_to_bookmarks(const char*);
354 868b3a8f 2022-04-13 op void write_buffer(const char *, struct tab *);
355 f26f1205 2022-02-09 op void humanify_url(const char *, char *, size_t);
356 f26f1205 2022-02-09 op int ui_send_net(int, uint32_t, const void *, uint16_t);
357 f26f1205 2022-02-09 op int ui_send_fs(int, uint32_t, const void *, uint16_t);
360 f26f1205 2022-02-09 op void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
361 f26f1205 2022-02-09 op struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
362 f26f1205 2022-02-09 op void tofu_add(struct ohash*, struct tofu_entry*);
363 f26f1205 2022-02-09 op void tofu_update(struct ohash*, struct tofu_entry*);
364 f26f1205 2022-02-09 op void tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
367 f26f1205 2022-02-09 op void erase_buffer(struct buffer *);
368 f26f1205 2022-02-09 op void empty_linelist(struct buffer*);
369 f26f1205 2022-02-09 op void empty_vlist(struct buffer*);
370 f26f1205 2022-02-09 op int wrap_one(struct buffer *, const char *, struct line *, size_t);
371 f26f1205 2022-02-09 op int wrap_text(struct buffer*, const char*, struct line*, size_t);
372 f26f1205 2022-02-09 op int hardwrap_text(struct buffer*, struct line*, size_t);
373 f26f1205 2022-02-09 op int wrap_page(struct buffer *, int width);
375 f26f1205 2022-02-09 op #endif /* TELESCOPE_H */