Strip whitespace for config inputs
[xombrero.git] / xombrero.h
blob9179412abd9805a8dc64c98ef756db5aff4950e2
1 /*
2 * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
3 * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us>
4 * Copyright (c) 2010, 2011, 2012 Edd Barrett <vext01@gmail.com>
5 * Copyright (c) 2012, 2013 Josh Rickmar <jrick@devio.us>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <ctype.h>
21 #include <dlfcn.h>
22 #include <err.h>
23 #include <errno.h>
24 #include <libgen.h>
25 #include <pwd.h>
26 #include <regex.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <dirent.h>
32 #include <fcntl.h>
33 #include <inttypes.h>
35 #include <sys/types.h>
36 #if defined(__linux__)
37 #include "linux/util.h"
38 #include "linux/tree.h"
39 #include <bsd/stdlib.h>
40 #include <X11/Xlib.h>
41 #include <sys/un.h>
42 # if !defined(sane_libbsd_headers)
43 void arc4random_buf(void *, size_t);
44 u_int32_t arc4random_uniform(u_int32_t);
45 # endif
46 #elif defined(__APPLE__)
47 #include "osx/util.h"
48 #include "osx/tree.h"
49 #include <stdlib.h>
50 #include <X11/Xlib.h>
51 #include <sys/un.h>
52 #include <sys/param.h>
53 #include <sys/ucred.h>
54 #define LOGIN_NAME_MAX MAXLOGNAME
55 #elif defined(__FreeBSD__)
56 #include <libutil.h>
57 #include "freebsd/util.h"
58 #include <sys/tree.h>
59 #include <X11/Xlib.h>
60 #include <sys/un.h>
61 #include <sys/param.h>
62 #define LOGIN_NAME_MAX MAXLOGNAME
63 #elif defined(__DragonFly__)
64 #include <sys/param.h>
65 #include <sys/un.h>
66 #include <libutil.h>
67 #include "dragonfly/util.h"
68 #include <sys/tree.h>
69 #include <X11/Xlib.h>
70 #define LOGIN_NAME_MAX MAXLOGNAME
71 #elif defined(__NetBSD__)
72 #include <sys/param.h>
73 #include <sys/un.h>
74 #include "netbsd/util.h"
75 #include <sys/tree.h>
76 #include <X11/Xlib.h>
77 #define LOGIN_NAME_MAX_MAXLOGNAME
78 #elif defined(__OpenBSD__)
79 #include <util.h>
80 #include <sys/tree.h>
81 #include <X11/Xlib.h>
82 #include <sys/un.h>
83 #else
84 /* mingw */
85 void arc4random_buf(void *, size_t);
86 uint32_t arc4random_uniform(uint32_t);
87 #include "tree.h"
88 #endif
89 #include <sys/queue.h>
90 #include <sys/socket.h>
91 #include <sys/stat.h>
92 #include <sys/time.h>
94 #include <gtk/gtk.h>
95 #include <gdk/gdk.h>
96 #include <gdk/gdkkeysyms.h>
98 #if GTK_CHECK_VERSION(3,0,0)
99 /* we still use GDK_* instead of GDK_KEY_* */
100 #include <gdk/gdkkeysyms-compat.h>
101 #endif
103 #include <webkit/webkit.h>
104 #include <libsoup/soup.h>
105 #include <JavaScriptCore/JavaScript.h>
106 #include <gnutls/gnutls.h>
107 #include <gnutls/x509.h>
109 /* set if you don't want to use resource limits */
110 #ifndef XT_RESOURCE_LIMITS_DISABLE
111 #include <sys/resource.h>
112 #endif
114 #include "javascript.h"
116 javascript.h borrowed from vimprobable2 under the following license:
118 Copyright (c) 2009 Leon Winter
119 Copyright (c) 2009-2011 Hannes Schueller
120 Copyright (c) 2009-2010 Matto Fransen
121 Copyright (c) 2010-2011 Hans-Peter Deifel
122 Copyright (c) 2010-2011 Thomas Adam
123 Copyright (c) 2011 Albert Kim
124 Copyright (c) 2011 Daniel Carl
126 Permission is hereby granted, free of charge, to any person obtaining a copy
127 of this software and associated documentation files (the "Software"), to deal
128 in the Software without restriction, including without limitation the rights
129 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
130 copies of the Software, and to permit persons to whom the Software is
131 furnished to do so, subject to the following conditions:
133 The above copyright notice and this permission notice shall be included in
134 all copies or substantial portions of the Software.
136 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
137 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
138 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
139 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
140 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
141 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
142 THE SOFTWARE.
145 /*#define XT_DEBUG*/
146 #ifdef XT_DEBUG
147 #define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0)
148 #define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while (0)
149 #define XT_D_MOVE 0x0001
150 #define XT_D_KEY 0x0002
151 #define XT_D_TAB 0x0004
152 #define XT_D_URL 0x0008
153 #define XT_D_CMD 0x0010
154 #define XT_D_NAV 0x0020
155 #define XT_D_DOWNLOAD 0x0040
156 #define XT_D_CONFIG 0x0080
157 #define XT_D_JS 0x0100
158 #define XT_D_FAVORITE 0x0200
159 #define XT_D_PRINTING 0x0400
160 #define XT_D_COOKIE 0x0800
161 #define XT_D_KEYBINDING 0x1000
162 #define XT_D_CLIP 0x2000
163 #define XT_D_BUFFERCMD 0x4000
164 #define XT_D_INSPECTOR 0x8000
165 #define XT_D_VISITED 0x10000
166 #define XT_D_HISTORY 0x20000
167 #define XT_D_MISC 0x40000
168 #define XT_D_CUSTOM_URI 0x80000
169 #define XT_D_CMD_ALIAS 0x100000
170 #define XT_D_SEARCH 0x200000
171 extern uint32_t swm_debug;
172 #else
173 #define DPRINTF(x...)
174 #define DNPRINTF(n,x...)
175 #endif
177 #define LENGTH(x) (sizeof x / sizeof x[0])
178 #define CLEAN(mask) (mask & ~(GDK_MOD2_MASK) & \
179 ~(GDK_BUTTON1_MASK) & \
180 ~(GDK_BUTTON2_MASK) & \
181 ~(GDK_BUTTON3_MASK) & \
182 ~(GDK_BUTTON4_MASK) & \
183 ~(GDK_BUTTON5_MASK))
185 #define XT_MARKS "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'"
186 #define XT_NOMARKS (sizeof(XT_MARKS) - 1)
187 #define XT_QMARKS "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
188 #define XT_NOQMARKS (sizeof(XT_QMARKS) - 1)
190 /* Path Separator */
191 #ifndef PS
192 #define PS "/"
193 #define PSC '/'
194 #endif
196 struct tab {
197 TAILQ_ENTRY(tab) entry;
198 GtkWidget *vbox;
199 GtkWidget *tab_content;
200 struct {
201 GtkWidget *label;
202 GtkWidget *favicon;
203 GtkWidget *eventbox;
204 GtkWidget *box;
205 } tab_elems;
206 GtkWidget *label;
207 GtkWidget *spinner;
208 GtkWidget *uri_entry;
209 #if !GTK_CHECK_VERSION(3, 0, 0)
210 GtkStyle *default_style;
211 #endif
212 GtkWidget *search_entry;
213 GtkWidget *toolbar;
214 GtkWidget *browser_win;
215 GtkWidget *statusbar;
216 struct {
217 GtkWidget *ebox; /* non window-less widget for colors */
218 GtkWidget *uri;
219 GtkWidget *buffercmd;
220 GtkWidget *zoom;
221 GtkWidget *position;
222 GtkWidget *tabs;
223 GtkWidget *proxy;
224 } sbe;
225 GtkWidget *cmd;
226 GtkWidget *buffers;
227 GtkWidget *oops;
228 GtkWidget *backward;
229 GtkWidget *forward;
230 GtkWidget *stop;
231 GtkWidget *gohome;
232 GtkWidget *js_toggle;
233 GtkWidget *proxy_toggle;
234 GtkEntryCompletion *completion;
235 guint tab_id;
236 WebKitWebView *wv;
238 WebKitWebBackForwardList *bfl;
239 WebKitWebHistoryItem *item;
241 /* favicon */
242 WebKitNetworkRequest *icon_request;
243 WebKitDownload *icon_download;
244 gchar *icon_dest_uri;
246 /* adjustments for browser */
247 GtkAdjustment *adjust_h;
248 GtkAdjustment *adjust_v;
250 /* flags */
251 int mode;
252 #define XT_MODE_COMMAND (0)
253 #define XT_MODE_INSERT (1)
254 #define XT_MODE_HINT (2)
255 #define XT_MODE_PASSTHROUGH (3)
256 int (*mode_cb)(struct tab *, GdkEventKey *, gpointer);
257 gpointer mode_cb_data;
258 int focus_wv;
259 int ctrl_click;
260 gchar *status;
261 int xtp_meaning; /* identifies dls/favorites */
262 int xtp_arg;
263 char *session_key;
264 gchar *tmp_uri;
265 int popup; /* 1 if cmd_entry has popup visible */
266 int download_requested;
268 /* hints */
269 int script_init;
270 int new_tab;
272 /* custom stylesheet */
273 int styled;
274 char *stylesheet;
276 /* search */
277 char *search_text;
278 int search_forward;
279 guint search_id;
281 /* settings */
282 WebKitWebSettings *settings;
283 int user_agent_id;
284 int http_accept_id;
285 gboolean load_images;
287 /* marks */
288 double mark[XT_NOMARKS];
290 /* inspector */
291 WebKitWebInspector *inspector;
292 GtkWidget *inspector_window;
293 GtkWidget *inspector_view;
295 /* focused text entry */
296 #if WEBKIT_CHECK_VERSION(1, 5, 0)
297 WebKitDOMElement *active;
298 char *active_text;
299 #endif
301 /* signal handles */
302 gulong progress_handle;
304 /* cert chain (pem) */
305 char *pem;
307 /* previous host (:cert show) */
308 char *about_cert_host;
310 TAILQ_HEAD(tab_list, tab);
312 struct karg {
313 int i;
314 char *s;
315 int precount;
316 void *ptr;
319 struct download {
320 RB_ENTRY(download) entry;
321 int id;
322 WebKitDownload *download;
323 struct tab *tab;
325 RB_HEAD(download_list, download);
326 RB_PROTOTYPE(download_list, download, entry, download_rb_cmp);
328 struct history {
329 RB_ENTRY(history) entry;
330 gchar *uri;
331 gchar *title;
332 time_t time; /* When the item was added. */
334 RB_HEAD(history_list, history);
335 RB_PROTOTYPE(history_list, history, entry, history_rb_cmp);
337 #define XT_STS_FLAGS_INCLUDE_SUBDOMAINS (1)
338 #define XT_STS_FLAGS_EXPAND (2)
339 #define XT_STS_FILE ("strict-transport")
341 struct strict_transport {
342 RB_ENTRY(strict_transport) entry;
343 gchar *host;
344 time_t timeout;
345 int flags;
347 RB_HEAD(strict_transport_tree, strict_transport);
348 RB_PROTOTYPE(strict_transport_tree, strict_transport, entry, strict_transport_rb_cmp);
350 struct secviolation {
351 RB_ENTRY(secviolation) entry;
352 int xtp_arg;
353 struct tab *t;
354 char *uri;
356 RB_HEAD(secviolation_list, secviolation);
357 RB_PROTOTYPE(secviolation_list, secviolation, entry, secviolation_rb_cmp);
359 struct user_agent {
360 RB_ENTRY(user_agent) entry;
361 int id;
362 char *value;
364 RB_HEAD(user_agent_list, user_agent);
365 RB_PROTOTYPE(user_agent_list, user_agent, entry, user_agent_rb_cmp);
367 struct http_accept {
368 RB_ENTRY(http_accept) entry;
369 int id;
370 char *value;
372 RB_HEAD(http_accept_list, http_accept);
373 RB_PROTOTYPE(http_accept_list, http_accept, entry, http_accept_rb_cmp);
375 struct domain_id {
376 RB_ENTRY(domain_id) entry;
377 int ua_id; /* user agent id key */
378 int ha_id; /* http accept header id key */
379 char *domain;
381 RB_HEAD(domain_id_list, domain_id);
382 RB_PROTOTYPE(domain_id_list, domain_id, entry, domain_id_rb_cmp);
384 /* utility */
385 #define XT_NAME ("xombrero")
386 #define XT_DIR (".xombrero")
387 #define XT_CB_HANDLED (TRUE)
388 #define XT_CB_PASSTHROUGH (FALSE)
389 #define XT_CONF_FILE ("xombrero.conf")
390 #define XT_CSS_FILE ("xombrero.css")
391 #define XT_FAVS_FILE ("favorites")
392 #define XT_SOD_FILE ("startofday")
393 #define XT_HSTS_PRELOAD_FILE ("hsts-preload")
394 #define XT_USER_AGENT_FILE ("user-agent-headers")
395 #define XT_HTTP_ACCEPT_FILE ("http-accept-headers")
396 #define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`"
398 int run_script(struct tab *, char *);
399 void js_autorun(struct tab *);
400 void xt_icon_from_file(struct tab *, char *);
401 GtkWidget *create_window(const gchar *);
402 void show_oops(struct tab *, const char *, ...);
403 gchar *get_html_page(gchar *, gchar *, gchar *, bool);
404 const gchar *get_uri(struct tab *);
405 const gchar *get_title(struct tab *, bool);
406 void load_uri(struct tab *t, const gchar *uri);
407 gboolean match_uri(const gchar *uri, const gchar *key);
408 int valid_url_type(const char *);
409 void expand_tilde(char *, size_t, const char *);
410 gchar *html_escape(const char *val);
411 void set_status(struct tab *t, gchar *fmt, ...);
413 void load_webkit_string(struct tab *, const char *, gchar *, int);
414 void button_set_stockid(GtkWidget *, char *);
415 void button_set_file(GtkWidget *, char *);
416 void webview_progress_changed_cb(WebKitWebView *, GParamSpec *, struct tab *);
418 /* cookies */
419 int remove_cookie(int);
420 int remove_cookie_domain(int);
421 int remove_cookie_all(void);
422 void print_cookie(char *msg, SoupCookie *);
423 void setup_cookies(void);
424 void soup_cookie_jar_add_cookie(SoupCookieJar *, SoupCookie *);
425 void soup_cookie_jar_delete_cookie(SoupCookieJar *, SoupCookie *);
427 /* history */
428 int insert_history_item(const gchar *uri, const gchar *title, time_t time);
429 int save_global_history_to_disk(struct tab *t);
430 int restore_global_history(void);
431 char *color_visited_helper(void);
432 int color_visited(struct tab *t, char *visited);
434 /* completion */
435 void completion_add(struct tab *);
436 void completion_add_uri(const gchar *uri);
438 /* external editor */
439 #define XT_EE_BUFSZ (64 * 1024)
440 int edit_src(struct tab *t, struct karg *args);
441 int edit_element(struct tab *t, struct karg *a);
443 /* proxy */
444 #define XT_PRXY_SHOW (1<<0)
445 #define XT_PRXY_TOGGLE (1<<1)
447 /* url modify */
448 #define XT_URL (1<<0)
449 #define XT_URL_PLUS (1<<1)
450 #define XT_URL_MIN (1<<2)
452 /* inspector */
453 #define XT_INS_SHOW (1<<0)
454 #define XT_INS_HIDE (1<<1)
455 #define XT_INS_CLOSE (1<<2)
457 WebKitWebView* inspector_inspect_web_view_cb(WebKitWebInspector *,
458 WebKitWebView*, struct tab *);
459 void setup_inspector(struct tab *);
460 int inspector_cmd(struct tab *, struct karg *);
462 /* tld public suffix */
463 void tld_tree_init();
464 char *tld_get_suffix(const char *);
466 /* about */
467 #define XT_XTP_STR "xxxt://"
468 #define XT_XTP_SCHEME "xxxt"
469 #define XT_URI_ABOUT ("about:")
470 #define XT_URI_ABOUT_LEN (strlen(XT_URI_ABOUT))
471 #define XT_URI_ABOUT_ABOUT ("about")
472 #define XT_URI_ABOUT_ALLTHETHINGS ("allthethings")
473 #define XT_URI_ABOUT_BLANK ("blank")
474 #define XT_URI_ABOUT_CERTS ("certs")
475 #define XT_URI_ABOUT_COOKIEWL ("cookiewl")
476 #define XT_URI_ABOUT_COOKIEJAR ("cookiejar")
477 #define XT_URI_ABOUT_DOWNLOADS ("downloads")
478 #define XT_URI_ABOUT_FAVORITES ("favorites")
479 #define XT_URI_ABOUT_HELP ("help")
480 #define XT_URI_ABOUT_HISTORY ("history")
481 #define XT_URI_ABOUT_JSWL ("jswl")
482 #define XT_URI_ABOUT_PLUGINWL ("plwl")
483 #define XT_URI_ABOUT_HTTPS ("https")
484 #define XT_URI_ABOUT_SET ("set")
485 #define XT_URI_ABOUT_STATS ("stats")
486 #define XT_URI_ABOUT_MARCO ("marco")
487 #define XT_URI_ABOUT_STARTPAGE ("startpage")
488 #define XT_URI_ABOUT_WEBKIT ("webkit")
489 #define XT_URI_ABOUT_SEARCH ("search")
490 #define XT_URI_ABOUT_SECVIOLATION ("secviolation")
491 #define XT_URI_ABOUT_RUNTIME ("runtime")
493 struct about_type {
494 char *name;
495 int (*func)(struct tab *, struct karg *);
498 struct sp {
499 char *line;
500 TAILQ_ENTRY(sp) entry;
502 TAILQ_HEAD(sp_list, sp);
504 int blank(struct tab *, struct karg *);
505 int help(struct tab *, struct karg *);
506 int stats(struct tab *, struct karg *);
507 void show_certs(struct tab *, gnutls_x509_crt_t *,
508 size_t, char *);
509 int ca_cmd(struct tab *, struct karg *);
510 int cookie_show_wl(struct tab *, struct karg *);
511 int xtp_page_ab(struct tab *, struct karg *);
512 int xtp_page_cl(struct tab *, struct karg *);
513 int xtp_page_dl(struct tab *, struct karg *);
514 int xtp_page_fl(struct tab *, struct karg *);
515 int xtp_page_hl(struct tab *, struct karg *);
516 int xtp_page_sl(struct tab *, struct karg *);
517 int xtp_page_sv(struct tab *, struct karg *);
518 int parse_xtp_url(struct tab *, const char *);
519 int add_favorite(struct tab *, struct karg *);
520 void update_favorite_tabs(struct tab *);
521 void update_history_tabs(struct tab *);
522 void update_download_tabs(struct tab *);
523 size_t about_list_size(void);
524 int cookie_cmd(struct tab *, struct karg *);
525 int js_cmd(struct tab *, struct karg *);
526 int pl_cmd(struct tab *, struct karg *);
527 int https_cmd(struct tab *, struct karg *);
528 void startpage_add(const char *, ...);
531 * xtp tab meanings
532 * identifies which tabs have xtp pages in (corresponding to about_list indices)
534 #define XT_XTP_TAB_MEANING_NORMAL (-1) /* normal url */
535 #define XT_XTP_TAB_MEANING_AB (0) /* any other about page */
536 #define XT_XTP_TAB_MEANING_BL (2) /* about:blank in this tab */
537 #define XT_XTP_TAB_MEANING_CL (5) /* cookie manager in this tab */
538 #define XT_XTP_TAB_MEANING_DL (6) /* download manager in this tab */
539 #define XT_XTP_TAB_MEANING_FL (7) /* favorite manager in this tab */
540 #define XT_XTP_TAB_MEANING_HL (9) /* history manager in this tab */
541 #define XT_XTP_TAB_MEANING_SET (11) /* settings manager/viewer */
542 #define XT_XTP_TAB_MEANING_SL (18) /* search engine chooser */
543 #define XT_XTP_TAB_MEANING_RT (19) /* about:runtime in this tab */
544 #define XT_XTP_TAB_MEANING_SV (20) /* about:secviolation in tab */
546 /* whitelists */
547 #define XT_WL_TOGGLE (1<<0)
548 #define XT_WL_ENABLE (1<<1)
549 #define XT_WL_DISABLE (1<<2)
550 #define XT_WL_FQDN (1<<3) /* default */
551 #define XT_WL_TOPLEVEL (1<<4)
552 #define XT_WL_PERSISTENT (1<<5)
553 #define XT_WL_SESSION (1<<6)
554 #define XT_WL_RELOAD (1<<7)
555 #define XT_SHOW (1<<8)
556 #define XT_DELETE (1<<9)
557 #define XT_SAVE (1<<10)
558 #define XT_OPEN (1<<11)
559 #define XT_CACHE (1<<12)
560 #define XT_WL_REGEX (1<<13)
562 #define XT_WL_INVALID (0)
563 #define XT_WL_JAVASCRIPT (1)
564 #define XT_WL_COOKIE (2)
565 #define XT_WL_PLUGIN (3)
566 #define XT_WL_HTTPS (4)
568 struct wl_entry {
569 regex_t *re;
570 char *pat;
571 int handy; /* app use */
572 TAILQ_ENTRY(wl_entry) entry;
574 TAILQ_HEAD(wl_list, wl_entry);
576 int wl_show(struct tab *, struct karg *, char *,
577 struct wl_list *);
579 /* uri aliases */
580 struct alias {
581 char *a_name;
582 char *a_uri;
583 TAILQ_ENTRY(alias) entry;
585 TAILQ_HEAD(alias_list, alias);
587 /* mime types */
588 struct mime_type {
589 char *mt_type;
590 char *mt_action;
591 int mt_default;
592 int mt_download;
593 TAILQ_ENTRY(mime_type) entry;
595 TAILQ_HEAD(mime_type_list, mime_type);
597 struct wl_entry * wl_find(const gchar *, struct wl_list *);
598 int wl_save(struct tab *, struct karg *, int);
599 int toggle_cwl(struct tab *, struct karg *);
600 int toggle_js(struct tab *, struct karg *);
601 int toggle_pl(struct tab *, struct karg *);
602 int toggle_force_https(struct tab *, struct karg *);
604 /* input autofocus */
605 void input_autofocus(struct tab *);
606 void *input_check_mode(struct tab *);
607 int command_mode(struct tab *, struct karg *);
609 /* settings */
610 #define XT_BM_NORMAL (0)
611 #define XT_BM_WHITELIST (1)
612 #define XT_BM_KIOSK (2)
614 #define XT_GM_CLASSIC (0)
615 #define XT_GM_MINIMAL (1)
617 #define XT_TABS_NORMAL (0)
618 #define XT_TABS_COMPACT (1)
620 #define XT_STATUSBAR_URL (0)
621 #define XT_STATUSBAR_TITLE (1)
623 #define XT_EM_HYBRID (0)
624 #define XT_EM_VI (1)
626 #define XT_DM_START (0)
627 #define XT_DM_ASK (1)
628 #define XT_DM_ADD (2)
630 #define XT_REFERER_ALWAYS (0)
631 #define XT_REFERER_NEVER (1)
632 #define XT_REFERER_SAME_DOMAIN (2)
633 #define XT_REFERER_CUSTOM (3)
634 #define XT_REFERER_SAME_FQDN (4)
636 #define CTRL GDK_CONTROL_MASK
637 #define MOD1 GDK_MOD1_MASK
638 #define SHFT GDK_SHIFT_MASK
640 /* runtime default settings */
641 #define XT_DS_SHOW_TABS (1)
642 #define XT_DS_TAB_STYLE XT_TABS_NORMAL
643 #define XT_DS_STATUSBAR_STYLE XT_STATUSBAR_URL
644 #define XT_DS_SHOW_URL (1)
645 #define XT_DS_SHOW_SCROLLBARS (1)
646 #define XT_DS_SHOW_STATUSBAR (0)
647 #define XT_DS_CTRL_CLICK_FOCUS (0)
648 #define XT_DS_COOKIES_ENABLED (1)
649 #define XT_DS_READ_ONLY_COOKIES (0)
650 #define XT_DS_ENABLE_SCRIPTS (1)
651 #define XT_DS_ENABLE_PLUGINS (1)
652 #define XT_DS_DEFAULT_ZOOM_LEVEL (1.0)
653 #define XT_DS_DEFAULT_SCRIPT ("")
654 #define XT_DS_REFRESH_INTERVAL (10)
655 #define XT_DS_ENABLE_PLUGIN_WHITELIST (0)
656 #define XT_DS_ENABLE_COOKIE_WHITELIST (0)
657 #define XT_DS_ENABLE_JS_WHITELIST (0)
658 #define XT_DS_ENABLE_LOCALSTORAGE (1)
659 #define XT_DS_SESSION_TIMEOUT (3600)
660 #define XT_DS_COOKIE_POLICY SOUP_COOKIE_JAR_ACCEPT_ALWAYS
661 #define XT_DS_SSL_STRICT_CERTS FALSE
662 #define XT_DS_SSL_CA_FILE ("")
663 #define XT_DS_ENABLE_STRICT_TRANSPORT TRUE
664 #define XT_DS_APPEND_NEXT (1)
665 #define XT_DS_HOME ("https://www.cyphertite.com/")
666 #define XT_DS_SEARCH_STRING ("about:search")
667 #define XT_DS_COLOR_VISITED_URIS (1)
668 #define XT_DS_SESSION_AUTOSAVE (0)
669 #define XT_DS_GUESS_SEARCH (0)
670 #define XT_DS_ENABLE_SPELL_CHECKING (0)
671 #define XT_DS_SPELL_CHECK_LANGUAGES ("en_US")
672 #define XT_DS_URL_REGEX ("^[[:blank:]]*[^[:blank:]]*([[:alnum:]-]+\\.)+[[:alnum:]-][^[:blank:]]*[[:blank:]]*$")
673 #define XT_DS_ENCODING ("UTF-8")
674 #define XT_DS_AUTOFOCUS_ONLOAD (0)
675 #define XT_DS_ENABLE_JS_AUTORUN (1)
676 #define XT_DS_USERSTYLE_GLOBAL (0)
677 #define XT_DS_AUTO_LOAD_IMAGES (1)
678 #define XT_DS_ENABLE_AUTOSCROLL (0)
679 #define XT_DS_ENABLE_FAVICON_ENTRY (1)
680 #define XT_DS_ENABLE_FAVICON_TABS (0)
681 #define XT_DS_EXTERNAL_EDITOR (NULL)
682 #define XT_DS_REFERER_MODE XT_REFERER_ALWAYS
683 #define XT_DS_REFERER_CUSTOM ("always")
684 #define XT_DS_DOWNLOAD_NOTIFICATIONS (0)
685 #define XT_DS_CMD_FONT_NAME ("monospace normal 9")
686 #define XT_DS_OOPS_FONT_NAME ("monospace normal 9")
687 #define XT_DS_STATUSBAR_FONT_NAME ("monospace normal 9")
688 #define XT_DS_TABBAR_FONT_NAME ("monospace normal 9")
689 #define XT_DS_ALLOW_INSECURE_CONTENT (TRUE)
690 #define XT_DS_ALLOW_INSECURE_SCRIPTS (TRUE)
691 #define XT_DS_WARN_CERT_CHANGES (0)
692 #define XT_DS_RESOURCE_DIR ("/usr/local/share/xombrero")
693 #define XT_DS_DO_NOT_TRACK (0)
694 #define XT_DS_PRELOAD_STRICT_TRANSPORT (1)
695 #define XT_DS_GNUTLS_PRIORITY_STRING (NULL)
696 #define XT_DS_JS_AUTO_OPEN_WINDOWS (1)
698 /* actions */
699 #define XT_STYLE_CURRENT_TAB (0)
700 #define XT_STYLE_GLOBAL (1)
702 #define XT_TAB_LAST (-4)
703 #define XT_TAB_FIRST (-3)
704 #define XT_TAB_PREV (-2)
705 #define XT_TAB_NEXT (-1)
706 #define XT_TAB_INVALID (0)
707 #define XT_TAB_NEW (1)
708 #define XT_TAB_DELETE (2)
709 #define XT_TAB_DELQUIT (3)
710 #define XT_TAB_OPEN (4)
711 #define XT_TAB_UNDO_CLOSE (5)
712 #define XT_TAB_SHOW (6)
713 #define XT_TAB_HIDE (7)
714 #define XT_TAB_NEXTSTYLE (8)
715 #define XT_TAB_LOAD_IMAGES (9)
716 #define XT_TAB_ONLY (10)
718 #define XT_URL_SHOW (1)
719 #define XT_URL_HIDE (2)
721 /* XTP classes (xxxt://<class>) */
722 #define XT_XTP_INVALID (0) /* invalid */
723 #define XT_XTP_DL (1) /* downloads */
724 #define XT_XTP_HL (2) /* history */
725 #define XT_XTP_CL (3) /* cookies */
726 #define XT_XTP_FL (4) /* favorites */
727 #define XT_XTP_SL (5) /* search */
728 #define XT_XTP_AB (6) /* about */
729 #define XT_XTP_SV (7) /* security violation */
730 #define XT_XTP_RT (8) /* set */
732 /* XTP download actions */
733 #define XT_XTP_DL_LIST (1)
734 #define XT_XTP_DL_CANCEL (2)
735 #define XT_XTP_DL_REMOVE (3)
736 #define XT_XTP_DL_UNLINK (4)
737 #define XT_XTP_DL_START (5)
739 /* XTP history actions */
740 #define XT_XTP_HL_LIST (1)
741 #define XT_XTP_HL_REMOVE (2)
742 #define XT_XTP_HL_REMOVE_ALL (3)
744 /* XTP cookie actions */
745 #define XT_XTP_CL_LIST (1)
746 #define XT_XTP_CL_REMOVE (2)
747 #define XT_XTP_CL_REMOVE_DOMAIN (3)
748 #define XT_XTP_CL_REMOVE_ALL (4)
750 /* XTP cookie actions */
751 #define XT_XTP_FL_LIST (1)
752 #define XT_XTP_FL_REMOVE (2)
754 /* XPT search actions */
755 #define XT_XTP_SL_SET (1)
757 /* XPT about actions */
758 #define XT_XTP_AB_EDIT_CONF (1)
760 /* XTP security violation actions */
761 #define XT_XTP_SV_SHOW_NEW_CERT (1)
762 #define XT_XTP_SV_ALLOW_SESSION (2)
763 #define XT_XTP_SV_CACHE (3)
764 #define XT_XTP_SV_SHOW_CACHED_CERT (4)
766 /* XTP set actions */
767 #define XT_XTP_RT_SAVE (1)
769 /* needed for xtp_page_rt in settings.c */
770 void generate_xtp_session_key(char **);
772 struct key_binding {
773 char *cmd;
774 guint mask;
775 guint use_in_entry;
776 guint key;
777 TAILQ_ENTRY(key_binding) entry; /* in bss so no need to init */
779 TAILQ_HEAD(keybinding_list, key_binding);
781 struct custom_uri {
782 char *uri;
783 char cmd[PATH_MAX];
784 TAILQ_ENTRY(custom_uri) entry;
786 TAILQ_HEAD(custom_uri_list, custom_uri);
788 struct cmd_alias {
789 char *alias;
790 char *cmd;
791 TAILQ_ENTRY(cmd_alias) entry;
793 TAILQ_HEAD(cmd_alias_list, cmd_alias);
795 struct set_reject {
796 char *name;
797 char *value;
798 TAILQ_ENTRY(set_reject) entry;
800 TAILQ_HEAD(set_reject_list, set_reject);
802 struct settings {
803 char *name;
804 int type;
805 #define XT_S_INVALID (0)
806 #define XT_S_INT (1)
807 #define XT_S_STR (2)
808 #define XT_S_FLOAT (3)
809 #define XT_S_BOOL (4)
810 uint32_t flags;
811 #define XT_SF_RESTART (1<<0)
812 #define XT_SF_RUNTIME (1<<1)
813 #define XT_SF_INVISIBLE (1<<2)
814 int *ival;
815 char **sval;
816 struct special *s;
817 double *fval;
818 int (*activate)(char *);
819 int (*ismodified)(char **);
820 char *tt;
823 struct special {
824 int (*set)(struct settings *, char *);
825 char *(*get)(struct settings *);
826 void (*walk)(struct settings *,
827 void (*cb)(struct settings *, char *, void *),
828 void *);
829 char *valid_options[];
832 int set(struct tab *, struct karg *);
833 int xtp_page_rt(struct tab *, struct karg *);
834 size_t get_settings_size(void);
835 int settings_add(char *, char *);
836 int setup_proxy(const char *);
837 int proxy_cmd(struct tab *, struct karg *);
838 int set_browser_mode(struct settings *, char *);
839 int set_encoding(struct tab *, struct karg *);
840 int set_gui_mode(struct settings *, char *);
841 int set_cookie_policy(struct settings *, char *);
842 int set_search_string(char *);
843 int set_ssl_ca_file(struct settings *, char *);
844 char *get_browser_mode(struct settings *);
845 char *get_gui_mode(struct settings *);
846 char *get_cookie_policy(struct settings *);
847 void init_keybindings(void);
848 void config_parse(char *, int);
849 char *get_setting_name(int);
850 void statusbar_set_visibility(void);
851 int tabaction(struct tab *, struct karg *);
852 int urlaction(struct tab *, struct karg *);
853 int userstyle_cmd(struct tab *, struct karg *);
854 struct tab *get_current_tab(void);
855 int resizetab(struct tab *, struct karg *);
856 int cert_cmd(struct tab *, struct karg *);
857 void focus_webview(struct tab *);
858 int is_g_object_setting(GObject *, char *);
859 int set_scrollbar_visibility(struct tab *, int);
860 int save_runtime_setting(const char *, const char *);
861 void wl_add(const char *, struct wl_list *, int);
863 #ifndef SOUP_CHECK_VERSION
864 #define SOUP_CHECK_VERSION(major, minor, micro) (0)
865 #endif
867 #if GTK_CHECK_VERSION(3,0,0)
868 #define modify_font gtk_widget_override_font
869 #else
870 #define modify_font gtk_widget_modify_font
871 #endif
873 #define XT_DL_START (0)
874 #define XT_DL_RESTART (1)
875 int download_start(struct tab *, struct download *, int flag);
877 extern int tabless;
878 extern int enable_socket;
879 extern int single_instance;
880 extern int fancy_bar;
881 extern int browser_mode;
882 extern int enable_localstorage;
883 extern char *statusbar_elems;
885 #if SOUP_CHECK_VERSION(2, 42, 2)
886 extern GProxyResolver *proxy_uri;
887 extern gchar *proxy_exclude[];
888 #else
889 extern SoupURI *proxy_uri;
890 #endif
892 extern int show_tabs;
893 extern int tab_style;
894 extern int statusbar_style;
895 extern int show_url;
896 extern int show_scrollbars;
897 extern int show_statusbar;
898 extern int ctrl_click_focus;
899 extern int cookies_enabled;
900 extern int read_only_cookies;
901 extern int enable_cache;
902 extern int enable_scripts;
903 extern int enable_plugins;
904 extern double default_zoom_level;
905 extern char default_script[PATH_MAX];
906 extern int window_height;
907 extern int window_width;
908 extern int window_maximize;
909 extern int icon_size;
910 extern int refresh_interval;
911 extern int enable_plugin_whitelist;
912 extern int enable_cookie_whitelist;
913 extern int enable_js_whitelist;
914 extern int session_timeout;
915 extern int cookie_policy;
916 extern char ssl_ca_file[PATH_MAX];
917 extern char *resource_dir;
918 extern gboolean ssl_strict_certs;
919 extern gboolean enable_strict_transport;
920 extern int append_next;
921 extern char *home;
922 extern char *search_string;
923 extern char *http_proxy;
924 extern int http_proxy_starts_enabled;
925 extern char *external_editor;
926 extern char download_dir[PATH_MAX];
927 extern int download_mode;
928 extern char runtime_settings[PATH_MAX];
929 extern int allow_volatile_cookies;
930 extern int color_visited_uris;
931 extern int save_global_history;
932 extern int save_rejected_cookies;
933 extern int session_autosave;
934 extern int guess_search;
935 extern gint max_connections;
936 extern gint max_host_connections;
937 extern gint enable_spell_checking;
938 extern char *spell_check_languages;
939 extern char *url_regex;
940 extern int history_autosave;
941 extern char search_file[PATH_MAX];
942 extern char command_file[PATH_MAX];
943 extern char *encoding;
944 extern int autofocus_onload;
945 extern int enable_js_autorun;
946 extern char *cmd_font_name;
947 extern char *oops_font_name;
948 extern char *statusbar_font_name;
949 extern char *tabbar_font_name;
950 extern int edit_mode;
951 extern char *userstyle;
952 extern char *stylesheet;
953 extern int userstyle_global;
954 extern int auto_load_images;
955 extern int enable_autoscroll;
956 extern int enable_favicon_entry;
957 extern int enable_favicon_tabs;
958 extern int referer_mode;
959 extern char *referer_custom;
960 extern int download_notifications;
961 extern int warn_cert_changes;
962 extern regex_t url_re;
963 extern int allow_insecure_content;
964 extern int allow_insecure_scripts;
965 extern int do_not_track;
966 extern int preload_strict_transport;
967 extern char *gnutls_priority_string;
968 extern int anonymize_headers;
969 extern int js_auto_open_windows;
971 /* globals */
972 extern void (*os_init)(void);
973 extern char *version;
974 extern char *icons[];
975 extern char rc_fname[PATH_MAX];
976 extern char work_dir[PATH_MAX];
977 extern char temp_dir[PATH_MAX];
978 extern struct passwd *pwd;
979 extern SoupCookieJar *s_cookiejar;
980 extern SoupCookieJar *p_cookiejar;
981 extern SoupSession *session;
982 extern GtkNotebook *notebook;
983 extern GtkListStore *completion_model;
984 extern uint64_t blocked_cookies;
985 extern SoupSession *session;
987 extern void (*_soup_cookie_jar_add_cookie)(SoupCookieJar *, SoupCookie *);
988 extern void (*_soup_cookie_jar_delete_cookie)(SoupCookieJar *,
989 SoupCookie *);
991 extern struct history_list hl;
992 extern int hl_purge_count;
993 extern struct download_list downloads;
994 extern struct tab_list tabs;
995 extern struct about_type about_list[];
996 extern struct wl_list c_wl;
997 extern struct wl_list js_wl;
998 extern struct wl_list pl_wl;
999 extern struct wl_list force_https;
1000 extern struct wl_list svil;
1001 extern struct strict_transport_tree st_tree;
1002 extern struct alias_list aliases;
1003 extern struct mime_type_list mtl;
1004 extern struct keybinding_list kbl;
1005 extern struct sp_list spl;
1006 extern struct user_agent_list ua_list;
1007 extern struct http_accept_list ha_list;
1008 extern struct cmd_alias_list cal;
1009 extern struct custom_uri_list cul;
1010 extern struct secviolation_list svl;
1011 extern struct set_reject_list srl;
1012 extern struct settings rs[];
1014 extern PangoFontDescription *cmd_font;
1015 extern PangoFontDescription *oops_font;
1016 extern PangoFontDescription *statusbar_font;
1017 extern PangoFontDescription *tabbar_font;