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 f63b8f73 2022-04-24 op typedef void (*parserinit)(struct parser *);
150 d54dd816 2022-04-13 op typedef int (*parsechunkfn)(struct parser *, const char *, size_t);
151 d54dd816 2022-04-13 op typedef int (*parserfreefn)(struct parser *);
152 0110411e 2022-04-13 op typedef int (*parserserial)(struct parser *, FILE *);
154 f26f1205 2022-02-09 op typedef void (imsg_handlerfn)(struct imsg*, size_t);
156 f26f1205 2022-02-09 op struct parser {
157 f26f1205 2022-02-09 op const char *name;
158 f26f1205 2022-02-09 op char title[128+1];
163 f26f1205 2022-02-09 op #define PARSER_IN_BODY 1
164 f26f1205 2022-02-09 op #define PARSER_IN_PRE 2
165 f26f1205 2022-02-09 op #define PARSER_IN_PATCH_HDR 4
167 f63b8f73 2022-04-24 op parserinit init;
168 f26f1205 2022-02-09 op parsechunkfn parse;
169 f26f1205 2022-02-09 op parserfreefn free;
170 f26f1205 2022-02-09 op parserserial serialize;
172 f26f1205 2022-02-09 op TAILQ_HEAD(, line) head;
176 f26f1205 2022-02-09 op * differnt types of trust for a certificate. Following
177 f26f1205 2022-02-09 op * gemini://thfr.info/gemini/modified-trust-verify.gmi
179 f26f1205 2022-02-09 op enum trust_state {
181 f26f1205 2022-02-09 op TS_UNTRUSTED,
182 f26f1205 2022-02-09 op TS_TEMP_TRUSTED,
187 f26f1205 2022-02-09 op struct tofu_entry {
188 f26f1205 2022-02-09 op char domain[GEMINI_URL_LEN];
191 f26f1205 2022-02-09 op * enough space for ``PROTO:HASH''. probably isn't a good
194 f26f1205 2022-02-09 op char hash[128+1];
195 f26f1205 2022-02-09 op int verified;
198 f26f1205 2022-02-09 op struct histhead {
199 f26f1205 2022-02-09 op TAILQ_HEAD(mhisthead, hist) head;
202 f26f1205 2022-02-09 op struct hist {
203 f26f1205 2022-02-09 op char h[1025];
204 f26f1205 2022-02-09 op size_t line_off;
205 f26f1205 2022-02-09 op size_t current_off;
206 f26f1205 2022-02-09 op TAILQ_ENTRY(hist) entries;
209 f26f1205 2022-02-09 op struct buffer {
210 f26f1205 2022-02-09 op struct parser page;
212 f26f1205 2022-02-09 op size_t last_line_off;
213 f26f1205 2022-02-09 op int force_redraw;
217 f26f1205 2022-02-09 op size_t line_off;
218 f26f1205 2022-02-09 op size_t line_max;
219 f26f1205 2022-02-09 op struct vline *top_line;
220 f26f1205 2022-02-09 op struct vline *current_line;
221 f26f1205 2022-02-09 op size_t cpoff;
222 f26f1205 2022-02-09 op TAILQ_HEAD(vhead, vline) head;
225 f26f1205 2022-02-09 op #define TAB_CURRENT 0x1 /* only for save_session */
226 f26f1205 2022-02-09 op #define TAB_KILLED 0x2 /* only for save_session */
227 f26f1205 2022-02-09 op #define TAB_URGENT 0x4
228 f26f1205 2022-02-09 op #define TAB_LAZY 0x8 /* to lazy load tabs */
230 f26f1205 2022-02-09 op #define NEW_TAB_URL "about:new"
232 f26f1205 2022-02-09 op TAILQ_HEAD(tabshead, tab);
233 f26f1205 2022-02-09 op extern struct tabshead tabshead;
234 f26f1205 2022-02-09 op extern struct tabshead ktabshead;
236 f26f1205 2022-02-09 op TAILQ_ENTRY(tab) tabs;
238 f26f1205 2022-02-09 op uint32_t flags;
241 f26f1205 2022-02-09 op enum trust_state trust;
242 f26f1205 2022-02-09 op struct proxy *proxy;
243 f26f1205 2022-02-09 op struct phos_uri uri;
244 f26f1205 2022-02-09 op struct histhead hist;
245 f26f1205 2022-02-09 op struct hist *hist_cur;
246 f26f1205 2022-02-09 op size_t hist_off;
247 f26f1205 2022-02-09 op char *last_input_url;
250 f26f1205 2022-02-09 op char meta[GEMINI_URL_LEN];
251 f26f1205 2022-02-09 op int redirect_count;
253 f26f1205 2022-02-09 op struct buffer buffer;
255 f26f1205 2022-02-09 op short loading_anim;
256 f26f1205 2022-02-09 op short loading_anim_step;
257 f26f1205 2022-02-09 op struct event loadingev;
260 f26f1205 2022-02-09 op extern TAILQ_HEAD(proxylist, proxy) proxies;
261 f26f1205 2022-02-09 op struct proxy {
262 f26f1205 2022-02-09 op char *match_proto;
268 f26f1205 2022-02-09 op TAILQ_ENTRY(proxy) proxies;
272 f26f1205 2022-02-09 op PROTO_FINGER,
273 f26f1205 2022-02-09 op PROTO_GEMINI,
274 f26f1205 2022-02-09 op PROTO_GOPHER,
278 f26f1205 2022-02-09 op struct get_req {
280 f26f1205 2022-02-09 op char host[254];
281 f26f1205 2022-02-09 op char port[16];
282 f26f1205 2022-02-09 op char req[1027];
286 f26f1205 2022-02-09 op const char *cmd;
287 f26f1205 2022-02-09 op void (*fn)(struct buffer *);
288 f26f1205 2022-02-09 op const char *descr;
290 f26f1205 2022-02-09 op extern struct cmd cmds[];
292 f26f1205 2022-02-09 op /* defaults.c */
293 f26f1205 2022-02-09 op void config_init(void);
294 f26f1205 2022-02-09 op int config_setprfx(const char *, const char *, const char *);
295 f26f1205 2022-02-09 op int config_setvari(const char *, int);
296 f26f1205 2022-02-09 op int config_setvars(const char *, char *);
297 f26f1205 2022-02-09 op int config_setcolor(int, const char *, int, int, int);
298 f26f1205 2022-02-09 op int config_setattr(const char *, int, int, int);
299 f26f1205 2022-02-09 op void config_apply_style(void);
301 f26f1205 2022-02-09 op /* downloads.c */
302 f26f1205 2022-02-09 op extern STAILQ_HEAD(downloads, download) downloads;
303 f26f1205 2022-02-09 op struct download {
306 f26f1205 2022-02-09 op size_t bytes;
309 f26f1205 2022-02-09 op STAILQ_ENTRY(download) entries;
312 f26f1205 2022-02-09 op void recompute_downloads(void);
313 f63b8f73 2022-04-24 op struct download *enqueue_download(uint32_t, const char *, int);
314 868b3a8f 2022-04-13 op void dequeue_first_download(void);
315 f26f1205 2022-02-09 op struct download *download_by_id(uint32_t);
318 f26f1205 2022-02-09 op void recompute_help(void);
321 f26f1205 2022-02-09 op void hist_clear(struct histhead *);
322 f26f1205 2022-02-09 op void hist_clear_forward(struct histhead*, struct hist*);
323 f26f1205 2022-02-09 op void hist_push(struct histhead*, struct hist*);
324 f26f1205 2022-02-09 op void hist_add_before(struct histhead *, struct hist *, struct hist *);
325 f26f1205 2022-02-09 op struct hist *hist_pop(struct histhead *);
328 f26f1205 2022-02-09 op int setup_parser_for(struct tab*);
331 f26f1205 2022-02-09 op int net_main(void);
333 f26f1205 2022-02-09 op /* parse.y */
334 f26f1205 2022-02-09 op void parseconfig(const char *, int);
336 f26f1205 2022-02-09 op /* sandbox.c */
337 f26f1205 2022-02-09 op void sandbox_net_process(void);
338 f26f1205 2022-02-09 op void sandbox_ui_process(void);
340 f26f1205 2022-02-09 op /* telescope.c */
341 f26f1205 2022-02-09 op extern int operating;
342 f26f1205 2022-02-09 op extern int safe_mode;
344 f26f1205 2022-02-09 op #define LU_MODE_NONE 0x0
345 f26f1205 2022-02-09 op #define LU_MODE_NOHIST 0x1
346 f26f1205 2022-02-09 op #define LU_MODE_NOCACHE 0x2
348 f26f1205 2022-02-09 op void gopher_send_search_req(struct tab *, const char *);
349 f26f1205 2022-02-09 op int load_page_from_str(struct tab *, const char *);
350 f26f1205 2022-02-09 op void load_url(struct tab *, const char *, const char *, int);
351 f26f1205 2022-02-09 op void load_url_in_tab(struct tab *, const char *, const char *, int);
352 f26f1205 2022-02-09 op int load_previous_page(struct tab*);
353 f26f1205 2022-02-09 op int load_next_page(struct tab*);
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);
359 f26f1205 2022-02-09 op void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
360 f26f1205 2022-02-09 op struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
361 f26f1205 2022-02-09 op void tofu_add(struct ohash*, struct tofu_entry*);
362 f26f1205 2022-02-09 op void tofu_update(struct ohash*, struct tofu_entry*);
363 f26f1205 2022-02-09 op void tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
366 f26f1205 2022-02-09 op void erase_buffer(struct buffer *);
367 f26f1205 2022-02-09 op void empty_linelist(struct buffer*);
368 f26f1205 2022-02-09 op void empty_vlist(struct buffer*);
369 f26f1205 2022-02-09 op int wrap_one(struct buffer *, const char *, struct line *, size_t);
370 f26f1205 2022-02-09 op int wrap_text(struct buffer*, const char*, struct line*, size_t);
371 f26f1205 2022-02-09 op int hardwrap_text(struct buffer*, struct line*, size_t);
372 f26f1205 2022-02-09 op int wrap_page(struct buffer *, int width);
374 f26f1205 2022-02-09 op #endif /* TELESCOPE_H */