deal with deprecated call
[xombrero.git] / settings.c
blob9267d6967ccf0f61b4652cfd35efb0d714e3d490
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 double 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_DOUBLE, 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 - 0.0001) ||
702 default_zoom_level > (XT_DS_DEFAULT_ZOOM_LEVEL + 0.0001));
706 set_cookies_enabled(char *value)
708 int tmp;
709 const char *errstr;
711 if (value == NULL || strlen(value) == 0)
712 cookies_enabled = XT_DS_COOKIES_ENABLED;
713 else {
714 tmp = strtonum(value, 0, 1, &errstr);
715 if (errstr)
716 return (-1);
717 cookies_enabled = tmp;
719 return (0);
723 check_cookies_enabled(char **tt)
725 *tt = g_strdup_printf("Default: %s",
726 XT_DS_COOKIES_ENABLED ? "Enabled" : "Disabled");
727 return (cookies_enabled != XT_DS_COOKIES_ENABLED);
731 set_append_next(char *value)
733 int tmp;
734 const char *errstr;
736 if (value == NULL || strlen(value) == 0)
737 append_next = XT_DS_APPEND_NEXT;
738 else {
739 tmp = strtonum(value, 0, 1, &errstr);
740 if (errstr)
741 return (-1);
742 append_next = tmp;
744 return (0);
748 check_append_next(char **tt)
750 *tt = g_strdup_printf("Default: %s",
751 XT_DS_APPEND_NEXT ? "Enabled" : "Disabled");
752 return (append_next != XT_DS_APPEND_NEXT);
756 set_cmd_font(char *value)
758 struct tab *t;
760 if (cmd_font_name)
761 g_free(cmd_font_name);
762 if (cmd_font)
763 pango_font_description_free(cmd_font);
764 if (value == NULL || strlen(value) == 0)
765 cmd_font_name = g_strdup(XT_DS_CMD_FONT_NAME);
766 else
767 cmd_font_name = g_strdup(value);
768 cmd_font = pango_font_description_from_string(cmd_font_name);
769 TAILQ_FOREACH(t, &tabs, entry)
770 modify_font(GTK_WIDGET(t->cmd), cmd_font);
771 return (0);
775 check_cmd_font(char **tt)
777 *tt = g_strdup_printf("Default: %s", XT_DS_CMD_FONT_NAME);
778 return (g_strcmp0(cmd_font_name, XT_DS_CMD_FONT_NAME));
782 set_oops_font(char *value)
784 struct tab *t;
786 if (oops_font_name)
787 g_free(oops_font_name);
788 if (oops_font)
789 pango_font_description_free(oops_font);
790 if (value == NULL || strlen(value) == 0)
791 cmd_font_name = g_strdup(XT_DS_OOPS_FONT_NAME);
792 else
793 oops_font_name = g_strdup(value);
794 oops_font = pango_font_description_from_string(oops_font_name);
795 TAILQ_FOREACH(t, &tabs, entry)
796 modify_font(GTK_WIDGET(t->oops), oops_font);
797 return (0);
801 check_oops_font(char **tt)
803 *tt = g_strdup_printf("Default: %s", XT_DS_OOPS_FONT_NAME);
804 return (g_strcmp0(oops_font_name, XT_DS_OOPS_FONT_NAME));
808 check_read_only_cookies(char **tt)
810 *tt = g_strdup_printf("Default: %s",
811 XT_DS_READ_ONLY_COOKIES ? "Enabled" : "Disabled");
812 return (read_only_cookies != XT_DS_READ_ONLY_COOKIES);
816 set_statusbar_font(char *value)
818 struct tab *t;
820 if (statusbar_font_name)
821 g_free(statusbar_font_name);
822 if (statusbar_font)
823 pango_font_description_free(statusbar_font);
824 if (value == NULL || strlen(value) == 0)
825 statusbar_font_name = g_strdup(XT_DS_STATUSBAR_FONT_NAME);
826 else
827 statusbar_font_name = g_strdup(value);
828 statusbar_font = pango_font_description_from_string(
829 statusbar_font_name);
830 TAILQ_FOREACH(t, &tabs, entry) {
831 modify_font(GTK_WIDGET(t->sbe.uri),
832 statusbar_font);
833 if (t->sbe.buffercmd != NULL)
834 modify_font(GTK_WIDGET(t->sbe.buffercmd),
835 statusbar_font);
836 if (t->sbe.zoom != NULL)
837 modify_font(GTK_WIDGET(t->sbe.zoom),
838 statusbar_font);
839 if (t->sbe.position != NULL)
840 modify_font(GTK_WIDGET(t->sbe.position),
841 statusbar_font);
842 if (t->sbe.proxy != NULL)
843 modify_font(GTK_WIDGET(t->sbe.proxy),
844 statusbar_font);
846 return (0);
850 check_statusbar_font(char **tt)
852 *tt = g_strdup_printf("Default: %s", XT_DS_STATUSBAR_FONT_NAME);
853 return (g_strcmp0(statusbar_font_name, XT_DS_STATUSBAR_FONT_NAME));
857 set_tabbar_font(char *value)
859 struct tab *t;
861 if (tabbar_font_name)
862 g_free(tabbar_font_name);
863 if (tabbar_font)
864 pango_font_description_free(tabbar_font);
865 if (value == NULL || strlen(value) == 0)
866 tabbar_font_name = g_strdup(XT_DS_TABBAR_FONT_NAME);
867 else
868 tabbar_font_name = g_strdup(value);
869 tabbar_font = pango_font_description_from_string(tabbar_font_name);
870 TAILQ_FOREACH(t, &tabs, entry)
871 modify_font(GTK_WIDGET(t->tab_elems.label),
872 tabbar_font);
873 return (0);
877 check_tabbar_font(char **tt)
879 *tt = g_strdup_printf("Default: %s", XT_DS_TABBAR_FONT_NAME);
880 return (g_strcmp0(tabbar_font_name, XT_DS_TABBAR_FONT_NAME));
884 check_tabless(char **tt)
886 *tt = g_strdup_printf("Default: Disabled\n");
887 return (tabless != 0);
891 set_color_visited_uris(char *value)
893 int tmp;
894 const char *errstr;
896 if (value == NULL || strlen(value) == 0)
897 color_visited_uris = XT_DS_COLOR_VISITED_URIS;
898 else {
899 tmp = strtonum(value, 0, 1, &errstr);
900 if (errstr)
901 return (-1);
902 color_visited_uris = tmp;
904 return (0);
908 check_color_visited_uris(char **tt)
910 *tt = g_strdup_printf("Default: %s",
911 XT_DS_COLOR_VISITED_URIS ? "Enabled" : "Disabled");
912 return (color_visited_uris != XT_DS_COLOR_VISITED_URIS);
916 set_home(char *value)
918 if (home)
919 g_free(home);
920 if (value == NULL || strlen(value) == 0)
921 home = g_strdup(XT_DS_HOME);
922 else
923 home = g_strdup(value);
924 return (0);
928 check_home(char **tt)
930 *tt = g_strdup_printf("Default: %s", XT_DS_HOME);
931 return (g_strcmp0(home, XT_DS_HOME));
935 set_search_string(char *value)
937 struct tab *t;
939 if (search_string)
940 g_free(search_string);
941 if (value == NULL || strlen(value) == 0) {
942 search_string = NULL;
943 TAILQ_FOREACH(t, &tabs, entry)
944 gtk_widget_hide(t->search_entry);
945 } else {
946 search_string = g_strdup(value);
947 TAILQ_FOREACH(t, &tabs, entry)
948 gtk_widget_show(t->search_entry);
950 return (0);
954 check_search_string(char **tt)
956 *tt = g_strdup_printf("Default: %s", XT_DS_SEARCH_STRING);
957 return (g_strcmp0(search_string, XT_DS_SEARCH_STRING));
960 size_t
961 get_settings_size(void)
963 return (LENGTH(rs));
966 char *
967 get_setting_name(int i)
969 if (i > LENGTH(rs))
970 return (NULL);
971 return (rs[i].name);
974 char *
975 get_as_string(struct settings *s)
977 char *r = NULL;
979 if (s == NULL)
980 return (NULL);
982 if (s->s && s->s->get)
983 r = s->s->get(s);
984 else if (s->type == XT_S_INT)
985 r = g_strdup_printf("%d", *s->ival);
986 else if (s->type == XT_S_STR)
987 r = g_strdup(*s->sval);
988 else if (s->type == XT_S_DOUBLE)
989 r = g_strdup_printf("%lf", *s->dval);
990 else if (s->type == XT_S_BOOL)
991 r = g_strdup_printf("%d", *s->ival);
992 else
993 r = g_strdup_printf("INVALID TYPE");
995 return (r);
998 void
999 settings_walk(void (*cb)(struct settings *, char *, void *), void *cb_args)
1001 int i;
1002 char *s;
1004 for (i = 0; i < LENGTH(rs); i++) {
1005 if (rs[i].s && rs[i].s->walk)
1006 rs[i].s->walk(&rs[i], cb, cb_args);
1007 else {
1008 s = get_as_string(&rs[i]);
1009 cb(&rs[i], s, cb_args);
1010 g_free(s);
1016 check_allow_volatile_cookies(char **tt)
1018 *tt = g_strdup("Default: Disabled");
1019 return (allow_volatile_cookies != 0);
1023 check_anonymize_headers(char **tt)
1025 *tt = g_strdup("Default: Disabled");
1026 return (anonymize_headers != 0);
1030 set_browser_mode(struct settings *s, char *val)
1032 if (!strcmp(val, "whitelist")) {
1033 browser_mode = XT_BM_WHITELIST;
1034 allow_volatile_cookies = 0;
1035 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
1036 cookies_enabled = 1;
1037 enable_cookie_whitelist = 1;
1038 enable_plugin_whitelist = 1;
1039 enable_plugins = 0;
1040 read_only_cookies = 0;
1041 save_rejected_cookies = 0;
1042 session_timeout = 3600;
1043 enable_scripts = 0;
1044 enable_js_whitelist = 1;
1045 enable_localstorage = 0;
1046 referer_mode = XT_REFERER_SAME_DOMAIN;
1047 allow_insecure_content = 0;
1048 allow_insecure_scripts = 0;
1049 do_not_track = 1;
1050 } else if (!strcmp(val, "normal")) {
1051 browser_mode = XT_BM_NORMAL;
1052 allow_volatile_cookies = 0;
1053 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1054 cookies_enabled = 1;
1055 enable_cookie_whitelist = 0;
1056 enable_plugin_whitelist = 0;
1057 enable_plugins = 1;
1058 read_only_cookies = 0;
1059 save_rejected_cookies = 0;
1060 session_timeout = 3600;
1061 enable_scripts = 1;
1062 enable_js_whitelist = 0;
1063 enable_localstorage = 1;
1064 referer_mode = XT_REFERER_ALWAYS;
1065 allow_insecure_content = 1;
1066 allow_insecure_scripts = 1;
1067 do_not_track = 0;
1068 } else if (!strcmp(val, "kiosk")) {
1069 browser_mode = XT_BM_KIOSK;
1070 allow_volatile_cookies = 0;
1071 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1072 cookies_enabled = 1;
1073 enable_cookie_whitelist = 0;
1074 enable_plugin_whitelist = 0;
1075 enable_plugins = 1;
1076 read_only_cookies = 0;
1077 save_rejected_cookies = 0;
1078 session_timeout = 3600;
1079 enable_scripts = 1;
1080 enable_js_whitelist = 0;
1081 enable_localstorage = 1;
1082 referer_mode = XT_REFERER_ALWAYS;
1083 allow_insecure_content = 1;
1084 allow_insecure_scripts = 1;
1085 do_not_track = 0;
1086 show_tabs = 0;
1087 tabless = 1;
1088 } else
1089 return (1);
1091 return (0);
1094 char *
1095 get_browser_mode(struct settings *s)
1097 char *r = NULL;
1099 if (browser_mode == XT_BM_WHITELIST)
1100 r = g_strdup("whitelist");
1101 else if (browser_mode == XT_BM_NORMAL)
1102 r = g_strdup("normal");
1103 else if (browser_mode == XT_BM_KIOSK)
1104 r = g_strdup("kiosk");
1105 else
1106 return (NULL);
1108 return (r);
1112 check_browser_mode(char **tt)
1114 *tt = g_strdup("Default: normal");
1115 return (browser_mode != XT_BM_NORMAL);
1119 set_gui_mode(struct settings *s, char *val)
1121 if (!strcmp(val, "classic")) {
1122 fancy_bar = 1;
1123 show_tabs = 1;
1124 tab_style = XT_TABS_NORMAL;
1125 show_url = 1;
1126 show_statusbar = 0;
1127 show_scrollbars = 1;
1128 } else if (!strcmp(val, "minimal")) {
1129 fancy_bar = 0;
1130 show_tabs = 1;
1131 tab_style = XT_TABS_COMPACT;
1132 show_url = 0;
1133 show_statusbar = 1;
1134 show_scrollbars = 0;
1135 } else
1136 return (1);
1138 return (0);
1141 char *
1142 get_gui_mode(struct settings *s)
1144 char *r = NULL;
1146 if (gui_mode == XT_GM_CLASSIC)
1147 r = g_strdup("classic");
1148 else if (browser_mode == XT_GM_MINIMAL)
1149 r = g_strdup("minimal");
1150 else
1151 return (NULL);
1153 return (r);
1157 check_gui_mode(char **tt)
1159 *tt = g_strdup("Default: classic");
1160 return (gui_mode != XT_GM_CLASSIC);
1164 check_history_autosave(char **tt)
1166 *tt = g_strdup("Default: Disabled");
1167 return (history_autosave != 0);
1171 set_cookie_policy(struct settings *s, char *val)
1173 if (!strcmp(val, "no3rdparty"))
1174 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
1175 else if (!strcmp(val, "accept"))
1176 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1177 else if (!strcmp(val, "reject"))
1178 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
1179 else
1180 return (1);
1182 return (0);
1186 set_cookie_policy_rt(char *value)
1188 if (value == NULL || strlen(value) == 0)
1189 cookie_policy = XT_DS_COOKIE_POLICY;
1190 else if (set_cookie_policy(NULL, value))
1191 return (-1);
1192 g_object_set(G_OBJECT(s_cookiejar), SOUP_COOKIE_JAR_ACCEPT_POLICY,
1193 cookie_policy, (void *)NULL);
1194 return (0);
1198 check_cookie_policy(char **tt)
1200 *tt = g_strdup("Default (depends on browser_mode):\n"
1201 "\tnormal:\talways\n"
1202 "\twhitelist:\tno3rdparty\n"
1203 "\tkiosk:\talways");
1204 if (browser_mode == XT_BM_WHITELIST &&
1205 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1206 return (1);
1207 if (browser_mode == XT_BM_NORMAL &&
1208 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1209 return (1);
1210 if (browser_mode == XT_BM_KIOSK &&
1211 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1212 return (1);
1213 return (0);
1216 char *
1217 get_cookie_policy(struct settings *s)
1219 char *r = NULL;
1221 if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1222 r = g_strdup("no3rdparty");
1223 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1224 r = g_strdup("accept");
1225 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
1226 r = g_strdup("reject");
1227 else
1228 return (NULL);
1230 return (r);
1233 char *
1234 get_default_script(struct settings *s)
1236 if (default_script[0] == '\0')
1237 return (0);
1238 return (g_strdup(default_script));
1242 set_default_script(struct settings *s, char *val)
1244 expand_tilde(default_script, sizeof default_script, val);
1245 return (0);
1249 check_default_script(char **tt)
1251 *tt = g_strdup("Default: (empty)");
1252 return (g_strcmp0(default_script, XT_DS_DEFAULT_SCRIPT));
1256 set_default_script_rt(char *value)
1258 if (value == NULL || strlen(value) == 0)
1259 return set_default_script(NULL, "");
1260 return (set_default_script(NULL, value));
1264 set_do_not_track(char *value)
1266 int tmp;
1267 const char *errstr;
1269 if (value == NULL || strlen(value) == 0)
1270 do_not_track = XT_DS_DO_NOT_TRACK;
1271 else {
1272 tmp = strtonum(value, 0, 1, &errstr);
1273 if (errstr)
1274 return (-1);
1275 do_not_track = tmp;
1277 return (0);
1281 check_do_not_track(char **tt)
1283 *tt = g_strdup("Default (depends on browser_mode):\n"
1284 "\tnormal:\tDisabled\n"
1285 "\twhitelist:\tEnabled\n"
1286 "\tkiosk:\tDisabled");
1287 if (browser_mode == XT_BM_WHITELIST && do_not_track != 1)
1288 return (1);
1289 if (browser_mode == XT_BM_NORMAL && do_not_track != 0)
1290 return (1);
1291 if (browser_mode == XT_BM_KIOSK && do_not_track != 0)
1292 return (1);
1293 return (0);
1296 char *
1297 get_download_dir(struct settings *s)
1299 if (download_dir[0] == '\0')
1300 return (0);
1301 return (g_strdup(download_dir));
1305 set_download_dir(struct settings *s, char *val)
1307 expand_tilde(download_dir, sizeof download_dir, val);
1308 return (0);
1312 check_download_dir(char **tt)
1314 struct passwd *pwd;
1315 char buf[PATH_MAX] = {0};
1317 /* XXX this might need some additonal magic on windows */
1318 if ((pwd = getpwuid(getuid())) == NULL)
1319 return (-1);
1320 snprintf(buf, sizeof buf, "%s" PS "downloads", pwd->pw_dir);
1321 *tt = g_strdup_printf("Default: %s", buf);
1322 return (g_strcmp0(download_dir, buf));
1326 add_alias(struct settings *s, char *line)
1328 char *l, *alias;
1329 struct alias *a = NULL;
1331 if (s == NULL || line == NULL) {
1332 show_oops(NULL, "add_alias invalid parameters");
1333 return (1);
1336 l = line;
1337 a = g_malloc(sizeof(*a));
1339 if ((alias = strsep(&l, " \t,")) == NULL || l == NULL) {
1340 show_oops(NULL, "add_alias: incomplete alias definition");
1341 goto bad;
1344 /* Remove additional leading whitespace */
1345 l += (long)strspn(l, " \t");
1347 if (strlen(alias) == 0 || strlen(l) == 0) {
1348 show_oops(NULL, "add_alias: invalid alias definition");
1349 goto bad;
1352 a->a_name = g_strdup(alias);
1353 a->a_uri = g_strdup(l);
1355 DNPRINTF(XT_D_CONFIG, "add_alias: %s for %s\n", a->a_name, a->a_uri);
1357 TAILQ_INSERT_TAIL(&aliases, a, entry);
1359 return (0);
1360 bad:
1361 if (a)
1362 g_free(a);
1363 return (1);
1366 void
1367 walk_alias(struct settings *s,
1368 void (*cb)(struct settings *, char *, void *), void *cb_args)
1370 struct alias *a;
1371 char *str;
1373 if (s == NULL || cb == NULL) {
1374 show_oops(NULL, "walk_alias invalid parameters");
1375 return;
1378 TAILQ_FOREACH(a, &aliases, entry) {
1379 str = g_strdup_printf("%s --> %s", a->a_name, a->a_uri);
1380 cb(s, str, cb_args);
1381 g_free(str);
1386 add_mime_type(struct settings *s, char *line)
1388 char *mime_type;
1389 char *l;
1390 struct mime_type *m = NULL;
1391 int downloadfirst = 0;
1393 /* XXX this could be smarter */
1395 if (line == NULL || strlen(line) == 0) {
1396 show_oops(NULL, "add_mime_type invalid parameters");
1397 return (1);
1400 l = line;
1401 if (*l == '@') {
1402 downloadfirst = 1;
1403 l++;
1405 m = g_malloc(sizeof(*m));
1407 if ((mime_type = strsep(&l, " \t,")) == NULL || l == NULL) {
1408 show_oops(NULL, "add_mime_type: invalid mime_type");
1409 goto bad;
1411 if (mime_type[strlen(mime_type) - 1] == '*') {
1412 mime_type[strlen(mime_type) - 1] = '\0';
1413 m->mt_default = 1;
1414 } else
1415 m->mt_default = 0;
1417 if (strlen(mime_type) == 0 || strlen(l) == 0) {
1418 show_oops(NULL, "add_mime_type: invalid mime_type");
1419 goto bad;
1422 m->mt_type = g_strdup(mime_type);
1423 m->mt_action = g_strdup(l);
1424 m->mt_download = downloadfirst;
1426 DNPRINTF(XT_D_CONFIG, "add_mime_type: type %s action %s default %d\n",
1427 m->mt_type, m->mt_action, m->mt_default);
1429 TAILQ_INSERT_TAIL(&mtl, m, entry);
1431 return (0);
1432 bad:
1433 if (m)
1434 g_free(m);
1435 return (1);
1438 void
1439 walk_mime_type(struct settings *s,
1440 void (*cb)(struct settings *, char *, void *), void *cb_args)
1442 struct mime_type *m;
1443 char *str;
1445 if (s == NULL || cb == NULL) {
1446 show_oops(NULL, "walk_mime_type invalid parameters");
1447 return;
1450 TAILQ_FOREACH(m, &mtl, entry) {
1451 str = g_strdup_printf("%s%s --> %s",
1452 m->mt_type,
1453 m->mt_default ? "*" : "",
1454 m->mt_action);
1455 cb(s, str, cb_args);
1456 g_free(str);
1460 /* inherent to GTK not all keys will be caught at all times */
1461 /* XXX sort key bindings */
1462 struct key_binding keys[] = {
1463 { "command_mode", 0, 1, GDK_Escape },
1464 { "insert_mode", 0, 0, GDK_i },
1465 { "cookiejar", MOD1, 1, GDK_j },
1466 { "downloadmgr", MOD1, 1, GDK_d },
1467 { "history", MOD1, 1, GDK_h },
1468 { "print", CTRL, 1, GDK_p },
1469 { "search", 0, 0, GDK_slash },
1470 { "searchb", 0, 0, GDK_question },
1471 { "statustoggle", CTRL, 1, GDK_n },
1472 { "command", 0, 0, GDK_colon },
1473 { "qa", CTRL, 1, GDK_q },
1474 { "restart", MOD1, 1, GDK_q },
1475 { "js toggle", CTRL, 1, GDK_j },
1476 { "plugin toggle", MOD1, 1, GDK_p },
1477 { "cookie toggle", MOD1, 1, GDK_c },
1478 { "togglesrc", CTRL, 1, GDK_s },
1479 { "yankuri", 0, 0, GDK_y },
1480 { "pasteuricur", 0, 0, GDK_p },
1481 { "pasteurinew", 0, 0, GDK_P },
1482 { "toplevel toggle", 0, 1, GDK_F4 },
1483 { "help", 0, 1, GDK_F1 },
1484 { "run_script", MOD1, 1, GDK_r },
1485 { "proxy toggle", 0, 1, GDK_F2 },
1486 { "editelement", CTRL, 1, GDK_i },
1487 { "passthrough", CTRL, 1, GDK_z },
1488 { "modurl", CTRL, 1, GDK_Return },
1489 { "modsearchentry", CTRL, 1, GDK_Return },
1490 { "urlmod plus", MOD1, 1, GDK_a },
1491 { "urlmod min", MOD1, 1, GDK_A },
1493 /* search */
1494 { "searchnext", 0, 0, GDK_n },
1495 { "searchprevious", 0, 0, GDK_N },
1497 /* focus */
1498 { "focusaddress", 0, 1, GDK_F6 },
1499 { "focussearch", 0, 1, GDK_F7 },
1501 /* hinting */
1502 { "hinting", 0, 0, GDK_f },
1503 { "hinting", 0, 0, GDK_period },
1504 { "hinting_newtab", SHFT, 0, GDK_F },
1505 { "hinting_newtab", 0, 0, GDK_comma },
1507 /* custom stylesheet */
1508 { "userstyle", 0, 0, GDK_s },
1509 { "userstyle_global", SHFT, 0, GDK_S },
1511 /* navigation */
1512 { "goback", 0, 0, GDK_BackSpace },
1513 { "goback", MOD1, 1, GDK_Left },
1514 { "goforward", SHFT, 1, GDK_BackSpace },
1515 { "goforward", MOD1, 1, GDK_Right },
1516 { "reload", 0, 1, GDK_F5 },
1517 { "reload", CTRL, 1, GDK_r },
1518 { "reload", CTRL, 1, GDK_l },
1519 { "favorites", MOD1, 1, GDK_f },
1521 /* vertical movement */
1522 { "scrolldown", 0, 0, GDK_j },
1523 { "scrolldown", 0, 0, GDK_Down },
1524 { "scrollup", 0, 0, GDK_Up },
1525 { "scrollup", 0, 0, GDK_k },
1526 { "scrollbottom", 0, 0, GDK_G },
1527 { "scrollbottom", 0, 0, GDK_End },
1528 { "scrolltop", 0, 0, GDK_Home },
1529 { "scrollpagedown", 0, 0, GDK_space },
1530 { "scrollpagedown", CTRL, 1, GDK_f },
1531 { "scrollhalfdown", CTRL, 1, GDK_d },
1532 { "scrollpagedown", 0, 0, GDK_Page_Down },
1533 { "scrollpageup", 0, 0, GDK_Page_Up },
1534 { "scrollpageup", CTRL, 1, GDK_b },
1535 { "scrollhalfup", CTRL, 1, GDK_u },
1536 /* horizontal movement */
1537 { "scrollright", 0, 0, GDK_l },
1538 { "scrollright", 0, 0, GDK_Right },
1539 { "scrollleft", 0, 0, GDK_Left },
1540 { "scrollleft", 0, 0, GDK_h },
1541 { "scrollfarright", 0, 0, GDK_dollar },
1542 { "scrollfarleft", 0, 0, GDK_0 },
1544 /* tabs */
1545 { "tabnew", CTRL, 1, GDK_t },
1546 { "999tabnew", CTRL, 1, GDK_T },
1547 { "tabclose", CTRL, 1, GDK_w },
1548 { "tabundoclose", 0, 0, GDK_U },
1549 { "tabnext 1", CTRL, 1, GDK_1 },
1550 { "tabnext 2", CTRL, 1, GDK_2 },
1551 { "tabnext 3", CTRL, 1, GDK_3 },
1552 { "tabnext 4", CTRL, 1, GDK_4 },
1553 { "tabnext 5", CTRL, 1, GDK_5 },
1554 { "tabnext 6", CTRL, 1, GDK_6 },
1555 { "tabnext 7", CTRL, 1, GDK_7 },
1556 { "tabnext 8", CTRL, 1, GDK_8 },
1557 { "tabnext 9", CTRL, 1, GDK_9 },
1558 { "tabfirst", CTRL, 1, GDK_less },
1559 { "tablast", CTRL, 1, GDK_greater },
1560 { "tabprevious", CTRL, 1, GDK_Left },
1561 { "tabnext", CTRL, 1, GDK_Right },
1562 { "focusout", CTRL, 1, GDK_minus },
1563 { "focusin", CTRL, 1, GDK_plus },
1564 { "focusin", CTRL, 1, GDK_equal },
1565 { "focusreset", CTRL, 1, GDK_0 },
1567 /* command aliases (handy when -S flag is used) */
1568 { ":open ", 0, 1, GDK_F9 },
1569 { ":open <uri>", 0, 1, GDK_F10 },
1570 { ":tabnew ", 0, 1, GDK_F11 },
1571 { ":tabnew <uri>", 0, 1, GDK_F12 },
1574 void
1575 walk_kb(struct settings *s,
1576 void (*cb)(struct settings *, char *, void *), void *cb_args)
1578 struct key_binding *k;
1579 char str[1024];
1581 if (s == NULL || cb == NULL) {
1582 show_oops(NULL, "walk_kb invalid parameters");
1583 return;
1586 TAILQ_FOREACH(k, &kbl, entry) {
1587 if (k->cmd == NULL)
1588 continue;
1589 str[0] = '\0';
1591 /* sanity */
1592 if (gdk_keyval_name(k->key) == NULL)
1593 continue;
1595 strlcat(str, k->cmd, sizeof str);
1596 strlcat(str, ",", sizeof str);
1598 if (k->mask & GDK_SHIFT_MASK)
1599 strlcat(str, "S-", sizeof str);
1600 if (k->mask & GDK_CONTROL_MASK)
1601 strlcat(str, "C-", sizeof str);
1602 if (k->mask & GDK_MOD1_MASK)
1603 strlcat(str, "M1-", sizeof str);
1604 if (k->mask & GDK_MOD2_MASK)
1605 strlcat(str, "M2-", sizeof str);
1606 if (k->mask & GDK_MOD3_MASK)
1607 strlcat(str, "M3-", sizeof str);
1608 if (k->mask & GDK_MOD4_MASK)
1609 strlcat(str, "M4-", sizeof str);
1610 if (k->mask & GDK_MOD5_MASK)
1611 strlcat(str, "M5-", sizeof str);
1613 strlcat(str, gdk_keyval_name(k->key), sizeof str);
1614 cb(s, str, cb_args);
1618 void
1619 init_keybindings(void)
1621 int i;
1622 struct key_binding *k;
1624 for (i = 0; i < LENGTH(keys); i++) {
1625 k = g_malloc0(sizeof *k);
1626 k->cmd = keys[i].cmd;
1627 k->mask = keys[i].mask;
1628 k->use_in_entry = keys[i].use_in_entry;
1629 k->key = keys[i].key;
1630 TAILQ_INSERT_HEAD(&kbl, k, entry);
1632 DNPRINTF(XT_D_KEYBINDING, "init_keybindings: added: %s\n",
1633 k->cmd ? k->cmd : "unnamed key");
1637 void
1638 keybinding_clearall(void)
1640 struct key_binding *k, *next;
1642 for (k = TAILQ_FIRST(&kbl); k; k = next) {
1643 next = TAILQ_NEXT(k, entry);
1644 if (k->cmd == NULL)
1645 continue;
1647 DNPRINTF(XT_D_KEYBINDING, "keybinding_clearall: %s\n",
1648 k->cmd ? k->cmd : "unnamed key");
1649 TAILQ_REMOVE(&kbl, k, entry);
1650 g_free(k);
1655 keybinding_set(char *cmd, char *key, int use_in_entry)
1657 struct key_binding *k;
1658 guint keyval, mask = 0;
1659 int i;
1661 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: %s %s\n", cmd, key);
1663 /* Keys which are to be used in entry have been prefixed with an
1664 * exclamation mark. */
1665 if (use_in_entry)
1666 key++;
1668 /* find modifier keys */
1669 if (strstr(key, "S-"))
1670 mask |= GDK_SHIFT_MASK;
1671 if (strstr(key, "C-"))
1672 mask |= GDK_CONTROL_MASK;
1673 if (strstr(key, "M1-"))
1674 mask |= GDK_MOD1_MASK;
1675 if (strstr(key, "M2-"))
1676 mask |= GDK_MOD2_MASK;
1677 if (strstr(key, "M3-"))
1678 mask |= GDK_MOD3_MASK;
1679 if (strstr(key, "M4-"))
1680 mask |= GDK_MOD4_MASK;
1681 if (strstr(key, "M5-"))
1682 mask |= GDK_MOD5_MASK;
1684 /* find keyname */
1685 for (i = strlen(key) - 1; i > 0; i--)
1686 if (key[i] == '-')
1687 key = &key[i + 1];
1689 /* validate keyname */
1690 keyval = gdk_keyval_from_name(key);
1691 if (keyval == GDK_VoidSymbol) {
1692 warnx("invalid keybinding name %s", key);
1693 return (1);
1695 /* must run this test too, gtk+ doesn't handle 10 for example */
1696 if (gdk_keyval_name(keyval) == NULL) {
1697 warnx("invalid keybinding name %s", key);
1698 return (1);
1701 /* Remove eventual dupes. */
1702 TAILQ_FOREACH(k, &kbl, entry)
1703 if (k->key == keyval && k->mask == mask) {
1704 TAILQ_REMOVE(&kbl, k, entry);
1705 g_free(k);
1706 break;
1709 if (strcmp(cmd, "unbind") == 0) {
1710 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: just unbinding: %s\n",
1711 gdk_keyval_name(keyval));
1712 printf("keybinding_set: just unbinding: %s\n",
1713 gdk_keyval_name(keyval));
1714 return (0);
1717 /* add keyname */
1718 k = g_malloc0(sizeof *k);
1719 k->cmd = g_strdup(cmd);
1720 k->mask = mask;
1721 k->use_in_entry = use_in_entry;
1722 k->key = keyval;
1724 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: %s 0x%x %d 0x%x\n",
1725 k->cmd,
1726 k->mask,
1727 k->use_in_entry,
1728 k->key);
1729 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: adding: %s %s\n",
1730 k->cmd, gdk_keyval_name(keyval));
1732 TAILQ_INSERT_HEAD(&kbl, k, entry);
1734 return (0);
1738 cmd_alias_add(char *alias, char *cmd)
1740 struct cmd_alias *c;
1742 /* XXX */
1743 TAILQ_FOREACH(c, &cal, entry)
1744 if (!strcmp((alias), c->alias)) {
1745 TAILQ_REMOVE(&cal, c, entry);
1746 g_free(c);
1749 c = g_malloc(sizeof (struct cmd_alias));
1750 c->alias = g_strchug(g_strdup(alias));
1751 c->cmd = g_strchug(g_strdup(cmd));
1753 DNPRINTF(XT_D_CUSTOM_URI, "cmd_alias_add: %s %s\n", c->alias, c->cmd);
1755 TAILQ_INSERT_HEAD(&cal, c, entry);
1756 return (0);
1760 custom_uri_add(char *uri, char *cmd)
1762 struct custom_uri *u;
1764 TAILQ_FOREACH(u, &cul, entry)
1765 if (!strcmp((uri), u->uri) && !strcmp(cmd, u->cmd)) {
1766 TAILQ_REMOVE(&cul, u, entry);
1767 g_free(u);
1770 u = g_malloc(sizeof (struct custom_uri));
1771 u->uri = g_strdup(uri);
1772 expand_tilde(u->cmd, sizeof u->cmd, cmd);
1774 DNPRINTF(XT_D_CUSTOM_URI, "custom_uri_add: %s %s\n", u->uri, u->cmd);
1776 /* don't check here if the script is valid, wait until running it */
1777 TAILQ_INSERT_HEAD(&cul, u, entry);
1778 return (0);
1782 add_kb(struct settings *s, char *entry)
1784 char *kb, *key;
1786 DNPRINTF(XT_D_KEYBINDING, "add_kb: %s\n", entry);
1788 /* clearall is special */
1789 if (!strcmp(entry, "clearall")) {
1790 keybinding_clearall();
1791 return (0);
1794 kb = strstr(entry, ",");
1795 if (kb == NULL)
1796 return (1);
1797 *kb = '\0';
1798 key = kb + 1;
1800 return (keybinding_set(entry, key, key[0] == '!'));
1804 add_custom_uri(struct settings *s, char *entry)
1806 char *uri, *cmd;
1808 DNPRINTF(XT_D_CUSTOM_URI, "add_custom_uri: %s\n", entry);
1810 uri = strstr(entry, ",");
1811 if (uri == NULL)
1812 return (1);
1813 *uri = '\0';
1814 cmd = uri + 1;
1816 return (custom_uri_add(entry, cmd));
1819 void
1820 walk_custom_uri(struct settings *s,
1821 void (*cb)(struct settings *, char *, void *), void *cb_args)
1823 struct custom_uri *u;
1824 char buf[1024];
1826 if (s == NULL || cb == NULL) {
1827 show_oops(NULL, "walk_custom_uri invalid parameters");
1828 return;
1831 TAILQ_FOREACH(u, &cul, entry) {
1832 snprintf(buf, sizeof buf, "%s,%s", u->uri, u->cmd);
1833 cb(s, buf, cb_args);
1838 add_ua(struct settings *s, char *value)
1840 struct user_agent *ua;
1841 static int ua_count = 0;
1843 ua = g_malloc(sizeof *ua);
1844 ua->id = ua_count++;
1845 ua->value = g_strdup(value);
1847 RB_INSERT(user_agent_list, &ua_list, ua);
1849 return (0);
1853 void
1854 walk_ua(struct settings *s,
1855 void (*cb)(struct settings *, char *, void *), void *cb_args)
1857 struct user_agent *ua;
1859 if (s == NULL || cb == NULL) {
1860 show_oops(NULL, "walk_ua invalid parameters");
1861 return;
1864 RB_FOREACH(ua, user_agent_list, &ua_list)
1865 cb(s, ua->value, cb_args);
1869 add_force_https(struct settings *s, char *value)
1871 if (g_str_has_prefix(value, "re:")) {
1872 value = &value[3];
1873 wl_add(value, &force_https, XT_WL_PERSISTENT | XT_WL_REGEX);
1874 } else
1875 wl_add(value, &force_https, XT_WL_PERSISTENT);
1876 return (0);
1880 add_http_accept(struct settings *s, char *value)
1882 struct http_accept *ha;
1883 static int ha_count = 0;
1885 ha = g_malloc(sizeof *ha);
1886 ha->id = ha_count++;
1887 ha->value = g_strdup(value);
1889 RB_INSERT(http_accept_list, &ha_list, ha);
1891 return (0);
1894 void
1895 walk_http_accept(struct settings *s,
1896 void (*cb)(struct settings *, char *, void *), void *cb_args)
1898 struct http_accept *ha;
1900 if (s == NULL || cb == NULL) {
1901 show_oops(NULL, "%s: invalid parameters", __func__);
1902 return;
1905 RB_FOREACH(ha, http_accept_list, &ha_list)
1906 cb(s, ha->value, cb_args);
1910 add_cmd_alias(struct settings *s, char *entry)
1912 char *alias, *cmd;
1914 DNPRINTF(XT_D_CMD_ALIAS, "add_cmd_alias: %s\n", entry);
1916 alias = strstr(entry, ",");
1917 if (alias == NULL)
1918 return (1);
1919 *alias = '\0';
1920 cmd = alias + 1;
1922 return (cmd_alias_add(entry, cmd));
1925 void
1926 walk_cmd_alias(struct settings *s,
1927 void (*cb)(struct settings *, char *, void *), void *cb_args)
1929 struct cmd_alias *c;
1930 char buf[1024];
1932 if (s == NULL || cb == NULL) {
1933 show_oops(NULL, "walk_cmd_alias invalid parameters");
1934 return;
1937 TAILQ_FOREACH(c, &cal, entry) {
1938 snprintf(buf, sizeof buf, "%s --> %s", c->alias, c->cmd);
1939 cb(s, buf, cb_args);
1944 set_allow_insecure_content(char *value)
1946 struct tab *t;
1947 int tmp;
1948 const char *errstr;
1950 if (value == NULL || strlen(value) == 0)
1951 allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
1952 else {
1953 tmp = strtonum(value, 0, 1, &errstr);
1954 if (errstr)
1955 return (-1);
1956 allow_insecure_content = tmp;
1958 TAILQ_FOREACH(t, &tabs, entry)
1959 if (is_g_object_setting(G_OBJECT(t->settings),
1960 "enable-display-of-insecure-content")) {
1961 g_object_set(G_OBJECT(t->settings),
1962 "enable-display-of-insecure-content",
1963 allow_insecure_content, (char *)NULL);
1964 webkit_web_view_set_settings(t->wv, t->settings);
1966 return (0);
1970 check_allow_insecure_content(char **tt)
1972 *tt = g_strdup("Default (depends on browser_mode):\n"
1973 "\tnormal:\tEnabled\n"
1974 "\twhitelist:\tDisabled\n"
1975 "\tkiosk:\tEnabled");
1976 if (browser_mode == XT_BM_NORMAL && allow_insecure_content != 1)
1977 return (1);
1978 if (browser_mode == XT_BM_WHITELIST && allow_insecure_content != 0)
1979 return (1);
1980 if (browser_mode == XT_BM_KIOSK && allow_insecure_content != 1)
1981 return (1);
1982 return (0);
1986 set_allow_insecure_scripts(char *value)
1988 struct tab *t;
1989 int tmp;
1990 const char *errstr;
1992 if (value == NULL || strlen(value) == 0)
1993 allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
1994 else {
1995 tmp = strtonum(value, 0, 1, &errstr);
1996 if (errstr)
1997 return (-1);
1998 allow_insecure_scripts = tmp;
2000 TAILQ_FOREACH(t, &tabs, entry)
2001 if (is_g_object_setting(G_OBJECT(t->settings),
2002 "enable-running-of-insecure-content")) {
2003 g_object_set(G_OBJECT(t->settings),
2004 "enable-running-of-insecure-content",
2005 allow_insecure_scripts, (char *)NULL);
2006 webkit_web_view_set_settings(t->wv, t->settings);
2008 return (0);
2012 check_allow_insecure_scripts(char **tt)
2014 *tt = g_strdup("Default (depends on browser_mode):\n"
2015 "\tnormal:\tEnabled\n"
2016 "\twhitelist:\tDisabled\n"
2017 "\tkiosk:\tEnabled");
2018 if (browser_mode == XT_BM_NORMAL && allow_insecure_scripts != 1)
2019 return (1);
2020 if (browser_mode == XT_BM_WHITELIST && allow_insecure_scripts != 0)
2021 return (1);
2022 if (browser_mode == XT_BM_KIOSK && allow_insecure_scripts != 1)
2023 return (1);
2024 return (0);
2028 set_auto_load_images(char *value)
2030 struct tab *t;
2031 int tmp;
2032 const char *errstr;
2034 if (value == NULL || strlen(value) == 0)
2035 auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
2036 else {
2037 tmp = strtonum(value, 0, 1, &errstr);
2038 if (errstr)
2039 return (-1);
2040 auto_load_images = tmp;
2042 TAILQ_FOREACH(t, &tabs, entry) {
2043 g_object_set(G_OBJECT(t->settings),
2044 "auto-load-images", auto_load_images, (char *)NULL);
2045 webkit_web_view_set_settings(t->wv, t->settings);
2047 return (0);
2051 check_auto_load_images(char **tt)
2053 *tt = g_strdup_printf("Default: %s",
2054 XT_DS_AUTO_LOAD_IMAGES ? "Enabled" : "Disabled");
2055 return (auto_load_images != XT_DS_AUTO_LOAD_IMAGES);
2059 set_autofocus_onload(char *value)
2061 int tmp;
2062 const char *errstr;
2064 if (value == NULL || strlen(value) == 0)
2065 autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
2066 else {
2067 tmp = strtonum(value, 0, 1, &errstr);
2068 if (errstr)
2069 return (-1);
2070 autofocus_onload = tmp;
2072 return (0);
2076 check_autofocus_onload(char **tt)
2078 *tt = g_strdup_printf("Default: %s",
2079 XT_DS_AUTOFOCUS_ONLOAD ? "Enabled" : "Disabled");
2080 return (autofocus_onload != XT_DS_AUTOFOCUS_ONLOAD);
2084 set_ctrl_click_focus(char *value)
2086 int tmp;
2087 const char *errstr;
2089 if (value == NULL || strlen(value) == 0)
2090 ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS;
2091 else {
2092 tmp = strtonum(value, 0, 1, &errstr);
2093 if (errstr)
2094 return (-1);
2095 ctrl_click_focus = tmp;
2097 return (0);
2101 check_ctrl_click_focus(char **tt)
2103 *tt = g_strdup_printf("Default: %s",
2104 XT_DS_CTRL_CLICK_FOCUS ? "Enabled" : "Disabled");
2105 return (ctrl_click_focus != XT_DS_CTRL_CLICK_FOCUS);
2109 set_download_notifications(char *value)
2111 int tmp;
2112 const char *errstr;
2114 if (value == NULL || strlen(value) == 0)
2115 download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
2116 else {
2117 tmp = strtonum(value, 0, 1, &errstr);
2118 if (errstr)
2119 return (-1);
2120 download_notifications = tmp;
2122 return (0);
2126 check_download_notifications(char **tt)
2128 *tt = g_strdup_printf("Default: %s",
2129 XT_DS_DOWNLOAD_NOTIFICATIONS ? "Enabled" : "Disabled");
2130 return (download_notifications != XT_DS_DOWNLOAD_NOTIFICATIONS);
2134 set_enable_autoscroll(char *value)
2136 int tmp;
2137 const char *errstr;
2139 if (value == NULL || strlen(value) == 0)
2140 enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
2141 else {
2142 tmp = strtonum(value, 0, 1, &errstr);
2143 if (errstr)
2144 return (-1);
2145 enable_autoscroll = tmp;
2147 return (0);
2151 check_enable_autoscroll(char **tt)
2153 *tt = g_strdup_printf("Default: %s",
2154 XT_DS_ENABLE_AUTOSCROLL ? "Enabled" : "Disabled");
2155 return (enable_autoscroll != XT_DS_ENABLE_AUTOSCROLL);
2159 set_enable_cache(char *value)
2161 int tmp;
2162 const char *errstr;
2164 if (value == NULL || strlen(value) == 0)
2165 enable_cache = 1;
2166 else {
2167 tmp = (int)strtonum(value, 0, 1, &errstr);
2168 if (errstr)
2169 return (-1);
2170 enable_cache = tmp;
2172 if (enable_cache)
2173 webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
2174 else
2175 webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
2177 return (0);
2181 check_enable_cache(char **tt)
2183 *tt = g_strdup_printf("Default: Disabled");
2185 return (enable_cache);
2189 set_enable_cookie_whitelist(char *value)
2191 int tmp;
2192 const char *errstr;
2194 if (value == NULL || strlen(value) == 0)
2195 enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
2196 else {
2197 tmp = strtonum(value, 0, 1, &errstr);
2198 if (errstr)
2199 return (-1);
2200 enable_cookie_whitelist = tmp;
2202 return (0);
2206 check_enable_cookie_whitelist(char **tt)
2208 *tt = g_strdup("Default (depends on browser_mode):\n"
2209 "\tnormal:\tDisabled\n"
2210 "\twhitelist:\tEnabled\n"
2211 "\tkiosk:\tDisabled");
2212 if (browser_mode == XT_BM_WHITELIST && enable_cookie_whitelist != 1)
2213 return (1);
2214 if (browser_mode == XT_BM_NORMAL && enable_cookie_whitelist != 0)
2215 return (1);
2216 if (browser_mode == XT_BM_KIOSK && enable_cookie_whitelist != 0)
2217 return (1);
2218 return (0);
2222 set_enable_js_autorun(char *value)
2224 int tmp;
2225 const char *errstr;
2227 if (value == NULL || strlen(value) == 0)
2228 enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
2229 else {
2230 tmp = strtonum(value, 0, 1, &errstr);
2231 if (errstr)
2232 return (-1);
2233 enable_js_autorun = tmp;
2235 return (0);
2239 check_enable_js_autorun(char **tt)
2241 *tt = g_strdup_printf("Default: %s",
2242 XT_DS_ENABLE_JS_AUTORUN ? "Enabled" : "Disabled");
2243 return (enable_js_autorun != XT_DS_ENABLE_JS_AUTORUN);
2247 set_enable_js_whitelist(char *value)
2249 int tmp;
2250 const char *errstr;
2252 if (value == NULL || strlen(value) == 0)
2253 enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
2254 else {
2255 tmp = strtonum(value, 0, 1, &errstr);
2256 if (errstr)
2257 return (-1);
2258 enable_js_whitelist = tmp;
2260 return (0);
2264 check_enable_js_whitelist(char **tt)
2266 *tt = g_strdup("Default (depends on browser_mode):\n"
2267 "\tnormal:\tDisabled\n"
2268 "\twhitelist:\tEnabled\n"
2269 "\tkiosk:\tDisabled");
2270 if (browser_mode == XT_BM_WHITELIST && enable_js_whitelist != 1)
2271 return (1);
2272 if (browser_mode == XT_BM_NORMAL && enable_js_whitelist != 0)
2273 return (1);
2274 if (browser_mode == XT_BM_KIOSK && enable_js_whitelist != 0)
2275 return (1);
2276 return (0);
2280 set_enable_favicon_entry(char *value)
2282 int tmp;
2283 const char *errstr;
2285 if (value == NULL || strlen(value) == 0)
2286 enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
2287 else {
2288 tmp = strtonum(value, 0, 1, &errstr);
2289 if (errstr)
2290 return (-1);
2291 enable_favicon_entry = tmp;
2293 return (0);
2297 check_enable_favicon_entry(char **tt)
2299 *tt = g_strdup_printf("Default: %s",
2300 XT_DS_ENABLE_FAVICON_ENTRY ? "Enabled" : "Disabled");
2301 return (enable_favicon_entry != XT_DS_ENABLE_FAVICON_ENTRY);
2305 set_enable_favicon_tabs(char *value)
2307 int tmp;
2308 const char *errstr;
2310 if (value == NULL || strlen(value) == 0)
2311 enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
2312 else {
2313 tmp = strtonum(value, 0, 1, &errstr);
2314 if (errstr)
2315 return (-1);
2316 enable_favicon_tabs = tmp;
2318 return (0);
2322 check_enable_favicon_tabs(char **tt)
2324 *tt = g_strdup_printf("Default: %s",
2325 XT_DS_ENABLE_FAVICON_TABS ? "Enabled" : "Disabled");
2326 return (enable_favicon_tabs != XT_DS_ENABLE_FAVICON_TABS);
2330 set_enable_localstorage(char *value)
2332 struct tab *t;
2333 int tmp;
2334 const char *errstr;
2336 if (value == NULL || strlen(value) == 0)
2337 enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
2338 else {
2339 tmp = strtonum(value, 0, 1, &errstr);
2340 if (errstr)
2341 return (-1);
2342 enable_localstorage = tmp;
2344 TAILQ_FOREACH(t, &tabs, entry)
2345 g_object_set(G_OBJECT(t->settings),
2346 "enable-html5-local-storage", enable_localstorage,
2347 (char *)NULL);
2348 return (0);
2352 check_enable_localstorage(char **tt)
2354 *tt = g_strdup("Default (depends on browser_mode):\n"
2355 "\tnormal:\tEnabled\n"
2356 "\twhitelist:\tDisabled\n"
2357 "\tkiosk:\tEnabled");
2358 if (browser_mode == XT_BM_WHITELIST && enable_localstorage != 0)
2359 return (1);
2360 if (browser_mode == XT_BM_NORMAL && enable_localstorage != 1)
2361 return (1);
2362 if (browser_mode == XT_BM_KIOSK && enable_localstorage != 1)
2363 return (1);
2364 return (0);
2368 set_enable_plugins(char *value)
2370 struct tab *t;
2371 int tmp;
2372 const char *errstr;
2374 if (value == NULL || strlen(value) == 0)
2375 enable_plugins = XT_DS_ENABLE_PLUGINS;
2376 else {
2377 tmp = strtonum(value, 0, 1, &errstr);
2378 if (errstr)
2379 return (-1);
2380 enable_plugins = tmp;
2382 TAILQ_FOREACH(t, &tabs, entry)
2383 g_object_set(G_OBJECT(t->settings), "enable-plugins",
2384 enable_plugins, (char *)NULL);
2385 return (0);
2389 check_enable_plugins(char **tt)
2391 *tt = g_strdup("Default (depends on browser_mode):\n"
2392 "\tnormal:\tEnabled\n"
2393 "\twhitelist:\tDisabled\n"
2394 "\tkiosk:\tEnabled");
2395 if (browser_mode == XT_BM_WHITELIST && enable_plugins != 0)
2396 return (1);
2397 if (browser_mode == XT_BM_NORMAL && enable_plugins != 1)
2398 return (1);
2399 if (browser_mode == XT_BM_KIOSK && enable_plugins != 1)
2400 return (1);
2401 return (0);
2405 set_enable_plugin_whitelist(char *value)
2407 int tmp;
2408 const char *errstr;
2410 if (value == NULL || strlen(value) == 0)
2411 enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
2412 else {
2413 tmp = strtonum(value, 0, 1, &errstr);
2414 if (errstr)
2415 return (-1);
2416 enable_plugin_whitelist = tmp;
2418 return (0);
2422 check_enable_plugin_whitelist(char **tt)
2424 *tt = g_strdup("Default (depends on browser_mode):\n"
2425 "\tnormal:\tDisabled\n"
2426 "\twhitelist:\tEnabled\n"
2427 "\tkiosk:\tDisabled");
2428 if (browser_mode == XT_BM_WHITELIST && enable_plugin_whitelist != 1)
2429 return (1);
2430 if (browser_mode == XT_BM_NORMAL && enable_plugin_whitelist != 0)
2431 return (1);
2432 if (browser_mode == XT_BM_KIOSK && enable_plugin_whitelist != 0)
2433 return (1);
2434 return (0);
2438 set_enable_scripts(char *value)
2440 struct tab *t;
2441 int tmp;
2442 const char *errstr;
2444 if (value == NULL || strlen(value) == 0)
2445 enable_scripts = XT_DS_ENABLE_SCRIPTS;
2446 else {
2447 tmp = strtonum(value, 0, 1, &errstr);
2448 if (errstr)
2449 return (-1);
2450 enable_scripts = tmp;
2452 TAILQ_FOREACH(t, &tabs, entry)
2453 g_object_set(G_OBJECT(t->settings), "enable-scripts",
2454 enable_scripts, (char *)NULL);
2455 return (0);
2459 check_enable_scripts(char **tt)
2461 *tt = g_strdup("Default (depends on browser_mode):\n"
2462 "\tnormal:\tEnabled\n"
2463 "\twhitelist:\tDisabled\n"
2464 "\tkiosk:\tEnabled");
2465 if (browser_mode == XT_BM_WHITELIST && enable_scripts != 0)
2466 return (1);
2467 if (browser_mode == XT_BM_NORMAL && enable_scripts != 1)
2468 return (1);
2469 if (browser_mode == XT_BM_KIOSK && enable_scripts != 1)
2470 return (1);
2471 return (0);
2475 check_enable_socket(char **tt)
2477 *tt = g_strdup("Default: Disabled");
2478 return (enable_socket != 0);
2482 set_enable_spell_checking(char *value)
2484 struct tab *t;
2485 int tmp;
2486 const char *errstr;
2488 if (value == NULL || strlen(value) == 0)
2489 enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
2490 else {
2491 tmp = strtonum(value, 0, 1, &errstr);
2492 if (errstr)
2493 return (-1);
2494 enable_spell_checking = tmp;
2496 TAILQ_FOREACH(t, &tabs, entry)
2497 g_object_set(G_OBJECT(t->settings), "enable_spell_checking",
2498 enable_spell_checking, (char *)NULL);
2499 return (0);
2503 check_enable_spell_checking(char **tt)
2505 *tt = g_strdup_printf("Default: %s",
2506 XT_DS_ENABLE_SPELL_CHECKING ? "Enabled" : "Disabled");
2507 return (enable_spell_checking != XT_DS_ENABLE_SPELL_CHECKING);
2511 set_enable_strict_transport(char *value)
2513 int tmp;
2514 const char *errstr;
2516 if (value == NULL || strlen(value) == 0)
2517 enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
2518 else {
2519 tmp = strtonum(value, 0, 1, &errstr);
2520 if (errstr)
2521 return (-1);
2522 enable_strict_transport = tmp;
2524 return (0);
2528 check_enable_strict_transport(char **tt)
2530 *tt = g_strdup_printf("Default: %s",
2531 XT_DS_ENABLE_STRICT_TRANSPORT ? "Enabled" : "Disabled");
2532 return (enable_strict_transport != XT_DS_ENABLE_STRICT_TRANSPORT);
2535 #if 0
2537 * XXX: this is currently broken. Need to figure out what to do with
2538 * this. Problemm is set_encoding will refresh the tab it's run on, so
2539 * we can either put a big fat warning in the manpage and refresh every
2540 * single open tab with the new encoding or scrap it as a runtime
2541 * setting.
2544 set_encoding_rt(char *value)
2546 struct karg args = {0};
2548 if (value == NULL || strlen(value) == 0)
2549 return (-1);
2550 if (encoding)
2551 g_free(encoding);
2552 encoding = g_strdup(value);
2553 args.s = encoding;
2554 set_encoding(get_current_tab(), &args);
2555 return (0);
2557 #endif
2560 check_encoding(char **tt)
2562 *tt = g_strdup_printf("Default: %s", XT_DS_ENCODING);
2563 return (g_strcmp0(encoding, XT_DS_ENCODING));
2567 check_gnutls_search_string(char **tt)
2569 *tt = g_strdup("Default: (empty)");
2570 return (g_strcmp0(gnutls_priority_string,
2571 XT_DS_GNUTLS_PRIORITY_STRING));
2575 set_gnutls_priority_string(struct settings *s, char *value)
2577 return (!g_setenv("G_TLS_GNUTLS_PRIORITY", value, FALSE));
2580 char *
2581 get_gnutls_priority_string(struct settings *s)
2583 return (g_strdup(g_getenv("G_TLS_GNUTLS_PRIORITY")));
2587 set_guess_search(char *value)
2589 int tmp;
2590 const char *errstr;
2592 if (value == NULL || strlen(value) == 0)
2593 guess_search = XT_DS_GUESS_SEARCH;
2594 else {
2595 tmp = strtonum(value, 0, 1, &errstr);
2596 if (errstr)
2597 return (-1);
2598 guess_search = tmp;
2600 return (0);
2604 check_guess_search(char **tt)
2606 *tt = g_strdup_printf("Default: %s",
2607 XT_DS_GUESS_SEARCH ? "Enabled" : "Disabled");
2608 return (guess_search != XT_DS_GUESS_SEARCH);
2612 set_js_auto_open_windows(char *value)
2614 int tmp;
2615 const char *errstr;
2616 struct tab *t;
2618 if (value == NULL || strlen(value) == 0)
2619 js_auto_open_windows = XT_DS_JS_AUTO_OPEN_WINDOWS;
2620 else {
2621 tmp = (int)strtonum(value, 0, 1, &errstr);
2622 if (errstr)
2623 return (-1);
2624 js_auto_open_windows = tmp;
2626 TAILQ_FOREACH(t, &tabs, entry)
2627 g_object_set(G_OBJECT(t->settings),
2628 "javascript-can-open-windows-automatically",
2629 js_auto_open_windows, NULL);
2630 return (0);
2634 check_js_auto_open_windows(char **tt)
2636 *tt = g_strdup("Default: Enabled");
2637 return (js_auto_open_windows != XT_DS_JS_AUTO_OPEN_WINDOWS);
2640 char *
2641 get_referer(struct settings *s)
2643 if (referer_mode == XT_REFERER_ALWAYS)
2644 return (g_strdup("always"));
2645 if (referer_mode == XT_REFERER_NEVER)
2646 return (g_strdup("never"));
2647 if (referer_mode == XT_REFERER_SAME_DOMAIN)
2648 return (g_strdup("same-domain"));
2649 if (referer_mode == XT_REFERER_SAME_FQDN)
2650 return (g_strdup("same-fqdn"));
2651 if (referer_mode == XT_REFERER_CUSTOM)
2652 return (g_strdup(referer_custom));
2653 return (NULL);
2657 set_referer(struct settings *s, char *value)
2659 if (referer_custom) {
2660 g_free(referer_custom);
2661 referer_custom = NULL;
2664 if (!strcmp(value, "always"))
2665 referer_mode = XT_REFERER_ALWAYS;
2666 else if (!strcmp(value, "never"))
2667 referer_mode = XT_REFERER_NEVER;
2668 else if (!strcmp(value, "same-domain"))
2669 referer_mode = XT_REFERER_SAME_DOMAIN;
2670 else if (!strcmp(value, "same-fqdn"))
2671 referer_mode = XT_REFERER_SAME_FQDN;
2672 else if (!valid_url_type(value)) {
2673 referer_mode = XT_REFERER_CUSTOM;
2674 referer_custom = g_strdup(value);
2675 } else {
2676 /* we've already free'd the custom referer */
2677 if (referer_mode == XT_REFERER_CUSTOM)
2678 referer_mode = XT_REFERER_NEVER;
2679 return (1);
2682 return (0);
2686 set_referer_rt(char *value)
2688 if (value == NULL || strlen(value) == 0) {
2689 if (referer_custom)
2690 g_free(referer_custom);
2691 referer_custom = g_strdup(XT_DS_REFERER_CUSTOM);
2692 referer_mode = XT_DS_REFERER_MODE;
2693 return (0);
2695 return (set_referer(NULL, value));
2699 check_referer(char **tt)
2701 *tt = g_strdup("Default (depends on browser_mode):\n"
2702 "\tnormal:\talways\n"
2703 "\twhitelist:\tsame-domain\n"
2704 "\tkiosk:\talways");
2705 if (browser_mode == XT_BM_WHITELIST &&
2706 referer_mode != XT_REFERER_SAME_DOMAIN)
2707 return (1);
2708 if (browser_mode == XT_BM_NORMAL && referer_mode != XT_REFERER_ALWAYS)
2709 return (1);
2710 if (browser_mode == XT_BM_KIOSK && referer_mode != XT_REFERER_ALWAYS)
2711 return (1);
2712 return (0);
2715 char *
2716 get_ssl_ca_file(struct settings *s)
2718 if (strlen(ssl_ca_file) == 0)
2719 return (NULL);
2720 return (g_strdup(ssl_ca_file));
2724 set_refresh_interval(char *value)
2726 int tmp;
2727 const char *errstr;
2729 if (value == NULL || strlen(value) == 0)
2730 refresh_interval = XT_DS_REFRESH_INTERVAL;
2731 else {
2732 tmp = strtonum(value, 0, INT_MAX, &errstr);
2733 if (errstr)
2734 return (-1);
2735 refresh_interval = tmp;
2737 return (0);
2741 check_resource_dir(char **tt)
2743 *tt = g_strdup_printf("Default: %s", XT_DS_RESOURCE_DIR);
2744 return (g_strcmp0(resource_dir, XT_DS_RESOURCE_DIR));
2748 check_save_global_history(char **tt)
2750 *tt = g_strdup("Default: Disabled");
2751 return (save_global_history != 0);
2755 check_save_rejected_cookies(char **tt)
2757 *tt = g_strdup("Default: Disabled");
2758 return (save_rejected_cookies != 0);
2762 check_refresh_interval(char **tt)
2764 *tt = g_strdup_printf("Default: %d", XT_DS_REFRESH_INTERVAL);
2765 return (refresh_interval != XT_DS_REFRESH_INTERVAL);
2769 set_session_autosave(char *value)
2771 int tmp;
2772 const char *errstr;
2774 if (value == NULL || strlen(value) == 0)
2775 session_autosave = XT_DS_SESSION_AUTOSAVE;
2776 else {
2777 tmp = strtonum(value, 0, 1, &errstr);
2778 if (errstr)
2779 return (-1);
2780 session_autosave = tmp;
2782 return (0);
2786 check_session_autosave(char **tt)
2788 *tt = g_strdup_printf("Default: %s",
2789 XT_DS_SESSION_AUTOSAVE ? "Enabled" : "Disabled");
2790 return (session_autosave != XT_DS_SESSION_AUTOSAVE);
2794 set_session_timeout(char *value)
2796 int tmp;
2797 const char *errstr;
2799 if (value == NULL || strlen(value) == 0)
2800 session_timeout = XT_DS_SESSION_TIMEOUT;
2801 else {
2802 tmp = strtonum(value, 0, INT_MAX, &errstr);
2803 if (errstr)
2804 return (-1);
2805 session_timeout = tmp;
2807 return (0);
2811 check_session_timeout(char **tt)
2813 *tt = g_strdup_printf("Default: %d", XT_DS_SESSION_TIMEOUT);
2814 return (session_timeout != XT_DS_SESSION_TIMEOUT);
2818 set_show_scrollbars(char *value)
2820 struct tab *t;
2821 int tmp;
2822 const char *errstr;
2824 if (value == NULL || strlen(value) == 0)
2825 tmp = XT_DS_SHOW_SCROLLBARS;
2826 else {
2827 tmp = strtonum(value, 0, 1, &errstr);
2828 if (errstr)
2829 return (-1);
2831 show_scrollbars = tmp;
2832 TAILQ_FOREACH(t, &tabs, entry)
2833 if (set_scrollbar_visibility(t, show_scrollbars))
2834 return (-1);
2835 return (0);
2839 check_show_scrollbars(char **tt)
2841 *tt = g_strdup("Default (depends on gui_mode):\n"
2842 "\tclassic:\tEnabled\n"
2843 "\tminimal:\tDisabled");
2844 if (gui_mode == XT_GM_CLASSIC && show_scrollbars != 1)
2845 return (1);
2846 if (gui_mode == XT_GM_MINIMAL && show_scrollbars != 0)
2847 return (1);
2848 return (0);
2852 set_show_statusbar(char *value)
2854 int tmp;
2855 const char *errstr;
2857 if (value == NULL || strlen(value) == 0)
2858 tmp = XT_DS_SHOW_STATUSBAR;
2859 else {
2860 tmp = strtonum(value, 0, 1, &errstr);
2861 if (errstr)
2862 return (-1);
2864 show_statusbar = tmp;
2865 statusbar_set_visibility();
2866 return (0);
2870 check_show_statusbar(char **tt)
2872 *tt = g_strdup("Default (depends on gui_mode):\n"
2873 "\tclassic:\tDisabled\n"
2874 "\tminimal:\tEnabled");
2875 if (gui_mode == XT_GM_CLASSIC && show_statusbar != 0)
2876 return (1);
2877 if (gui_mode == XT_GM_MINIMAL && show_statusbar != 1)
2878 return (1);
2879 return (0);
2883 set_show_tabs(char *value)
2885 struct karg args = {0};
2886 int val;
2887 const char *errstr;
2889 if (value == NULL || strlen(value) == 0)
2890 val = XT_DS_SHOW_TABS;
2891 else {
2892 val = strtonum(value, 0, 1, &errstr);
2893 if (errstr)
2894 return (-1);
2896 args.i = val ? XT_TAB_SHOW : XT_TAB_HIDE;
2897 tabaction(get_current_tab(), &args);
2898 return (0);
2902 check_show_tabs(char **tt)
2904 *tt = g_strdup("Default (depends on gui_mode):\n"
2905 "\tclassic:\tEnabled\n"
2906 "\tminimal:\tDisabled");
2907 if (gui_mode == XT_GM_CLASSIC && show_tabs != 1)
2908 return (1);
2909 if (gui_mode == XT_GM_MINIMAL && show_tabs != 0)
2910 return (1);
2911 return (0);
2915 set_show_url(char *value)
2917 struct karg args = {0};
2918 int val;
2919 const char *errstr;
2921 if (value == NULL || strlen(value) == 0)
2922 val = XT_DS_SHOW_URL;
2923 else {
2924 val = strtonum(value, 0, 1, &errstr);
2925 if (errstr)
2926 return (-1);
2928 args.i = val ? XT_URL_SHOW : XT_URL_HIDE;
2929 urlaction(get_current_tab(), &args);
2930 return (0);
2934 check_show_url(char **tt)
2936 *tt = g_strdup("Default (depends on gui_mode):\n"
2937 "\tclassic:\tEnabled\n"
2938 "\tminimal:\tDisabled");
2939 if (gui_mode == XT_GM_CLASSIC && show_url != 1)
2940 return (1);
2941 if (gui_mode == XT_GM_MINIMAL && show_url != 0)
2942 return (1);
2943 return (0);
2947 check_single_instance(char **tt)
2949 *tt = g_strdup("Default: Disabled");
2950 return (single_instance != 0);
2954 set_spell_check_languages(char *value)
2956 struct tab *t;
2958 if (spell_check_languages)
2959 g_free(spell_check_languages);
2960 if (value == NULL || strlen(value) == 0)
2961 spell_check_languages = g_strdup(XT_DS_SPELL_CHECK_LANGUAGES);
2962 else
2963 spell_check_languages = g_strdup(value);
2964 TAILQ_FOREACH(t, &tabs, entry)
2965 g_object_set(G_OBJECT(t->settings), "spell_checking_languages",
2966 spell_check_languages, (char *)NULL);
2967 return (0);
2971 check_spell_check_languages(char **tt)
2973 *tt = g_strdup_printf("Default: %s", XT_DS_SPELL_CHECK_LANGUAGES);
2974 return (g_strcmp0(spell_check_languages, XT_DS_SPELL_CHECK_LANGUAGES));
2978 check_valid_file(char *name)
2980 struct stat sb;
2982 if (name == NULL || stat(name, &sb))
2983 return (-1);
2984 return (0);
2988 set_ssl_ca_file_rt(char *value)
2990 if (value == NULL || strlen(value) == 0) {
2991 strlcpy(ssl_ca_file, XT_DS_SSL_CA_FILE, sizeof ssl_ca_file);
2992 g_object_set(session, SOUP_SESSION_SSL_CA_FILE, "", NULL);
2993 return (0);
2994 } else
2995 return (set_ssl_ca_file(NULL, value));
2999 check_ssl_ca_file(char **tt)
3001 *tt = g_strdup("Default: (empty)");
3002 return (g_strcmp0(ssl_ca_file, XT_DS_SSL_CA_FILE));
3006 set_ssl_strict_certs(char *value)
3008 int tmp;
3009 const char *errstr;
3011 if (value == NULL || strlen(value) == 0)
3012 ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
3013 else {
3014 tmp = strtonum(value, 0, 1, &errstr);
3015 if (errstr)
3016 return (-1);
3017 ssl_strict_certs = tmp;
3019 g_object_set(session, SOUP_SESSION_SSL_STRICT, ssl_strict_certs, NULL);
3020 return (0);
3024 check_ssl_strict_certs(char **tt)
3026 *tt = g_strdup_printf("Default: %s",
3027 XT_DS_SSL_STRICT_CERTS ? "Enabled" : "Disabled");
3028 return (ssl_strict_certs != XT_DS_SSL_STRICT_CERTS);
3032 check_statusbar_elems(char **tt)
3034 *tt = g_strdup("Default: BP");
3035 return (g_strcmp0(statusbar_elems, "BP"));
3039 set_external_editor(char *editor)
3041 if (external_editor)
3042 g_free(external_editor);
3043 if (editor == NULL || strlen(editor) == 0)
3044 external_editor = NULL;
3045 else
3046 external_editor = g_strdup(editor);
3047 return (0);
3051 check_external_editor(char **tt)
3053 *tt = g_strdup("Default: (empty)");
3054 return (g_strcmp0(external_editor, NULL));
3058 set_fancy_bar(char *value)
3060 struct tab *t;
3061 int tmp;
3062 const char *errstr;
3064 if (value == NULL || strlen(value) == 0)
3065 fancy_bar = 1; /* XXX */
3066 else {
3067 tmp = strtonum(value, 0, 1, &errstr);
3068 if (errstr)
3069 return (-1);
3070 fancy_bar = tmp;
3072 TAILQ_FOREACH(t, &tabs, entry)
3073 if (fancy_bar) {
3074 gtk_widget_show(t->backward);
3075 gtk_widget_show(t->forward);
3076 gtk_widget_show(t->stop);
3077 gtk_widget_show(t->js_toggle);
3078 if (search_string && strlen(search_string))
3079 gtk_widget_show(t->search_entry);
3080 } else {
3081 gtk_widget_hide(t->backward);
3082 gtk_widget_hide(t->forward);
3083 gtk_widget_hide(t->stop);
3084 gtk_widget_hide(t->js_toggle);
3085 gtk_widget_hide(t->search_entry);
3087 return (0);
3091 check_fancy_bar(char **tt)
3093 *tt = g_strdup("Default (depends on gui_mode):\n"
3094 "\tclassic:\tEnabled\n"
3095 "\tminimal:\tDisabled");
3096 if (gui_mode == XT_GM_CLASSIC && fancy_bar != 1)
3097 return (1);
3098 if (gui_mode == XT_GM_MINIMAL && fancy_bar != 0)
3099 return (1);
3100 return (0);
3104 setup_proxy(const char *uri)
3106 struct tab *t;
3108 if (proxy_uri) {
3109 #if SOUP_CHECK_VERSION(2, 42, 2)
3110 g_object_set(session, "proxy-resolver", NULL, (char *)NULL);
3111 g_object_unref(proxy_uri);
3112 #else
3113 g_object_set(session, "proxy-uri", NULL, (char *)NULL);
3114 soup_uri_free(proxy_uri);
3115 #endif
3116 proxy_uri = NULL;
3117 TAILQ_FOREACH(t, &tabs, entry)
3118 if (t->sbe.proxy != NULL)
3119 gtk_label_set_text(GTK_LABEL(t->sbe.proxy), "");
3122 if (http_proxy) {
3123 if (http_proxy != uri) {
3124 g_free(http_proxy);
3125 http_proxy = NULL;
3129 if (uri && check_http_proxy_scheme(uri) != 1)
3130 return (1);
3132 if (uri) {
3133 http_proxy = g_strdup(uri);
3134 DNPRINTF(XT_D_CONFIG, "setup_proxy: %s\n", uri);
3135 #if SOUP_CHECK_VERSION(2, 42, 2)
3136 proxy_uri = g_simple_proxy_resolver_new(http_proxy, proxy_exclude);
3137 if (proxy_uri != NULL) {
3138 g_object_set(session, "proxy-resolver", proxy_uri,
3139 (char *)NULL);
3140 #else
3141 proxy_uri = soup_uri_new(http_proxy);
3142 if (proxy_uri != NULL && SOUP_URI_VALID_FOR_HTTP(proxy_uri)) {
3143 g_object_set(session, "proxy-uri", proxy_uri,
3144 (char *)NULL);
3145 #endif
3146 TAILQ_FOREACH(t, &tabs, entry) {
3147 if (t->sbe.proxy != NULL) {
3148 gtk_label_set_text(
3149 GTK_LABEL(t->sbe.proxy), "proxy");
3151 gtk_widget_show(t->proxy_toggle);
3152 button_set_file(t->proxy_toggle,
3153 "torenabled.ico");
3156 } else {
3157 TAILQ_FOREACH(t, &tabs, entry)
3158 button_set_file(t->proxy_toggle, "tordisabled.ico");
3160 return (0);
3163 char *
3164 get_tab_style(struct settings *s)
3166 if (tab_style == XT_TABS_NORMAL)
3167 return (g_strdup("normal"));
3168 else
3169 return (g_strdup("compact"));
3173 set_tab_style(struct settings *s, char *val)
3175 if (!strcmp(val, "normal"))
3176 tab_style = XT_TABS_NORMAL;
3177 else if (!strcmp(val, "compact"))
3178 tab_style = XT_TABS_COMPACT;
3179 else
3180 return (1);
3182 return (0);
3186 check_tab_style(char **tt)
3188 *tt = g_strdup("Default (depends on gui_mode):\n"
3189 "\tclassic:\tnormal\n"
3190 "\tminimal:\tcompact");
3191 if (gui_mode == XT_GM_CLASSIC && tab_style != XT_TABS_NORMAL)
3192 return (1);
3193 if (gui_mode == XT_GM_MINIMAL && tab_style != XT_TABS_COMPACT)
3194 return (1);
3195 return (0);
3199 set_tab_style_rt(char *value)
3201 struct karg args = {0};
3202 int old_tab_style;
3204 if (value == NULL || strlen(value) == 0) {
3205 if (tab_style == XT_DS_TAB_STYLE)
3206 return (0);
3207 tab_style = XT_TABS_COMPACT;
3208 args.i = XT_TAB_NEXTSTYLE;
3209 } else {
3210 old_tab_style = tab_style;
3211 if (set_tab_style(NULL, value))
3212 return (-1);
3213 if (old_tab_style != tab_style) {
3214 tab_style = old_tab_style;
3215 args.i = XT_TAB_NEXTSTYLE;
3218 tabaction(get_current_tab(), &args);
3219 return (0);
3222 char *
3223 get_statusbar_style(struct settings *s)
3225 if (statusbar_style == XT_STATUSBAR_URL)
3226 return (g_strdup("url"));
3227 else
3228 return (g_strdup("title"));
3232 set_statusbar_style(struct settings *s, char *val)
3234 if (!strcmp(val, "url"))
3235 statusbar_style = XT_STATUSBAR_URL;
3236 else if (!strcmp(val, "title"))
3237 statusbar_style = XT_STATUSBAR_TITLE;
3238 else
3239 return (1);
3241 return (0);
3245 set_statusbar_style_rt(char *value)
3247 struct tab *t;
3248 const gchar *page_uri;
3250 if (value == NULL || strlen(value) == 0) {
3251 if (statusbar_style == XT_DS_STATUSBAR_STYLE)
3252 return (0);
3253 statusbar_style = XT_DS_STATUSBAR_STYLE;
3254 } else {
3255 if (!strcmp(value, "url"))
3256 statusbar_style = XT_STATUSBAR_URL;
3257 else if (!strcmp(value, "title"))
3258 statusbar_style = XT_STATUSBAR_TITLE;
3261 /* apply changes */
3262 TAILQ_FOREACH(t, &tabs, entry) {
3263 if (statusbar_style == XT_STATUSBAR_TITLE)
3264 set_status(t, "%s", get_title(t, FALSE));
3265 else if ((page_uri = get_uri(t)) != NULL)
3266 set_status(t, "%s", page_uri);
3269 return (0);
3273 check_statusbar_style(char **tt)
3275 *tt = g_strdup("Default: url");
3276 return (statusbar_style != XT_DS_STATUSBAR_STYLE);
3280 set_url_regex(char *value)
3282 if (value == NULL || strlen(value) == 0) {
3283 if (url_regex)
3284 g_free(url_regex);
3285 url_regex = g_strdup(XT_DS_URL_REGEX);
3286 } else {
3287 if (regcomp(&url_re, value, REG_EXTENDED | REG_NOSUB))
3288 return (-1);
3289 if (url_regex)
3290 g_free(url_regex);
3291 url_regex = g_strdup(value);
3293 return (0);
3297 check_url_regex(char **tt)
3299 *tt = g_strdup_printf("Default: %s", XT_DS_URL_REGEX);
3300 return (g_strcmp0(url_regex, XT_DS_URL_REGEX));
3304 set_userstyle(struct settings *s, char *value)
3306 int rv = 0;
3307 char script[PATH_MAX] = {'\0'};
3308 char *tmp;
3310 if (value == NULL || strlen(value) == 0) {
3311 snprintf(script, sizeof script, "%s" PS "style.css", resource_dir);
3312 tmp = g_filename_to_uri(script, NULL, NULL);
3313 if (tmp == NULL)
3314 rv = -1;
3315 else {
3316 if (userstyle)
3317 g_free(userstyle);
3318 userstyle = tmp;
3320 } else {
3321 expand_tilde(script, sizeof script, value);
3322 tmp = g_filename_to_uri(script, NULL, NULL);
3323 if (tmp == NULL)
3324 rv = -1;
3325 else {
3326 if (userstyle)
3327 g_free(userstyle);
3328 userstyle = tmp;
3331 if (stylesheet)
3332 g_free(stylesheet);
3333 stylesheet = g_strdup(userstyle);
3334 return (rv);
3337 char *
3338 get_userstyle(struct settings *s)
3340 if (userstyle)
3341 return (g_filename_from_uri(userstyle, NULL, NULL));
3342 return (NULL);
3346 set_userstyle_rt(char *value)
3348 return (set_userstyle(NULL, value));
3352 check_userstyle(char **tt)
3354 int rv = 0;
3355 char buf[PATH_MAX];
3356 char *file = NULL;
3358 snprintf(buf, sizeof buf, "%s" PS "%s", resource_dir, "style.css");
3359 *tt = g_strdup_printf("Default: %s", buf);
3360 file = g_filename_from_uri(userstyle, NULL, NULL);
3361 rv = g_strcmp0(file, buf);
3362 if (file)
3363 g_free(file);
3364 return (rv);
3368 set_userstyle_global(char *value)
3370 struct karg args = {0};
3371 int tmp, old_style;
3372 const char *errstr;
3374 if (value == NULL || strlen(value) == 0) {
3375 if (userstyle_global == XT_DS_USERSTYLE_GLOBAL)
3376 return (0);
3377 userstyle_global = 1;
3378 args.i = XT_STYLE_GLOBAL;
3379 userstyle_cmd(get_current_tab(), &args);
3380 } else {
3381 old_style = userstyle_global;
3382 tmp = strtonum(value, 0, 1, &errstr);
3383 if (errstr)
3384 return (-1);
3385 if (tmp != old_style) {
3386 args.i = XT_STYLE_GLOBAL;
3387 userstyle_cmd(get_current_tab(), &args);
3390 return (0);
3394 check_userstyle_global(char **tt)
3396 *tt = g_strdup_printf("Default: %s",
3397 XT_DS_USERSTYLE_GLOBAL ? "Enabled" : "Disabled");
3398 return (userstyle_global != XT_DS_USERSTYLE_GLOBAL);
3402 set_warn_cert_changes(char *value)
3404 int tmp;
3405 const char *errstr;
3407 if (value == NULL || strlen(value) == 0)
3408 warn_cert_changes = XT_DS_WARN_CERT_CHANGES;
3409 else {
3410 tmp = strtonum(value, 0, 1, &errstr);
3411 if (errstr)
3412 return (-1);
3413 warn_cert_changes = tmp;
3415 return (0);
3419 check_warn_cert_changes(char **tt)
3421 *tt = g_strdup_printf("Default: %s",
3422 XT_DS_WARN_CERT_CHANGES ? "Enabled" : "Disabled");
3423 return (warn_cert_changes != XT_DS_WARN_CERT_CHANGES);
3427 check_window_height(char **tt)
3429 *tt = g_strdup_printf("Default: %d", 768);
3430 return (window_height != 768);
3434 check_window_maximize(char **tt)
3436 *tt = g_strdup("Default: Disabled");
3437 return (window_maximize != 0);
3441 check_window_width(char **tt)
3443 *tt = g_strdup_printf("Default: %d", 768);
3444 return (window_width != 1024);
3448 check_work_dir(char **tt)
3450 struct passwd *pwd;
3451 char buf[PATH_MAX];
3453 if ((pwd = getpwuid(getuid())) == NULL)
3454 return (-1);
3455 snprintf(buf, sizeof buf, "%s" PS ".xombrero", pwd->pw_dir);
3456 *tt = g_strdup_printf("Default: %s", buf);
3457 return (g_strcmp0(work_dir, buf));
3460 char *
3461 get_edit_mode(struct settings *s)
3463 if (edit_mode == XT_EM_HYBRID)
3464 return (g_strdup("hybrid"));
3465 else
3466 return (g_strdup("vi"));
3470 set_edit_mode(struct settings *s, char *val)
3472 if (!strcmp(val, "hybrid"))
3473 edit_mode = XT_EM_HYBRID;
3474 else if (!strcmp(val, "vi"))
3475 edit_mode = XT_EM_VI;
3476 else
3477 return (1);
3479 return (0);
3483 check_edit_mode(char **tt)
3485 *tt = g_strdup("Default: hybrid");
3486 return (edit_mode != XT_EM_HYBRID);
3489 char *
3490 get_download_mode(struct settings *s)
3492 switch (download_mode) {
3493 case XT_DM_START:
3494 return (g_strdup("start"));
3495 break;
3496 case XT_DM_ASK:
3497 return (g_strdup("ask"));
3498 break;
3499 case XT_DM_ADD:
3500 return (g_strdup("add"));
3501 break;
3503 return (g_strdup("unknown"));
3507 set_download_mode(struct settings *s, char *val)
3509 if (val == NULL || strlen(val) == 0 || !strcmp(val, "start"))
3510 download_mode = XT_DM_START;
3511 else if (!strcmp(val, "ask"))
3512 download_mode = XT_DM_ASK;
3513 else if (!strcmp(val, "add"))
3514 download_mode = XT_DM_ADD;
3515 else
3516 return (1);
3518 return (0);
3522 set_download_mode_rt(char *val)
3524 return (set_download_mode(NULL, val));
3528 check_download_mode(char **tt)
3530 *tt = g_strdup("Default: start");
3531 return (download_mode != XT_DM_START);
3534 char *
3535 get_work_dir(struct settings *s)
3537 if (work_dir[0] == '\0')
3538 return (0);
3539 return (g_strdup(work_dir));
3543 set_work_dir(struct settings *s, char *val)
3545 expand_tilde(work_dir, sizeof work_dir, val);
3546 return (0);
3549 void
3550 walk_cookie_wl(struct settings *s,
3551 void (*cb)(struct settings *, char *, void *), void *cb_args)
3553 struct wl_entry *w;
3555 if (s == NULL || cb == NULL) {
3556 show_oops(NULL, "walk_cookie_wl invalid parameters");
3557 return;
3560 TAILQ_FOREACH_REVERSE(w, &c_wl, wl_list, entry)
3561 cb(s, w->pat, cb_args);
3564 void
3565 walk_js_wl(struct settings *s,
3566 void (*cb)(struct settings *, char *, void *), void *cb_args)
3568 struct wl_entry *w;
3570 if (s == NULL || cb == NULL) {
3571 show_oops(NULL, "walk_js_wl invalid parameters");
3572 return;
3575 TAILQ_FOREACH_REVERSE(w, &js_wl, wl_list, entry)
3576 cb(s, w->pat, cb_args);
3579 void
3580 walk_pl_wl(struct settings *s,
3581 void (*cb)(struct settings *, char *, void *), void *cb_args)
3583 struct wl_entry *w;
3585 if (s == NULL || cb == NULL) {
3586 show_oops(NULL, "walk_pl_wl invalid parameters");
3587 return;
3590 TAILQ_FOREACH_REVERSE(w, &pl_wl, wl_list, entry)
3591 cb(s, w->pat, cb_args);
3594 void
3595 walk_force_https(struct settings *s,
3596 void (*cb)(struct settings *, char *, void *), void *cb_args)
3598 struct wl_entry *w;
3600 if (s == NULL || cb == NULL) {
3601 show_oops(NULL, "walk_force_https invalid parameters");
3602 return;
3605 TAILQ_FOREACH_REVERSE(w, &force_https, wl_list, entry)
3606 cb(s, w->pat, cb_args);
3610 settings_add(char *var, char *val)
3612 int i, rv, *p;
3613 int tmp;
3614 double *d;
3615 char c[PATH_MAX], **s;
3616 const char *errstr;
3618 /* get settings */
3619 for (i = 0, rv = 0; i < LENGTH(rs); i++) {
3620 errstr = NULL;
3622 if (strcmp(var, rs[i].name))
3623 continue;
3625 if (!strcmp(var, "include_config")) {
3626 expand_tilde(c, sizeof c, val);
3627 config_parse(c, 0);
3628 rv = 1;
3629 break;
3632 if (rs[i].s) {
3633 if (rs[i].s->set(&rs[i], val))
3634 startpage_add("invalid value for %s: %s", var,
3635 val);
3636 rv = 1;
3637 break;
3638 } else
3639 switch (rs[i].type) {
3640 case XT_S_INT: /* FALLTHROUGH */
3641 case XT_S_BOOL:
3642 p = rs[i].ival;
3643 tmp = strtonum(val, INT_MIN, INT_MAX, &errstr);
3644 if (errstr)
3645 break;
3646 *p = tmp;
3647 rv = 1;
3648 break;
3649 case XT_S_STR:
3650 s = rs[i].sval;
3651 if (s == NULL)
3652 errx(1, "invalid sval for %s",
3653 rs[i].name);
3654 if (*s)
3655 g_free(*s);
3656 *s = g_strdup(val);
3657 rv = 1;
3658 break;
3659 case XT_S_DOUBLE:
3660 d = rs[i].dval;
3661 *d = g_ascii_strtod(val, NULL);
3662 rv = 1;
3663 break;
3664 case XT_S_INVALID:
3665 default:
3666 errx(1, "invalid type for %s", var);
3668 break;
3670 return (rv);
3673 #define WS "\n= \t"
3674 void
3675 config_parse(char *filename, int runtime)
3677 FILE *config, *f;
3678 char *line, *cp, *var, *val;
3679 size_t len, lineno = 0;
3680 int handled;
3681 char file[PATH_MAX];
3682 struct stat sb;
3684 DNPRINTF(XT_D_CONFIG, "config_parse: filename %s\n", filename);
3686 if (filename == NULL)
3687 return;
3689 if (runtime && runtime_settings[0] != '\0') {
3690 snprintf(file, sizeof file, "%s" PS "%s",
3691 work_dir, runtime_settings);
3692 if (stat(file, &sb)) {
3693 warnx("runtime file doesn't exist, creating it");
3694 if ((f = fopen(file, "w")) == NULL)
3695 err(1, "runtime");
3696 fprintf(f, "# AUTO GENERATED, DO NOT EDIT\n");
3697 fclose(f);
3699 } else
3700 strlcpy(file, filename, sizeof file);
3702 if ((config = fopen(file, "r")) == NULL) {
3703 warn("config_parse: cannot open %s", filename);
3704 return;
3707 for (;;) {
3708 if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL)
3709 if (feof(config) || ferror(config))
3710 break;
3712 cp = line;
3713 cp += (long)strspn(cp, WS);
3714 if (cp[0] == '\0') {
3715 /* empty line */
3716 free(line);
3717 continue;
3720 if ((var = strsep(&cp, WS)) == NULL || cp == NULL)
3721 startpage_add("invalid configuration file entry: %s",
3722 line);
3723 else {
3724 cp += (long)strspn(cp, WS);
3726 if ((val = strsep(&cp, "\0")) == NULL)
3727 break;
3729 DNPRINTF(XT_D_CONFIG, "config_parse: %s=%s\n",
3730 var, val);
3731 g_strstrip(val);
3732 handled = settings_add(var, val);
3734 if (handled == 0)
3735 startpage_add("invalid configuration file entry"
3736 ": %s=%s", var, val);
3739 free(line);
3742 fclose(config);
3745 struct settings_args {
3746 char **body;
3747 int i;
3750 void
3751 print_setting(struct settings *s, char *val, void *cb_args)
3753 char *color;
3754 gchar *tmp, *enc_val;
3755 struct settings_args *sa = cb_args;
3757 if (sa == NULL || s->flags & XT_SF_INVISIBLE)
3758 return;
3760 if (s->flags & XT_SF_RUNTIME)
3761 color = "#22cc22";
3762 else
3763 color = "#cccccc";
3765 enc_val = html_escape(val);
3766 tmp = *sa->body;
3767 *sa->body = g_strdup_printf(
3768 "%s\n<tr>"
3769 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
3770 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
3771 *sa->body,
3772 color,
3773 s->name,
3774 color,
3775 enc_val == NULL ? "" : enc_val
3777 g_free(tmp);
3778 if (enc_val)
3779 g_free(enc_val);
3780 sa->i++;
3783 void
3784 print_runtime_setting(struct settings *s, char *val, void *cb_args)
3786 char *tmp, *tt = NULL;
3787 struct settings_args *sa = cb_args;
3788 int modified = 0;
3789 int i;
3791 if (sa == NULL)
3792 return;
3794 if (s == NULL || s->flags & XT_SF_INVISIBLE || s->activate == NULL)
3795 return;
3797 tmp = *sa->body;
3798 if (s->ismodified)
3799 modified = s->ismodified(&tt);
3800 *sa->body = g_strdup_printf(
3801 "%s\n<tr %s>"
3802 "<td title=\"%s\" style='width: 240px;'><div style='width: 100%%;'>%s</div></td>"
3803 "<td title=\"%s\"><div style='width: 100%%; word-break:break-all'>",
3804 *sa->body,
3805 modified ? "id='modified'" : "",
3806 s->tt ? s->tt : "",
3807 s->name,
3808 tt);
3809 g_free(tmp);
3810 g_free(tt);
3812 tmp = *sa->body;
3813 if (s->type == XT_S_STR && s->s && s->s->valid_options[0]) {
3814 *sa->body = g_strdup_printf("%s<select name='%s'>",
3815 *sa->body,
3816 s->name);
3817 for (i = 0; s->s->valid_options[i]; ++i) {
3818 g_free(tmp);
3819 tmp = *sa->body;
3820 *sa->body = g_strdup_printf("%s"
3821 "<option value='%s' %s>%s</option>",
3822 *sa->body,
3823 s->s->valid_options[i],
3824 !strcmp(s->s->valid_options[i], val) ? "selected" : "",
3825 s->s->valid_options[i]);
3827 } else if (s->type == XT_S_STR)
3828 *sa->body = g_strdup_printf(
3829 "%s<input style='width: 98%%' type='text' name='%s' value='%s'>"
3830 "</div></td></tr>",
3831 *sa->body,
3832 s->name,
3833 val ? val : "");
3834 else if (s->type == XT_S_INT)
3835 *sa->body = g_strdup_printf(
3836 "%s<input type='number' name='%s' value='%s'>"
3837 "</div></td></tr>",
3838 *sa->body,
3839 s->name,
3840 val);
3841 else if (s->type == XT_S_DOUBLE)
3842 *sa->body = g_strdup_printf(
3843 "%s<input type='number' step='0.000001' name='%s' value='%s'>"
3844 "</div></td></tr>",
3845 *sa->body,
3846 s->name,
3847 val);
3848 else if (s->type == XT_S_BOOL)
3849 *sa->body = g_strdup_printf(
3850 "%s<input type='hidden' name='%s' value='0'>"
3851 "<input type='checkbox' name='%s' value='1''%s>"
3852 "</div></td></tr>",
3853 *sa->body,
3854 s->name,
3855 s->name,
3856 atoi(val) ? " checked='checked'" : "");
3857 else {
3858 *sa->body = g_strdup(*sa->body);
3859 warnx("Did not print setting %s", s->name);
3861 g_free(tmp);
3862 sa->i++;
3865 char *
3866 print_set_rejects(void)
3868 struct set_reject *sr, *st;
3869 char *body = NULL, *tmp;
3871 if (TAILQ_EMPTY(&srl))
3872 return (NULL);
3874 body = g_strdup_printf("The following settings were invalid and could "
3875 "not be set:<br><div align='center'><table id='settings'>"
3876 "<th align='left'>Setting</th>"
3877 "<th align='left'>Value</th>");
3878 TAILQ_FOREACH_SAFE(sr, &srl, entry, st) {
3879 tmp = body;
3880 body = g_strdup_printf("%s\n<tr>"
3881 "<td style='width:240px'><div>%s</div></td>"
3882 "<td><div style='word-break:break-all'>%s</div></td></tr>",
3883 body,
3884 sr->name,
3885 sr->value);
3886 g_free(tmp);
3887 TAILQ_REMOVE(&srl, sr, entry);
3888 g_free(sr->name);
3889 g_free(sr->value);
3890 g_free(sr);
3892 tmp = body;
3893 body = g_strdup_printf("%s</table></div><br>", body);
3894 g_free(tmp);
3895 return (body);
3899 xtp_page_set(struct tab *t, struct karg *args)
3901 char *body, *page, *tmp;
3902 int i = 1;
3903 struct settings_args sa;
3905 bzero(&sa, sizeof sa);
3906 sa.body = &body;
3908 /* body */
3909 body = g_strdup_printf("<div align='center'><table><tr>"
3910 "<th align='left'>Setting</th>"
3911 "<th align='left'>Value</th></tr>\n");
3913 settings_walk(print_setting, &sa);
3914 i = sa.i;
3916 /* small message if there are none */
3917 if (i == 1) {
3918 tmp = body;
3919 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3920 "colspan='2'>No settings</td></tr>\n", body);
3921 g_free(tmp);
3924 tmp = body;
3925 body = g_strdup_printf("%s</table></div>", body);
3926 g_free(tmp);
3928 page = get_html_page("Settings", body, "", 0);
3930 g_free(body);
3932 load_webkit_string(t, page, XT_URI_ABOUT_SET, 0);
3934 g_free(page);
3936 return (XT_CB_PASSTHROUGH);
3940 xtp_page_rt(struct tab *t, struct karg *args)
3942 char *body = NULL, *page, *tmp;
3943 int i = 1;
3944 struct settings_args sa;
3946 generate_xtp_session_key(&t->session_key);
3948 bzero(&sa, sizeof sa);
3949 sa.body = &body;
3951 /* body */
3952 body = print_set_rejects();
3954 tmp = body;
3955 body = g_strdup_printf("%s<div align='center'>"
3956 "<form method='GET' action='%s%d/%s/%d'>"
3957 "<input type='submit' value='Save Settings'>"
3958 "<table id='settings'>"
3959 "<th align='left'>Setting</th>"
3960 "<th align='left'>Value</th>\n",
3961 body ? body : "",
3962 XT_XTP_STR,
3963 XT_XTP_RT,
3964 t->session_key,
3965 XT_XTP_RT_SAVE);
3966 g_free(tmp);
3968 settings_walk(print_runtime_setting, &sa);
3969 i = sa.i;
3971 /* small message if there are none */
3972 if (i == 1) {
3973 tmp = body;
3974 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3975 "colspan='2'>No settings</td></tr>\n", body);
3976 g_free(tmp);
3979 tmp = body;
3980 body = g_strdup_printf("%s</table>"
3981 "<input type='submit' value='Save Settings'></form></div>", body);
3982 g_free(tmp);
3984 page = get_html_page("Runtime Settings", body, "", 1);
3986 g_free(body);
3988 load_webkit_string(t, page, XT_URI_ABOUT_RUNTIME, 0);
3990 g_free(page);
3992 return (XT_CB_PASSTHROUGH);
3996 set(struct tab *t, struct karg *args)
3998 char *p, *val;
3999 int i;
4001 if (args == NULL || args->s == NULL)
4002 return (xtp_page_set(t, args));
4004 /* strip spaces */
4005 p = g_strstrip(args->s);
4007 if (strlen(p) == 0)
4008 return (xtp_page_set(t, args));
4010 /* we got some sort of string */
4011 val = g_strstr_len(p, strlen(p), "=");
4012 if (val) {
4013 *val++ = '\0';
4014 val = g_strstrip(val);
4015 p = g_strchomp(p);
4017 for (i = 0; i < get_settings_size(); i++) {
4018 if (strcmp(rs[i].name, p))
4019 continue;
4021 if (rs[i].activate) {
4022 if (rs[i].activate(val))
4023 show_oops(t, "%s invalid value %s",
4024 p, val);
4025 else
4026 show_oops(t, ":set %s = %s", p, val);
4027 goto done;
4028 } else {
4029 show_oops(t, "not a runtime option: %s", p);
4030 goto done;
4033 show_oops(t, "unknown option: %s", p);
4034 } else {
4035 p = g_strchomp(p);
4037 for (i = 0; i < get_settings_size(); i++) {
4038 if (strcmp(rs[i].name, p))
4039 continue;
4041 /* XXX this could use some cleanup */
4042 switch (rs[i].type) {
4043 case XT_S_INT: /* FALLTHROUGH */
4044 case XT_S_BOOL:
4045 if (rs[i].ival)
4046 show_oops(t, "%s = %d",
4047 rs[i].name, *rs[i].ival);
4048 else if (rs[i].s && rs[i].s->get)
4049 show_oops(t, "%s = %s",
4050 rs[i].name,
4051 rs[i].s->get(&rs[i]));
4052 else if (rs[i].s && rs[i].s->get == NULL)
4053 show_oops(t, "%s = ...", rs[i].name);
4054 else
4055 show_oops(t, "%s = ", rs[i].name);
4056 break;
4057 case XT_S_DOUBLE:
4058 if (rs[i].dval)
4059 show_oops(t, "%s = %f",
4060 rs[i].name, *rs[i].dval);
4061 else if (rs[i].s && rs[i].s->get)
4062 show_oops(t, "%s = %s",
4063 rs[i].name,
4064 rs[i].s->get(&rs[i]));
4065 else if (rs[i].s && rs[i].s->get == NULL)
4066 show_oops(t, "%s = ...", rs[i].name);
4067 else
4068 show_oops(t, "%s = ", rs[i].name);
4069 break;
4070 case XT_S_STR:
4071 if (rs[i].sval && *rs[i].sval)
4072 show_oops(t, "%s = %s",
4073 rs[i].name, *rs[i].sval);
4074 else if (rs[i].s && rs[i].s->get)
4075 show_oops(t, "%s = %s",
4076 rs[i].name,
4077 rs[i].s->get(&rs[i]));
4078 else if (rs[i].s && rs[i].s->get == NULL)
4079 show_oops(t, "%s = ...", rs[i].name);
4080 else
4081 show_oops(t, "%s = ", rs[i].name);
4082 break;
4083 default:
4084 show_oops(t, "unknown type for %s", rs[i].name);
4085 goto done;
4088 goto done;
4090 show_oops(t, "unknown option: %s", p);
4092 done:
4093 return (XT_CB_PASSTHROUGH);