2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "phos/phos.h"
26 #define MIN(a, b) ((a) < (b) ? (a) : (b))
27 #define MAX(a, b) ((a) > (b) ? (a) : (b))
29 #define GEMINI_URL_LEN 1024
32 /* ui <-> client/fs */
33 IMSG_GET, /* data is URL, peerid the tab id */
65 extern struct lineprefix line_prefixes[];
71 extern struct line_face line_faces[];
74 int background, tab, current_tab;
76 extern struct tab_face tab_face;
78 struct modeline_face {
81 extern struct modeline_face modeline_face;
83 struct minibuffer_face {
86 extern struct minibuffer_face minibuffer_face;
106 TAILQ_ENTRY(line) lines;
110 const struct line *parent;
113 TAILQ_ENTRY(vline) vlines;
119 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
120 typedef int (*parserfreefn)(struct parser*);
122 typedef void (imsg_handlerfn)(struct imsg*, size_t);
134 TAILQ_HEAD(, line) head;
138 * differnt types of trust for a certificate. Following
139 * gemini://thfr.info/gemini/modified-trust-verify.gmi
149 char domain[GEMINI_URL_LEN];
152 * enough space for ``PROTO:HASH''. probably isn't a good
160 TAILQ_HEAD(mhisthead, hist) head;
165 TAILQ_ENTRY(hist) entries;
174 struct vline *current_line;
176 TAILQ_HEAD(vhead, vline) head;
179 extern TAILQ_HEAD(tabshead, tab) tabshead;
181 TAILQ_ENTRY(tab) tabs;
186 enum trust_state trust;
188 struct histhead hist;
189 struct hist *hist_cur;
193 char meta[GEMINI_URL_LEN];
196 struct buffer buffer;
199 short loading_anim_step;
200 struct event loadingev;
211 * should load the given url in the tab. Optionally, it may
212 * consider the given url as relative to the one already
213 * present in tab. It must set tab->urlstr to a serialized
214 * human-friendly URL.
216 void (*loadfn)(struct tab*, const char*);
220 TAILQ_HEAD(map, keymap) m;
221 void (*unhandled_input)(void);
228 void (*fn)(struct buffer*);
230 TAILQ_ENTRY(keymap) keymaps;
235 int fs_main(struct imsgbuf*);
236 int load_certs(struct ohash*);
237 int load_last_session(void(*)(const char*));
240 int client_main(struct imsgbuf*);
243 void gemtext_initparser(struct parser*);
246 void hist_clear_forward(struct histhead*, struct hist*);
247 void hist_push(struct histhead*, struct hist*);
250 int kbd(const char*);
251 const char *unkbd(int);
252 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
255 int setup_parser_for(struct tab*);
258 extern const char *about_new;
260 #define CANNOT_FETCH 0
261 #define TOO_MUCH_REDIRECTS 1
262 #define MALFORMED_RESPONSE 2
263 #define UNKNOWN_TYPE_OR_CSET 3
264 extern const char *err_pages[70];
267 void parseconfig(const char *, int);
270 int parser_append(struct parser*, const char*, size_t);
271 int parser_set_buf(struct parser*, const char*, size_t);
272 int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
275 void sandbox_network_process(void);
276 void sandbox_ui_process(void);
277 void sandbox_fs_process(void);
280 void load_about_url(struct tab*, const char*);
281 void load_gemini_url(struct tab*, const char*);
282 void load_url(struct tab*, const char*);
283 int load_previous_page(struct tab*);
284 int load_next_page(struct tab*);
285 void stop_tab(struct tab*);
286 void add_to_bookmarks(const char*);
287 void save_session(void);
290 void textplain_initparser(struct parser*);
293 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
294 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
295 void tofu_add(struct ohash*, struct tofu_entry*);
296 void tofu_update(struct ohash*, struct tofu_entry*);
299 unsigned int tab_new_id(void);
300 int ui_init(int, char * const*);
301 void ui_on_tab_loaded(struct tab*);
302 void ui_on_tab_refresh(struct tab*);
303 void ui_require_input(struct tab*, int);
304 void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
305 void ui_yornp(const char*, void (*)(int, unsigned int), unsigned int);
306 void ui_notify(const char*, ...) __attribute__((format(printf, 1, 2)));
310 uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
311 size_t utf8_encode(uint32_t, char*);
312 char *utf8_nth(char*, size_t);
313 size_t utf8_cplen(char*);
314 size_t utf8_chwidth(uint32_t);
315 size_t utf8_snwidth(const char*, size_t);
316 size_t utf8_swidth(const char*);
317 size_t utf8_swidth_between(const char*, const char*);
318 char *utf8_next_cp(const char*);
319 char *utf8_prev_cp(const char*, const char*);
322 int mark_nonblock(int);
323 int has_prefix(const char*, const char*);
324 int unicode_isspace(uint32_t);
325 int unicode_isgraph(uint32_t);
326 void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
329 void empty_linelist(struct buffer*);
330 void empty_vlist(struct buffer*);
331 int wrap_text(struct buffer*, const char*, struct line*, size_t);
332 int hardwrap_text(struct buffer*, struct line*, size_t);
334 #endif /* TELESCOPE_H */