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
33 void (*handler)(int, short, void *);
39 /* ui <-> client/fs */
40 IMSG_GET, /* data is URL, peerid the tab id */
41 IMSG_GET_RAW, /* get but with an explicit req str */
69 extern char *new_tab_url;
70 extern int fill_column;
71 extern int olivetti_mode;
72 extern int enable_colors;
73 extern int hide_pre_context;
74 extern int hide_pre_blocks;
80 extern struct lineprefix line_prefixes[];
83 int prfx_pair, pair, trail_pair;
84 int prfx_bg, bg, trail_bg;
85 int prfx_fg, fg, trail_fg;
86 int prfx_attr, attr, trail_attr;
88 int prefix, text, trail;
90 extern struct line_face line_faces[];
93 int bg_attr, bg_bg, bg_fg;
94 int t_attr, t_bg, t_fg;
95 int c_attr, c_bg, c_fg;
97 int background, tab, current;
99 extern struct tab_face tab_face;
106 int left, body, right;
108 extern struct body_face body_face;
110 struct modeline_face {
114 extern struct modeline_face modeline_face;
116 struct minibuffer_face {
120 extern struct minibuffer_face minibuffer_face;
135 /* for lines: mark as hidden */
138 /* for vlines: mark as continuation */
139 #define L_CONTINUATION 2
146 TAILQ_ENTRY(line) lines;
150 const struct line *parent;
153 TAILQ_ENTRY(vline) vlines;
159 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
160 typedef int (*parserfreefn)(struct parser*);
162 typedef void (imsg_handlerfn)(struct imsg*, size_t);
171 #define PARSER_IN_BODY 1
172 #define PARSER_IN_PRE 2
177 TAILQ_HEAD(, line) head;
181 * differnt types of trust for a certificate. Following
182 * gemini://thfr.info/gemini/modified-trust-verify.gmi
193 char domain[GEMINI_URL_LEN];
196 * enough space for ``PROTO:HASH''. probably isn't a good
204 TAILQ_HEAD(mhisthead, hist) head;
209 TAILQ_ENTRY(hist) entries;
215 size_t last_line_off;
222 struct vline *top_line;
223 struct vline *current_line;
225 TAILQ_HEAD(vhead, vline) head;
228 #define TAB_CURRENT 0x1
229 #define TAB_URGENT 0x2
231 #define NEW_TAB_URL "about:new"
233 extern TAILQ_HEAD(tabshead, tab) tabshead;
235 TAILQ_ENTRY(tab) tabs;
240 enum trust_state trust;
243 struct histhead hist;
244 struct hist *hist_cur;
248 char meta[GEMINI_URL_LEN];
251 struct buffer buffer;
254 short loading_anim_step;
255 struct event loadingev;
266 * should load the given url in the tab. Optionally, it may
267 * consider the given url as relative to the one already
268 * present in tab. It must set tab->urlstr to a serialized
269 * human-friendly URL.
271 void (*loadfn)(struct tab*, const char*);
274 extern TAILQ_HEAD(proxylist, proxy) proxies;
282 TAILQ_ENTRY(proxy) proxies;
298 TAILQ_HEAD(map, keymap) m;
299 void (*unhandled_input)(void);
301 extern struct kmap global_map, minibuffer_map;
303 typedef void(interactivefn)(struct buffer *);
311 TAILQ_ENTRY(keymap) keymaps;
316 void (*fn)(struct buffer *);
318 extern struct cmd cmds[];
321 void config_init(void);
322 int config_setprfx(const char *, const char *, const char *);
323 int config_setvari(const char *, int);
324 int config_setvars(const char *, char *);
325 int config_setcolor(int, const char *, int, int, int);
326 int config_setattr(const char *, int, int, int);
327 void config_apply_style(void);
332 int load_certs(struct ohash*);
333 int load_last_session(void(*)(const char*));
336 int client_main(void);
339 void hist_clear_forward(struct histhead*, struct hist*);
340 void hist_push(struct histhead*, struct hist*);
343 int kbd(const char*);
344 const char *unkbd(int);
345 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
348 int setup_parser_for(struct tab*);
351 extern const char *about_about;
352 extern const char *about_blank;
353 extern const char *about_help;
354 extern const char *about_new;
356 #define CANNOT_FETCH 0
357 #define TOO_MUCH_REDIRECTS 1
358 #define MALFORMED_RESPONSE 2
359 #define UNKNOWN_TYPE_OR_CSET 3
360 extern const char *err_pages[70];
363 void parseconfig(const char *, int);
366 void sandbox_net_process(void);
367 void sandbox_ui_process(void);
368 void sandbox_fs_process(void);
371 void load_about_url(struct tab*, const char*);
372 void load_gemini_url(struct tab*, const char*);
373 void load_via_proxy(struct tab *, const char *, struct proxy *);
374 void load_url(struct tab*, const char*);
375 int load_previous_page(struct tab*);
376 int load_next_page(struct tab*);
377 void stop_tab(struct tab*);
378 void add_to_bookmarks(const char*);
379 void save_session(void);
382 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
383 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
384 void tofu_add(struct ohash*, struct tofu_entry*);
385 void tofu_update(struct ohash*, struct tofu_entry*);
386 void tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
389 int mark_nonblock(int);
390 int has_prefix(const char*, const char*);
391 int unicode_isspace(uint32_t);
392 int unicode_isgraph(uint32_t);
393 void dispatch_imsg(struct imsgev*, short, imsg_handlerfn**, size_t);
394 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, const void *, uint16_t);
397 void erase_buffer(struct buffer *);
398 void empty_linelist(struct buffer*);
399 void empty_vlist(struct buffer*);
400 int wrap_text(struct buffer*, const char*, struct line*, size_t);
401 int hardwrap_text(struct buffer*, struct line*, size_t);
403 #endif /* TELESCOPE_H */