2 5e11c00c 2021-03-02 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 5e11c00c 2021-03-02 op * Permission to use, copy, modify, and distribute this software for any
5 5e11c00c 2021-03-02 op * purpose with or without fee is hereby granted, provided that the above
6 5e11c00c 2021-03-02 op * copyright notice and this permission notice appear in all copies.
8 5e11c00c 2021-03-02 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 5e11c00c 2021-03-02 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 5e11c00c 2021-03-02 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 5e11c00c 2021-03-02 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 5e11c00c 2021-03-02 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 5e11c00c 2021-03-02 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 5e11c00c 2021-03-02 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 5e11c00c 2021-03-02 op #ifndef TELESCOPE_H
18 5e11c00c 2021-03-02 op #define TELESCOPE_H
20 09312eb3 2021-05-14 op #include "cmd.h"
21 b0003f58 2021-03-08 op #include "compat.h"
22 e2226342 2021-05-12 op #include "phos/phos.h"
24 65d9b3ca 2021-03-14 op #include <event.h>
26 dc5df781 2021-03-13 op #define MIN(a, b) ((a) < (b) ? (a) : (b))
27 dc5df781 2021-03-13 op #define MAX(a, b) ((a) > (b) ? (a) : (b))
29 5e11c00c 2021-03-02 op #define GEMINI_URL_LEN 1024
31 5e11c00c 2021-03-02 op enum imsg_type {
32 740f578b 2021-03-15 op /* ui <-> client/fs */
33 5e11c00c 2021-03-02 op IMSG_GET, /* data is URL, peerid the tab id */
35 5e11c00c 2021-03-02 op IMSG_CHECK_CERT,
36 5e11c00c 2021-03-02 op IMSG_CERT_STATUS,
37 5e11c00c 2021-03-02 op IMSG_GOT_CODE,
38 5e11c00c 2021-03-02 op IMSG_GOT_META,
45 740f578b 2021-03-15 op /* ui <-> fs */
46 740f578b 2021-03-15 op IMSG_BOOKMARK_PAGE,
47 740f578b 2021-03-15 op IMSG_BOOKMARK_OK,
48 3a227e9a 2021-03-18 op IMSG_SAVE_CERT,
49 3a227e9a 2021-03-18 op IMSG_SAVE_CERT_OK,
50 288fd238 2021-04-25 op IMSG_UPDATE_CERT,
51 288fd238 2021-04-25 op IMSG_UPDATE_CERT_OK,
53 de2a69bb 2021-05-17 op IMSG_FILE_OPEN,
54 de2a69bb 2021-05-17 op IMSG_FILE_OPENED,
56 c7107cec 2021-04-01 op IMSG_SESSION_START,
57 c7107cec 2021-04-01 op IMSG_SESSION_TAB,
58 c7107cec 2021-04-01 op IMSG_SESSION_END,
61 c92e529c 2021-06-15 op struct lineprefix {
62 c92e529c 2021-06-15 op const char *prfx1;
63 c92e529c 2021-06-15 op const char *prfx2;
65 c92e529c 2021-06-15 op extern struct lineprefix line_prefixes[];
67 c92e529c 2021-06-15 op struct line_face {
68 c92e529c 2021-06-15 op int prefix_prop;
69 c92e529c 2021-06-15 op int text_prop;
71 c92e529c 2021-06-15 op extern struct line_face line_faces[];
73 c92e529c 2021-06-15 op struct tab_face {
74 c92e529c 2021-06-15 op int background, tab, current_tab;
76 c92e529c 2021-06-15 op extern struct tab_face tab_face;
78 5e11c00c 2021-03-02 op enum line_type {
86 5e11c00c 2021-03-02 op LINE_PRE_START,
87 5e11c00c 2021-03-02 op LINE_PRE_CONTENT,
92 5e11c00c 2021-03-02 op enum line_type type;
96 5e11c00c 2021-03-02 op TAILQ_ENTRY(line) lines;
99 9a25f829 2021-03-14 op struct vline {
100 9a25f829 2021-03-14 op const struct line *parent;
103 9a25f829 2021-03-14 op TAILQ_ENTRY(vline) vlines;
106 5e11c00c 2021-03-02 op struct parser;
109 5e11c00c 2021-03-02 op typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
110 a5c3e03d 2021-03-02 op typedef int (*parserfreefn)(struct parser*);
112 5e11c00c 2021-03-02 op typedef void (imsg_handlerfn)(struct imsg*, size_t);
114 5e11c00c 2021-03-02 op struct parser {
115 fc43eadd 2021-03-12 op const char *name;
116 dc5df781 2021-03-13 op char title[32+1];
121 5e11c00c 2021-03-02 op parsechunkfn parse;
122 5e11c00c 2021-03-02 op parserfreefn free;
124 5e11c00c 2021-03-02 op TAILQ_HEAD(, line) head;
128 10346511 2021-03-17 op * differnt types of trust for a certificate. Following
129 10346511 2021-03-17 op * gemini://thfr.info/gemini/modified-trust-verify.gmi
131 10346511 2021-03-17 op enum trust_state {
133 10346511 2021-03-17 op TS_UNTRUSTED,
138 cbcc75fb 2021-03-17 op struct tofu_entry {
139 cbcc75fb 2021-03-17 op char domain[GEMINI_URL_LEN];
142 f1c6e31e 2021-05-12 op * enough space for ``PROTO:HASH''. probably isn't a good
145 cbcc75fb 2021-03-17 op char hash[128+1];
146 cbcc75fb 2021-03-17 op int verified;
149 2ba66cea 2021-03-22 op struct histhead {
150 2ba66cea 2021-03-22 op TAILQ_HEAD(mhisthead, hist) head;
153 2ba66cea 2021-03-22 op struct hist {
154 2ba66cea 2021-03-22 op char h[1025];
155 2ba66cea 2021-03-22 op TAILQ_ENTRY(hist) entries;
158 46f6e974 2021-05-17 op struct buffer {
159 2ba66cea 2021-03-22 op struct parser page;
162 2ba66cea 2021-03-22 op size_t line_off;
163 2ba66cea 2021-03-22 op size_t line_max;
164 2ba66cea 2021-03-22 op struct vline *current_line;
165 2ba66cea 2021-03-22 op size_t cpoff;
166 2ba66cea 2021-03-22 op TAILQ_HEAD(vhead, vline) head;
169 5e11c00c 2021-03-02 op extern TAILQ_HEAD(tabshead, tab) tabshead;
171 5e11c00c 2021-03-02 op TAILQ_ENTRY(tab) tabs;
173 5e11c00c 2021-03-02 op uint32_t flags;
176 10346511 2021-03-17 op enum trust_state trust;
177 31f1a758 2021-04-22 op struct phos_uri uri;
178 2051e653 2021-03-13 op struct histhead hist;
179 2051e653 2021-03-13 op struct hist *hist_cur;
180 2051e653 2021-03-13 op size_t hist_off;
183 0972d8b2 2021-03-02 op char meta[GEMINI_URL_LEN];
184 0972d8b2 2021-03-02 op int redirect_count;
186 46f6e974 2021-05-17 op struct buffer buffer;
188 2ba66cea 2021-03-22 op short loading_anim;
189 2ba66cea 2021-03-22 op short loading_anim_step;
190 2ba66cea 2021-03-22 op struct event loadingev;
193 de2a69bb 2021-05-17 op size_t bytes;
197 4d3785b1 2021-03-09 op struct proto {
198 4d3785b1 2021-03-09 op const char *schema;
201 f1c6e31e 2021-05-12 op * should load the given url in the tab. Optionally, it may
202 4d3785b1 2021-03-09 op * consider the given url as relative to the one already
203 4d3785b1 2021-03-09 op * present in tab. It must set tab->urlstr to a serialized
204 f1c6e31e 2021-05-12 op * human-friendly URL.
206 4d3785b1 2021-03-09 op void (*loadfn)(struct tab*, const char*);
209 67c8ed7f 2021-03-13 op struct kmap {
210 67c8ed7f 2021-03-13 op TAILQ_HEAD(map, keymap) m;
211 67c8ed7f 2021-03-13 op void (*unhandled_input)(void);
214 67c8ed7f 2021-03-13 op struct keymap {
217 67c8ed7f 2021-03-13 op struct kmap map;
218 46f6e974 2021-05-17 op void (*fn)(struct buffer*);
220 67c8ed7f 2021-03-13 op TAILQ_ENTRY(keymap) keymaps;
224 3a227e9a 2021-03-18 op int fs_init(void);
225 35e1f40a 2021-03-14 op int fs_main(struct imsgbuf*);
226 3a227e9a 2021-03-18 op int load_certs(struct ohash*);
227 c7107cec 2021-04-01 op int load_last_session(void(*)(const char*));
229 5e11c00c 2021-03-02 op /* gemini.c */
230 35e1f40a 2021-03-14 op int client_main(struct imsgbuf*);
232 5e11c00c 2021-03-02 op /* gemtext.c */
233 5e11c00c 2021-03-02 op void gemtext_initparser(struct parser*);
236 2051e653 2021-03-13 op void hist_clear_forward(struct histhead*, struct hist*);
237 2051e653 2021-03-13 op void hist_push(struct histhead*, struct hist*);
239 67c8ed7f 2021-03-13 op /* keymap.c */
240 67c8ed7f 2021-03-13 op int kbd(const char*);
241 67c8ed7f 2021-03-13 op const char *unkbd(int);
242 46f6e974 2021-05-17 op int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
245 c07ac996 2021-03-12 op int setup_parser_for(struct tab*);
247 0972d8b2 2021-03-02 op /* pages.c */
248 0972d8b2 2021-03-02 op extern const char *about_new;
250 0972d8b2 2021-03-02 op #define CANNOT_FETCH 0
251 0972d8b2 2021-03-02 op #define TOO_MUCH_REDIRECTS 1
252 5cd2ebb1 2021-03-11 op #define MALFORMED_RESPONSE 2
253 c07ac996 2021-03-12 op #define UNKNOWN_TYPE_OR_CSET 3
254 0972d8b2 2021-03-02 op extern const char *err_pages[70];
256 c92e529c 2021-06-15 op /* parse.y */
257 c92e529c 2021-06-15 op void parseconfig(const char *, int);
259 3d70083d 2021-03-12 op /* parser.c */
260 3d70083d 2021-03-12 op int parser_append(struct parser*, const char*, size_t);
261 3d70083d 2021-03-12 op int parser_set_buf(struct parser*, const char*, size_t);
262 a5845bb5 2021-03-20 op int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
264 ebdcadbf 2021-03-12 op /* sandbox.c */
265 ebdcadbf 2021-03-12 op void sandbox_network_process(void);
266 b1d4d01b 2021-03-14 op void sandbox_ui_process(void);
267 35e1f40a 2021-03-14 op void sandbox_fs_process(void);
269 bcb0b073 2021-03-07 op /* telescope.c */
270 4d3785b1 2021-03-09 op void load_about_url(struct tab*, const char*);
271 4d3785b1 2021-03-09 op void load_gemini_url(struct tab*, const char*);
272 bcb0b073 2021-03-07 op void load_url(struct tab*, const char*);
273 2051e653 2021-03-13 op int load_previous_page(struct tab*);
274 2051e653 2021-03-13 op int load_next_page(struct tab*);
275 9ad4627d 2021-03-10 op void stop_tab(struct tab*);
276 740f578b 2021-03-15 op void add_to_bookmarks(const char*);
277 c7107cec 2021-04-01 op void save_session(void);
279 c49d61bc 2021-03-12 op /* textplain.c */
280 c49d61bc 2021-03-12 op void textplain_initparser(struct parser*);
283 c36d43ac 2021-04-25 op void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
284 c36d43ac 2021-04-25 op struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
285 c36d43ac 2021-04-25 op void tofu_add(struct ohash*, struct tofu_entry*);
286 288fd238 2021-04-25 op void tofu_update(struct ohash*, struct tofu_entry*);
289 2eef3403 2021-04-22 op unsigned int tab_new_id(void);
290 6cd6a9e1 2021-03-20 op int ui_init(int, char * const*);
291 8af5e5ed 2021-03-08 op void ui_on_tab_loaded(struct tab*);
292 5e11c00c 2021-03-02 op void ui_on_tab_refresh(struct tab*);
293 5cd2ebb1 2021-03-11 op void ui_require_input(struct tab*, int);
294 de2a69bb 2021-05-17 op void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
295 b3575139 2021-04-01 op void ui_yornp(const char*, void (*)(int, unsigned int), unsigned int);
296 740f578b 2021-03-15 op void ui_notify(const char*, ...) __attribute__((format(printf, 1, 2)));
297 5e11c00c 2021-03-02 op void ui_end(void);
300 8947c1f2 2021-03-21 op uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
301 17e5106b 2021-03-21 op size_t utf8_encode(uint32_t, char*);
302 174b3cdf 2021-03-21 op char *utf8_nth(char*, size_t);
303 174b3cdf 2021-03-21 op size_t utf8_cplen(char*);
304 174b3cdf 2021-03-21 op size_t utf8_chwidth(uint32_t);
305 174b3cdf 2021-03-21 op size_t utf8_snwidth(const char*, size_t);
306 174b3cdf 2021-03-21 op size_t utf8_swidth(const char*);
307 17e5106b 2021-03-21 op size_t utf8_swidth_between(const char*, const char*);
308 2ba66cea 2021-03-22 op char *utf8_next_cp(const char*);
309 2ba66cea 2021-03-22 op char *utf8_prev_cp(const char*, const char*);
312 5e11c00c 2021-03-02 op int mark_nonblock(int);
313 5c88f028 2021-03-09 op int has_prefix(const char*, const char*);
314 17e5106b 2021-03-21 op int unicode_isspace(uint32_t);
315 17e5106b 2021-03-21 op int unicode_isgraph(uint32_t);
316 1304bbdd 2021-03-15 op void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
319 46f6e974 2021-05-17 op void empty_linelist(struct buffer*);
320 46f6e974 2021-05-17 op void empty_vlist(struct buffer*);
321 46f6e974 2021-05-17 op int wrap_text(struct buffer*, const char*, struct line*, size_t);
322 46f6e974 2021-05-17 op int hardwrap_text(struct buffer*, struct line*, size_t);
324 5e11c00c 2021-03-02 op #endif /* TELESCOPE_H */