2 * Copyright (c) 2010, 2011 Marco Peereboom <marco@peereboom.us>
3 * Copyright (c) 2011 Stevan Andjelkovic <stevan@student.chalmers.se>
4 * Copyright (c) 2010, 2011 Edd Barrett <vext01@gmail.com>
5 * Copyright (c) 2011 Todd T. Fries <todd@fries.net>
6 * Copyright (c) 2011 Raphael Graf <r@undefined.ch>
7 * Copyright (c) 2011 Michal Mazurek <akfaew@jasminek.net>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 SoupURI
*proxy_uri
= NULL
;
26 PangoFontDescription
*cmd_font
;
27 PangoFontDescription
*oops_font
;
28 PangoFontDescription
*statusbar_font
;
29 PangoFontDescription
*tabbar_font
;
31 /* settings that require restart */
32 int tabless
= 0; /* allow only 1 tab */
33 int enable_socket
= 0;
34 int single_instance
= 0; /* only allow one xxxterm to run */
35 int fancy_bar
= 1; /* fancy toolbar */
36 int browser_mode
= XT_BM_NORMAL
;
37 int gui_mode
= XT_GM_CLASSIC
;
38 int enable_localstorage
= 1;
39 char *statusbar_elems
= NULL
;
41 /* runtime settings */
42 int show_tabs
= 1; /* show tabs on notebook */
43 int tab_style
= XT_TABS_NORMAL
; /* tab bar style */
44 int show_url
= 1; /* show url toolbar on notebook */
45 int show_statusbar
= 0; /* vimperator style status bar */
46 int ctrl_click_focus
= 0; /* ctrl click gets focus */
47 int cookies_enabled
= 1; /* enable cookies */
48 int read_only_cookies
= 0; /* enable to not write cookies */
49 int enable_scripts
= 1;
50 int enable_plugins
= 1;
51 gfloat default_zoom_level
= 1.0;
52 char default_script
[PATH_MAX
];
53 int window_height
= 768;
54 int window_width
= 1024;
55 int window_maximize
= 0;
56 int icon_size
= 2; /* 1 = smallest, 2+ = bigger */
57 int refresh_interval
= 10; /* download refresh interval */
58 int enable_plugin_whitelist
= 0;
59 int enable_cookie_whitelist
= 0;
60 int enable_js_whitelist
= 0;
61 int session_timeout
= 3600; /* cookie session timeout */
62 int cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
63 char *ssl_ca_file
= NULL
;
64 char *resource_dir
= NULL
;
65 gboolean ssl_strict_certs
= FALSE
;
66 int append_next
= 1; /* append tab after current tab */
68 char *search_string
= NULL
;
69 char *http_proxy
= NULL
;
70 char download_dir
[PATH_MAX
];
71 int download_mode
= XT_DM_START
;
72 char runtime_settings
[PATH_MAX
]; /* override of settings */
73 int allow_volatile_cookies
= 0;
74 int color_visited_uris
= 1;
75 int save_global_history
= 0; /* save global history to disk */
76 struct user_agent
*user_agent
= NULL
;
77 int save_rejected_cookies
= 0;
78 int session_autosave
= 0;
80 int dns_prefetch
= FALSE
;
81 gint max_connections
= 25;
82 gint max_host_connections
= 5;
83 gint enable_spell_checking
= 0;
84 char *spell_check_languages
= NULL
;
85 int xterm_workaround
= 0;
86 char *url_regex
= NULL
;
87 int history_autosave
= 0;
88 char search_file
[PATH_MAX
];
89 char command_file
[PATH_MAX
];
90 char *encoding
= NULL
;
91 int autofocus_onload
= 0;
92 int js_autorun_enabled
= 1;
93 int edit_mode
= XT_EM_HYBRID
;
94 int userstyle_global
= 0;
95 int auto_load_images
= 1;
96 int enable_autoscroll
= 0;
97 int enable_favicon_entry
= 1;
98 int enable_favicon_tabs
= 0;
99 char *external_editor
= NULL
;
100 int referer_mode
= XT_REFERER_ALWAYS
;
101 char *referer_custom
= NULL
;
103 char *cmd_font_name
= NULL
;
104 char *oops_font_name
= NULL
;
105 char *statusbar_font_name
= NULL
;
106 char *tabbar_font_name
= NULL
;
108 char *get_download_dir(struct settings
*);
109 char *get_default_script(struct settings
*);
110 char *get_runtime_dir(struct settings
*);
111 char *get_tab_style(struct settings
*);
112 char *get_edit_mode(struct settings
*);
113 char *get_download_mode(struct settings
*);
114 char *get_work_dir(struct settings
*);
115 char *get_referer(struct settings
*);
117 int add_cookie_wl(struct settings
*, char *);
118 int add_js_wl(struct settings
*, char *);
119 int add_pl_wl(struct settings
*, char *);
120 int add_mime_type(struct settings
*, char *);
121 int add_alias(struct settings
*, char *);
122 int add_kb(struct settings
*, char *);
123 int add_ua(struct settings
*, char *);
125 int set_download_dir(struct settings
*, char *);
126 int set_default_script(struct settings
*, char *);
127 int set_runtime_dir(struct settings
*, char *);
128 int set_tab_style(struct settings
*, char *);
129 int set_edit_mode(struct settings
*, char *);
130 int set_work_dir(struct settings
*, char *);
131 int set_auto_load_images(char *value
);
132 int set_enable_autoscroll(char *value
);
133 int set_enable_favicon_entry(char *value
);
134 int set_enable_favicon_tabs(char *value
);
135 int set_download_mode(struct settings
*, char *);
136 int set_download_mode_rt(char *);
137 int set_referer(struct settings
*, char *);
138 int set_referer_rt(char *);
139 int set_external_editor(char *);
141 void walk_mime_type(struct settings
*, void (*)(struct settings
*,
142 char *, void *), void *);
143 void walk_alias(struct settings
*, void (*)(struct settings
*,
144 char *, void *), void *);
145 void walk_cookie_wl(struct settings
*, void (*)(struct settings
*,
146 char *, void *), void *);
147 void walk_js_wl(struct settings
*, void (*)(struct settings
*,
148 char *, void *), void *);
149 void walk_pl_wl(struct settings
*, void (*)(struct settings
*,
150 char *, void *), void *);
151 void walk_kb(struct settings
*, void (*)(struct settings
*, char *,
153 void walk_ua(struct settings
*, void (*)(struct settings
*, char *,
157 set_http_proxy(char *proxy
)
164 /* see if we need to clear it instead */
165 if (strlen(proxy
) == 0) {
170 uri
= soup_uri_new(proxy
);
171 if (uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(uri
))
182 int (*set
)(struct settings
*, char *);
183 char *(*get
)(struct settings
*);
184 void (*walk
)(struct settings
*,
185 void (*cb
)(struct settings
*, char *, void *),
189 struct special s_browser_mode
= {
195 struct special s_gui_mode
= {
201 struct special s_cookie
= {
207 struct special s_alias
= {
213 struct special s_mime
= {
219 struct special s_js
= {
225 struct special s_pl
= {
231 struct special s_kb
= {
237 struct special s_cookie_wl
= {
243 struct special s_default_script
= {
249 struct special s_download_dir
= {
255 struct special s_work_dir
= {
261 struct special s_tab_style
= {
267 struct special s_edit_mode
= {
273 struct special s_download_mode
= {
279 struct special s_ua
= {
285 struct special s_referer
= {
291 struct settings rs
[] = {
292 { "allow_volatile_cookies", XT_S_INT
, 0, &allow_volatile_cookies
, NULL
, NULL
},
293 { "append_next", XT_S_INT
, 0, &append_next
, NULL
, NULL
},
294 { "autofocus_onload", XT_S_INT
, 0, &autofocus_onload
, NULL
, NULL
},
295 { "browser_mode", XT_S_INT
, 0, NULL
, NULL
,&s_browser_mode
},
296 { "gui_mode", XT_S_INT
, 0, NULL
, NULL
,&s_gui_mode
},
297 { "color_visited_uris", XT_S_INT
, 0, &color_visited_uris
, NULL
, NULL
},
298 { "cookie_policy", XT_S_INT
, 0, NULL
, NULL
,&s_cookie
},
299 { "cookies_enabled", XT_S_INT
, 0, &cookies_enabled
, NULL
, NULL
},
300 { "ctrl_click_focus", XT_S_INT
, 0, &ctrl_click_focus
, NULL
, NULL
},
301 { "default_zoom_level", XT_S_FLOAT
, 0, NULL
, NULL
, NULL
, &default_zoom_level
},
302 { "default_script", XT_S_STR
, 0, NULL
, NULL
,&s_default_script
},
303 { "download_dir", XT_S_STR
, 0, NULL
, NULL
,&s_download_dir
},
304 { "download_mode", XT_S_STR
, 0, NULL
, NULL
,&s_download_mode
, NULL
, set_download_mode_rt
},
305 { "edit_mode", XT_S_STR
, 0, NULL
, NULL
,&s_edit_mode
},
306 { "enable_cookie_whitelist", XT_S_INT
, 0, &enable_cookie_whitelist
, NULL
, NULL
},
307 { "enable_js_whitelist", XT_S_INT
, 0, &enable_js_whitelist
, NULL
, NULL
},
308 { "enable_plugin_whitelist", XT_S_INT
, 0, &enable_plugin_whitelist
, NULL
, NULL
},
309 { "enable_localstorage", XT_S_INT
, 0, &enable_localstorage
, NULL
, NULL
},
310 { "enable_plugins", XT_S_INT
, 0, &enable_plugins
, NULL
, NULL
},
311 { "enable_scripts", XT_S_INT
, 0, &enable_scripts
, NULL
, NULL
},
312 { "enable_socket", XT_S_INT
, XT_SF_RESTART
,&enable_socket
, NULL
, NULL
},
313 { "enable_spell_checking", XT_S_INT
, 0, &enable_spell_checking
, NULL
, NULL
},
314 { "encoding", XT_S_STR
, 0, NULL
, &encoding
, NULL
},
315 { "external_editor", XT_S_STR
,0, NULL
, &external_editor
, NULL
, NULL
, set_external_editor
},
316 { "fancy_bar", XT_S_INT
, XT_SF_RESTART
,&fancy_bar
, NULL
, NULL
},
317 { "guess_search", XT_S_INT
, 0, &guess_search
, NULL
, NULL
},
318 { "history_autosave", XT_S_INT
, 0, &history_autosave
, NULL
, NULL
},
319 { "home", XT_S_STR
, 0, NULL
, &home
, NULL
},
320 { "http_proxy", XT_S_STR
, 0, NULL
, &http_proxy
, NULL
, NULL
, set_http_proxy
},
321 { "icon_size", XT_S_INT
, 0, &icon_size
, NULL
, NULL
},
322 { "js_autorun_enabled", XT_S_INT
, 0, &js_autorun_enabled
, NULL
, NULL
},
323 { "max_connections", XT_S_INT
, XT_SF_RESTART
,&max_connections
, NULL
, NULL
},
324 { "max_host_connections", XT_S_INT
, XT_SF_RESTART
,&max_host_connections
, NULL
, NULL
},
325 { "read_only_cookies", XT_S_INT
, 0, &read_only_cookies
, NULL
, NULL
},
326 { "refresh_interval", XT_S_INT
, 0, &refresh_interval
, NULL
, NULL
},
327 { "resource_dir", XT_S_STR
, 0, NULL
, &resource_dir
, NULL
},
328 { "search_string", XT_S_STR
, 0, NULL
, &search_string
, NULL
},
329 { "save_global_history", XT_S_INT
, XT_SF_RESTART
,&save_global_history
, NULL
, NULL
},
330 { "save_rejected_cookies", XT_S_INT
, XT_SF_RESTART
,&save_rejected_cookies
, NULL
, NULL
},
331 { "session_timeout", XT_S_INT
, 0, &session_timeout
, NULL
, NULL
},
332 { "session_autosave", XT_S_INT
, 0, &session_autosave
, NULL
, NULL
},
333 { "single_instance", XT_S_INT
, XT_SF_RESTART
,&single_instance
, NULL
, NULL
},
334 { "show_tabs", XT_S_INT
, 0, &show_tabs
, NULL
, NULL
},
335 { "show_url", XT_S_INT
, 0, &show_url
, NULL
, NULL
},
336 { "show_statusbar", XT_S_INT
, 0, &show_statusbar
, NULL
, NULL
},
337 { "spell_check_languages", XT_S_STR
, 0, NULL
, &spell_check_languages
, NULL
},
338 { "ssl_ca_file", XT_S_STR
, 0, NULL
, &ssl_ca_file
, NULL
},
339 { "ssl_strict_certs", XT_S_INT
, 0, &ssl_strict_certs
, NULL
, NULL
},
340 { "statusbar_elems", XT_S_STR
, 0, NULL
, &statusbar_elems
, NULL
},
341 { "tab_style", XT_S_STR
, 0, NULL
, NULL
,&s_tab_style
},
342 { "url_regex", XT_S_STR
, 0, NULL
, &url_regex
, NULL
},
343 { "window_height", XT_S_INT
, 0, &window_height
, NULL
, NULL
},
344 { "window_width", XT_S_INT
, 0, &window_width
, NULL
, NULL
},
345 { "window_maximize", XT_S_INT
, 0, &window_maximize
, NULL
, NULL
},
346 { "work_dir", XT_S_STR
, 0, NULL
, NULL
,&s_work_dir
},
347 { "xterm_workaround", XT_S_INT
, 0, &xterm_workaround
, NULL
, NULL
},
348 { "auto_load_images", XT_S_INT
, 0, &auto_load_images
, NULL
, NULL
, NULL
, set_auto_load_images
},
349 { "enable_autoscroll", XT_S_INT
, 0, &enable_autoscroll
, NULL
, NULL
, NULL
, set_enable_autoscroll
},
350 { "enable_favicon_entry", XT_S_INT
, 0, &enable_favicon_entry
, NULL
, NULL
, NULL
, set_enable_favicon_entry
},
351 { "enable_favicon_tabs", XT_S_INT
, 0, &enable_favicon_tabs
, NULL
, NULL
, NULL
, set_enable_favicon_tabs
},
352 { "referer", XT_S_STR
, 0, NULL
, NULL
,&s_referer
, NULL
, set_referer_rt
},
355 { "cmd_font", XT_S_STR
, 0, NULL
, &cmd_font_name
, NULL
},
356 { "oops_font", XT_S_STR
, 0, NULL
, &oops_font_name
, NULL
},
357 { "statusbar_font", XT_S_STR
, 0, NULL
, &statusbar_font_name
, NULL
},
358 { "tabbar_font", XT_S_STR
, 0, NULL
, &tabbar_font_name
, NULL
},
360 /* runtime settings */
361 { "alias", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_alias
},
362 { "cookie_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_cookie_wl
},
363 { "js_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_js
},
364 { "keybinding", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_kb
},
365 { "mime_type", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_mime
},
366 { "pl_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_pl
},
367 { "user_agent", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_ua
},
371 get_settings_size(void)
377 get_setting_name(int i
)
385 get_as_string(struct settings
*s
)
396 warnx("get_as_string skip %s\n", s
->name
);
397 } else if (s
->type
== XT_S_INT
)
398 r
= g_strdup_printf("%d", *s
->ival
);
399 else if (s
->type
== XT_S_STR
)
400 r
= g_strdup(*s
->sval
);
401 else if (s
->type
== XT_S_FLOAT
)
402 r
= g_strdup_printf("%f", *s
->fval
);
404 r
= g_strdup_printf("INVALID TYPE");
410 settings_walk(void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
415 for (i
= 0; i
< LENGTH(rs
); i
++) {
416 if (rs
[i
].s
&& rs
[i
].s
->walk
)
417 rs
[i
].s
->walk(&rs
[i
], cb
, cb_args
);
419 s
= get_as_string(&rs
[i
]);
420 cb(&rs
[i
], s
, cb_args
);
427 set_browser_mode(struct settings
*s
, char *val
)
429 if (!strcmp(val
, "whitelist")) {
430 browser_mode
= XT_BM_WHITELIST
;
431 allow_volatile_cookies
= 0;
432 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
;
434 enable_cookie_whitelist
= 1;
435 enable_plugin_whitelist
= 1;
437 read_only_cookies
= 0;
438 save_rejected_cookies
= 0;
439 session_timeout
= 3600;
441 enable_js_whitelist
= 1;
442 enable_localstorage
= 0;
443 referer_mode
= XT_REFERER_SAME_DOMAIN
;
444 } else if (!strcmp(val
, "normal")) {
445 browser_mode
= XT_BM_NORMAL
;
446 allow_volatile_cookies
= 0;
447 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
449 enable_cookie_whitelist
= 0;
450 enable_plugin_whitelist
= 0;
452 read_only_cookies
= 0;
453 save_rejected_cookies
= 0;
454 session_timeout
= 3600;
456 enable_js_whitelist
= 0;
457 enable_localstorage
= 1;
458 referer_mode
= XT_REFERER_ALWAYS
;
459 } else if (!strcmp(val
, "kiosk")) {
460 browser_mode
= XT_BM_KIOSK
;
461 allow_volatile_cookies
= 0;
462 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
464 enable_cookie_whitelist
= 0;
465 enable_plugin_whitelist
= 0;
467 read_only_cookies
= 0;
468 save_rejected_cookies
= 0;
469 session_timeout
= 3600;
471 enable_js_whitelist
= 0;
472 enable_localstorage
= 1;
473 referer_mode
= XT_REFERER_ALWAYS
;
483 get_browser_mode(struct settings
*s
)
487 if (browser_mode
== XT_BM_WHITELIST
)
488 r
= g_strdup("whitelist");
489 else if (browser_mode
== XT_BM_NORMAL
)
490 r
= g_strdup("normal");
491 else if (browser_mode
== XT_BM_KIOSK
)
492 r
= g_strdup("kiosk");
500 set_gui_mode(struct settings
*s
, char *val
)
502 if (!strcmp(val
, "classic")) {
505 tab_style
= XT_TABS_NORMAL
;
508 } else if (!strcmp(val
, "minimal")) {
511 tab_style
= XT_TABS_COMPACT
;
521 get_gui_mode(struct settings
*s
)
525 if (gui_mode
== XT_GM_CLASSIC
)
526 r
= g_strdup("classic");
527 else if (browser_mode
== XT_GM_MINIMAL
)
528 r
= g_strdup("minimal");
536 set_cookie_policy(struct settings
*s
, char *val
)
538 if (!strcmp(val
, "no3rdparty"))
539 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
;
540 else if (!strcmp(val
, "accept"))
541 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
542 else if (!strcmp(val
, "reject"))
543 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NEVER
;
551 get_cookie_policy(struct settings
*s
)
555 if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
)
556 r
= g_strdup("no3rdparty");
557 else if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_ALWAYS
)
558 r
= g_strdup("accept");
559 else if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_NEVER
)
560 r
= g_strdup("reject");
568 get_default_script(struct settings
*s
)
570 if (default_script
[0] == '\0')
572 return (g_strdup(default_script
));
576 set_default_script(struct settings
*s
, char *val
)
579 snprintf(default_script
, sizeof default_script
, "%s/%s",
580 pwd
->pw_dir
, &val
[1]);
582 strlcpy(default_script
, val
, sizeof default_script
);
588 get_download_dir(struct settings
*s
)
590 if (download_dir
[0] == '\0')
592 return (g_strdup(download_dir
));
596 set_download_dir(struct settings
*s
, char *val
)
599 snprintf(download_dir
, sizeof download_dir
, "%s/%s",
600 pwd
->pw_dir
, &val
[1]);
602 strlcpy(download_dir
, val
, sizeof download_dir
);
608 add_alias(struct settings
*s
, char *line
)
611 struct alias
*a
= NULL
;
613 if (s
== NULL
|| line
== NULL
) {
614 show_oops(NULL
, "add_alias invalid parameters");
619 a
= g_malloc(sizeof(*a
));
621 if ((alias
= strsep(&l
, " \t,")) == NULL
|| l
== NULL
) {
622 show_oops(NULL
, "add_alias: incomplete alias definition");
625 if (strlen(alias
) == 0 || strlen(l
) == 0) {
626 show_oops(NULL
, "add_alias: invalid alias definition");
630 a
->a_name
= g_strdup(alias
);
631 a
->a_uri
= g_strdup(l
);
633 DNPRINTF(XT_D_CONFIG
, "add_alias: %s for %s\n", a
->a_name
, a
->a_uri
);
635 TAILQ_INSERT_TAIL(&aliases
, a
, entry
);
645 walk_alias(struct settings
*s
,
646 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
651 if (s
== NULL
|| cb
== NULL
) {
652 show_oops(NULL
, "walk_alias invalid parameters");
656 TAILQ_FOREACH(a
, &aliases
, entry
) {
657 str
= g_strdup_printf("%s --> %s", a
->a_name
, a
->a_uri
);
664 add_mime_type(struct settings
*s
, char *line
)
668 struct mime_type
*m
= NULL
;
669 int downloadfirst
= 0;
671 /* XXX this could be smarter */
673 if (line
== NULL
|| strlen(line
) == 0) {
674 show_oops(NULL
, "add_mime_type invalid parameters");
683 m
= g_malloc(sizeof(*m
));
685 if ((mime_type
= strsep(&l
, " \t,")) == NULL
|| l
== NULL
) {
686 show_oops(NULL
, "add_mime_type: invalid mime_type");
689 if (mime_type
[strlen(mime_type
) - 1] == '*') {
690 mime_type
[strlen(mime_type
) - 1] = '\0';
695 if (strlen(mime_type
) == 0 || strlen(l
) == 0) {
696 show_oops(NULL
, "add_mime_type: invalid mime_type");
700 m
->mt_type
= g_strdup(mime_type
);
701 m
->mt_action
= g_strdup(l
);
702 m
->mt_download
= downloadfirst
;
704 DNPRINTF(XT_D_CONFIG
, "add_mime_type: type %s action %s default %d\n",
705 m
->mt_type
, m
->mt_action
, m
->mt_default
);
707 TAILQ_INSERT_TAIL(&mtl
, m
, entry
);
717 walk_mime_type(struct settings
*s
,
718 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
723 if (s
== NULL
|| cb
== NULL
) {
724 show_oops(NULL
, "walk_mime_type invalid parameters");
728 TAILQ_FOREACH(m
, &mtl
, entry
) {
729 str
= g_strdup_printf("%s%s --> %s",
731 m
->mt_default
? "*" : "",
738 /* inherent to GTK not all keys will be caught at all times */
739 /* XXX sort key bindings */
740 struct key_binding keys
[] = {
741 { "command_mode", 0, 1, GDK_Escape
},
742 { "insert_mode", 0, 0, GDK_i
},
743 { "cookiejar", MOD1
, 1, GDK_j
},
744 { "downloadmgr", MOD1
, 1, GDK_d
},
745 { "history", MOD1
, 1, GDK_h
},
746 { "print", CTRL
, 1, GDK_p
},
747 { "search", 0, 0, GDK_slash
},
748 { "searchb", 0, 0, GDK_question
},
749 { "statustoggle", CTRL
, 1, GDK_n
},
750 { "command", 0, 0, GDK_colon
},
751 { "qa", CTRL
, 1, GDK_q
},
752 { "restart", MOD1
, 1, GDK_q
},
753 { "js toggle", CTRL
, 1, GDK_j
},
754 { "plugin toggle", MOD1
, 1, GDK_p
},
755 { "cookie toggle", MOD1
, 1, GDK_c
},
756 { "togglesrc", CTRL
, 1, GDK_s
},
757 { "yankuri", 0, 0, GDK_y
},
758 { "pasteuricur", 0, 0, GDK_p
},
759 { "pasteurinew", 0, 0, GDK_P
},
760 { "toplevel toggle", 0, 1, GDK_F4
},
761 { "help", 0, 1, GDK_F1
},
762 { "run_script", MOD1
, 1, GDK_r
},
763 { "proxy toggle", 0, 1, GDK_F2
},
764 { "editelement", CTRL
, 1, GDK_i
},
765 { "passthrough", CTRL
, 1, GDK_z
},
768 { "searchnext", 0, 0, GDK_n
},
769 { "searchprevious", 0, 0, GDK_N
},
772 { "focusaddress", 0, 1, GDK_F6
},
773 { "focussearch", 0, 1, GDK_F7
},
776 { "hinting", 0, 0, GDK_f
},
777 { "hinting", 0, 0, GDK_period
},
778 { "hinting_newtab", SHFT
, 0, GDK_F
},
779 { "hinting_newtab", 0, 0, GDK_comma
},
781 /* custom stylesheet */
782 { "userstyle", 0, 0, GDK_s
},
783 { "userstyle_global", SHFT
, 0, GDK_S
},
786 { "goback", 0, 0, GDK_BackSpace
},
787 { "goback", MOD1
, 1, GDK_Left
},
788 { "goforward", SHFT
, 1, GDK_BackSpace
},
789 { "goforward", MOD1
, 1, GDK_Right
},
790 { "reload", 0, 1, GDK_F5
},
791 { "reload", CTRL
, 1, GDK_r
},
792 { "reload", CTRL
, 1, GDK_l
},
793 { "favorites", MOD1
, 1, GDK_f
},
795 /* vertical movement */
796 { "scrolldown", 0, 0, GDK_j
},
797 { "scrolldown", 0, 0, GDK_Down
},
798 { "scrollup", 0, 0, GDK_Up
},
799 { "scrollup", 0, 0, GDK_k
},
800 { "scrollbottom", 0, 0, GDK_G
},
801 { "scrollbottom", 0, 0, GDK_End
},
802 { "scrolltop", 0, 0, GDK_Home
},
803 { "scrollpagedown", 0, 0, GDK_space
},
804 { "scrollpagedown", CTRL
, 1, GDK_f
},
805 { "scrollhalfdown", CTRL
, 1, GDK_d
},
806 { "scrollpagedown", 0, 0, GDK_Page_Down
},
807 { "scrollpageup", 0, 0, GDK_Page_Up
},
808 { "scrollpageup", CTRL
, 1, GDK_b
},
809 { "scrollhalfup", CTRL
, 1, GDK_u
},
810 /* horizontal movement */
811 { "scrollright", 0, 0, GDK_l
},
812 { "scrollright", 0, 0, GDK_Right
},
813 { "scrollleft", 0, 0, GDK_Left
},
814 { "scrollleft", 0, 0, GDK_h
},
815 { "scrollfarright", 0, 0, GDK_dollar
},
816 { "scrollfarleft", 0, 0, GDK_0
},
819 { "tabnew", CTRL
, 1, GDK_t
},
820 { "999tabnew", CTRL
, 1, GDK_T
},
821 { "tabclose", CTRL
, 1, GDK_w
},
822 { "tabundoclose", 0, 0, GDK_U
},
823 { "tabnext 1", CTRL
, 1, GDK_1
},
824 { "tabnext 2", CTRL
, 1, GDK_2
},
825 { "tabnext 3", CTRL
, 1, GDK_3
},
826 { "tabnext 4", CTRL
, 1, GDK_4
},
827 { "tabnext 5", CTRL
, 1, GDK_5
},
828 { "tabnext 6", CTRL
, 1, GDK_6
},
829 { "tabnext 7", CTRL
, 1, GDK_7
},
830 { "tabnext 8", CTRL
, 1, GDK_8
},
831 { "tabnext 9", CTRL
, 1, GDK_9
},
832 { "tabfirst", CTRL
, 1, GDK_less
},
833 { "tablast", CTRL
, 1, GDK_greater
},
834 { "tabprevious", CTRL
, 1, GDK_Left
},
835 { "tabnext", CTRL
, 1, GDK_Right
},
836 { "focusout", CTRL
, 1, GDK_minus
},
837 { "focusin", CTRL
, 1, GDK_plus
},
838 { "focusin", CTRL
, 1, GDK_equal
},
839 { "focusreset", CTRL
, 1, GDK_0
},
841 /* command aliases (handy when -S flag is used) */
842 { "promptopen", 0, 1, GDK_F9
},
843 { "promptopencurrent", 0, 1, GDK_F10
},
844 { "prompttabnew", 0, 1, GDK_F11
},
845 { "prompttabnewcurrent",0, 1, GDK_F12
},
849 walk_kb(struct settings
*s
,
850 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
852 struct key_binding
*k
;
855 if (s
== NULL
|| cb
== NULL
) {
856 show_oops(NULL
, "walk_kb invalid parameters");
860 TAILQ_FOREACH(k
, &kbl
, entry
) {
866 if (gdk_keyval_name(k
->key
) == NULL
)
869 strlcat(str
, k
->cmd
, sizeof str
);
870 strlcat(str
, ",", sizeof str
);
872 if (k
->mask
& GDK_SHIFT_MASK
)
873 strlcat(str
, "S-", sizeof str
);
874 if (k
->mask
& GDK_CONTROL_MASK
)
875 strlcat(str
, "C-", sizeof str
);
876 if (k
->mask
& GDK_MOD1_MASK
)
877 strlcat(str
, "M1-", sizeof str
);
878 if (k
->mask
& GDK_MOD2_MASK
)
879 strlcat(str
, "M2-", sizeof str
);
880 if (k
->mask
& GDK_MOD3_MASK
)
881 strlcat(str
, "M3-", sizeof str
);
882 if (k
->mask
& GDK_MOD4_MASK
)
883 strlcat(str
, "M4-", sizeof str
);
884 if (k
->mask
& GDK_MOD5_MASK
)
885 strlcat(str
, "M5-", sizeof str
);
887 strlcat(str
, gdk_keyval_name(k
->key
), sizeof str
);
893 init_keybindings(void)
896 struct key_binding
*k
;
898 for (i
= 0; i
< LENGTH(keys
); i
++) {
899 k
= g_malloc0(sizeof *k
);
900 k
->cmd
= keys
[i
].cmd
;
901 k
->mask
= keys
[i
].mask
;
902 k
->use_in_entry
= keys
[i
].use_in_entry
;
903 k
->key
= keys
[i
].key
;
904 TAILQ_INSERT_HEAD(&kbl
, k
, entry
);
906 DNPRINTF(XT_D_KEYBINDING
, "init_keybindings: added: %s\n",
907 k
->cmd
? k
->cmd
: "unnamed key");
912 keybinding_clearall(void)
914 struct key_binding
*k
, *next
;
916 for (k
= TAILQ_FIRST(&kbl
); k
; k
= next
) {
917 next
= TAILQ_NEXT(k
, entry
);
921 DNPRINTF(XT_D_KEYBINDING
, "keybinding_clearall: %s\n",
922 k
->cmd
? k
->cmd
: "unnamed key");
923 TAILQ_REMOVE(&kbl
, k
, entry
);
929 keybinding_add(char *cmd
, char *key
, int use_in_entry
)
931 struct key_binding
*k
;
932 guint keyval
, mask
= 0;
935 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: %s %s\n", cmd
, key
);
937 /* Keys which are to be used in entry have been prefixed with an
938 * exclamation mark. */
942 /* find modifier keys */
943 if (strstr(key
, "S-"))
944 mask
|= GDK_SHIFT_MASK
;
945 if (strstr(key
, "C-"))
946 mask
|= GDK_CONTROL_MASK
;
947 if (strstr(key
, "M1-"))
948 mask
|= GDK_MOD1_MASK
;
949 if (strstr(key
, "M2-"))
950 mask
|= GDK_MOD2_MASK
;
951 if (strstr(key
, "M3-"))
952 mask
|= GDK_MOD3_MASK
;
953 if (strstr(key
, "M4-"))
954 mask
|= GDK_MOD4_MASK
;
955 if (strstr(key
, "M5-"))
956 mask
|= GDK_MOD5_MASK
;
959 for (i
= strlen(key
) - 1; i
> 0; i
--)
963 /* validate keyname */
964 keyval
= gdk_keyval_from_name(key
);
965 if (keyval
== GDK_VoidSymbol
) {
966 warnx("invalid keybinding name %s", key
);
969 /* must run this test too, gtk+ doesn't handle 10 for example */
970 if (gdk_keyval_name(keyval
) == NULL
) {
971 warnx("invalid keybinding name %s", key
);
975 /* Remove eventual dupes. */
976 TAILQ_FOREACH(k
, &kbl
, entry
)
977 if (k
->key
== keyval
&& k
->mask
== mask
) {
978 TAILQ_REMOVE(&kbl
, k
, entry
);
984 k
= g_malloc0(sizeof *k
);
985 k
->cmd
= g_strdup(cmd
);
987 k
->use_in_entry
= use_in_entry
;
990 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: %s 0x%x %d 0x%x\n",
995 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: adding: %s %s\n",
996 k
->cmd
, gdk_keyval_name(keyval
));
998 TAILQ_INSERT_HEAD(&kbl
, k
, entry
);
1004 add_kb(struct settings
*s
, char *entry
)
1008 DNPRINTF(XT_D_KEYBINDING
, "add_kb: %s\n", entry
);
1010 /* clearall is special */
1011 if (!strcmp(entry
, "clearall")) {
1012 keybinding_clearall();
1016 kb
= strstr(entry
, ",");
1022 return (keybinding_add(entry
, key
, key
[0] == '!'));
1026 add_ua(struct settings
*s
, char *value
)
1028 struct user_agent
*ua
;
1030 ua
= g_malloc0(sizeof *ua
);
1031 ua
->value
= g_strdup(value
);
1033 TAILQ_INSERT_HEAD(&ua_list
, ua
, entry
);
1035 /* use the last added user agent */
1036 user_agent
= TAILQ_FIRST(&ua_list
);
1044 walk_ua(struct settings
*s
,
1045 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1047 struct user_agent
*ua
;
1049 if (s
== NULL
|| cb
== NULL
) {
1050 show_oops(NULL
, "walk_ua invalid parameters");
1054 TAILQ_FOREACH(ua
, &ua_list
, entry
) {
1055 cb(s
, ua
->value
, cb_args
);
1060 set_auto_load_images(char *value
)
1064 auto_load_images
= atoi(value
);
1065 TAILQ_FOREACH(t
, &tabs
, entry
) {
1066 g_object_set(G_OBJECT(t
->settings
),
1067 "auto-load-images", auto_load_images
, (char *)NULL
);
1068 webkit_web_view_set_settings(t
->wv
, t
->settings
);
1074 set_enable_autoscroll(char *value
)
1076 enable_autoscroll
= atoi(value
);
1081 set_enable_favicon_entry(char *value
)
1083 enable_favicon_entry
= atoi(value
);
1088 set_enable_favicon_tabs(char *value
)
1090 enable_favicon_tabs
= atoi(value
);
1095 get_referer(struct settings
*s
)
1097 if (referer_mode
== XT_REFERER_ALWAYS
)
1098 return (g_strdup("always"));
1099 if (referer_mode
== XT_REFERER_NEVER
)
1100 return (g_strdup("never"));
1101 if (referer_mode
== XT_REFERER_SAME_DOMAIN
)
1102 return (g_strdup("same-domain"));
1103 if (referer_mode
== XT_REFERER_CUSTOM
)
1104 return (g_strdup(referer_custom
));
1109 set_referer(struct settings
*s
, char *value
)
1112 g_free(referer_custom
);
1114 if (!strcmp(value
, "always"))
1115 referer_mode
= XT_REFERER_ALWAYS
;
1116 else if (!strcmp(value
, "never"))
1117 referer_mode
= XT_REFERER_NEVER
;
1118 else if (!strcmp(value
, "same-domain"))
1119 referer_mode
= XT_REFERER_SAME_DOMAIN
;
1120 else if (!valid_url_type(value
)) {
1121 referer_mode
= XT_REFERER_CUSTOM
;
1122 referer_custom
= g_strdup(value
);
1124 /* we've already free'd the custom referer */
1125 if (referer_mode
== XT_REFERER_CUSTOM
)
1126 referer_mode
= XT_REFERER_NEVER
;
1134 set_referer_rt(char *value
)
1136 return set_referer(NULL
, value
);
1140 set_external_editor(char *editor
)
1142 if (external_editor
)
1143 g_free(external_editor
);
1145 external_editor
= g_strdup(editor
);
1151 setup_proxy(char *uri
)
1154 g_object_set(session
, "proxy_uri", NULL
, (char *)NULL
);
1155 soup_uri_free(proxy_uri
);
1159 if (http_proxy
!= uri
) {
1166 http_proxy
= g_strdup(uri
);
1167 DNPRINTF(XT_D_CONFIG
, "setup_proxy: %s\n", uri
);
1168 proxy_uri
= soup_uri_new(http_proxy
);
1169 if (!(proxy_uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(proxy_uri
)))
1170 g_object_set(session
, "proxy-uri", proxy_uri
,
1176 get_tab_style(struct settings
*s
)
1178 if (tab_style
== XT_TABS_NORMAL
)
1179 return (g_strdup("normal"));
1181 return (g_strdup("compact"));
1185 set_tab_style(struct settings
*s
, char *val
)
1187 if (!strcmp(val
, "normal"))
1188 tab_style
= XT_TABS_NORMAL
;
1189 else if (!strcmp(val
, "compact"))
1190 tab_style
= XT_TABS_COMPACT
;
1198 get_edit_mode(struct settings
*s
)
1200 if (edit_mode
== XT_EM_HYBRID
)
1201 return (g_strdup("hybrid"));
1203 return (g_strdup("vi"));
1207 set_edit_mode(struct settings
*s
, char *val
)
1209 if (!strcmp(val
, "hybrid"))
1210 edit_mode
= XT_EM_HYBRID
;
1211 else if (!strcmp(val
, "vi"))
1212 edit_mode
= XT_EM_VI
;
1220 get_download_mode(struct settings
*s
)
1222 switch (download_mode
) {
1224 return (g_strdup("start"));
1227 return (g_strdup("ask"));
1230 return (g_strdup("add"));
1233 return (g_strdup("unknown"));
1237 set_download_mode(struct settings
*s
, char *val
)
1239 if (!strcmp(val
, "start"))
1240 download_mode
= XT_DM_START
;
1241 else if (!strcmp(val
, "ask"))
1242 download_mode
= XT_DM_ASK
;
1243 else if (!strcmp(val
, "add"))
1244 download_mode
= XT_DM_ADD
;
1252 set_download_mode_rt(char *val
)
1254 return set_download_mode(NULL
, val
);
1258 get_work_dir(struct settings
*s
)
1260 if (work_dir
[0] == '\0')
1262 return (g_strdup(work_dir
));
1266 set_work_dir(struct settings
*s
, char *val
)
1269 snprintf(work_dir
, sizeof work_dir
, "%s/%s",
1270 pwd
->pw_dir
, &val
[1]);
1272 strlcpy(work_dir
, val
, sizeof work_dir
);
1278 walk_cookie_wl(struct settings
*s
,
1279 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1283 if (s
== NULL
|| cb
== NULL
) {
1284 show_oops(NULL
, "walk_cookie_wl invalid parameters");
1288 RB_FOREACH_REVERSE(d
, domain_list
, &c_wl
)
1289 cb(s
, d
->d
, cb_args
);
1293 walk_js_wl(struct settings
*s
,
1294 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1298 if (s
== NULL
|| cb
== NULL
) {
1299 show_oops(NULL
, "walk_js_wl invalid parameters");
1303 RB_FOREACH_REVERSE(d
, domain_list
, &js_wl
)
1304 cb(s
, d
->d
, cb_args
);
1308 walk_pl_wl(struct settings
*s
,
1309 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1313 if (s
== NULL
|| cb
== NULL
) {
1314 show_oops(NULL
, "walk_pl_wl invalid parameters");
1318 RB_FOREACH_REVERSE(d
, domain_list
, &pl_wl
)
1319 cb(s
, d
->d
, cb_args
);
1323 settings_add(char *var
, char *val
)
1330 for (i
= 0, rv
= 0; i
< LENGTH(rs
); i
++) {
1331 if (strcmp(var
, rs
[i
].name
))
1335 if (rs
[i
].s
->set(&rs
[i
], val
))
1336 errx(1, "invalid value for %s: %s", var
, val
);
1340 switch (rs
[i
].type
) {
1349 errx(1, "invalid sval for %s",
1363 errx(1, "invalid type for %s", var
);
1372 config_parse(char *filename
, int runtime
)
1375 char *line
, *cp
, *var
, *val
;
1376 size_t len
, lineno
= 0;
1378 char file
[PATH_MAX
];
1381 DNPRINTF(XT_D_CONFIG
, "config_parse: filename %s\n", filename
);
1383 if (filename
== NULL
)
1386 if (runtime
&& runtime_settings
[0] != '\0') {
1387 snprintf(file
, sizeof file
, "%s/%s",
1388 work_dir
, runtime_settings
);
1389 if (stat(file
, &sb
)) {
1390 warnx("runtime file doesn't exist, creating it");
1391 if ((f
= fopen(file
, "w")) == NULL
)
1393 fprintf(f
, "# AUTO GENERATED, DO NOT EDIT\n");
1397 strlcpy(file
, filename
, sizeof file
);
1399 if ((config
= fopen(file
, "r")) == NULL
) {
1400 warn("config_parse: cannot open %s", filename
);
1405 if ((line
= fparseln(config
, &len
, &lineno
, NULL
, 0)) == NULL
)
1406 if (feof(config
) || ferror(config
))
1410 cp
+= (long)strspn(cp
, WS
);
1411 if (cp
[0] == '\0') {
1417 if ((var
= strsep(&cp
, WS
)) == NULL
|| cp
== NULL
)
1418 startpage_add("invalid configuration file entry: %s",
1421 cp
+= (long)strspn(cp
, WS
);
1423 if ((val
= strsep(&cp
, "\0")) == NULL
)
1426 DNPRINTF(XT_D_CONFIG
, "config_parse: %s=%s\n",
1428 handled
= settings_add(var
, val
);
1431 startpage_add("invalid configuration file entry"
1432 ": %s=%s", var
, val
);
1441 struct settings_args
{
1447 print_setting(struct settings
*s
, char *val
, void *cb_args
)
1450 struct settings_args
*sa
= cb_args
;
1455 if (s
->flags
& XT_SF_RUNTIME
)
1461 *sa
->body
= g_strdup_printf(
1463 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
1464 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
1476 set_show(struct tab
*t
, struct karg
*args
)
1478 char *body
, *page
, *tmp
;
1480 struct settings_args sa
;
1482 bzero(&sa
, sizeof sa
);
1486 body
= g_strdup_printf("<div align='center'><table><tr>"
1487 "<th align='left'>Setting</th>"
1488 "<th align='left'>Value</th></tr>\n");
1490 settings_walk(print_setting
, &sa
);
1493 /* small message if there are none */
1496 body
= g_strdup_printf("%s\n<tr><td style='text-align:center'"
1497 "colspan='2'>No settings</td></tr>\n", body
);
1502 body
= g_strdup_printf("%s</table></div>", body
);
1505 page
= get_html_page("Settings", body
, "", 0);
1509 load_webkit_string(t
, page
, XT_URI_ABOUT_SET
);
1513 return (XT_CB_PASSTHROUGH
);
1517 set(struct tab
*t
, struct karg
*args
)
1522 if (args
== NULL
|| args
->s
== NULL
)
1523 return (set_show(t
, args
));
1526 p
= g_strstrip(args
->s
);
1529 return (set_show(t
, args
));
1531 /* we got some sort of string */
1532 val
= g_strrstr(p
, "=");
1535 val
= g_strchomp(val
);
1538 for (i
= 0; i
< get_settings_size(); i
++) {
1539 if (strcmp(rs
[i
].name
, p
))
1542 if (rs
[i
].activate
) {
1543 if (rs
[i
].activate(val
))
1544 show_oops(t
, "%s invalid value %s",
1547 show_oops(t
, ":set %s = %s", p
, val
);
1550 show_oops(t
, "not a runtime option: %s", p
);
1554 show_oops(t
, "unknown option: %s", p
);
1558 for (i
= 0; i
< get_settings_size(); i
++) {
1559 if (strcmp(rs
[i
].name
, p
))
1562 /* XXX this could use some cleanup */
1563 switch (rs
[i
].type
) {
1566 show_oops(t
, "%s = %d",
1567 rs
[i
].name
, *rs
[i
].ival
);
1568 else if (rs
[i
].s
&& rs
[i
].s
->get
)
1569 show_oops(t
, "%s = %s",
1571 rs
[i
].s
->get(&rs
[i
]));
1572 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
1573 show_oops(t
, "%s = ...", rs
[i
].name
);
1575 show_oops(t
, "%s = ", rs
[i
].name
);
1579 show_oops(t
, "%s = %f",
1580 rs
[i
].name
, *rs
[i
].fval
);
1581 else if (rs
[i
].s
&& rs
[i
].s
->get
)
1582 show_oops(t
, "%s = %s",
1584 rs
[i
].s
->get(&rs
[i
]));
1585 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
1586 show_oops(t
, "%s = ...", rs
[i
].name
);
1588 show_oops(t
, "%s = ", rs
[i
].name
);
1591 if (rs
[i
].sval
&& *rs
[i
].sval
)
1592 show_oops(t
, "%s = %s",
1593 rs
[i
].name
, *rs
[i
].sval
);
1594 else if (rs
[i
].s
&& rs
[i
].s
->get
)
1595 show_oops(t
, "%s = %s",
1597 rs
[i
].s
->get(&rs
[i
]));
1598 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
1599 show_oops(t
, "%s = ...", rs
[i
].name
);
1601 show_oops(t
, "%s = ", rs
[i
].name
);
1604 show_oops(t
, "unknown type for %s", rs
[i
].name
);
1610 show_oops(t
, "unknown option: %s", p
);
1613 return (XT_CB_PASSTHROUGH
);