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