remove -lgcrypt from netbsd Makefile
[xombrero.git] / settings.c
blobf9d3e36ac0e4768676116d7cd1389f0ab1dd7719
1 /*
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>
8 * Copyright (c) 2012 Josh Rickmar <jrick@devio.us>
9 * Copyright (c) 2013 David Hill <dhill@mindcry.org>
11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies.
15 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <xombrero.h>
25 #include "tooltip.h"
27 /* globals */
28 #if SOUP_CHECK_VERSION(2, 42, 2)
29 GProxyResolver *proxy_uri = NULL;
30 gchar *proxy_exclude[] = { "fc00::/7", "::1", "127.0.0.1", NULL };
31 #else
32 SoupURI *proxy_uri = NULL;
33 #endif
35 PangoFontDescription *cmd_font;
36 PangoFontDescription *oops_font;
37 PangoFontDescription *statusbar_font;
38 PangoFontDescription *tabbar_font;
40 /* non-settings */
41 char search_file[PATH_MAX];
42 char command_file[PATH_MAX];
43 char runtime_settings[PATH_MAX]; /* override of settings */
45 /* settings that require restart */
46 int enable_socket = 0;
47 int single_instance = 0; /* only allow one xombrero to run */
48 int fancy_bar = 1; /* fancy toolbar */
49 int browser_mode = XT_BM_NORMAL;
50 int gui_mode = XT_GM_CLASSIC;
51 char *statusbar_elems = NULL;
52 int window_height = 768;
53 int window_width = 1024;
54 int window_maximize = 0;
55 int icon_size = 2; /* 1 = smallest, 2+ = bigger */
56 char *resource_dir = NULL;
57 char download_dir[PATH_MAX];
58 int allow_volatile_cookies = 0;
59 int save_global_history = 0; /* save global history to disk */
60 int save_rejected_cookies = 0;
61 gint max_connections = 25;
62 gint max_host_connections = 5;
63 int history_autosave = 0;
64 int edit_mode = XT_EM_HYBRID;
65 char *include_config = NULL;
66 int anonymize_headers = 0;
67 int tabless = 0; /* allow only 1 tab */
69 /* runtime settings */
70 int show_tabs = XT_DS_SHOW_TABS; /* show tabs on notebook */
71 int tab_style = XT_DS_TAB_STYLE; /* tab bar style */
72 int statusbar_style = XT_DS_STATUSBAR_STYLE; /* status bar style */
73 int show_url = XT_DS_SHOW_URL; /* show url toolbar on notebook */
74 int show_scrollbars = XT_DS_SHOW_SCROLLBARS;
75 int show_statusbar = XT_DS_SHOW_STATUSBAR; /* vimperator style status bar */
76 int ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS; /* ctrl click gets focus */
77 int cookies_enabled = XT_DS_COOKIES_ENABLED; /* enable cookies */
78 int read_only_cookies = XT_DS_READ_ONLY_COOKIES; /* enable to not write cookies */
79 int enable_scripts = XT_DS_ENABLE_SCRIPTS;
80 int enable_plugins = XT_DS_ENABLE_PLUGINS;
81 gfloat default_zoom_level = XT_DS_DEFAULT_ZOOM_LEVEL;
82 char default_script[PATH_MAX]; /* special setting - is never g_free'd */
83 int refresh_interval = XT_DS_REFRESH_INTERVAL; /* download refresh interval */
84 int enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
85 int enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
86 int enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
87 int enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
88 int session_timeout = XT_DS_SESSION_TIMEOUT; /* cookie session timeout */
89 int cookie_policy = XT_DS_COOKIE_POLICY;
90 char ssl_ca_file[PATH_MAX]; /* special setting - is never g_free'd */
91 gboolean ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
92 gboolean enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
93 int append_next = XT_DS_APPEND_NEXT; /* append tab after current tab */
94 char *home = NULL; /* allocated/set at startup */
95 char *search_string = NULL; /* allocated/set at startup */
96 char *http_proxy = NULL;
97 int http_proxy_starts_enabled = 1;
98 int download_mode = XT_DM_START;
99 int color_visited_uris = XT_DS_COLOR_VISITED_URIS;
100 int session_autosave = XT_DS_SESSION_AUTOSAVE;
101 int guess_search = XT_DS_GUESS_SEARCH;
102 gint enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
103 char *spell_check_languages = NULL; /* allocated/set at startup */
104 char *url_regex = NULL; /* allocated/set at startup */
105 char *encoding = NULL; /* allocated/set at startup */
106 int autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
107 int enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
108 char *userstyle = NULL; /* allocated/set at startup */
109 int userstyle_global = XT_DS_USERSTYLE_GLOBAL;
110 int auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
111 int enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
112 int enable_cache = 0;
113 int enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
114 int enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
115 char *external_editor = NULL;
116 int referer_mode = XT_DS_REFERER_MODE;
117 char *referer_custom = NULL;
118 int download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
119 int warn_cert_changes = 0;
120 int allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
121 int allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
122 int do_not_track = XT_DS_DO_NOT_TRACK;
123 int preload_strict_transport = XT_DS_PRELOAD_STRICT_TRANSPORT;
124 char *gnutls_priority_string = XT_DS_GNUTLS_PRIORITY_STRING;
125 int js_auto_open_windows = XT_DS_JS_AUTO_OPEN_WINDOWS;
126 char *cmd_font_name = NULL; /* these are all set at startup */
127 char *oops_font_name = NULL;
128 char *statusbar_font_name = NULL;
129 char *tabbar_font_name = NULL;
131 char *get_download_dir(struct settings *);
132 char *get_default_script(struct settings *);
133 char *get_runtime_dir(struct settings *);
134 char *get_tab_style(struct settings *);
135 char *get_statusbar_style(struct settings *);
136 char *get_edit_mode(struct settings *);
137 char *get_download_mode(struct settings *);
138 char *get_work_dir(struct settings *);
139 char *get_referer(struct settings *);
140 char *get_ssl_ca_file(struct settings *);
141 char *get_userstyle(struct settings *);
142 char *get_gnutls_priority_string(struct settings *);
144 int add_cookie_wl(struct settings *, char *);
145 int add_js_wl(struct settings *, char *);
146 int add_pl_wl(struct settings *, char *);
147 int add_mime_type(struct settings *, char *);
148 int add_alias(struct settings *, char *);
149 int add_kb(struct settings *, char *);
150 int add_ua(struct settings *, char *);
151 int add_http_accept(struct settings *, char *);
152 int add_cmd_alias(struct settings *, char *);
153 int add_custom_uri(struct settings *, char *);
154 int add_force_https(struct settings *, char *);
156 int set_append_next(char *);
157 int set_autofocus_onload(char *);
158 int set_cmd_font(char *);
159 int set_color_visited_uris(char *);
160 int set_cookie_policy_rt(char *);
161 int set_cookies_enabled(char *);
162 int set_ctrl_click_focus(char *);
163 int set_fancy_bar(char *);
164 int set_home(char *);
165 int set_download_dir(struct settings *, char *);
166 int set_download_notifications(char *);
167 int set_default_script(struct settings *, char *);
168 int set_default_script_rt(char *);
169 int set_default_zoom_level(char *);
170 int set_enable_cookie_whitelist(char *);
171 int set_enable_js_autorun(char *);
172 int set_enable_js_whitelist(char *);
173 int set_enable_localstorage(char *);
174 int set_enable_plugins(char *);
175 int set_enable_plugin_whitelist(char *);
176 int set_enable_scripts(char *);
177 int set_enable_spell_checking(char *);
178 int set_enable_strict_transport(char *);
179 int set_encoding_rt(char *);
180 int set_runtime_dir(struct settings *, char *);
181 int set_tabbar_font(char *value);
182 int set_tab_style(struct settings *, char *);
183 int set_tab_style_rt(char *);
184 int set_statusbar_style(struct settings *, char *);
185 int set_statusbar_style_rt(char *);
186 int set_edit_mode(struct settings *, char *);
187 int set_work_dir(struct settings *, char *);
188 int set_auto_load_images(char *);
189 int set_enable_autoscroll(char *);
190 int set_enable_cache(char *);
191 int set_enable_favicon_entry(char *);
192 int set_enable_favicon_tabs(char *);
193 int set_guess_search(char *);
194 int set_download_mode(struct settings *, char *);
195 int set_download_mode_rt(char *);
196 int set_js_auto_open_windows(char *);
197 int set_oops_font(char *);
198 int set_read_only_cookies(char *);
199 int set_referer(struct settings *, char *);
200 int set_referer_rt(char *);
201 int set_refresh_interval(char *);
202 int set_search_string(char *s);
203 int set_session_autosave(char *);
204 int set_session_timeout(char *);
205 int set_show_scrollbars(char *);
206 int set_show_statusbar(char *);
207 int set_show_tabs(char *);
208 int set_show_url(char *);
209 int set_spell_check_languages(char *);
210 int set_ssl_ca_file_rt(char *);
211 int set_ssl_strict_certs(char *);
212 int set_statusbar_font(char *);
213 int set_url_regex(char *);
214 int set_userstyle(struct settings *, char *);
215 int set_userstyle_rt(char *);
216 int set_userstyle_global(char *);
217 int set_external_editor(char *);
218 int set_warn_cert_changes(char *);
219 int set_allow_insecure_content(char *);
220 int set_allow_insecure_scripts(char *);
221 int set_http_proxy(char *);
222 int set_do_not_track(char *);
223 int set_gnutls_priority_string(struct settings *, char *);
225 int check_allow_insecure_content(char **);
226 int check_allow_insecure_scripts(char **);
227 int check_allow_volatile_cookies(char **);
228 int check_anonymize_headers(char **);
229 int check_append_next(char **);
230 int check_auto_load_images(char **);
231 int check_autofocus_onload(char **);
232 int check_browser_mode(char **);
233 int check_cmd_font(char **);
234 int check_color_visited_uris(char **);
235 int check_cookie_policy(char **);
236 int check_cookies_enabled(char **);
237 int check_ctrl_click_focus(char **);
238 int check_default_script(char **);
239 int check_default_zoom_level(char **);
240 int check_download_dir(char **);
241 int check_download_mode(char **);
242 int check_download_notifications(char **);
243 int check_edit_mode(char **);
244 int check_enable_autoscroll(char **);
245 int check_enable_cache(char **);
246 int check_enable_cookie_whitelist(char **);
247 int check_enable_favicon_entry(char **);
248 int check_enable_favicon_tabs(char **);
249 int check_enable_js_autorun(char **);
250 int check_enable_js_whitelist(char **);
251 int check_enable_localstorage(char **);
252 int check_enable_plugin_whitelist(char **);
253 int check_enable_plugins(char **);
254 int check_enable_scripts(char **);
255 int check_enable_socket(char **);
256 int check_enable_spell_checking(char **);
257 int check_enable_strict_transport(char **);
258 int check_encoding(char **);
259 int check_external_editor(char **);
260 int check_fancy_bar(char **);
261 int check_gnutls_search_string(char **);
262 int check_guess_search(char **);
263 int check_gui_mode(char **);
264 int check_history_autosave(char **);
265 int check_home(char **);
266 int check_http_proxy(char **);
267 int check_http_proxy_scheme(const char *);
268 int check_http_proxy_starts_enabled(char **);
269 int check_icon_size(char **);
270 int check_js_auto_open_windows(char **);
271 int check_max_connections(char **);
272 int check_max_host_connections(char **);
273 int check_oops_font(char **);
274 int check_read_only_cookies(char **);
275 int check_referer(char **);
276 int check_refresh_interval(char **);
277 int check_resource_dir(char **);
278 int check_save_global_history(char **);
279 int check_save_rejected_cookies(char **);
280 int check_search_string(char **);
281 int check_session_autosave(char **);
282 int check_session_timeout(char **);
283 int check_show_scrollbars(char **);
284 int check_show_statusbar(char **);
285 int check_show_tabs(char **);
286 int check_show_url(char **);
287 int check_single_instance(char **);
288 int check_spell_check_languages(char **);
289 int check_ssl_ca_file(char **);
290 int check_ssl_strict_certs(char **);
291 int check_statusbar_elems(char **);
292 int check_statusbar_font(char **);
293 int check_statusbar_style(char **);
294 int check_tab_style(char **);
295 int check_tabless(char **);
296 int check_tabbar_font(char **);
297 int check_url_regex(char **);
298 int check_userstyle(char **);
299 int check_userstyle_global(char **);
300 int check_warn_cert_changes(char **);
301 int check_window_height(char **);
302 int check_window_maximize(char **);
303 int check_window_width(char **);
304 int check_work_dir(char **);
305 int check_do_not_track(char **);
307 void walk_mime_type(struct settings *, void (*)(struct settings *,
308 char *, void *), void *);
309 void walk_alias(struct settings *, void (*)(struct settings *,
310 char *, void *), void *);
311 void walk_cookie_wl(struct settings *, void (*)(struct settings *,
312 char *, void *), void *);
313 void walk_js_wl(struct settings *, void (*)(struct settings *,
314 char *, void *), void *);
315 void walk_pl_wl(struct settings *, void (*)(struct settings *,
316 char *, void *), void *);
317 void walk_kb(struct settings *, void (*)(struct settings *, char *,
318 void *), void *);
319 void walk_ua(struct settings *, void (*)(struct settings *, char *,
320 void *), void *);
321 void walk_http_accept(struct settings *, void (*)(struct settings *,
322 char *, void *), void *);
323 void walk_cmd_alias(struct settings *, void (*)(struct settings *,
324 char *, void *), void *);
325 void walk_custom_uri(struct settings *, void (*)(struct settings *,
326 char *, void *), void *);
327 void walk_force_https(struct settings *, void (*)(struct settings *,
328 char *, void *), void *);
330 struct special s_browser_mode = {
331 set_browser_mode,
332 get_browser_mode,
333 NULL,
334 { "kiosk", "normal", "whitelist", NULL }
337 struct special s_gui_mode = {
338 set_gui_mode,
339 get_gui_mode,
340 NULL,
341 { "classic", "minimal", NULL }
344 struct special s_cookie = {
345 set_cookie_policy,
346 get_cookie_policy,
347 NULL,
348 { "accept", "no3rdparty", "reject", NULL }
351 struct special s_alias = {
352 add_alias,
353 NULL,
354 walk_alias,
355 { NULL }
358 struct special s_cmd_alias = {
359 add_cmd_alias,
360 NULL,
361 walk_cmd_alias,
362 { NULL }
365 struct special s_mime = {
366 add_mime_type,
367 NULL,
368 walk_mime_type,
369 { NULL }
372 struct special s_js = {
373 add_js_wl,
374 NULL,
375 walk_js_wl,
376 { NULL }
379 struct special s_pl = {
380 add_pl_wl,
381 NULL,
382 walk_pl_wl,
383 { NULL }
386 struct special s_kb = {
387 add_kb,
388 NULL,
389 walk_kb,
390 { NULL }
393 struct special s_cookie_wl = {
394 add_cookie_wl,
395 NULL,
396 walk_cookie_wl,
397 { NULL }
400 struct special s_uri = {
401 add_custom_uri,
402 NULL,
403 walk_custom_uri,
404 { NULL }
407 struct special s_default_script = {
408 set_default_script,
409 get_default_script,
410 NULL,
411 { NULL }
414 struct special s_ssl_ca_file = {
415 set_ssl_ca_file,
416 get_ssl_ca_file,
417 NULL,
418 { NULL }
421 struct special s_download_dir = {
422 set_download_dir,
423 get_download_dir,
424 NULL,
425 { NULL }
428 struct special s_work_dir = {
429 set_work_dir,
430 get_work_dir,
431 NULL,
432 { NULL }
435 struct special s_tab_style = {
436 set_tab_style,
437 get_tab_style,
438 NULL,
439 { "compact", "normal", NULL }
442 struct special s_statusbar_style = {
443 set_statusbar_style,
444 get_statusbar_style,
445 NULL,
446 { "title", "url", NULL }
449 struct special s_edit_mode = {
450 set_edit_mode,
451 get_edit_mode,
452 NULL,
453 { "hybrid", "vi", NULL }
456 struct special s_download_mode = {
457 set_download_mode,
458 get_download_mode,
459 NULL,
460 { "add", "ask", "start", NULL }
463 struct special s_ua = {
464 add_ua,
465 NULL,
466 walk_ua,
467 { NULL }
470 struct special s_http_accept = {
471 add_http_accept,
472 NULL,
473 walk_http_accept,
474 { NULL }
477 struct special s_referer = {
478 set_referer,
479 get_referer,
480 NULL,
481 { "always", "never", "same-domain", "same-fqdn", NULL }
484 struct special s_userstyle = {
485 set_userstyle,
486 get_userstyle,
487 NULL,
488 { NULL }
491 struct special s_force_https = {
492 add_force_https,
493 NULL,
494 walk_force_https,
495 { NULL }
498 struct special s_gnutls_priority_string = {
499 set_gnutls_priority_string,
500 get_gnutls_priority_string,
501 NULL,
502 { NULL }
505 struct settings rs[] = {
506 { "allow_insecure_content", XT_S_BOOL, 0, &allow_insecure_content, NULL, NULL, NULL, set_allow_insecure_content, check_allow_insecure_content, TT_ALLOW_INSECURE_CONTENT },
507 { "allow_insecure_scripts", XT_S_BOOL, 0, &allow_insecure_scripts, NULL, NULL, NULL, set_allow_insecure_scripts, check_allow_insecure_scripts, TT_ALLOW_INSECURE_SCRIPTS},
508 { "allow_volatile_cookies", XT_S_BOOL, 0, &allow_volatile_cookies, NULL, NULL, NULL, NULL, check_allow_volatile_cookies, TT_ALLOW_VOLATILE_COOKIES },
509 { "anonymize_headers", XT_S_BOOL, 0, &anonymize_headers, NULL, NULL, NULL, NULL, check_anonymize_headers, TT_ANONYMIZE_HEADERS },
510 { "append_next", XT_S_BOOL, 0, &append_next, NULL, NULL, NULL, set_append_next, check_append_next, TT_APPEND_NEXT },
511 { "auto_load_images", XT_S_BOOL, 0, &auto_load_images, NULL, NULL, NULL, set_auto_load_images, check_auto_load_images, TT_AUTO_LOAD_IMAGES },
512 { "autofocus_onload", XT_S_BOOL, 0, &autofocus_onload, NULL, NULL, NULL, set_autofocus_onload, check_autofocus_onload, TT_AUTOFOCUS_ONLOAD },
513 { "browser_mode", XT_S_STR, 0, NULL, NULL,&s_browser_mode, NULL, NULL, check_browser_mode, TT_BROWSER_MODE },
514 { "cmd_font", XT_S_STR, 0, NULL, &cmd_font_name, NULL, NULL, set_cmd_font, check_cmd_font, TT_CMD_FONT },
515 { "color_visited_uris", XT_S_BOOL, 0, &color_visited_uris , NULL, NULL, NULL, set_color_visited_uris, check_color_visited_uris, TT_COLOR_VISITED_URIS },
516 { "cookie_policy", XT_S_STR, 0, NULL, NULL,&s_cookie, NULL, set_cookie_policy_rt, check_cookie_policy, TT_COOKIE_POLICY },
517 { "cookies_enabled", XT_S_BOOL, 0, &cookies_enabled, NULL, NULL, NULL, set_cookies_enabled, check_cookies_enabled, TT_COOKIES_ENABLED },
518 { "ctrl_click_focus", XT_S_BOOL, 0, &ctrl_click_focus, NULL, NULL, NULL, set_ctrl_click_focus, check_ctrl_click_focus, TT_CTRL_CLICK_FOCUS },
519 { "default_script", XT_S_STR, 1, NULL, NULL,&s_default_script, NULL, set_default_script_rt, check_default_script, TT_DEFAULT_SCRIPT },
520 { "default_zoom_level", XT_S_FLOAT, 0, NULL, NULL, NULL, &default_zoom_level, set_default_zoom_level, check_default_zoom_level, TT_DEFAULT_ZOOM_LEVEL },
521 { "do_not_track", XT_S_BOOL, 0, &do_not_track, NULL, NULL, NULL, set_do_not_track, check_do_not_track, TT_DO_NOT_TRACK },
522 { "download_dir", XT_S_STR, 0, NULL, NULL,&s_download_dir, NULL, NULL, check_download_dir, TT_DOWNLOAD_DIR },
523 { "download_mode", XT_S_STR, 0, NULL, NULL,&s_download_mode, NULL, set_download_mode_rt, check_download_mode, TT_DOWNLOAD_MODE },
524 { "download_notifications", XT_S_BOOL, 0, &download_notifications, NULL, NULL, NULL, set_download_notifications, check_download_notifications, TT_DOWNLOAD_NOTIFICATIONS },
525 { "edit_mode", XT_S_STR, 0, NULL, NULL,&s_edit_mode, NULL, NULL, check_edit_mode, NULL },
526 { "enable_autoscroll", XT_S_BOOL, 0, &enable_autoscroll, NULL, NULL, NULL, set_enable_autoscroll, check_enable_autoscroll, TT_ENABLE_AUTOSCROLL },
527 { "enable_cache", XT_S_BOOL, 0, &enable_cache, NULL, NULL, NULL, set_enable_cache, check_enable_cache, TT_ENABLE_CACHE },
528 { "enable_cookie_whitelist", XT_S_BOOL, 0, &enable_cookie_whitelist, NULL, NULL, NULL, set_enable_cookie_whitelist, check_enable_cookie_whitelist, TT_ENABLE_COOKIE_WHITELIST },
529 { "enable_favicon_entry", XT_S_BOOL, 0, &enable_favicon_entry, NULL, NULL, NULL, set_enable_favicon_entry, check_enable_favicon_entry, TT_ENABLE_FAVICON_ENTRY },
530 { "enable_favicon_tabs", XT_S_BOOL, 0, &enable_favicon_tabs, NULL, NULL, NULL, set_enable_favicon_tabs, check_enable_favicon_tabs, TT_ENABLE_FAVICON_TABS },
531 { "enable_js_autorun", XT_S_BOOL, 0, &enable_js_autorun, NULL, NULL, NULL, set_enable_js_autorun, check_enable_js_autorun, TT_ENABLE_JS_AUTORUN },
532 { "enable_js_whitelist", XT_S_BOOL, 0, &enable_js_whitelist, NULL, NULL, NULL, set_enable_js_whitelist, check_enable_js_whitelist, TT_ENABLE_JS_WHITELIST },
533 { "enable_localstorage", XT_S_BOOL, 0, &enable_localstorage, NULL, NULL, NULL, set_enable_localstorage, check_enable_localstorage, TT_ENABLE_LOCALSTORAGE },
534 { "enable_plugin_whitelist", XT_S_BOOL, 0, &enable_plugin_whitelist, NULL, NULL, NULL, set_enable_plugin_whitelist, check_enable_plugin_whitelist, TT_ENABLE_PLUGIN_WHITELIST },
535 { "enable_plugins", XT_S_BOOL, 0, &enable_plugins, NULL, NULL, NULL, set_enable_plugins, check_enable_plugins, TT_ENABLE_PLUGINS },
536 { "enable_scripts", XT_S_BOOL, 0, &enable_scripts, NULL, NULL, NULL, set_enable_scripts, check_enable_scripts, TT_ENABLE_SCRIPTS },
537 { "enable_socket", XT_S_BOOL,XT_SF_RESTART,&enable_socket, NULL, NULL, NULL, NULL, check_enable_socket, TT_ENABLE_SOCKET },
538 { "enable_spell_checking", XT_S_BOOL, 0, &enable_spell_checking, NULL, NULL, NULL, set_enable_spell_checking, check_enable_spell_checking, TT_ENABLE_SPELL_CHECKING },
539 { "enable_strict_transport", XT_S_BOOL, 0, &enable_strict_transport, NULL, NULL, NULL, set_enable_strict_transport, check_enable_strict_transport, TT_ENABLE_STRICT_TRANSPORT },
540 { "encoding", XT_S_STR, 0, NULL, &encoding, NULL, NULL, NULL, check_encoding, TT_ENCODING },
541 { "external_editor", XT_S_STR,0, NULL, &external_editor, NULL, NULL, set_external_editor, check_external_editor, TT_EXTERNAL_EDITOR },
542 { "fancy_bar", XT_S_BOOL,XT_SF_RESTART,&fancy_bar, NULL, NULL, NULL, set_fancy_bar, check_fancy_bar, TT_FANCY_BAR },
543 { "gnutls_priority_string", XT_S_STR, 0, NULL, NULL,&s_gnutls_priority_string, NULL, NULL, check_gnutls_search_string, TT_GNUTLS_PRIORITY_STRING },
544 { "guess_search", XT_S_BOOL, 0, &guess_search, NULL, NULL, NULL, set_guess_search, check_guess_search, TT_GUESS_SEARCH },
545 { "gui_mode", XT_S_STR, 0, NULL, NULL,&s_gui_mode, NULL, NULL, check_gui_mode, TT_GUI_MODE },
546 { "history_autosave", XT_S_BOOL, 0, &history_autosave, NULL, NULL, NULL, NULL, check_history_autosave, TT_HISTORY_AUTOSAVE },
547 { "home", XT_S_STR, 0, NULL, &home, NULL, NULL, set_home, check_home, TT_HOME },
548 { "http_proxy", XT_S_STR, 0, NULL, &http_proxy, NULL, NULL, set_http_proxy, check_http_proxy, TT_HTTP_PROXY },
549 { "http_proxy_starts_enabled", XT_S_BOOL, 0, &http_proxy_starts_enabled, NULL, NULL, NULL, NULL, check_http_proxy_starts_enabled, TT_HTTP_PROXY_STARTS_ENABLED },
550 { "icon_size", XT_S_INT, 0, &icon_size, NULL, NULL, NULL, NULL, check_icon_size, TT_ICON_SIZE },
551 { "include_config", XT_S_STR, XT_SF_INVISIBLE, NULL, &include_config, NULL, NULL, NULL, NULL },
552 { "js_auto_open_windows", XT_S_BOOL, 1, &js_auto_open_windows, NULL, NULL, NULL, set_js_auto_open_windows, check_js_auto_open_windows, TT_JS_AUTO_OPEN_WINDOWS },
553 { "max_connections", XT_S_INT, XT_SF_RESTART,&max_connections, NULL, NULL, NULL, NULL, check_max_connections, TT_MAX_CONNECTIONS },
554 { "max_host_connections", XT_S_INT, XT_SF_RESTART,&max_host_connections, NULL, NULL, NULL, NULL, check_max_host_connections, TT_MAX_HOST_CONNECTIONS },
555 { "oops_font", XT_S_STR, 0, NULL, &oops_font_name, NULL, NULL, set_oops_font, check_oops_font, TT_OOPS_FONT },
556 { "preload_strict_transport", XT_S_BOOL, 0, &preload_strict_transport, NULL, NULL, NULL, NULL, NULL, TT_PRELOAD_STRICT_TRANSPORT },
557 { "read_only_cookies", XT_S_BOOL, 0, &read_only_cookies, NULL, NULL, NULL, NULL, check_read_only_cookies, TT_READ_ONLY_COOKIES },
558 { "referer", XT_S_STR, 0, NULL, NULL,&s_referer, NULL, set_referer_rt, check_referer, TT_REFERER },
559 { "refresh_interval", XT_S_INT, 0, &refresh_interval, NULL, NULL, NULL, set_refresh_interval, check_refresh_interval, TT_REFRESH_INTERVAL },
560 { "resource_dir", XT_S_STR, 0, NULL, &resource_dir, NULL, NULL, NULL, check_resource_dir, TT_RESOURCE_DIR },
561 { "save_global_history", XT_S_BOOL,XT_SF_RESTART,&save_global_history, NULL, NULL, NULL, NULL, check_save_global_history, TT_SAVE_GLOBAL_HISTORY },
562 { "save_rejected_cookies", XT_S_BOOL,XT_SF_RESTART,&save_rejected_cookies, NULL, NULL, NULL, NULL, check_save_rejected_cookies, TT_SAVE_REJECTED_COOKIES },
563 { "search_string", XT_S_STR, 0, NULL, &search_string, NULL, NULL, set_search_string, check_search_string, TT_SEARCH_STRING },
564 { "session_autosave", XT_S_BOOL, 0, &session_autosave, NULL, NULL, NULL, set_session_autosave, check_session_autosave, TT_SESSION_AUTOSAVE },
565 { "session_timeout", XT_S_INT, 0, &session_timeout, NULL, NULL, NULL, set_session_timeout, check_session_timeout, TT_SESSION_TIMEOUT },
566 { "show_scrollbars", XT_S_BOOL, 0, &show_scrollbars, NULL, NULL, NULL, set_show_scrollbars, check_show_scrollbars, TT_SHOW_SCROLLBARS },
567 { "show_statusbar", XT_S_BOOL, 0, &show_statusbar, NULL, NULL, NULL, set_show_statusbar, check_show_statusbar, TT_SHOW_STATUSBAR },
568 { "show_tabs", XT_S_BOOL, 0, &show_tabs, NULL, NULL, NULL, set_show_tabs, check_show_tabs, TT_SHOW_TABS },
569 { "show_url", XT_S_BOOL, 0, &show_url, NULL, NULL, NULL, set_show_url, check_show_url, TT_SHOW_URL },
570 { "single_instance", XT_S_BOOL,XT_SF_RESTART,&single_instance, NULL, NULL, NULL, NULL, check_single_instance, TT_SINGLE_INSTANCE },
571 { "spell_check_languages", XT_S_STR, 0, NULL, &spell_check_languages, NULL, NULL, set_spell_check_languages, check_spell_check_languages, TT_SPELL_CHECK_LANGUAGES },
572 { "ssl_ca_file", XT_S_STR, 0, NULL, NULL,&s_ssl_ca_file, NULL, set_ssl_ca_file_rt, check_ssl_ca_file, TT_SSL_CA_FILE },
573 { "ssl_strict_certs", XT_S_BOOL, 0, &ssl_strict_certs, NULL, NULL, NULL, set_ssl_strict_certs, check_ssl_strict_certs, TT_SSL_STRICT_CERTS },
574 { "statusbar_elems", XT_S_STR, 0, NULL, &statusbar_elems, NULL, NULL, NULL, check_statusbar_elems, TT_STATUSBAR_ELEMS },
575 { "statusbar_font", XT_S_STR, 0, NULL, &statusbar_font_name, NULL, NULL, set_statusbar_font, check_statusbar_font, TT_STATUSBAR_FONT },
576 { "statusbar_style", XT_S_STR, 0, NULL, NULL,&s_statusbar_style, NULL, set_statusbar_style_rt, check_statusbar_style, TT_STATUSBAR_STYLE },
577 { "tab_style", XT_S_STR, 0, NULL, NULL,&s_tab_style, NULL, set_tab_style_rt, check_tab_style, TT_TAB_STYLE },
578 { "tabbar_font", XT_S_STR, 0, NULL, &tabbar_font_name, NULL, NULL, set_tabbar_font, check_tabbar_font, TT_TABBAR_FONT },
579 { "tabless", XT_S_BOOL, 0, &tabless, NULL, NULL, NULL, NULL, check_tabless, TT_TABLESS },
580 { "url_regex", XT_S_STR, 0, NULL, &url_regex, NULL, NULL, set_url_regex, check_url_regex, TT_URL_REGEX },
581 { "userstyle", XT_S_STR, 0, NULL, NULL,&s_userstyle, NULL, set_userstyle_rt, check_userstyle, TT_USERSTYLE },
582 { "userstyle_global", XT_S_BOOL, 0, &userstyle_global, NULL, NULL, NULL, set_userstyle_global, check_userstyle_global, TT_USERSTYLE_GLOBAL },
583 { "warn_cert_changes", XT_S_BOOL, 0, &warn_cert_changes, NULL, NULL, NULL, set_warn_cert_changes, check_warn_cert_changes, TT_WARN_CERT_CHANGES },
584 { "window_height", XT_S_INT, 0, &window_height, NULL, NULL, NULL, NULL, check_window_height, TT_WINDOW_HEIGHT },
585 { "window_maximize", XT_S_BOOL, 0, &window_maximize, NULL, NULL, NULL, NULL, check_window_maximize, TT_WINDOW_MAXIMIZE },
586 { "window_width", XT_S_INT, 0, &window_width, NULL, NULL, NULL, NULL, check_window_width, TT_WINDOW_WIDTH },
587 { "work_dir", XT_S_STR, 0, NULL, NULL,&s_work_dir, NULL, NULL, check_work_dir, TT_WORK_DIR },
589 /* special settings */
590 { "alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_alias, NULL, NULL },
591 { "cmd_alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cmd_alias, NULL, NULL },
592 { "cookie_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cookie_wl, NULL, NULL },
593 { "custom_uri", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_uri, NULL, NULL },
594 { "force_https", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_force_https, NULL, NULL },
595 { "http_accept", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_http_accept, NULL, NULL },
596 { "js_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_js, NULL, NULL },
597 { "keybinding", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_kb, NULL, NULL },
598 { "mime_type", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_mime, NULL, NULL },
599 { "pl_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_pl, NULL, NULL },
600 { "user_agent", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_ua, NULL, NULL },
604 set_http_proxy(char *proxy)
606 char *tmpproxy = proxy;
608 /* see if we need to clear it */
609 if (proxy == NULL || strlen(proxy) == 0)
610 tmpproxy = NULL;
612 if (check_http_proxy_scheme(proxy) == 0)
613 tmpproxy = NULL;
615 return (setup_proxy(tmpproxy));
619 check_http_proxy(char **tt)
621 *tt = g_strdup("Default: (empty)");
622 return (g_strcmp0(http_proxy, NULL));
626 check_http_proxy_scheme(const char *uri)
628 int rv = 0;
629 char *scheme;
631 if (!uri)
632 return (0);
634 scheme = g_uri_parse_scheme(uri);
635 if (!scheme)
636 return (0);
638 #if SOUP_CHECK_VERSION(2, 42, 2)
639 if (strcmp(scheme, "socks5") == 0 || strcmp(scheme, "socks4a") == 0 ||
640 strcmp(scheme, "socks4") == 0 || strcmp(scheme, "socks") == 0 ||
641 strcmp(scheme, "http") == 0) {
642 rv = 1;
644 #else
645 if (strcmp(scheme, "http") == 0) {
646 rv = 1;
648 #endif
649 free(scheme);
650 return (rv);
654 check_http_proxy_starts_enabled(char **tt)
656 *tt = g_strdup("Default: Enabled");
657 return (http_proxy_starts_enabled != 1);
661 check_icon_size(char **tt)
663 *tt = g_strdup_printf("Default: %d", 2);
664 return (icon_size != 2);
668 check_max_connections(char **tt)
670 *tt = g_strdup_printf("Default: %d", 25);
671 return (max_connections != 25);
675 check_max_host_connections(char **tt)
677 *tt = g_strdup_printf("Default: %d", 5);
678 return (max_host_connections != 5);
682 set_default_zoom_level(char *value)
684 struct karg args = {0};
685 struct tab *t;
687 if (value == NULL || strlen(value) == 0)
688 default_zoom_level = XT_DS_DEFAULT_ZOOM_LEVEL;
689 else
690 default_zoom_level = g_strtod(value, NULL);
691 args.i = 100; /* adjust = 100 percent for no additional adjustment */
692 TAILQ_FOREACH(t, &tabs, entry)
693 resizetab(t, &args);
694 return (0);
698 check_default_zoom_level(char **tt)
700 *tt = g_strdup_printf("Default: %f", XT_DS_DEFAULT_ZOOM_LEVEL);
701 return (default_zoom_level != XT_DS_DEFAULT_ZOOM_LEVEL);
705 set_cookies_enabled(char *value)
707 int tmp;
708 const char *errstr;
710 if (value == NULL || strlen(value) == 0)
711 cookies_enabled = XT_DS_COOKIES_ENABLED;
712 else {
713 tmp = strtonum(value, 0, 1, &errstr);
714 if (errstr)
715 return (-1);
716 cookies_enabled = tmp;
718 return (0);
722 check_cookies_enabled(char **tt)
724 *tt = g_strdup_printf("Default: %s",
725 XT_DS_COOKIES_ENABLED ? "Enabled" : "Disabled");
726 return (cookies_enabled != XT_DS_COOKIES_ENABLED);
730 set_append_next(char *value)
732 int tmp;
733 const char *errstr;
735 if (value == NULL || strlen(value) == 0)
736 append_next = XT_DS_APPEND_NEXT;
737 else {
738 tmp = strtonum(value, 0, 1, &errstr);
739 if (errstr)
740 return (-1);
741 append_next = tmp;
743 return (0);
747 check_append_next(char **tt)
749 *tt = g_strdup_printf("Default: %s",
750 XT_DS_APPEND_NEXT ? "Enabled" : "Disabled");
751 return (append_next != XT_DS_APPEND_NEXT);
755 set_cmd_font(char *value)
757 struct tab *t;
759 if (cmd_font_name)
760 g_free(cmd_font_name);
761 if (cmd_font)
762 pango_font_description_free(cmd_font);
763 if (value == NULL || strlen(value) == 0)
764 cmd_font_name = g_strdup(XT_DS_CMD_FONT_NAME);
765 else
766 cmd_font_name = g_strdup(value);
767 cmd_font = pango_font_description_from_string(cmd_font_name);
768 TAILQ_FOREACH(t, &tabs, entry)
769 modify_font(GTK_WIDGET(t->cmd), cmd_font);
770 return (0);
774 check_cmd_font(char **tt)
776 *tt = g_strdup_printf("Default: %s", XT_DS_CMD_FONT_NAME);
777 return (g_strcmp0(cmd_font_name, XT_DS_CMD_FONT_NAME));
781 set_oops_font(char *value)
783 struct tab *t;
785 if (oops_font_name)
786 g_free(oops_font_name);
787 if (oops_font)
788 pango_font_description_free(oops_font);
789 if (value == NULL || strlen(value) == 0)
790 cmd_font_name = g_strdup(XT_DS_OOPS_FONT_NAME);
791 else
792 oops_font_name = g_strdup(value);
793 oops_font = pango_font_description_from_string(oops_font_name);
794 TAILQ_FOREACH(t, &tabs, entry)
795 modify_font(GTK_WIDGET(t->oops), oops_font);
796 return (0);
800 check_oops_font(char **tt)
802 *tt = g_strdup_printf("Default: %s", XT_DS_OOPS_FONT_NAME);
803 return (g_strcmp0(oops_font_name, XT_DS_OOPS_FONT_NAME));
807 check_read_only_cookies(char **tt)
809 *tt = g_strdup_printf("Default: %s",
810 XT_DS_READ_ONLY_COOKIES ? "Enabled" : "Disabled");
811 return (read_only_cookies != XT_DS_READ_ONLY_COOKIES);
815 set_statusbar_font(char *value)
817 struct tab *t;
819 if (statusbar_font_name)
820 g_free(statusbar_font_name);
821 if (statusbar_font)
822 pango_font_description_free(statusbar_font);
823 if (value == NULL || strlen(value) == 0)
824 statusbar_font_name = g_strdup(XT_DS_STATUSBAR_FONT_NAME);
825 else
826 statusbar_font_name = g_strdup(value);
827 statusbar_font = pango_font_description_from_string(
828 statusbar_font_name);
829 TAILQ_FOREACH(t, &tabs, entry) {
830 modify_font(GTK_WIDGET(t->sbe.uri),
831 statusbar_font);
832 if (t->sbe.buffercmd != NULL)
833 modify_font(GTK_WIDGET(t->sbe.buffercmd),
834 statusbar_font);
835 if (t->sbe.zoom != NULL)
836 modify_font(GTK_WIDGET(t->sbe.zoom),
837 statusbar_font);
838 if (t->sbe.position != NULL)
839 modify_font(GTK_WIDGET(t->sbe.position),
840 statusbar_font);
841 if (t->sbe.proxy != NULL)
842 modify_font(GTK_WIDGET(t->sbe.proxy),
843 statusbar_font);
845 return (0);
849 check_statusbar_font(char **tt)
851 *tt = g_strdup_printf("Default: %s", XT_DS_STATUSBAR_FONT_NAME);
852 return (g_strcmp0(statusbar_font_name, XT_DS_STATUSBAR_FONT_NAME));
856 set_tabbar_font(char *value)
858 struct tab *t;
860 if (tabbar_font_name)
861 g_free(tabbar_font_name);
862 if (tabbar_font)
863 pango_font_description_free(tabbar_font);
864 if (value == NULL || strlen(value) == 0)
865 tabbar_font_name = g_strdup(XT_DS_TABBAR_FONT_NAME);
866 else
867 tabbar_font_name = g_strdup(value);
868 tabbar_font = pango_font_description_from_string(tabbar_font_name);
869 TAILQ_FOREACH(t, &tabs, entry)
870 modify_font(GTK_WIDGET(t->tab_elems.label),
871 tabbar_font);
872 return (0);
876 check_tabbar_font(char **tt)
878 *tt = g_strdup_printf("Default: %s", XT_DS_TABBAR_FONT_NAME);
879 return (g_strcmp0(tabbar_font_name, XT_DS_TABBAR_FONT_NAME));
883 check_tabless(char **tt)
885 *tt = g_strdup_printf("Default: Disabled\n");
886 return (tabless != 0);
890 set_color_visited_uris(char *value)
892 int tmp;
893 const char *errstr;
895 if (value == NULL || strlen(value) == 0)
896 color_visited_uris = XT_DS_COLOR_VISITED_URIS;
897 else {
898 tmp = strtonum(value, 0, 1, &errstr);
899 if (errstr)
900 return (-1);
901 color_visited_uris = tmp;
903 return (0);
907 check_color_visited_uris(char **tt)
909 *tt = g_strdup_printf("Default: %s",
910 XT_DS_COLOR_VISITED_URIS ? "Enabled" : "Disabled");
911 return (color_visited_uris != XT_DS_COLOR_VISITED_URIS);
915 set_home(char *value)
917 if (home)
918 g_free(home);
919 if (value == NULL || strlen(value) == 0)
920 home = g_strdup(XT_DS_HOME);
921 else
922 home = g_strdup(value);
923 return (0);
927 check_home(char **tt)
929 *tt = g_strdup_printf("Default: %s", XT_DS_HOME);
930 return (g_strcmp0(home, XT_DS_HOME));
934 set_search_string(char *value)
936 struct tab *t;
938 if (search_string)
939 g_free(search_string);
940 if (value == NULL || strlen(value) == 0) {
941 search_string = NULL;
942 TAILQ_FOREACH(t, &tabs, entry)
943 gtk_widget_hide(t->search_entry);
944 } else {
945 search_string = g_strdup(value);
946 TAILQ_FOREACH(t, &tabs, entry)
947 gtk_widget_show(t->search_entry);
949 return (0);
953 check_search_string(char **tt)
955 *tt = g_strdup_printf("Default: %s", XT_DS_SEARCH_STRING);
956 return (g_strcmp0(search_string, XT_DS_SEARCH_STRING));
959 size_t
960 get_settings_size(void)
962 return (LENGTH(rs));
965 char *
966 get_setting_name(int i)
968 if (i > LENGTH(rs))
969 return (NULL);
970 return (rs[i].name);
973 char *
974 get_as_string(struct settings *s)
976 char *r = NULL;
978 if (s == NULL)
979 return (NULL);
981 if (s->s && s->s->get)
982 r = s->s->get(s);
983 else if (s->type == XT_S_INT)
984 r = g_strdup_printf("%d", *s->ival);
985 else if (s->type == XT_S_STR)
986 r = g_strdup(*s->sval);
987 else if (s->type == XT_S_FLOAT)
988 r = g_strdup_printf("%f", *s->fval);
989 else if (s->type == XT_S_BOOL)
990 r = g_strdup_printf("%d", *s->ival);
991 else
992 r = g_strdup_printf("INVALID TYPE");
994 return (r);
997 void
998 settings_walk(void (*cb)(struct settings *, char *, void *), void *cb_args)
1000 int i;
1001 char *s;
1003 for (i = 0; i < LENGTH(rs); i++) {
1004 if (rs[i].s && rs[i].s->walk)
1005 rs[i].s->walk(&rs[i], cb, cb_args);
1006 else {
1007 s = get_as_string(&rs[i]);
1008 cb(&rs[i], s, cb_args);
1009 g_free(s);
1015 check_allow_volatile_cookies(char **tt)
1017 *tt = g_strdup("Default: Disabled");
1018 return (allow_volatile_cookies != 0);
1022 check_anonymize_headers(char **tt)
1024 *tt = g_strdup("Default: Disabled");
1025 return (anonymize_headers != 0);
1029 set_browser_mode(struct settings *s, char *val)
1031 if (!strcmp(val, "whitelist")) {
1032 browser_mode = XT_BM_WHITELIST;
1033 allow_volatile_cookies = 0;
1034 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
1035 cookies_enabled = 1;
1036 enable_cookie_whitelist = 1;
1037 enable_plugin_whitelist = 1;
1038 enable_plugins = 0;
1039 read_only_cookies = 0;
1040 save_rejected_cookies = 0;
1041 session_timeout = 3600;
1042 enable_scripts = 0;
1043 enable_js_whitelist = 1;
1044 enable_localstorage = 0;
1045 referer_mode = XT_REFERER_SAME_DOMAIN;
1046 allow_insecure_content = 0;
1047 allow_insecure_scripts = 0;
1048 do_not_track = 1;
1049 } else if (!strcmp(val, "normal")) {
1050 browser_mode = XT_BM_NORMAL;
1051 allow_volatile_cookies = 0;
1052 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1053 cookies_enabled = 1;
1054 enable_cookie_whitelist = 0;
1055 enable_plugin_whitelist = 0;
1056 enable_plugins = 1;
1057 read_only_cookies = 0;
1058 save_rejected_cookies = 0;
1059 session_timeout = 3600;
1060 enable_scripts = 1;
1061 enable_js_whitelist = 0;
1062 enable_localstorage = 1;
1063 referer_mode = XT_REFERER_ALWAYS;
1064 allow_insecure_content = 1;
1065 allow_insecure_scripts = 1;
1066 do_not_track = 0;
1067 } else if (!strcmp(val, "kiosk")) {
1068 browser_mode = XT_BM_KIOSK;
1069 allow_volatile_cookies = 0;
1070 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1071 cookies_enabled = 1;
1072 enable_cookie_whitelist = 0;
1073 enable_plugin_whitelist = 0;
1074 enable_plugins = 1;
1075 read_only_cookies = 0;
1076 save_rejected_cookies = 0;
1077 session_timeout = 3600;
1078 enable_scripts = 1;
1079 enable_js_whitelist = 0;
1080 enable_localstorage = 1;
1081 referer_mode = XT_REFERER_ALWAYS;
1082 allow_insecure_content = 1;
1083 allow_insecure_scripts = 1;
1084 do_not_track = 0;
1085 show_tabs = 0;
1086 tabless = 1;
1087 } else
1088 return (1);
1090 return (0);
1093 char *
1094 get_browser_mode(struct settings *s)
1096 char *r = NULL;
1098 if (browser_mode == XT_BM_WHITELIST)
1099 r = g_strdup("whitelist");
1100 else if (browser_mode == XT_BM_NORMAL)
1101 r = g_strdup("normal");
1102 else if (browser_mode == XT_BM_KIOSK)
1103 r = g_strdup("kiosk");
1104 else
1105 return (NULL);
1107 return (r);
1111 check_browser_mode(char **tt)
1113 *tt = g_strdup("Default: normal");
1114 return (browser_mode != XT_BM_NORMAL);
1118 set_gui_mode(struct settings *s, char *val)
1120 if (!strcmp(val, "classic")) {
1121 fancy_bar = 1;
1122 show_tabs = 1;
1123 tab_style = XT_TABS_NORMAL;
1124 show_url = 1;
1125 show_statusbar = 0;
1126 show_scrollbars = 1;
1127 } else if (!strcmp(val, "minimal")) {
1128 fancy_bar = 0;
1129 show_tabs = 1;
1130 tab_style = XT_TABS_COMPACT;
1131 show_url = 0;
1132 show_statusbar = 1;
1133 show_scrollbars = 0;
1134 } else
1135 return (1);
1137 return (0);
1140 char *
1141 get_gui_mode(struct settings *s)
1143 char *r = NULL;
1145 if (gui_mode == XT_GM_CLASSIC)
1146 r = g_strdup("classic");
1147 else if (browser_mode == XT_GM_MINIMAL)
1148 r = g_strdup("minimal");
1149 else
1150 return (NULL);
1152 return (r);
1156 check_gui_mode(char **tt)
1158 *tt = g_strdup("Default: classic");
1159 return (gui_mode != XT_GM_CLASSIC);
1163 check_history_autosave(char **tt)
1165 *tt = g_strdup("Default: Disabled");
1166 return (history_autosave != 0);
1170 set_cookie_policy(struct settings *s, char *val)
1172 if (!strcmp(val, "no3rdparty"))
1173 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
1174 else if (!strcmp(val, "accept"))
1175 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1176 else if (!strcmp(val, "reject"))
1177 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
1178 else
1179 return (1);
1181 return (0);
1185 set_cookie_policy_rt(char *value)
1187 if (value == NULL || strlen(value) == 0)
1188 cookie_policy = XT_DS_COOKIE_POLICY;
1189 else if (set_cookie_policy(NULL, value))
1190 return (-1);
1191 g_object_set(G_OBJECT(s_cookiejar), SOUP_COOKIE_JAR_ACCEPT_POLICY,
1192 cookie_policy, (void *)NULL);
1193 return (0);
1197 check_cookie_policy(char **tt)
1199 *tt = g_strdup("Default (depends on browser_mode):\n"
1200 "\tnormal:\talways\n"
1201 "\twhitelist:\tno3rdparty\n"
1202 "\tkiosk:\talways");
1203 if (browser_mode == XT_BM_WHITELIST &&
1204 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1205 return (1);
1206 if (browser_mode == XT_BM_NORMAL &&
1207 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1208 return (1);
1209 if (browser_mode == XT_BM_KIOSK &&
1210 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1211 return (1);
1212 return (0);
1215 char *
1216 get_cookie_policy(struct settings *s)
1218 char *r = NULL;
1220 if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1221 r = g_strdup("no3rdparty");
1222 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1223 r = g_strdup("accept");
1224 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
1225 r = g_strdup("reject");
1226 else
1227 return (NULL);
1229 return (r);
1232 char *
1233 get_default_script(struct settings *s)
1235 if (default_script[0] == '\0')
1236 return (0);
1237 return (g_strdup(default_script));
1241 set_default_script(struct settings *s, char *val)
1243 expand_tilde(default_script, sizeof default_script, val);
1244 return (0);
1248 check_default_script(char **tt)
1250 *tt = g_strdup("Default: (empty)");
1251 return (g_strcmp0(default_script, XT_DS_DEFAULT_SCRIPT));
1255 set_default_script_rt(char *value)
1257 if (value == NULL || strlen(value) == 0)
1258 return set_default_script(NULL, "");
1259 return (set_default_script(NULL, value));
1263 set_do_not_track(char *value)
1265 int tmp;
1266 const char *errstr;
1268 if (value == NULL || strlen(value) == 0)
1269 do_not_track = XT_DS_DO_NOT_TRACK;
1270 else {
1271 tmp = strtonum(value, 0, 1, &errstr);
1272 if (errstr)
1273 return (-1);
1274 do_not_track = tmp;
1276 return (0);
1280 check_do_not_track(char **tt)
1282 *tt = g_strdup("Default (depends on browser_mode):\n"
1283 "\tnormal:\tDisabled\n"
1284 "\twhitelist:\tEnabled\n"
1285 "\tkiosk:\tDisabled");
1286 if (browser_mode == XT_BM_WHITELIST && do_not_track != 1)
1287 return (1);
1288 if (browser_mode == XT_BM_NORMAL && do_not_track != 0)
1289 return (1);
1290 if (browser_mode == XT_BM_KIOSK && do_not_track != 0)
1291 return (1);
1292 return (0);
1295 char *
1296 get_download_dir(struct settings *s)
1298 if (download_dir[0] == '\0')
1299 return (0);
1300 return (g_strdup(download_dir));
1304 set_download_dir(struct settings *s, char *val)
1306 expand_tilde(download_dir, sizeof download_dir, val);
1307 return (0);
1311 check_download_dir(char **tt)
1313 struct passwd *pwd;
1314 char buf[PATH_MAX] = {0};
1316 /* XXX this might need some additonal magic on windows */
1317 if ((pwd = getpwuid(getuid())) == NULL)
1318 return (-1);
1319 snprintf(buf, sizeof buf, "%s" PS "downloads", pwd->pw_dir);
1320 *tt = g_strdup_printf("Default: %s", buf);
1321 return (g_strcmp0(download_dir, buf));
1325 add_alias(struct settings *s, char *line)
1327 char *l, *alias;
1328 struct alias *a = NULL;
1330 if (s == NULL || line == NULL) {
1331 show_oops(NULL, "add_alias invalid parameters");
1332 return (1);
1335 l = line;
1336 a = g_malloc(sizeof(*a));
1338 if ((alias = strsep(&l, " \t,")) == NULL || l == NULL) {
1339 show_oops(NULL, "add_alias: incomplete alias definition");
1340 goto bad;
1343 /* Remove additional leading whitespace */
1344 l += (long)strspn(l, " \t");
1346 if (strlen(alias) == 0 || strlen(l) == 0) {
1347 show_oops(NULL, "add_alias: invalid alias definition");
1348 goto bad;
1351 a->a_name = g_strdup(alias);
1352 a->a_uri = g_strdup(l);
1354 DNPRINTF(XT_D_CONFIG, "add_alias: %s for %s\n", a->a_name, a->a_uri);
1356 TAILQ_INSERT_TAIL(&aliases, a, entry);
1358 return (0);
1359 bad:
1360 if (a)
1361 g_free(a);
1362 return (1);
1365 void
1366 walk_alias(struct settings *s,
1367 void (*cb)(struct settings *, char *, void *), void *cb_args)
1369 struct alias *a;
1370 char *str;
1372 if (s == NULL || cb == NULL) {
1373 show_oops(NULL, "walk_alias invalid parameters");
1374 return;
1377 TAILQ_FOREACH(a, &aliases, entry) {
1378 str = g_strdup_printf("%s --> %s", a->a_name, a->a_uri);
1379 cb(s, str, cb_args);
1380 g_free(str);
1385 add_mime_type(struct settings *s, char *line)
1387 char *mime_type;
1388 char *l;
1389 struct mime_type *m = NULL;
1390 int downloadfirst = 0;
1392 /* XXX this could be smarter */
1394 if (line == NULL || strlen(line) == 0) {
1395 show_oops(NULL, "add_mime_type invalid parameters");
1396 return (1);
1399 l = line;
1400 if (*l == '@') {
1401 downloadfirst = 1;
1402 l++;
1404 m = g_malloc(sizeof(*m));
1406 if ((mime_type = strsep(&l, " \t,")) == NULL || l == NULL) {
1407 show_oops(NULL, "add_mime_type: invalid mime_type");
1408 goto bad;
1410 if (mime_type[strlen(mime_type) - 1] == '*') {
1411 mime_type[strlen(mime_type) - 1] = '\0';
1412 m->mt_default = 1;
1413 } else
1414 m->mt_default = 0;
1416 if (strlen(mime_type) == 0 || strlen(l) == 0) {
1417 show_oops(NULL, "add_mime_type: invalid mime_type");
1418 goto bad;
1421 m->mt_type = g_strdup(mime_type);
1422 m->mt_action = g_strdup(l);
1423 m->mt_download = downloadfirst;
1425 DNPRINTF(XT_D_CONFIG, "add_mime_type: type %s action %s default %d\n",
1426 m->mt_type, m->mt_action, m->mt_default);
1428 TAILQ_INSERT_TAIL(&mtl, m, entry);
1430 return (0);
1431 bad:
1432 if (m)
1433 g_free(m);
1434 return (1);
1437 void
1438 walk_mime_type(struct settings *s,
1439 void (*cb)(struct settings *, char *, void *), void *cb_args)
1441 struct mime_type *m;
1442 char *str;
1444 if (s == NULL || cb == NULL) {
1445 show_oops(NULL, "walk_mime_type invalid parameters");
1446 return;
1449 TAILQ_FOREACH(m, &mtl, entry) {
1450 str = g_strdup_printf("%s%s --> %s",
1451 m->mt_type,
1452 m->mt_default ? "*" : "",
1453 m->mt_action);
1454 cb(s, str, cb_args);
1455 g_free(str);
1459 /* inherent to GTK not all keys will be caught at all times */
1460 /* XXX sort key bindings */
1461 struct key_binding keys[] = {
1462 { "command_mode", 0, 1, GDK_Escape },
1463 { "insert_mode", 0, 0, GDK_i },
1464 { "cookiejar", MOD1, 1, GDK_j },
1465 { "downloadmgr", MOD1, 1, GDK_d },
1466 { "history", MOD1, 1, GDK_h },
1467 { "print", CTRL, 1, GDK_p },
1468 { "search", 0, 0, GDK_slash },
1469 { "searchb", 0, 0, GDK_question },
1470 { "statustoggle", CTRL, 1, GDK_n },
1471 { "command", 0, 0, GDK_colon },
1472 { "qa", CTRL, 1, GDK_q },
1473 { "restart", MOD1, 1, GDK_q },
1474 { "js toggle", CTRL, 1, GDK_j },
1475 { "plugin toggle", MOD1, 1, GDK_p },
1476 { "cookie toggle", MOD1, 1, GDK_c },
1477 { "togglesrc", CTRL, 1, GDK_s },
1478 { "yankuri", 0, 0, GDK_y },
1479 { "pasteuricur", 0, 0, GDK_p },
1480 { "pasteurinew", 0, 0, GDK_P },
1481 { "toplevel toggle", 0, 1, GDK_F4 },
1482 { "help", 0, 1, GDK_F1 },
1483 { "run_script", MOD1, 1, GDK_r },
1484 { "proxy toggle", 0, 1, GDK_F2 },
1485 { "editelement", CTRL, 1, GDK_i },
1486 { "passthrough", CTRL, 1, GDK_z },
1487 { "modurl", CTRL, 1, GDK_Return },
1488 { "urlmod plus", MOD1, 1, GDK_a },
1489 { "urlmod min", MOD1, 1, GDK_A },
1491 /* search */
1492 { "searchnext", 0, 0, GDK_n },
1493 { "searchprevious", 0, 0, GDK_N },
1495 /* focus */
1496 { "focusaddress", 0, 1, GDK_F6 },
1497 { "focussearch", 0, 1, GDK_F7 },
1499 /* hinting */
1500 { "hinting", 0, 0, GDK_f },
1501 { "hinting", 0, 0, GDK_period },
1502 { "hinting_newtab", SHFT, 0, GDK_F },
1503 { "hinting_newtab", 0, 0, GDK_comma },
1505 /* custom stylesheet */
1506 { "userstyle", 0, 0, GDK_s },
1507 { "userstyle_global", SHFT, 0, GDK_S },
1509 /* navigation */
1510 { "goback", 0, 0, GDK_BackSpace },
1511 { "goback", MOD1, 1, GDK_Left },
1512 { "goforward", SHFT, 1, GDK_BackSpace },
1513 { "goforward", MOD1, 1, GDK_Right },
1514 { "reload", 0, 1, GDK_F5 },
1515 { "reload", CTRL, 1, GDK_r },
1516 { "reload", CTRL, 1, GDK_l },
1517 { "favorites", MOD1, 1, GDK_f },
1519 /* vertical movement */
1520 { "scrolldown", 0, 0, GDK_j },
1521 { "scrolldown", 0, 0, GDK_Down },
1522 { "scrollup", 0, 0, GDK_Up },
1523 { "scrollup", 0, 0, GDK_k },
1524 { "scrollbottom", 0, 0, GDK_G },
1525 { "scrollbottom", 0, 0, GDK_End },
1526 { "scrolltop", 0, 0, GDK_Home },
1527 { "scrollpagedown", 0, 0, GDK_space },
1528 { "scrollpagedown", CTRL, 1, GDK_f },
1529 { "scrollhalfdown", CTRL, 1, GDK_d },
1530 { "scrollpagedown", 0, 0, GDK_Page_Down },
1531 { "scrollpageup", 0, 0, GDK_Page_Up },
1532 { "scrollpageup", CTRL, 1, GDK_b },
1533 { "scrollhalfup", CTRL, 1, GDK_u },
1534 /* horizontal movement */
1535 { "scrollright", 0, 0, GDK_l },
1536 { "scrollright", 0, 0, GDK_Right },
1537 { "scrollleft", 0, 0, GDK_Left },
1538 { "scrollleft", 0, 0, GDK_h },
1539 { "scrollfarright", 0, 0, GDK_dollar },
1540 { "scrollfarleft", 0, 0, GDK_0 },
1542 /* tabs */
1543 { "tabnew", CTRL, 1, GDK_t },
1544 { "999tabnew", CTRL, 1, GDK_T },
1545 { "tabclose", CTRL, 1, GDK_w },
1546 { "tabundoclose", 0, 0, GDK_U },
1547 { "tabnext 1", CTRL, 1, GDK_1 },
1548 { "tabnext 2", CTRL, 1, GDK_2 },
1549 { "tabnext 3", CTRL, 1, GDK_3 },
1550 { "tabnext 4", CTRL, 1, GDK_4 },
1551 { "tabnext 5", CTRL, 1, GDK_5 },
1552 { "tabnext 6", CTRL, 1, GDK_6 },
1553 { "tabnext 7", CTRL, 1, GDK_7 },
1554 { "tabnext 8", CTRL, 1, GDK_8 },
1555 { "tabnext 9", CTRL, 1, GDK_9 },
1556 { "tabfirst", CTRL, 1, GDK_less },
1557 { "tablast", CTRL, 1, GDK_greater },
1558 { "tabprevious", CTRL, 1, GDK_Left },
1559 { "tabnext", CTRL, 1, GDK_Right },
1560 { "focusout", CTRL, 1, GDK_minus },
1561 { "focusin", CTRL, 1, GDK_plus },
1562 { "focusin", CTRL, 1, GDK_equal },
1563 { "focusreset", CTRL, 1, GDK_0 },
1565 /* command aliases (handy when -S flag is used) */
1566 { ":open ", 0, 1, GDK_F9 },
1567 { ":open <uri>", 0, 1, GDK_F10 },
1568 { ":tabnew ", 0, 1, GDK_F11 },
1569 { ":tabnew <uri>", 0, 1, GDK_F12 },
1572 void
1573 walk_kb(struct settings *s,
1574 void (*cb)(struct settings *, char *, void *), void *cb_args)
1576 struct key_binding *k;
1577 char str[1024];
1579 if (s == NULL || cb == NULL) {
1580 show_oops(NULL, "walk_kb invalid parameters");
1581 return;
1584 TAILQ_FOREACH(k, &kbl, entry) {
1585 if (k->cmd == NULL)
1586 continue;
1587 str[0] = '\0';
1589 /* sanity */
1590 if (gdk_keyval_name(k->key) == NULL)
1591 continue;
1593 strlcat(str, k->cmd, sizeof str);
1594 strlcat(str, ",", sizeof str);
1596 if (k->mask & GDK_SHIFT_MASK)
1597 strlcat(str, "S-", sizeof str);
1598 if (k->mask & GDK_CONTROL_MASK)
1599 strlcat(str, "C-", sizeof str);
1600 if (k->mask & GDK_MOD1_MASK)
1601 strlcat(str, "M1-", sizeof str);
1602 if (k->mask & GDK_MOD2_MASK)
1603 strlcat(str, "M2-", sizeof str);
1604 if (k->mask & GDK_MOD3_MASK)
1605 strlcat(str, "M3-", sizeof str);
1606 if (k->mask & GDK_MOD4_MASK)
1607 strlcat(str, "M4-", sizeof str);
1608 if (k->mask & GDK_MOD5_MASK)
1609 strlcat(str, "M5-", sizeof str);
1611 strlcat(str, gdk_keyval_name(k->key), sizeof str);
1612 cb(s, str, cb_args);
1616 void
1617 init_keybindings(void)
1619 int i;
1620 struct key_binding *k;
1622 for (i = 0; i < LENGTH(keys); i++) {
1623 k = g_malloc0(sizeof *k);
1624 k->cmd = keys[i].cmd;
1625 k->mask = keys[i].mask;
1626 k->use_in_entry = keys[i].use_in_entry;
1627 k->key = keys[i].key;
1628 TAILQ_INSERT_HEAD(&kbl, k, entry);
1630 DNPRINTF(XT_D_KEYBINDING, "init_keybindings: added: %s\n",
1631 k->cmd ? k->cmd : "unnamed key");
1635 void
1636 keybinding_clearall(void)
1638 struct key_binding *k, *next;
1640 for (k = TAILQ_FIRST(&kbl); k; k = next) {
1641 next = TAILQ_NEXT(k, entry);
1642 if (k->cmd == NULL)
1643 continue;
1645 DNPRINTF(XT_D_KEYBINDING, "keybinding_clearall: %s\n",
1646 k->cmd ? k->cmd : "unnamed key");
1647 TAILQ_REMOVE(&kbl, k, entry);
1648 g_free(k);
1653 keybinding_set(char *cmd, char *key, int use_in_entry)
1655 struct key_binding *k;
1656 guint keyval, mask = 0;
1657 int i;
1659 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: %s %s\n", cmd, key);
1661 /* Keys which are to be used in entry have been prefixed with an
1662 * exclamation mark. */
1663 if (use_in_entry)
1664 key++;
1666 /* find modifier keys */
1667 if (strstr(key, "S-"))
1668 mask |= GDK_SHIFT_MASK;
1669 if (strstr(key, "C-"))
1670 mask |= GDK_CONTROL_MASK;
1671 if (strstr(key, "M1-"))
1672 mask |= GDK_MOD1_MASK;
1673 if (strstr(key, "M2-"))
1674 mask |= GDK_MOD2_MASK;
1675 if (strstr(key, "M3-"))
1676 mask |= GDK_MOD3_MASK;
1677 if (strstr(key, "M4-"))
1678 mask |= GDK_MOD4_MASK;
1679 if (strstr(key, "M5-"))
1680 mask |= GDK_MOD5_MASK;
1682 /* find keyname */
1683 for (i = strlen(key) - 1; i > 0; i--)
1684 if (key[i] == '-')
1685 key = &key[i + 1];
1687 /* validate keyname */
1688 keyval = gdk_keyval_from_name(key);
1689 if (keyval == GDK_VoidSymbol) {
1690 warnx("invalid keybinding name %s", key);
1691 return (1);
1693 /* must run this test too, gtk+ doesn't handle 10 for example */
1694 if (gdk_keyval_name(keyval) == NULL) {
1695 warnx("invalid keybinding name %s", key);
1696 return (1);
1699 /* Remove eventual dupes. */
1700 TAILQ_FOREACH(k, &kbl, entry)
1701 if (k->key == keyval && k->mask == mask) {
1702 TAILQ_REMOVE(&kbl, k, entry);
1703 g_free(k);
1704 break;
1707 if (strcmp(cmd, "unbind") == 0) {
1708 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: just unbinding: %s\n",
1709 gdk_keyval_name(keyval));
1710 printf("keybinding_set: just unbinding: %s\n",
1711 gdk_keyval_name(keyval));
1712 return (0);
1715 /* add keyname */
1716 k = g_malloc0(sizeof *k);
1717 k->cmd = g_strdup(cmd);
1718 k->mask = mask;
1719 k->use_in_entry = use_in_entry;
1720 k->key = keyval;
1722 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: %s 0x%x %d 0x%x\n",
1723 k->cmd,
1724 k->mask,
1725 k->use_in_entry,
1726 k->key);
1727 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: adding: %s %s\n",
1728 k->cmd, gdk_keyval_name(keyval));
1730 TAILQ_INSERT_HEAD(&kbl, k, entry);
1732 return (0);
1736 cmd_alias_add(char *alias, char *cmd)
1738 struct cmd_alias *c;
1740 /* XXX */
1741 TAILQ_FOREACH(c, &cal, entry)
1742 if (!strcmp((alias), c->alias)) {
1743 TAILQ_REMOVE(&cal, c, entry);
1744 g_free(c);
1747 c = g_malloc(sizeof (struct cmd_alias));
1748 c->alias = g_strchug(g_strdup(alias));
1749 c->cmd = g_strchug(g_strdup(cmd));
1751 DNPRINTF(XT_D_CUSTOM_URI, "cmd_alias_add: %s %s\n", c->alias, c->cmd);
1753 TAILQ_INSERT_HEAD(&cal, c, entry);
1754 return (0);
1758 custom_uri_add(char *uri, char *cmd)
1760 struct custom_uri *u;
1762 TAILQ_FOREACH(u, &cul, entry)
1763 if (!strcmp((uri), u->uri) && !strcmp(cmd, u->cmd)) {
1764 TAILQ_REMOVE(&cul, u, entry);
1765 g_free(u);
1768 u = g_malloc(sizeof (struct custom_uri));
1769 u->uri = g_strdup(uri);
1770 expand_tilde(u->cmd, sizeof u->cmd, cmd);
1772 DNPRINTF(XT_D_CUSTOM_URI, "custom_uri_add: %s %s\n", u->uri, u->cmd);
1774 /* don't check here if the script is valid, wait until running it */
1775 TAILQ_INSERT_HEAD(&cul, u, entry);
1776 return (0);
1780 add_kb(struct settings *s, char *entry)
1782 char *kb, *key;
1784 DNPRINTF(XT_D_KEYBINDING, "add_kb: %s\n", entry);
1786 /* clearall is special */
1787 if (!strcmp(entry, "clearall")) {
1788 keybinding_clearall();
1789 return (0);
1792 kb = strstr(entry, ",");
1793 if (kb == NULL)
1794 return (1);
1795 *kb = '\0';
1796 key = kb + 1;
1798 return (keybinding_set(entry, key, key[0] == '!'));
1802 add_custom_uri(struct settings *s, char *entry)
1804 char *uri, *cmd;
1806 DNPRINTF(XT_D_CUSTOM_URI, "add_custom_uri: %s\n", entry);
1808 uri = strstr(entry, ",");
1809 if (uri == NULL)
1810 return (1);
1811 *uri = '\0';
1812 cmd = uri + 1;
1814 return (custom_uri_add(entry, cmd));
1817 void
1818 walk_custom_uri(struct settings *s,
1819 void (*cb)(struct settings *, char *, void *), void *cb_args)
1821 struct custom_uri *u;
1822 char buf[1024];
1824 if (s == NULL || cb == NULL) {
1825 show_oops(NULL, "walk_custom_uri invalid parameters");
1826 return;
1829 TAILQ_FOREACH(u, &cul, entry) {
1830 snprintf(buf, sizeof buf, "%s,%s", u->uri, u->cmd);
1831 cb(s, buf, cb_args);
1836 add_ua(struct settings *s, char *value)
1838 struct user_agent *ua;
1839 static int ua_count = 0;
1841 ua = g_malloc(sizeof *ua);
1842 ua->id = ua_count++;
1843 ua->value = g_strdup(value);
1845 RB_INSERT(user_agent_list, &ua_list, ua);
1847 return (0);
1851 void
1852 walk_ua(struct settings *s,
1853 void (*cb)(struct settings *, char *, void *), void *cb_args)
1855 struct user_agent *ua;
1857 if (s == NULL || cb == NULL) {
1858 show_oops(NULL, "walk_ua invalid parameters");
1859 return;
1862 RB_FOREACH(ua, user_agent_list, &ua_list)
1863 cb(s, ua->value, cb_args);
1867 add_force_https(struct settings *s, char *value)
1869 if (g_str_has_prefix(value, "re:")) {
1870 value = &value[3];
1871 wl_add(value, &force_https, XT_WL_PERSISTENT | XT_WL_REGEX);
1872 } else
1873 wl_add(value, &force_https, XT_WL_PERSISTENT);
1874 return (0);
1878 add_http_accept(struct settings *s, char *value)
1880 struct http_accept *ha;
1881 static int ha_count = 0;
1883 ha = g_malloc(sizeof *ha);
1884 ha->id = ha_count++;
1885 ha->value = g_strdup(value);
1887 RB_INSERT(http_accept_list, &ha_list, ha);
1889 return (0);
1892 void
1893 walk_http_accept(struct settings *s,
1894 void (*cb)(struct settings *, char *, void *), void *cb_args)
1896 struct http_accept *ha;
1898 if (s == NULL || cb == NULL) {
1899 show_oops(NULL, "%s: invalid parameters", __func__);
1900 return;
1903 RB_FOREACH(ha, http_accept_list, &ha_list)
1904 cb(s, ha->value, cb_args);
1908 add_cmd_alias(struct settings *s, char *entry)
1910 char *alias, *cmd;
1912 DNPRINTF(XT_D_CMD_ALIAS, "add_cmd_alias: %s\n", entry);
1914 alias = strstr(entry, ",");
1915 if (alias == NULL)
1916 return (1);
1917 *alias = '\0';
1918 cmd = alias + 1;
1920 return (cmd_alias_add(entry, cmd));
1923 void
1924 walk_cmd_alias(struct settings *s,
1925 void (*cb)(struct settings *, char *, void *), void *cb_args)
1927 struct cmd_alias *c;
1928 char buf[1024];
1930 if (s == NULL || cb == NULL) {
1931 show_oops(NULL, "walk_cmd_alias invalid parameters");
1932 return;
1935 TAILQ_FOREACH(c, &cal, entry) {
1936 snprintf(buf, sizeof buf, "%s --> %s", c->alias, c->cmd);
1937 cb(s, buf, cb_args);
1942 set_allow_insecure_content(char *value)
1944 struct tab *t;
1945 int tmp;
1946 const char *errstr;
1948 if (value == NULL || strlen(value) == 0)
1949 allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
1950 else {
1951 tmp = strtonum(value, 0, 1, &errstr);
1952 if (errstr)
1953 return (-1);
1954 allow_insecure_content = tmp;
1956 TAILQ_FOREACH(t, &tabs, entry)
1957 if (is_g_object_setting(G_OBJECT(t->settings),
1958 "enable-display-of-insecure-content")) {
1959 g_object_set(G_OBJECT(t->settings),
1960 "enable-display-of-insecure-content",
1961 allow_insecure_content, (char *)NULL);
1962 webkit_web_view_set_settings(t->wv, t->settings);
1964 return (0);
1968 check_allow_insecure_content(char **tt)
1970 *tt = g_strdup("Default (depends on browser_mode):\n"
1971 "\tnormal:\tEnabled\n"
1972 "\twhitelist:\tDisabled\n"
1973 "\tkiosk:\tEnabled");
1974 if (browser_mode == XT_BM_NORMAL && allow_insecure_content != 1)
1975 return (1);
1976 if (browser_mode == XT_BM_WHITELIST && allow_insecure_content != 0)
1977 return (1);
1978 if (browser_mode == XT_BM_KIOSK && allow_insecure_content != 1)
1979 return (1);
1980 return (0);
1984 set_allow_insecure_scripts(char *value)
1986 struct tab *t;
1987 int tmp;
1988 const char *errstr;
1990 if (value == NULL || strlen(value) == 0)
1991 allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
1992 else {
1993 tmp = strtonum(value, 0, 1, &errstr);
1994 if (errstr)
1995 return (-1);
1996 allow_insecure_scripts = tmp;
1998 TAILQ_FOREACH(t, &tabs, entry)
1999 if (is_g_object_setting(G_OBJECT(t->settings),
2000 "enable-running-of-insecure-content")) {
2001 g_object_set(G_OBJECT(t->settings),
2002 "enable-running-of-insecure-content",
2003 allow_insecure_scripts, (char *)NULL);
2004 webkit_web_view_set_settings(t->wv, t->settings);
2006 return (0);
2010 check_allow_insecure_scripts(char **tt)
2012 *tt = g_strdup("Default (depends on browser_mode):\n"
2013 "\tnormal:\tEnabled\n"
2014 "\twhitelist:\tDisabled\n"
2015 "\tkiosk:\tEnabled");
2016 if (browser_mode == XT_BM_NORMAL && allow_insecure_scripts != 1)
2017 return (1);
2018 if (browser_mode == XT_BM_WHITELIST && allow_insecure_scripts != 0)
2019 return (1);
2020 if (browser_mode == XT_BM_KIOSK && allow_insecure_scripts != 1)
2021 return (1);
2022 return (0);
2026 set_auto_load_images(char *value)
2028 struct tab *t;
2029 int tmp;
2030 const char *errstr;
2032 if (value == NULL || strlen(value) == 0)
2033 auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
2034 else {
2035 tmp = strtonum(value, 0, 1, &errstr);
2036 if (errstr)
2037 return (-1);
2038 auto_load_images = tmp;
2040 TAILQ_FOREACH(t, &tabs, entry) {
2041 g_object_set(G_OBJECT(t->settings),
2042 "auto-load-images", auto_load_images, (char *)NULL);
2043 webkit_web_view_set_settings(t->wv, t->settings);
2045 return (0);
2049 check_auto_load_images(char **tt)
2051 *tt = g_strdup_printf("Default: %s",
2052 XT_DS_AUTO_LOAD_IMAGES ? "Enabled" : "Disabled");
2053 return (auto_load_images != XT_DS_AUTO_LOAD_IMAGES);
2057 set_autofocus_onload(char *value)
2059 int tmp;
2060 const char *errstr;
2062 if (value == NULL || strlen(value) == 0)
2063 autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
2064 else {
2065 tmp = strtonum(value, 0, 1, &errstr);
2066 if (errstr)
2067 return (-1);
2068 autofocus_onload = tmp;
2070 return (0);
2074 check_autofocus_onload(char **tt)
2076 *tt = g_strdup_printf("Default: %s",
2077 XT_DS_AUTOFOCUS_ONLOAD ? "Enabled" : "Disabled");
2078 return (autofocus_onload != XT_DS_AUTOFOCUS_ONLOAD);
2082 set_ctrl_click_focus(char *value)
2084 int tmp;
2085 const char *errstr;
2087 if (value == NULL || strlen(value) == 0)
2088 ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS;
2089 else {
2090 tmp = strtonum(value, 0, 1, &errstr);
2091 if (errstr)
2092 return (-1);
2093 ctrl_click_focus = tmp;
2095 return (0);
2099 check_ctrl_click_focus(char **tt)
2101 *tt = g_strdup_printf("Default: %s",
2102 XT_DS_CTRL_CLICK_FOCUS ? "Enabled" : "Disabled");
2103 return (ctrl_click_focus != XT_DS_CTRL_CLICK_FOCUS);
2107 set_download_notifications(char *value)
2109 int tmp;
2110 const char *errstr;
2112 if (value == NULL || strlen(value) == 0)
2113 download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
2114 else {
2115 tmp = strtonum(value, 0, 1, &errstr);
2116 if (errstr)
2117 return (-1);
2118 download_notifications = tmp;
2120 return (0);
2124 check_download_notifications(char **tt)
2126 *tt = g_strdup_printf("Default: %s",
2127 XT_DS_DOWNLOAD_NOTIFICATIONS ? "Enabled" : "Disabled");
2128 return (download_notifications != XT_DS_DOWNLOAD_NOTIFICATIONS);
2132 set_enable_autoscroll(char *value)
2134 int tmp;
2135 const char *errstr;
2137 if (value == NULL || strlen(value) == 0)
2138 enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
2139 else {
2140 tmp = strtonum(value, 0, 1, &errstr);
2141 if (errstr)
2142 return (-1);
2143 enable_autoscroll = tmp;
2145 return (0);
2149 check_enable_autoscroll(char **tt)
2151 *tt = g_strdup_printf("Default: %s",
2152 XT_DS_ENABLE_AUTOSCROLL ? "Enabled" : "Disabled");
2153 return (enable_autoscroll != XT_DS_ENABLE_AUTOSCROLL);
2157 set_enable_cache(char *value)
2159 int tmp;
2160 const char *errstr;
2162 if (value == NULL || strlen(value) == 0)
2163 enable_cache = 1;
2164 else {
2165 tmp = (int)strtonum(value, 0, 1, &errstr);
2166 if (errstr)
2167 return (-1);
2168 enable_cache = tmp;
2170 if (enable_cache)
2171 webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
2172 else
2173 webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
2175 return (0);
2179 check_enable_cache(char **tt)
2181 *tt = g_strdup_printf("Default: Disabled");
2183 return (enable_cache);
2187 set_enable_cookie_whitelist(char *value)
2189 int tmp;
2190 const char *errstr;
2192 if (value == NULL || strlen(value) == 0)
2193 enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
2194 else {
2195 tmp = strtonum(value, 0, 1, &errstr);
2196 if (errstr)
2197 return (-1);
2198 enable_cookie_whitelist = tmp;
2200 return (0);
2204 check_enable_cookie_whitelist(char **tt)
2206 *tt = g_strdup("Default (depends on browser_mode):\n"
2207 "\tnormal:\tDisabled\n"
2208 "\twhitelist:\tEnabled\n"
2209 "\tkiosk:\tDisabled");
2210 if (browser_mode == XT_BM_WHITELIST && enable_cookie_whitelist != 1)
2211 return (1);
2212 if (browser_mode == XT_BM_NORMAL && enable_cookie_whitelist != 0)
2213 return (1);
2214 if (browser_mode == XT_BM_KIOSK && enable_cookie_whitelist != 0)
2215 return (1);
2216 return (0);
2220 set_enable_js_autorun(char *value)
2222 int tmp;
2223 const char *errstr;
2225 if (value == NULL || strlen(value) == 0)
2226 enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
2227 else {
2228 tmp = strtonum(value, 0, 1, &errstr);
2229 if (errstr)
2230 return (-1);
2231 enable_js_autorun = tmp;
2233 return (0);
2237 check_enable_js_autorun(char **tt)
2239 *tt = g_strdup_printf("Default: %s",
2240 XT_DS_ENABLE_JS_AUTORUN ? "Enabled" : "Disabled");
2241 return (enable_js_autorun != XT_DS_ENABLE_JS_AUTORUN);
2245 set_enable_js_whitelist(char *value)
2247 int tmp;
2248 const char *errstr;
2250 if (value == NULL || strlen(value) == 0)
2251 enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
2252 else {
2253 tmp = strtonum(value, 0, 1, &errstr);
2254 if (errstr)
2255 return (-1);
2256 enable_js_whitelist = tmp;
2258 return (0);
2262 check_enable_js_whitelist(char **tt)
2264 *tt = g_strdup("Default (depends on browser_mode):\n"
2265 "\tnormal:\tDisabled\n"
2266 "\twhitelist:\tEnabled\n"
2267 "\tkiosk:\tDisabled");
2268 if (browser_mode == XT_BM_WHITELIST && enable_js_whitelist != 1)
2269 return (1);
2270 if (browser_mode == XT_BM_NORMAL && enable_js_whitelist != 0)
2271 return (1);
2272 if (browser_mode == XT_BM_KIOSK && enable_js_whitelist != 0)
2273 return (1);
2274 return (0);
2278 set_enable_favicon_entry(char *value)
2280 int tmp;
2281 const char *errstr;
2283 if (value == NULL || strlen(value) == 0)
2284 enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
2285 else {
2286 tmp = strtonum(value, 0, 1, &errstr);
2287 if (errstr)
2288 return (-1);
2289 enable_favicon_entry = tmp;
2291 return (0);
2295 check_enable_favicon_entry(char **tt)
2297 *tt = g_strdup_printf("Default: %s",
2298 XT_DS_ENABLE_FAVICON_ENTRY ? "Enabled" : "Disabled");
2299 return (enable_favicon_entry != XT_DS_ENABLE_FAVICON_ENTRY);
2303 set_enable_favicon_tabs(char *value)
2305 int tmp;
2306 const char *errstr;
2308 if (value == NULL || strlen(value) == 0)
2309 enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
2310 else {
2311 tmp = strtonum(value, 0, 1, &errstr);
2312 if (errstr)
2313 return (-1);
2314 enable_favicon_tabs = tmp;
2316 return (0);
2320 check_enable_favicon_tabs(char **tt)
2322 *tt = g_strdup_printf("Default: %s",
2323 XT_DS_ENABLE_FAVICON_TABS ? "Enabled" : "Disabled");
2324 return (enable_favicon_tabs != XT_DS_ENABLE_FAVICON_TABS);
2328 set_enable_localstorage(char *value)
2330 struct tab *t;
2331 int tmp;
2332 const char *errstr;
2334 if (value == NULL || strlen(value) == 0)
2335 enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
2336 else {
2337 tmp = strtonum(value, 0, 1, &errstr);
2338 if (errstr)
2339 return (-1);
2340 enable_localstorage = tmp;
2342 TAILQ_FOREACH(t, &tabs, entry)
2343 g_object_set(G_OBJECT(t->settings),
2344 "enable-html5-local-storage", enable_localstorage,
2345 (char *)NULL);
2346 return (0);
2350 check_enable_localstorage(char **tt)
2352 *tt = g_strdup("Default (depends on browser_mode):\n"
2353 "\tnormal:\tEnabled\n"
2354 "\twhitelist:\tDisabled\n"
2355 "\tkiosk:\tEnabled");
2356 if (browser_mode == XT_BM_WHITELIST && enable_localstorage != 0)
2357 return (1);
2358 if (browser_mode == XT_BM_NORMAL && enable_localstorage != 1)
2359 return (1);
2360 if (browser_mode == XT_BM_KIOSK && enable_localstorage != 1)
2361 return (1);
2362 return (0);
2366 set_enable_plugins(char *value)
2368 struct tab *t;
2369 int tmp;
2370 const char *errstr;
2372 if (value == NULL || strlen(value) == 0)
2373 enable_plugins = XT_DS_ENABLE_PLUGINS;
2374 else {
2375 tmp = strtonum(value, 0, 1, &errstr);
2376 if (errstr)
2377 return (-1);
2378 enable_plugins = tmp;
2380 TAILQ_FOREACH(t, &tabs, entry)
2381 g_object_set(G_OBJECT(t->settings), "enable-plugins",
2382 enable_plugins, (char *)NULL);
2383 return (0);
2387 check_enable_plugins(char **tt)
2389 *tt = g_strdup("Default (depends on browser_mode):\n"
2390 "\tnormal:\tEnabled\n"
2391 "\twhitelist:\tDisabled\n"
2392 "\tkiosk:\tEnabled");
2393 if (browser_mode == XT_BM_WHITELIST && enable_plugins != 0)
2394 return (1);
2395 if (browser_mode == XT_BM_NORMAL && enable_plugins != 1)
2396 return (1);
2397 if (browser_mode == XT_BM_KIOSK && enable_plugins != 1)
2398 return (1);
2399 return (0);
2403 set_enable_plugin_whitelist(char *value)
2405 int tmp;
2406 const char *errstr;
2408 if (value == NULL || strlen(value) == 0)
2409 enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
2410 else {
2411 tmp = strtonum(value, 0, 1, &errstr);
2412 if (errstr)
2413 return (-1);
2414 enable_plugin_whitelist = tmp;
2416 return (0);
2420 check_enable_plugin_whitelist(char **tt)
2422 *tt = g_strdup("Default (depends on browser_mode):\n"
2423 "\tnormal:\tDisabled\n"
2424 "\twhitelist:\tEnabled\n"
2425 "\tkiosk:\tDisabled");
2426 if (browser_mode == XT_BM_WHITELIST && enable_plugin_whitelist != 1)
2427 return (1);
2428 if (browser_mode == XT_BM_NORMAL && enable_plugin_whitelist != 0)
2429 return (1);
2430 if (browser_mode == XT_BM_KIOSK && enable_plugin_whitelist != 0)
2431 return (1);
2432 return (0);
2436 set_enable_scripts(char *value)
2438 struct tab *t;
2439 int tmp;
2440 const char *errstr;
2442 if (value == NULL || strlen(value) == 0)
2443 enable_scripts = XT_DS_ENABLE_SCRIPTS;
2444 else {
2445 tmp = strtonum(value, 0, 1, &errstr);
2446 if (errstr)
2447 return (-1);
2448 enable_scripts = tmp;
2450 TAILQ_FOREACH(t, &tabs, entry)
2451 g_object_set(G_OBJECT(t->settings), "enable-scripts",
2452 enable_scripts, (char *)NULL);
2453 return (0);
2457 check_enable_scripts(char **tt)
2459 *tt = g_strdup("Default (depends on browser_mode):\n"
2460 "\tnormal:\tEnabled\n"
2461 "\twhitelist:\tDisabled\n"
2462 "\tkiosk:\tEnabled");
2463 if (browser_mode == XT_BM_WHITELIST && enable_scripts != 0)
2464 return (1);
2465 if (browser_mode == XT_BM_NORMAL && enable_scripts != 1)
2466 return (1);
2467 if (browser_mode == XT_BM_KIOSK && enable_scripts != 1)
2468 return (1);
2469 return (0);
2473 check_enable_socket(char **tt)
2475 *tt = g_strdup("Default: Disabled");
2476 return (enable_socket != 0);
2480 set_enable_spell_checking(char *value)
2482 struct tab *t;
2483 int tmp;
2484 const char *errstr;
2486 if (value == NULL || strlen(value) == 0)
2487 enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
2488 else {
2489 tmp = strtonum(value, 0, 1, &errstr);
2490 if (errstr)
2491 return (-1);
2492 enable_spell_checking = tmp;
2494 TAILQ_FOREACH(t, &tabs, entry)
2495 g_object_set(G_OBJECT(t->settings), "enable_spell_checking",
2496 enable_spell_checking, (char *)NULL);
2497 return (0);
2501 check_enable_spell_checking(char **tt)
2503 *tt = g_strdup_printf("Default: %s",
2504 XT_DS_ENABLE_SPELL_CHECKING ? "Enabled" : "Disabled");
2505 return (enable_spell_checking != XT_DS_ENABLE_SPELL_CHECKING);
2509 set_enable_strict_transport(char *value)
2511 int tmp;
2512 const char *errstr;
2514 if (value == NULL || strlen(value) == 0)
2515 enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
2516 else {
2517 tmp = strtonum(value, 0, 1, &errstr);
2518 if (errstr)
2519 return (-1);
2520 enable_strict_transport = tmp;
2522 return (0);
2526 check_enable_strict_transport(char **tt)
2528 *tt = g_strdup_printf("Default: %s",
2529 XT_DS_ENABLE_STRICT_TRANSPORT ? "Enabled" : "Disabled");
2530 return (enable_strict_transport != XT_DS_ENABLE_STRICT_TRANSPORT);
2533 #if 0
2535 * XXX: this is currently broken. Need to figure out what to do with
2536 * this. Problemm is set_encoding will refresh the tab it's run on, so
2537 * we can either put a big fat warning in the manpage and refresh every
2538 * single open tab with the new encoding or scrap it as a runtime
2539 * setting.
2542 set_encoding_rt(char *value)
2544 struct karg args = {0};
2546 if (value == NULL || strlen(value) == 0)
2547 return (-1);
2548 if (encoding)
2549 g_free(encoding);
2550 encoding = g_strdup(value);
2551 args.s = encoding;
2552 set_encoding(get_current_tab(), &args);
2553 return (0);
2555 #endif
2558 check_encoding(char **tt)
2560 *tt = g_strdup_printf("Default: %s", XT_DS_ENCODING);
2561 return (g_strcmp0(encoding, XT_DS_ENCODING));
2565 check_gnutls_search_string(char **tt)
2567 *tt = g_strdup("Default: (empty)");
2568 return (g_strcmp0(gnutls_priority_string,
2569 XT_DS_GNUTLS_PRIORITY_STRING));
2573 set_gnutls_priority_string(struct settings *s, char *value)
2575 return (!g_setenv("G_TLS_GNUTLS_PRIORITY", value, FALSE));
2578 char *
2579 get_gnutls_priority_string(struct settings *s)
2581 return (g_strdup(g_getenv("G_TLS_GNUTLS_PRIORITY")));
2585 set_guess_search(char *value)
2587 int tmp;
2588 const char *errstr;
2590 if (value == NULL || strlen(value) == 0)
2591 guess_search = XT_DS_GUESS_SEARCH;
2592 else {
2593 tmp = strtonum(value, 0, 1, &errstr);
2594 if (errstr)
2595 return (-1);
2596 guess_search = tmp;
2598 return (0);
2602 check_guess_search(char **tt)
2604 *tt = g_strdup_printf("Default: %s",
2605 XT_DS_GUESS_SEARCH ? "Enabled" : "Disabled");
2606 return (guess_search != XT_DS_GUESS_SEARCH);
2610 set_js_auto_open_windows(char *value)
2612 int tmp;
2613 const char *errstr;
2614 struct tab *t;
2616 if (value == NULL || strlen(value) == 0)
2617 js_auto_open_windows = XT_DS_JS_AUTO_OPEN_WINDOWS;
2618 else {
2619 tmp = (int)strtonum(value, 0, 1, &errstr);
2620 if (errstr)
2621 return (-1);
2622 js_auto_open_windows = tmp;
2624 TAILQ_FOREACH(t, &tabs, entry)
2625 g_object_set(G_OBJECT(t->settings),
2626 "javascript-can-open-windows-automatically",
2627 js_auto_open_windows, NULL);
2628 return (0);
2632 check_js_auto_open_windows(char **tt)
2634 *tt = g_strdup("Default: Enabled");
2635 return (js_auto_open_windows != XT_DS_JS_AUTO_OPEN_WINDOWS);
2638 char *
2639 get_referer(struct settings *s)
2641 if (referer_mode == XT_REFERER_ALWAYS)
2642 return (g_strdup("always"));
2643 if (referer_mode == XT_REFERER_NEVER)
2644 return (g_strdup("never"));
2645 if (referer_mode == XT_REFERER_SAME_DOMAIN)
2646 return (g_strdup("same-domain"));
2647 if (referer_mode == XT_REFERER_SAME_FQDN)
2648 return (g_strdup("same-fqdn"));
2649 if (referer_mode == XT_REFERER_CUSTOM)
2650 return (g_strdup(referer_custom));
2651 return (NULL);
2655 set_referer(struct settings *s, char *value)
2657 if (referer_custom) {
2658 g_free(referer_custom);
2659 referer_custom = NULL;
2662 if (!strcmp(value, "always"))
2663 referer_mode = XT_REFERER_ALWAYS;
2664 else if (!strcmp(value, "never"))
2665 referer_mode = XT_REFERER_NEVER;
2666 else if (!strcmp(value, "same-domain"))
2667 referer_mode = XT_REFERER_SAME_DOMAIN;
2668 else if (!strcmp(value, "same-fqdn"))
2669 referer_mode = XT_REFERER_SAME_FQDN;
2670 else if (!valid_url_type(value)) {
2671 referer_mode = XT_REFERER_CUSTOM;
2672 referer_custom = g_strdup(value);
2673 } else {
2674 /* we've already free'd the custom referer */
2675 if (referer_mode == XT_REFERER_CUSTOM)
2676 referer_mode = XT_REFERER_NEVER;
2677 return (1);
2680 return (0);
2684 set_referer_rt(char *value)
2686 if (value == NULL || strlen(value) == 0) {
2687 if (referer_custom)
2688 g_free(referer_custom);
2689 referer_custom = g_strdup(XT_DS_REFERER_CUSTOM);
2690 referer_mode = XT_DS_REFERER_MODE;
2691 return (0);
2693 return (set_referer(NULL, value));
2697 check_referer(char **tt)
2699 *tt = g_strdup("Default (depends on browser_mode):\n"
2700 "\tnormal:\talways\n"
2701 "\twhitelist:\tsame-domain\n"
2702 "\tkiosk:\talways");
2703 if (browser_mode == XT_BM_WHITELIST &&
2704 referer_mode != XT_REFERER_SAME_DOMAIN)
2705 return (1);
2706 if (browser_mode == XT_BM_NORMAL && referer_mode != XT_REFERER_ALWAYS)
2707 return (1);
2708 if (browser_mode == XT_BM_KIOSK && referer_mode != XT_REFERER_ALWAYS)
2709 return (1);
2710 return (0);
2713 char *
2714 get_ssl_ca_file(struct settings *s)
2716 if (strlen(ssl_ca_file) == 0)
2717 return (NULL);
2718 return (g_strdup(ssl_ca_file));
2722 set_refresh_interval(char *value)
2724 int tmp;
2725 const char *errstr;
2727 if (value == NULL || strlen(value) == 0)
2728 refresh_interval = XT_DS_REFRESH_INTERVAL;
2729 else {
2730 tmp = strtonum(value, 0, INT_MAX, &errstr);
2731 if (errstr)
2732 return (-1);
2733 refresh_interval = tmp;
2735 return (0);
2739 check_resource_dir(char **tt)
2741 *tt = g_strdup_printf("Default: %s", XT_DS_RESOURCE_DIR);
2742 return (g_strcmp0(resource_dir, XT_DS_RESOURCE_DIR));
2746 check_save_global_history(char **tt)
2748 *tt = g_strdup("Default: Disabled");
2749 return (save_global_history != 0);
2753 check_save_rejected_cookies(char **tt)
2755 *tt = g_strdup("Default: Disabled");
2756 return (save_rejected_cookies != 0);
2760 check_refresh_interval(char **tt)
2762 *tt = g_strdup_printf("Default: %d", XT_DS_REFRESH_INTERVAL);
2763 return (refresh_interval != XT_DS_REFRESH_INTERVAL);
2767 set_session_autosave(char *value)
2769 int tmp;
2770 const char *errstr;
2772 if (value == NULL || strlen(value) == 0)
2773 session_autosave = XT_DS_SESSION_AUTOSAVE;
2774 else {
2775 tmp = strtonum(value, 0, 1, &errstr);
2776 if (errstr)
2777 return (-1);
2778 session_autosave = tmp;
2780 return (0);
2784 check_session_autosave(char **tt)
2786 *tt = g_strdup_printf("Default: %s",
2787 XT_DS_SESSION_AUTOSAVE ? "Enabled" : "Disabled");
2788 return (session_autosave != XT_DS_SESSION_AUTOSAVE);
2792 set_session_timeout(char *value)
2794 int tmp;
2795 const char *errstr;
2797 if (value == NULL || strlen(value) == 0)
2798 session_timeout = XT_DS_SESSION_TIMEOUT;
2799 else {
2800 tmp = strtonum(value, 0, INT_MAX, &errstr);
2801 if (errstr)
2802 return (-1);
2803 session_timeout = tmp;
2805 return (0);
2809 check_session_timeout(char **tt)
2811 *tt = g_strdup_printf("Default: %d", XT_DS_SESSION_TIMEOUT);
2812 return (session_timeout != XT_DS_SESSION_TIMEOUT);
2816 set_show_scrollbars(char *value)
2818 struct tab *t;
2819 int tmp;
2820 const char *errstr;
2822 if (value == NULL || strlen(value) == 0)
2823 tmp = XT_DS_SHOW_SCROLLBARS;
2824 else {
2825 tmp = strtonum(value, 0, 1, &errstr);
2826 if (errstr)
2827 return (-1);
2829 show_scrollbars = tmp;
2830 TAILQ_FOREACH(t, &tabs, entry)
2831 if (set_scrollbar_visibility(t, show_scrollbars))
2832 return (-1);
2833 return (0);
2837 check_show_scrollbars(char **tt)
2839 *tt = g_strdup("Default (depends on gui_mode):\n"
2840 "\tclassic:\tEnabled\n"
2841 "\tminimal:\tDisabled");
2842 if (gui_mode == XT_GM_CLASSIC && show_scrollbars != 1)
2843 return (1);
2844 if (gui_mode == XT_GM_MINIMAL && show_scrollbars != 0)
2845 return (1);
2846 return (0);
2850 set_show_statusbar(char *value)
2852 int tmp;
2853 const char *errstr;
2855 if (value == NULL || strlen(value) == 0)
2856 tmp = XT_DS_SHOW_STATUSBAR;
2857 else {
2858 tmp = strtonum(value, 0, 1, &errstr);
2859 if (errstr)
2860 return (-1);
2862 show_statusbar = tmp;
2863 statusbar_set_visibility();
2864 return (0);
2868 check_show_statusbar(char **tt)
2870 *tt = g_strdup("Default (depends on gui_mode):\n"
2871 "\tclassic:\tDisabled\n"
2872 "\tminimal:\tEnabled");
2873 if (gui_mode == XT_GM_CLASSIC && show_statusbar != 0)
2874 return (1);
2875 if (gui_mode == XT_GM_MINIMAL && show_statusbar != 1)
2876 return (1);
2877 return (0);
2881 set_show_tabs(char *value)
2883 struct karg args = {0};
2884 int val;
2885 const char *errstr;
2887 if (value == NULL || strlen(value) == 0)
2888 val = XT_DS_SHOW_TABS;
2889 else {
2890 val = strtonum(value, 0, 1, &errstr);
2891 if (errstr)
2892 return (-1);
2894 args.i = val ? XT_TAB_SHOW : XT_TAB_HIDE;
2895 tabaction(get_current_tab(), &args);
2896 return (0);
2900 check_show_tabs(char **tt)
2902 *tt = g_strdup("Default (depends on gui_mode):\n"
2903 "\tclassic:\tEnabled\n"
2904 "\tminimal:\tDisabled");
2905 if (gui_mode == XT_GM_CLASSIC && show_tabs != 1)
2906 return (1);
2907 if (gui_mode == XT_GM_MINIMAL && show_tabs != 0)
2908 return (1);
2909 return (0);
2913 set_show_url(char *value)
2915 struct karg args = {0};
2916 int val;
2917 const char *errstr;
2919 if (value == NULL || strlen(value) == 0)
2920 val = XT_DS_SHOW_URL;
2921 else {
2922 val = strtonum(value, 0, 1, &errstr);
2923 if (errstr)
2924 return (-1);
2926 args.i = val ? XT_URL_SHOW : XT_URL_HIDE;
2927 urlaction(get_current_tab(), &args);
2928 return (0);
2932 check_show_url(char **tt)
2934 *tt = g_strdup("Default (depends on gui_mode):\n"
2935 "\tclassic:\tEnabled\n"
2936 "\tminimal:\tDisabled");
2937 if (gui_mode == XT_GM_CLASSIC && show_url != 1)
2938 return (1);
2939 if (gui_mode == XT_GM_MINIMAL && show_url != 0)
2940 return (1);
2941 return (0);
2945 check_single_instance(char **tt)
2947 *tt = g_strdup("Default: Disabled");
2948 return (single_instance != 0);
2952 set_spell_check_languages(char *value)
2954 struct tab *t;
2956 if (spell_check_languages)
2957 g_free(spell_check_languages);
2958 if (value == NULL || strlen(value) == 0)
2959 spell_check_languages = g_strdup(XT_DS_SPELL_CHECK_LANGUAGES);
2960 else
2961 spell_check_languages = g_strdup(value);
2962 TAILQ_FOREACH(t, &tabs, entry)
2963 g_object_set(G_OBJECT(t->settings), "spell_checking_languages",
2964 spell_check_languages, (char *)NULL);
2965 return (0);
2969 check_spell_check_languages(char **tt)
2971 *tt = g_strdup_printf("Default: %s", XT_DS_SPELL_CHECK_LANGUAGES);
2972 return (g_strcmp0(spell_check_languages, XT_DS_SPELL_CHECK_LANGUAGES));
2976 check_valid_file(char *name)
2978 struct stat sb;
2980 if (name == NULL || stat(name, &sb))
2981 return (-1);
2982 return (0);
2986 set_ssl_ca_file_rt(char *value)
2988 if (value == NULL || strlen(value) == 0) {
2989 strlcpy(ssl_ca_file, XT_DS_SSL_CA_FILE, sizeof ssl_ca_file);
2990 g_object_set(session, SOUP_SESSION_SSL_CA_FILE, "", NULL);
2991 return (0);
2992 } else
2993 return (set_ssl_ca_file(NULL, value));
2997 check_ssl_ca_file(char **tt)
2999 *tt = g_strdup("Default: (empty)");
3000 return (g_strcmp0(ssl_ca_file, XT_DS_SSL_CA_FILE));
3004 set_ssl_strict_certs(char *value)
3006 int tmp;
3007 const char *errstr;
3009 if (value == NULL || strlen(value) == 0)
3010 ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
3011 else {
3012 tmp = strtonum(value, 0, 1, &errstr);
3013 if (errstr)
3014 return (-1);
3015 ssl_strict_certs = tmp;
3017 g_object_set(session, SOUP_SESSION_SSL_STRICT, ssl_strict_certs, NULL);
3018 return (0);
3022 check_ssl_strict_certs(char **tt)
3024 *tt = g_strdup_printf("Default: %s",
3025 XT_DS_SSL_STRICT_CERTS ? "Enabled" : "Disabled");
3026 return (ssl_strict_certs != XT_DS_SSL_STRICT_CERTS);
3030 check_statusbar_elems(char **tt)
3032 *tt = g_strdup("Default: BP");
3033 return (g_strcmp0(statusbar_elems, "BP"));
3037 set_external_editor(char *editor)
3039 if (external_editor)
3040 g_free(external_editor);
3041 if (editor == NULL || strlen(editor) == 0)
3042 external_editor = NULL;
3043 else
3044 external_editor = g_strdup(editor);
3045 return (0);
3049 check_external_editor(char **tt)
3051 *tt = g_strdup("Default: (empty)");
3052 return (g_strcmp0(external_editor, NULL));
3056 set_fancy_bar(char *value)
3058 struct tab *t;
3059 int tmp;
3060 const char *errstr;
3062 if (value == NULL || strlen(value) == 0)
3063 fancy_bar = 1; /* XXX */
3064 else {
3065 tmp = strtonum(value, 0, 1, &errstr);
3066 if (errstr)
3067 return (-1);
3068 fancy_bar = tmp;
3070 TAILQ_FOREACH(t, &tabs, entry)
3071 if (fancy_bar) {
3072 gtk_widget_show(t->backward);
3073 gtk_widget_show(t->forward);
3074 gtk_widget_show(t->stop);
3075 gtk_widget_show(t->js_toggle);
3076 if (search_string && strlen(search_string))
3077 gtk_widget_show(t->search_entry);
3078 } else {
3079 gtk_widget_hide(t->backward);
3080 gtk_widget_hide(t->forward);
3081 gtk_widget_hide(t->stop);
3082 gtk_widget_hide(t->js_toggle);
3083 gtk_widget_hide(t->search_entry);
3085 return (0);
3089 check_fancy_bar(char **tt)
3091 *tt = g_strdup("Default (depends on gui_mode):\n"
3092 "\tclassic:\tEnabled\n"
3093 "\tminimal:\tDisabled");
3094 if (gui_mode == XT_GM_CLASSIC && fancy_bar != 1)
3095 return (1);
3096 if (gui_mode == XT_GM_MINIMAL && fancy_bar != 0)
3097 return (1);
3098 return (0);
3102 setup_proxy(const char *uri)
3104 struct tab *t;
3106 if (proxy_uri) {
3107 #if SOUP_CHECK_VERSION(2, 42, 2)
3108 g_object_set(session, "proxy-resolver", NULL, (char *)NULL);
3109 g_object_unref(proxy_uri);
3110 #else
3111 g_object_set(session, "proxy-uri", NULL, (char *)NULL);
3112 soup_uri_free(proxy_uri);
3113 #endif
3114 proxy_uri = NULL;
3115 TAILQ_FOREACH(t, &tabs, entry)
3116 if (t->sbe.proxy != NULL)
3117 gtk_label_set_text(GTK_LABEL(t->sbe.proxy), "");
3120 if (http_proxy) {
3121 if (http_proxy != uri) {
3122 g_free(http_proxy);
3123 http_proxy = NULL;
3127 if (uri && check_http_proxy_scheme(uri) != 1)
3128 return (1);
3130 if (uri) {
3131 http_proxy = g_strdup(uri);
3132 DNPRINTF(XT_D_CONFIG, "setup_proxy: %s\n", uri);
3133 #if SOUP_CHECK_VERSION(2, 42, 2)
3134 proxy_uri = g_simple_proxy_resolver_new(http_proxy, proxy_exclude);
3135 if (proxy_uri != NULL) {
3136 g_object_set(session, "proxy-resolver", proxy_uri,
3137 (char *)NULL);
3138 #else
3139 proxy_uri = soup_uri_new(http_proxy);
3140 if (proxy_uri != NULL && SOUP_URI_VALID_FOR_HTTP(proxy_uri)) {
3141 g_object_set(session, "proxy-uri", proxy_uri,
3142 (char *)NULL);
3143 #endif
3144 TAILQ_FOREACH(t, &tabs, entry) {
3145 if (t->sbe.proxy != NULL) {
3146 gtk_label_set_text(
3147 GTK_LABEL(t->sbe.proxy), "proxy");
3149 gtk_widget_show(t->proxy_toggle);
3150 button_set_file(t->proxy_toggle,
3151 "torenabled.ico");
3154 } else {
3155 TAILQ_FOREACH(t, &tabs, entry)
3156 button_set_file(t->proxy_toggle, "tordisabled.ico");
3158 return (0);
3161 char *
3162 get_tab_style(struct settings *s)
3164 if (tab_style == XT_TABS_NORMAL)
3165 return (g_strdup("normal"));
3166 else
3167 return (g_strdup("compact"));
3171 set_tab_style(struct settings *s, char *val)
3173 if (!strcmp(val, "normal"))
3174 tab_style = XT_TABS_NORMAL;
3175 else if (!strcmp(val, "compact"))
3176 tab_style = XT_TABS_COMPACT;
3177 else
3178 return (1);
3180 return (0);
3184 check_tab_style(char **tt)
3186 *tt = g_strdup("Default (depends on gui_mode):\n"
3187 "\tclassic:\tnormal\n"
3188 "\tminimal:\tcompact");
3189 if (gui_mode == XT_GM_CLASSIC && tab_style != XT_TABS_NORMAL)
3190 return (1);
3191 if (gui_mode == XT_GM_MINIMAL && tab_style != XT_TABS_COMPACT)
3192 return (1);
3193 return (0);
3197 set_tab_style_rt(char *value)
3199 struct karg args = {0};
3200 int old_tab_style;
3202 if (value == NULL || strlen(value) == 0) {
3203 if (tab_style == XT_DS_TAB_STYLE)
3204 return (0);
3205 tab_style = XT_TABS_COMPACT;
3206 args.i = XT_TAB_NEXTSTYLE;
3207 } else {
3208 old_tab_style = tab_style;
3209 if (set_tab_style(NULL, value))
3210 return (-1);
3211 if (old_tab_style != tab_style) {
3212 tab_style = old_tab_style;
3213 args.i = XT_TAB_NEXTSTYLE;
3216 tabaction(get_current_tab(), &args);
3217 return (0);
3220 char *
3221 get_statusbar_style(struct settings *s)
3223 if (statusbar_style == XT_STATUSBAR_URL)
3224 return (g_strdup("url"));
3225 else
3226 return (g_strdup("title"));
3230 set_statusbar_style(struct settings *s, char *val)
3232 if (!strcmp(val, "url"))
3233 statusbar_style = XT_STATUSBAR_URL;
3234 else if (!strcmp(val, "title"))
3235 statusbar_style = XT_STATUSBAR_TITLE;
3236 else
3237 return (1);
3239 return (0);
3243 set_statusbar_style_rt(char *value)
3245 struct tab *t;
3246 const gchar *page_uri;
3248 if (value == NULL || strlen(value) == 0) {
3249 if (statusbar_style == XT_DS_STATUSBAR_STYLE)
3250 return (0);
3251 statusbar_style = XT_DS_STATUSBAR_STYLE;
3252 } else {
3253 if (!strcmp(value, "url"))
3254 statusbar_style = XT_STATUSBAR_URL;
3255 else if (!strcmp(value, "title"))
3256 statusbar_style = XT_STATUSBAR_TITLE;
3259 /* apply changes */
3260 TAILQ_FOREACH(t, &tabs, entry) {
3261 if (statusbar_style == XT_STATUSBAR_TITLE)
3262 set_status(t, "%s", get_title(t, FALSE));
3263 else if ((page_uri = get_uri(t)) != NULL)
3264 set_status(t, "%s", page_uri);
3267 return (0);
3271 check_statusbar_style(char **tt)
3273 *tt = g_strdup("Default: url");
3274 return (statusbar_style != XT_DS_STATUSBAR_STYLE);
3278 set_url_regex(char *value)
3280 if (value == NULL || strlen(value) == 0) {
3281 if (url_regex)
3282 g_free(url_regex);
3283 url_regex = g_strdup(XT_DS_URL_REGEX);
3284 } else {
3285 if (regcomp(&url_re, value, REG_EXTENDED | REG_NOSUB))
3286 return (-1);
3287 if (url_regex)
3288 g_free(url_regex);
3289 url_regex = g_strdup(value);
3291 return (0);
3295 check_url_regex(char **tt)
3297 *tt = g_strdup_printf("Default: %s", XT_DS_URL_REGEX);
3298 return (g_strcmp0(url_regex, XT_DS_URL_REGEX));
3302 set_userstyle(struct settings *s, char *value)
3304 int rv = 0;
3305 char script[PATH_MAX] = {'\0'};
3306 char *tmp;
3308 if (value == NULL || strlen(value) == 0) {
3309 snprintf(script, sizeof script, "%s" PS "style.css", resource_dir);
3310 tmp = g_filename_to_uri(script, NULL, NULL);
3311 if (tmp == NULL)
3312 rv = -1;
3313 else {
3314 if (userstyle)
3315 g_free(userstyle);
3316 userstyle = tmp;
3318 } else {
3319 expand_tilde(script, sizeof script, value);
3320 tmp = g_filename_to_uri(script, NULL, NULL);
3321 if (tmp == NULL)
3322 rv = -1;
3323 else {
3324 if (userstyle)
3325 g_free(userstyle);
3326 userstyle = tmp;
3329 if (stylesheet)
3330 g_free(stylesheet);
3331 stylesheet = g_strdup(userstyle);
3332 return (rv);
3335 char *
3336 get_userstyle(struct settings *s)
3338 if (userstyle)
3339 return (g_filename_from_uri(userstyle, NULL, NULL));
3340 return (NULL);
3344 set_userstyle_rt(char *value)
3346 return (set_userstyle(NULL, value));
3350 check_userstyle(char **tt)
3352 int rv = 0;
3353 char buf[PATH_MAX];
3354 char *file = NULL;
3356 snprintf(buf, sizeof buf, "%s" PS "%s", resource_dir, "style.css");
3357 *tt = g_strdup_printf("Default: %s", buf);
3358 file = g_filename_from_uri(userstyle, NULL, NULL);
3359 rv = g_strcmp0(file, buf);
3360 if (file)
3361 g_free(file);
3362 return (rv);
3366 set_userstyle_global(char *value)
3368 struct karg args = {0};
3369 int tmp, old_style;
3370 const char *errstr;
3372 if (value == NULL || strlen(value) == 0) {
3373 if (userstyle_global == XT_DS_USERSTYLE_GLOBAL)
3374 return (0);
3375 userstyle_global = 1;
3376 args.i = XT_STYLE_GLOBAL;
3377 userstyle_cmd(get_current_tab(), &args);
3378 } else {
3379 old_style = userstyle_global;
3380 tmp = strtonum(value, 0, 1, &errstr);
3381 if (errstr)
3382 return (-1);
3383 if (tmp != old_style) {
3384 args.i = XT_STYLE_GLOBAL;
3385 userstyle_cmd(get_current_tab(), &args);
3388 return (0);
3392 check_userstyle_global(char **tt)
3394 *tt = g_strdup_printf("Default: %s",
3395 XT_DS_USERSTYLE_GLOBAL ? "Enabled" : "Disabled");
3396 return (userstyle_global != XT_DS_USERSTYLE_GLOBAL);
3400 set_warn_cert_changes(char *value)
3402 int tmp;
3403 const char *errstr;
3405 if (value == NULL || strlen(value) == 0)
3406 warn_cert_changes = XT_DS_WARN_CERT_CHANGES;
3407 else {
3408 tmp = strtonum(value, 0, 1, &errstr);
3409 if (errstr)
3410 return (-1);
3411 warn_cert_changes = tmp;
3413 return (0);
3417 check_warn_cert_changes(char **tt)
3419 *tt = g_strdup_printf("Default: %s",
3420 XT_DS_WARN_CERT_CHANGES ? "Enabled" : "Disabled");
3421 return (warn_cert_changes != XT_DS_WARN_CERT_CHANGES);
3425 check_window_height(char **tt)
3427 *tt = g_strdup_printf("Default: %d", 768);
3428 return (window_height != 768);
3432 check_window_maximize(char **tt)
3434 *tt = g_strdup("Default: Disabled");
3435 return (window_maximize != 0);
3439 check_window_width(char **tt)
3441 *tt = g_strdup_printf("Default: %d", 768);
3442 return (window_width != 1024);
3446 check_work_dir(char **tt)
3448 struct passwd *pwd;
3449 char buf[PATH_MAX];
3451 if ((pwd = getpwuid(getuid())) == NULL)
3452 return (-1);
3453 snprintf(buf, sizeof buf, "%s" PS ".xombrero", pwd->pw_dir);
3454 *tt = g_strdup_printf("Default: %s", buf);
3455 return (g_strcmp0(work_dir, buf));
3458 char *
3459 get_edit_mode(struct settings *s)
3461 if (edit_mode == XT_EM_HYBRID)
3462 return (g_strdup("hybrid"));
3463 else
3464 return (g_strdup("vi"));
3468 set_edit_mode(struct settings *s, char *val)
3470 if (!strcmp(val, "hybrid"))
3471 edit_mode = XT_EM_HYBRID;
3472 else if (!strcmp(val, "vi"))
3473 edit_mode = XT_EM_VI;
3474 else
3475 return (1);
3477 return (0);
3481 check_edit_mode(char **tt)
3483 *tt = g_strdup("Default: hybrid");
3484 return (edit_mode != XT_EM_HYBRID);
3487 char *
3488 get_download_mode(struct settings *s)
3490 switch (download_mode) {
3491 case XT_DM_START:
3492 return (g_strdup("start"));
3493 break;
3494 case XT_DM_ASK:
3495 return (g_strdup("ask"));
3496 break;
3497 case XT_DM_ADD:
3498 return (g_strdup("add"));
3499 break;
3501 return (g_strdup("unknown"));
3505 set_download_mode(struct settings *s, char *val)
3507 if (val == NULL || strlen(val) == 0 || !strcmp(val, "start"))
3508 download_mode = XT_DM_START;
3509 else if (!strcmp(val, "ask"))
3510 download_mode = XT_DM_ASK;
3511 else if (!strcmp(val, "add"))
3512 download_mode = XT_DM_ADD;
3513 else
3514 return (1);
3516 return (0);
3520 set_download_mode_rt(char *val)
3522 return (set_download_mode(NULL, val));
3526 check_download_mode(char **tt)
3528 *tt = g_strdup("Default: start");
3529 return (download_mode != XT_DM_START);
3532 char *
3533 get_work_dir(struct settings *s)
3535 if (work_dir[0] == '\0')
3536 return (0);
3537 return (g_strdup(work_dir));
3541 set_work_dir(struct settings *s, char *val)
3543 expand_tilde(work_dir, sizeof work_dir, val);
3544 return (0);
3547 void
3548 walk_cookie_wl(struct settings *s,
3549 void (*cb)(struct settings *, char *, void *), void *cb_args)
3551 struct wl_entry *w;
3553 if (s == NULL || cb == NULL) {
3554 show_oops(NULL, "walk_cookie_wl invalid parameters");
3555 return;
3558 TAILQ_FOREACH_REVERSE(w, &c_wl, wl_list, entry)
3559 cb(s, w->pat, cb_args);
3562 void
3563 walk_js_wl(struct settings *s,
3564 void (*cb)(struct settings *, char *, void *), void *cb_args)
3566 struct wl_entry *w;
3568 if (s == NULL || cb == NULL) {
3569 show_oops(NULL, "walk_js_wl invalid parameters");
3570 return;
3573 TAILQ_FOREACH_REVERSE(w, &js_wl, wl_list, entry)
3574 cb(s, w->pat, cb_args);
3577 void
3578 walk_pl_wl(struct settings *s,
3579 void (*cb)(struct settings *, char *, void *), void *cb_args)
3581 struct wl_entry *w;
3583 if (s == NULL || cb == NULL) {
3584 show_oops(NULL, "walk_pl_wl invalid parameters");
3585 return;
3588 TAILQ_FOREACH_REVERSE(w, &pl_wl, wl_list, entry)
3589 cb(s, w->pat, cb_args);
3592 void
3593 walk_force_https(struct settings *s,
3594 void (*cb)(struct settings *, char *, void *), void *cb_args)
3596 struct wl_entry *w;
3598 if (s == NULL || cb == NULL) {
3599 show_oops(NULL, "walk_force_https invalid parameters");
3600 return;
3603 TAILQ_FOREACH_REVERSE(w, &force_https, wl_list, entry)
3604 cb(s, w->pat, cb_args);
3608 settings_add(char *var, char *val)
3610 int i, rv, *p;
3611 gfloat *f;
3612 char c[PATH_MAX], **s;
3614 /* get settings */
3615 for (i = 0, rv = 0; i < LENGTH(rs); i++) {
3616 if (strcmp(var, rs[i].name))
3617 continue;
3619 if (!strcmp(var, "include_config")) {
3620 expand_tilde(c, sizeof c, val);
3621 config_parse(c, 0);
3622 rv = 1;
3623 break;
3626 if (rs[i].s) {
3627 if (rs[i].s->set(&rs[i], val))
3628 startpage_add("invalid value for %s: %s", var,
3629 val);
3630 rv = 1;
3631 break;
3632 } else
3633 switch (rs[i].type) {
3634 case XT_S_INT: /* FALLTHROUGH */
3635 case XT_S_BOOL:
3636 p = rs[i].ival;
3637 *p = atoi(val);
3638 rv = 1;
3639 break;
3640 case XT_S_STR:
3641 s = rs[i].sval;
3642 if (s == NULL)
3643 errx(1, "invalid sval for %s",
3644 rs[i].name);
3645 if (*s)
3646 g_free(*s);
3647 *s = g_strdup(val);
3648 rv = 1;
3649 break;
3650 case XT_S_FLOAT:
3651 f = rs[i].fval;
3652 *f = atof(val);
3653 rv = 1;
3654 break;
3655 case XT_S_INVALID:
3656 default:
3657 errx(1, "invalid type for %s", var);
3659 break;
3661 return (rv);
3664 #define WS "\n= \t"
3665 void
3666 config_parse(char *filename, int runtime)
3668 FILE *config, *f;
3669 char *line, *cp, *var, *val;
3670 size_t len, lineno = 0;
3671 int handled;
3672 char file[PATH_MAX];
3673 struct stat sb;
3675 DNPRINTF(XT_D_CONFIG, "config_parse: filename %s\n", filename);
3677 if (filename == NULL)
3678 return;
3680 if (runtime && runtime_settings[0] != '\0') {
3681 snprintf(file, sizeof file, "%s" PS "%s",
3682 work_dir, runtime_settings);
3683 if (stat(file, &sb)) {
3684 warnx("runtime file doesn't exist, creating it");
3685 if ((f = fopen(file, "w")) == NULL)
3686 err(1, "runtime");
3687 fprintf(f, "# AUTO GENERATED, DO NOT EDIT\n");
3688 fclose(f);
3690 } else
3691 strlcpy(file, filename, sizeof file);
3693 if ((config = fopen(file, "r")) == NULL) {
3694 warn("config_parse: cannot open %s", filename);
3695 return;
3698 for (;;) {
3699 if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL)
3700 if (feof(config) || ferror(config))
3701 break;
3703 cp = line;
3704 cp += (long)strspn(cp, WS);
3705 if (cp[0] == '\0') {
3706 /* empty line */
3707 free(line);
3708 continue;
3711 if ((var = strsep(&cp, WS)) == NULL || cp == NULL)
3712 startpage_add("invalid configuration file entry: %s",
3713 line);
3714 else {
3715 cp += (long)strspn(cp, WS);
3717 if ((val = strsep(&cp, "\0")) == NULL)
3718 break;
3720 DNPRINTF(XT_D_CONFIG, "config_parse: %s=%s\n",
3721 var, val);
3722 handled = settings_add(var, val);
3724 if (handled == 0)
3725 startpage_add("invalid configuration file entry"
3726 ": %s=%s", var, val);
3729 free(line);
3732 fclose(config);
3735 struct settings_args {
3736 char **body;
3737 int i;
3740 void
3741 print_setting(struct settings *s, char *val, void *cb_args)
3743 char *color;
3744 gchar *tmp, *enc_val;
3745 struct settings_args *sa = cb_args;
3747 if (sa == NULL || s->flags & XT_SF_INVISIBLE)
3748 return;
3750 if (s->flags & XT_SF_RUNTIME)
3751 color = "#22cc22";
3752 else
3753 color = "#cccccc";
3755 enc_val = html_escape(val);
3756 tmp = *sa->body;
3757 *sa->body = g_strdup_printf(
3758 "%s\n<tr>"
3759 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
3760 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
3761 *sa->body,
3762 color,
3763 s->name,
3764 color,
3765 enc_val == NULL ? "" : enc_val
3767 g_free(tmp);
3768 if (enc_val)
3769 g_free(enc_val);
3770 sa->i++;
3773 void
3774 print_runtime_setting(struct settings *s, char *val, void *cb_args)
3776 char *tmp, *tt = NULL;
3777 struct settings_args *sa = cb_args;
3778 int modified = 0;
3779 int i;
3781 if (sa == NULL)
3782 return;
3784 if (s == NULL || s->flags & XT_SF_INVISIBLE || s->activate == NULL)
3785 return;
3787 tmp = *sa->body;
3788 if (s->ismodified)
3789 modified = s->ismodified(&tt);
3790 *sa->body = g_strdup_printf(
3791 "%s\n<tr %s>"
3792 "<td title=\"%s\" style='width: 240px;'><div style='width: 100%%;'>%s</div></td>"
3793 "<td title=\"%s\"><div style='width: 100%%; word-break:break-all'>",
3794 *sa->body,
3795 modified ? "id='modified'" : "",
3796 s->tt ? s->tt : "",
3797 s->name,
3798 tt);
3799 g_free(tmp);
3800 g_free(tt);
3802 tmp = *sa->body;
3803 if (s->type == XT_S_STR && s->s && s->s->valid_options[0]) {
3804 *sa->body = g_strdup_printf("%s<select name='%s'>",
3805 *sa->body,
3806 s->name);
3807 for (i = 0; s->s->valid_options[i]; ++i) {
3808 g_free(tmp);
3809 tmp = *sa->body;
3810 *sa->body = g_strdup_printf("%s"
3811 "<option value='%s' %s>%s</option>",
3812 *sa->body,
3813 s->s->valid_options[i],
3814 !strcmp(s->s->valid_options[i], val) ? "selected" : "",
3815 s->s->valid_options[i]);
3817 } else if (s->type == XT_S_STR)
3818 *sa->body = g_strdup_printf(
3819 "%s<input style='width: 98%%' type='text' name='%s' value='%s'>"
3820 "</div></td></tr>",
3821 *sa->body,
3822 s->name,
3823 val ? val : "");
3824 else if (s->type == XT_S_INT)
3825 *sa->body = g_strdup_printf(
3826 "%s<input type='number' name='%s' value='%s'>"
3827 "</div></td></tr>",
3828 *sa->body,
3829 s->name,
3830 val);
3831 else if (s->type == XT_S_FLOAT)
3832 *sa->body = g_strdup_printf(
3833 "%s<input type='number' step='0.000001' name='%s' value='%s'>"
3834 "</div></td></tr>",
3835 *sa->body,
3836 s->name,
3837 val);
3838 else if (s->type == XT_S_BOOL)
3839 *sa->body = g_strdup_printf(
3840 "%s<input type='hidden' name='%s' value='0'>"
3841 "<input type='checkbox' name='%s' value='1''%s>"
3842 "</div></td></tr>",
3843 *sa->body,
3844 s->name,
3845 s->name,
3846 atoi(val) ? " checked='checked'" : "");
3847 else {
3848 *sa->body = g_strdup(*sa->body);
3849 warnx("Did not print setting %s", s->name);
3851 g_free(tmp);
3852 sa->i++;
3855 char *
3856 print_set_rejects(void)
3858 struct set_reject *sr, *st;
3859 char *body = NULL, *tmp;
3861 if (TAILQ_EMPTY(&srl))
3862 return (NULL);
3864 body = g_strdup_printf("The following settings were invalid and could "
3865 "not be set:<br><div align='center'><table id='settings'>"
3866 "<th align='left'>Setting</th>"
3867 "<th align='left'>Value</th>");
3868 TAILQ_FOREACH_SAFE(sr, &srl, entry, st) {
3869 tmp = body;
3870 body = g_strdup_printf("%s\n<tr>"
3871 "<td style='width:240px'><div>%s</div></td>"
3872 "<td><div style='word-break:break-all'>%s</div></td></tr>",
3873 body,
3874 sr->name,
3875 sr->value);
3876 g_free(tmp);
3877 TAILQ_REMOVE(&srl, sr, entry);
3878 g_free(sr->name);
3879 g_free(sr->value);
3880 g_free(sr);
3882 tmp = body;
3883 body = g_strdup_printf("%s</table></div><br>", body);
3884 g_free(tmp);
3885 return (body);
3889 xtp_page_set(struct tab *t, struct karg *args)
3891 char *body, *page, *tmp;
3892 int i = 1;
3893 struct settings_args sa;
3895 bzero(&sa, sizeof sa);
3896 sa.body = &body;
3898 /* body */
3899 body = g_strdup_printf("<div align='center'><table><tr>"
3900 "<th align='left'>Setting</th>"
3901 "<th align='left'>Value</th></tr>\n");
3903 settings_walk(print_setting, &sa);
3904 i = sa.i;
3906 /* small message if there are none */
3907 if (i == 1) {
3908 tmp = body;
3909 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3910 "colspan='2'>No settings</td></tr>\n", body);
3911 g_free(tmp);
3914 tmp = body;
3915 body = g_strdup_printf("%s</table></div>", body);
3916 g_free(tmp);
3918 page = get_html_page("Settings", body, "", 0);
3920 g_free(body);
3922 load_webkit_string(t, page, XT_URI_ABOUT_SET, 0);
3924 g_free(page);
3926 return (XT_CB_PASSTHROUGH);
3930 xtp_page_rt(struct tab *t, struct karg *args)
3932 char *body = NULL, *page, *tmp;
3933 int i = 1;
3934 struct settings_args sa;
3936 generate_xtp_session_key(&t->session_key);
3938 bzero(&sa, sizeof sa);
3939 sa.body = &body;
3941 /* body */
3942 body = print_set_rejects();
3944 tmp = body;
3945 body = g_strdup_printf("%s<div align='center'>"
3946 "<form method='GET' action='%s%d/%s/%d'>"
3947 "<input type='submit' value='Save Settings'>"
3948 "<table id='settings'>"
3949 "<th align='left'>Setting</th>"
3950 "<th align='left'>Value</th>\n",
3951 body ? body : "",
3952 XT_XTP_STR,
3953 XT_XTP_RT,
3954 t->session_key,
3955 XT_XTP_RT_SAVE);
3956 g_free(tmp);
3958 settings_walk(print_runtime_setting, &sa);
3959 i = sa.i;
3961 /* small message if there are none */
3962 if (i == 1) {
3963 tmp = body;
3964 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3965 "colspan='2'>No settings</td></tr>\n", body);
3966 g_free(tmp);
3969 tmp = body;
3970 body = g_strdup_printf("%s</table>"
3971 "<input type='submit' value='Save Settings'></form></div>", body);
3972 g_free(tmp);
3974 page = get_html_page("Runtime Settings", body, "", 1);
3976 g_free(body);
3978 load_webkit_string(t, page, XT_URI_ABOUT_RUNTIME, 0);
3980 g_free(page);
3982 return (XT_CB_PASSTHROUGH);
3986 set(struct tab *t, struct karg *args)
3988 char *p, *val;
3989 int i;
3991 if (args == NULL || args->s == NULL)
3992 return (xtp_page_set(t, args));
3994 /* strip spaces */
3995 p = g_strstrip(args->s);
3997 if (strlen(p) == 0)
3998 return (xtp_page_set(t, args));
4000 /* we got some sort of string */
4001 val = g_strstr_len(p, strlen(p), "=");
4002 if (val) {
4003 *val++ = '\0';
4004 val = g_strstrip(val);
4005 p = g_strchomp(p);
4007 for (i = 0; i < get_settings_size(); i++) {
4008 if (strcmp(rs[i].name, p))
4009 continue;
4011 if (rs[i].activate) {
4012 if (rs[i].activate(val))
4013 show_oops(t, "%s invalid value %s",
4014 p, val);
4015 else
4016 show_oops(t, ":set %s = %s", p, val);
4017 goto done;
4018 } else {
4019 show_oops(t, "not a runtime option: %s", p);
4020 goto done;
4023 show_oops(t, "unknown option: %s", p);
4024 } else {
4025 p = g_strchomp(p);
4027 for (i = 0; i < get_settings_size(); i++) {
4028 if (strcmp(rs[i].name, p))
4029 continue;
4031 /* XXX this could use some cleanup */
4032 switch (rs[i].type) {
4033 case XT_S_INT: /* FALLTHROUGH */
4034 case XT_S_BOOL:
4035 if (rs[i].ival)
4036 show_oops(t, "%s = %d",
4037 rs[i].name, *rs[i].ival);
4038 else if (rs[i].s && rs[i].s->get)
4039 show_oops(t, "%s = %s",
4040 rs[i].name,
4041 rs[i].s->get(&rs[i]));
4042 else if (rs[i].s && rs[i].s->get == NULL)
4043 show_oops(t, "%s = ...", rs[i].name);
4044 else
4045 show_oops(t, "%s = ", rs[i].name);
4046 break;
4047 case XT_S_FLOAT:
4048 if (rs[i].fval)
4049 show_oops(t, "%s = %f",
4050 rs[i].name, *rs[i].fval);
4051 else if (rs[i].s && rs[i].s->get)
4052 show_oops(t, "%s = %s",
4053 rs[i].name,
4054 rs[i].s->get(&rs[i]));
4055 else if (rs[i].s && rs[i].s->get == NULL)
4056 show_oops(t, "%s = ...", rs[i].name);
4057 else
4058 show_oops(t, "%s = ", rs[i].name);
4059 break;
4060 case XT_S_STR:
4061 if (rs[i].sval && *rs[i].sval)
4062 show_oops(t, "%s = %s",
4063 rs[i].name, *rs[i].sval);
4064 else if (rs[i].s && rs[i].s->get)
4065 show_oops(t, "%s = %s",
4066 rs[i].name,
4067 rs[i].s->get(&rs[i]));
4068 else if (rs[i].s && rs[i].s->get == NULL)
4069 show_oops(t, "%s = ...", rs[i].name);
4070 else
4071 show_oops(t, "%s = ", rs[i].name);
4072 break;
4073 default:
4074 show_oops(t, "unknown type for %s", rs[i].name);
4075 goto done;
4078 goto done;
4080 show_oops(t, "unknown option: %s", p);
4082 done:
4083 return (XT_CB_PASSTHROUGH);