add urlmod plus and min
[xombrero.git] / settings.c
blob98fd74cb479cbda93a29b1966896c981c8734980
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>
10 * Permission to use, copy, modify, and distribute this software for any
11 * purpose with or without fee is hereby granted, provided that the above
12 * copyright notice and this permission notice appear in all copies.
14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #include <xombrero.h>
24 #include "tooltip.h"
26 /* globals */
27 SoupURI *proxy_uri = NULL;
28 PangoFontDescription *cmd_font;
29 PangoFontDescription *oops_font;
30 PangoFontDescription *statusbar_font;
31 PangoFontDescription *tabbar_font;
33 /* non-settings */
34 char search_file[PATH_MAX];
35 char command_file[PATH_MAX];
36 char runtime_settings[PATH_MAX]; /* override of settings */
38 /* settings that require restart */
39 int enable_socket = 0;
40 int single_instance = 0; /* only allow one xombrero to run */
41 int fancy_bar = 1; /* fancy toolbar */
42 int browser_mode = XT_BM_NORMAL;
43 int gui_mode = XT_GM_CLASSIC;
44 char *statusbar_elems = NULL;
45 int window_height = 768;
46 int window_width = 1024;
47 int window_maximize = 0;
48 int icon_size = 2; /* 1 = smallest, 2+ = bigger */
49 char *resource_dir = NULL;
50 char download_dir[PATH_MAX];
51 int allow_volatile_cookies = 0;
52 int save_global_history = 0; /* save global history to disk */
53 int save_rejected_cookies = 0;
54 gint max_connections = 25;
55 gint max_host_connections = 5;
56 int history_autosave = 0;
57 int edit_mode = XT_EM_HYBRID;
58 char *include_config = NULL;
59 int anonymize_headers = 0;
60 int tabless = 0; /* allow only 1 tab */
62 /* runtime settings */
63 int show_tabs = XT_DS_SHOW_TABS; /* show tabs on notebook */
64 int tab_style = XT_DS_TAB_STYLE; /* tab bar style */
65 int statusbar_style = XT_DS_STATUSBAR_STYLE; /* status bar style */
66 int show_url = XT_DS_SHOW_URL; /* show url toolbar on notebook */
67 int show_scrollbars = XT_DS_SHOW_SCROLLBARS;
68 int show_statusbar = XT_DS_SHOW_STATUSBAR; /* vimperator style status bar */
69 int ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS; /* ctrl click gets focus */
70 int cookies_enabled = XT_DS_COOKIES_ENABLED; /* enable cookies */
71 int read_only_cookies = XT_DS_READ_ONLY_COOKIES; /* enable to not write cookies */
72 int enable_scripts = XT_DS_ENABLE_SCRIPTS;
73 int enable_plugins = XT_DS_ENABLE_PLUGINS;
74 gfloat default_zoom_level = XT_DS_DEFAULT_ZOOM_LEVEL;
75 char default_script[PATH_MAX]; /* special setting - is never g_free'd */
76 int refresh_interval = XT_DS_REFRESH_INTERVAL; /* download refresh interval */
77 int enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
78 int enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
79 int enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
80 int enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
81 int session_timeout = XT_DS_SESSION_TIMEOUT; /* cookie session timeout */
82 int cookie_policy = XT_DS_COOKIE_POLICY;
83 char ssl_ca_file[PATH_MAX]; /* special setting - is never g_free'd */
84 gboolean ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
85 gboolean enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
86 int append_next = XT_DS_APPEND_NEXT; /* append tab after current tab */
87 char *home = NULL; /* allocated/set at startup */
88 char *search_string = NULL; /* allocated/set at startup */
89 char *http_proxy = NULL;
90 int http_proxy_starts_enabled = 1;
91 int download_mode = XT_DM_START;
92 int color_visited_uris = XT_DS_COLOR_VISITED_URIS;
93 int session_autosave = XT_DS_SESSION_AUTOSAVE;
94 int guess_search = XT_DS_GUESS_SEARCH;
95 gint enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
96 char *spell_check_languages = NULL; /* allocated/set at startup */
97 char *url_regex = NULL; /* allocated/set at startup */
98 char *encoding = NULL; /* allocated/set at startup */
99 int autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
100 int enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
101 char *userstyle = NULL; /* allocated/set at startup */
102 int userstyle_global = XT_DS_USERSTYLE_GLOBAL;
103 int auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
104 int enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
105 int enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
106 int enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
107 char *external_editor = NULL;
108 int referer_mode = XT_DS_REFERER_MODE;
109 char *referer_custom = NULL;
110 int download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
111 int warn_cert_changes = 0;
112 int allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
113 int allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
114 int do_not_track = XT_DS_DO_NOT_TRACK;
115 int preload_strict_transport = XT_DS_PRELOAD_STRICT_TRANSPORT;
116 char *gnutls_priority_string = XT_DS_GNUTLS_PRIORITY_STRING;
118 char *cmd_font_name = NULL; /* these are all set at startup */
119 char *oops_font_name = NULL;
120 char *statusbar_font_name = NULL;
121 char *tabbar_font_name = NULL;
123 char *get_download_dir(struct settings *);
124 char *get_default_script(struct settings *);
125 char *get_runtime_dir(struct settings *);
126 char *get_tab_style(struct settings *);
127 char *get_statusbar_style(struct settings *);
128 char *get_edit_mode(struct settings *);
129 char *get_download_mode(struct settings *);
130 char *get_work_dir(struct settings *);
131 char *get_referer(struct settings *);
132 char *get_ssl_ca_file(struct settings *);
133 char *get_userstyle(struct settings *);
134 char *get_gnutls_priority_string(struct settings *);
136 int add_cookie_wl(struct settings *, char *);
137 int add_js_wl(struct settings *, char *);
138 int add_pl_wl(struct settings *, char *);
139 int add_mime_type(struct settings *, char *);
140 int add_alias(struct settings *, char *);
141 int add_kb(struct settings *, char *);
142 int add_ua(struct settings *, char *);
143 int add_http_accept(struct settings *, char *);
144 int add_cmd_alias(struct settings *, char *);
145 int add_custom_uri(struct settings *, char *);
146 int add_force_https(struct settings *, char *);
148 int set_append_next(char *);
149 int set_autofocus_onload(char *);
150 int set_cmd_font(char *);
151 int set_color_visited_uris(char *);
152 int set_cookie_policy_rt(char *);
153 int set_cookies_enabled(char *);
154 int set_ctrl_click_focus(char *);
155 int set_fancy_bar(char *);
156 int set_home(char *);
157 int set_download_dir(struct settings *, char *);
158 int set_download_notifications(char *);
159 int set_default_script(struct settings *, char *);
160 int set_default_script_rt(char *);
161 int set_default_zoom_level(char *);
162 int set_enable_cookie_whitelist(char *);
163 int set_enable_js_autorun(char *);
164 int set_enable_js_whitelist(char *);
165 int set_enable_localstorage(char *);
166 int set_enable_plugins(char *);
167 int set_enable_plugin_whitelist(char *);
168 int set_enable_scripts(char *);
169 int set_enable_spell_checking(char *);
170 int set_enable_strict_transport(char *);
171 int set_encoding_rt(char *);
172 int set_runtime_dir(struct settings *, char *);
173 int set_tabbar_font(char *value);
174 int set_tab_style(struct settings *, char *);
175 int set_tab_style_rt(char *);
176 int set_statusbar_style(struct settings *, char *);
177 int set_statusbar_style_rt(char *);
178 int set_edit_mode(struct settings *, char *);
179 int set_work_dir(struct settings *, char *);
180 int set_auto_load_images(char *);
181 int set_enable_autoscroll(char *);
182 int set_enable_favicon_entry(char *);
183 int set_enable_favicon_tabs(char *);
184 int set_guess_search(char *);
185 int set_download_mode(struct settings *, char *);
186 int set_download_mode_rt(char *);
187 int set_oops_font(char *);
188 int set_read_only_cookies(char *);
189 int set_referer(struct settings *, char *);
190 int set_referer_rt(char *);
191 int set_refresh_interval(char *);
192 int set_search_string(char *s);
193 int set_session_autosave(char *);
194 int set_session_timeout(char *);
195 int set_show_scrollbars(char *);
196 int set_show_statusbar(char *);
197 int set_show_tabs(char *);
198 int set_show_url(char *);
199 int set_spell_check_languages(char *);
200 int set_ssl_ca_file_rt(char *);
201 int set_ssl_strict_certs(char *);
202 int set_statusbar_font(char *);
203 int set_url_regex(char *);
204 int set_userstyle(struct settings *, char *);
205 int set_userstyle_rt(char *);
206 int set_userstyle_global(char *);
207 int set_external_editor(char *);
208 int set_warn_cert_changes(char *);
209 int set_allow_insecure_content(char *);
210 int set_allow_insecure_scripts(char *);
211 int set_http_proxy(char *);
212 int set_do_not_track(char *);
213 int set_gnutls_priority_string(struct settings *, char *);
215 int check_allow_insecure_content(char **);
216 int check_allow_insecure_scripts(char **);
217 int check_allow_volatile_cookies(char **);
218 int check_anonymize_headers(char **);
219 int check_append_next(char **);
220 int check_auto_load_images(char **);
221 int check_autofocus_onload(char **);
222 int check_browser_mode(char **);
223 int check_cmd_font(char **);
224 int check_color_visited_uris(char **);
225 int check_cookie_policy(char **);
226 int check_cookies_enabled(char **);
227 int check_ctrl_click_focus(char **);
228 int check_default_script(char **);
229 int check_default_zoom_level(char **);
230 int check_download_dir(char **);
231 int check_download_mode(char **);
232 int check_download_notifications(char **);
233 int check_edit_mode(char **);
234 int check_enable_autoscroll(char **);
235 int check_enable_cookie_whitelist(char **);
236 int check_enable_favicon_entry(char **);
237 int check_enable_favicon_tabs(char **);
238 int check_enable_js_autorun(char **);
239 int check_enable_js_whitelist(char **);
240 int check_enable_localstorage(char **);
241 int check_enable_plugin_whitelist(char **);
242 int check_enable_plugins(char **);
243 int check_enable_scripts(char **);
244 int check_enable_socket(char **);
245 int check_enable_spell_checking(char **);
246 int check_enable_strict_transport(char **);
247 int check_encoding(char **);
248 int check_external_editor(char **);
249 int check_fancy_bar(char **);
250 int check_gnutls_search_string(char **);
251 int check_guess_search(char **);
252 int check_gui_mode(char **);
253 int check_history_autosave(char **);
254 int check_home(char **);
255 int check_http_proxy(char **);
256 int check_http_proxy_starts_enabled(char **);
257 int check_icon_size(char **);
258 int check_max_connections(char **);
259 int check_max_host_connections(char **);
260 int check_oops_font(char **);
261 int check_read_only_cookies(char **);
262 int check_referer(char **);
263 int check_refresh_interval(char **);
264 int check_resource_dir(char **);
265 int check_save_global_history(char **);
266 int check_save_rejected_cookies(char **);
267 int check_search_string(char **);
268 int check_session_autosave(char **);
269 int check_session_timeout(char **);
270 int check_show_scrollbars(char **);
271 int check_show_statusbar(char **);
272 int check_show_tabs(char **);
273 int check_show_url(char **);
274 int check_single_instance(char **);
275 int check_spell_check_languages(char **);
276 int check_ssl_ca_file(char **);
277 int check_ssl_strict_certs(char **);
278 int check_statusbar_elems(char **);
279 int check_statusbar_font(char **);
280 int check_statusbar_style(char **);
281 int check_tab_style(char **);
282 int check_tabless(char **);
283 int check_tabbar_font(char **);
284 int check_url_regex(char **);
285 int check_userstyle(char **);
286 int check_userstyle_global(char **);
287 int check_warn_cert_changes(char **);
288 int check_window_height(char **);
289 int check_window_maximize(char **);
290 int check_window_width(char **);
291 int check_work_dir(char **);
292 int check_do_not_track(char **);
294 void walk_mime_type(struct settings *, void (*)(struct settings *,
295 char *, void *), void *);
296 void walk_alias(struct settings *, void (*)(struct settings *,
297 char *, void *), void *);
298 void walk_cookie_wl(struct settings *, void (*)(struct settings *,
299 char *, void *), void *);
300 void walk_js_wl(struct settings *, void (*)(struct settings *,
301 char *, void *), void *);
302 void walk_pl_wl(struct settings *, void (*)(struct settings *,
303 char *, void *), void *);
304 void walk_kb(struct settings *, void (*)(struct settings *, char *,
305 void *), void *);
306 void walk_ua(struct settings *, void (*)(struct settings *, char *,
307 void *), void *);
308 void walk_http_accept(struct settings *, void (*)(struct settings *,
309 char *, void *), void *);
310 void walk_cmd_alias(struct settings *, void (*)(struct settings *,
311 char *, void *), void *);
312 void walk_custom_uri(struct settings *, void (*)(struct settings *,
313 char *, void *), void *);
314 void walk_force_https(struct settings *, void (*)(struct settings *,
315 char *, void *), void *);
317 struct special s_browser_mode = {
318 set_browser_mode,
319 get_browser_mode,
320 NULL,
321 { "kiosk", "normal", "whitelist", NULL }
324 struct special s_gui_mode = {
325 set_gui_mode,
326 get_gui_mode,
327 NULL,
328 { "classic", "minimal", NULL }
331 struct special s_cookie = {
332 set_cookie_policy,
333 get_cookie_policy,
334 NULL,
335 { "accept", "no3rdparty", "reject", NULL }
338 struct special s_alias = {
339 add_alias,
340 NULL,
341 walk_alias,
342 { NULL }
345 struct special s_cmd_alias = {
346 add_cmd_alias,
347 NULL,
348 walk_cmd_alias,
349 { NULL }
352 struct special s_mime = {
353 add_mime_type,
354 NULL,
355 walk_mime_type,
356 { NULL }
359 struct special s_js = {
360 add_js_wl,
361 NULL,
362 walk_js_wl,
363 { NULL }
366 struct special s_pl = {
367 add_pl_wl,
368 NULL,
369 walk_pl_wl,
370 { NULL }
373 struct special s_kb = {
374 add_kb,
375 NULL,
376 walk_kb,
377 { NULL }
380 struct special s_cookie_wl = {
381 add_cookie_wl,
382 NULL,
383 walk_cookie_wl,
384 { NULL }
387 struct special s_uri = {
388 add_custom_uri,
389 NULL,
390 walk_custom_uri,
391 { NULL }
394 struct special s_default_script = {
395 set_default_script,
396 get_default_script,
397 NULL,
398 { NULL }
401 struct special s_ssl_ca_file = {
402 set_ssl_ca_file,
403 get_ssl_ca_file,
404 NULL,
405 { NULL }
408 struct special s_download_dir = {
409 set_download_dir,
410 get_download_dir,
411 NULL,
412 { NULL }
415 struct special s_work_dir = {
416 set_work_dir,
417 get_work_dir,
418 NULL,
419 { NULL }
422 struct special s_tab_style = {
423 set_tab_style,
424 get_tab_style,
425 NULL,
426 { "compact", "normal", NULL }
429 struct special s_statusbar_style = {
430 set_statusbar_style,
431 get_statusbar_style,
432 NULL,
433 { "title", "url", NULL }
436 struct special s_edit_mode = {
437 set_edit_mode,
438 get_edit_mode,
439 NULL,
440 { "hybrid", "vi", NULL }
443 struct special s_download_mode = {
444 set_download_mode,
445 get_download_mode,
446 NULL,
447 { "add", "ask", "start", NULL }
450 struct special s_ua = {
451 add_ua,
452 NULL,
453 walk_ua,
454 { NULL }
457 struct special s_http_accept = {
458 add_http_accept,
459 NULL,
460 walk_http_accept,
461 { NULL }
464 struct special s_referer = {
465 set_referer,
466 get_referer,
467 NULL,
468 { "always", "never", "same-domain", "same-fqdn", NULL }
471 struct special s_userstyle = {
472 set_userstyle,
473 get_userstyle,
474 NULL,
475 { NULL }
478 struct special s_force_https = {
479 add_force_https,
480 NULL,
481 walk_force_https,
482 { NULL }
485 struct special s_gnutls_priority_string = {
486 set_gnutls_priority_string,
487 get_gnutls_priority_string,
488 NULL,
489 { NULL }
492 struct settings rs[] = {
493 { "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 },
494 { "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},
495 { "allow_volatile_cookies", XT_S_BOOL, 0, &allow_volatile_cookies, NULL, NULL, NULL, NULL, check_allow_volatile_cookies, TT_ALLOW_VOLATILE_COOKIES },
496 { "anonymize_headers", XT_S_BOOL, 0, &anonymize_headers, NULL, NULL, NULL, NULL, check_anonymize_headers, TT_ANONYMIZE_HEADERS },
497 { "append_next", XT_S_BOOL, 0, &append_next, NULL, NULL, NULL, set_append_next, check_append_next, TT_APPEND_NEXT },
498 { "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 },
499 { "autofocus_onload", XT_S_BOOL, 0, &autofocus_onload, NULL, NULL, NULL, set_autofocus_onload, check_autofocus_onload, TT_AUTOFOCUS_ONLOAD },
500 { "browser_mode", XT_S_STR, 0, NULL, NULL,&s_browser_mode, NULL, NULL, check_browser_mode, TT_BROWSER_MODE },
501 { "cmd_font", XT_S_STR, 0, NULL, &cmd_font_name, NULL, NULL, set_cmd_font, check_cmd_font, TT_CMD_FONT },
502 { "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 },
503 { "cookie_policy", XT_S_STR, 0, NULL, NULL,&s_cookie, NULL, set_cookie_policy_rt, check_cookie_policy, TT_COOKIE_POLICY },
504 { "cookies_enabled", XT_S_BOOL, 0, &cookies_enabled, NULL, NULL, NULL, set_cookies_enabled, check_cookies_enabled, TT_COOKIES_ENABLED },
505 { "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 },
506 { "default_script", XT_S_STR, 1, NULL, NULL,&s_default_script, NULL, set_default_script_rt, check_default_script, TT_DEFAULT_SCRIPT },
507 { "default_zoom_level", XT_S_FLOAT, 0, NULL, NULL, NULL, &default_zoom_level, set_default_zoom_level, check_default_zoom_level, TT_DEFAULT_ZOOM_LEVEL },
508 { "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 },
509 { "download_dir", XT_S_STR, 0, NULL, NULL,&s_download_dir, NULL, NULL, check_download_dir, TT_DOWNLOAD_DIR },
510 { "download_mode", XT_S_STR, 0, NULL, NULL,&s_download_mode, NULL, set_download_mode_rt, check_download_mode, TT_DOWNLOAD_MODE },
511 { "download_notifications", XT_S_BOOL, 0, &download_notifications, NULL, NULL, NULL, set_download_notifications, check_download_notifications, TT_DOWNLOAD_NOTIFICATIONS },
512 { "edit_mode", XT_S_STR, 0, NULL, NULL,&s_edit_mode, NULL, NULL, check_edit_mode, NULL },
513 { "enable_autoscroll", XT_S_BOOL, 0, &enable_autoscroll, NULL, NULL, NULL, set_enable_autoscroll, check_enable_autoscroll, TT_ENABLE_AUTOSCROLL },
514 { "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 },
515 { "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 },
516 { "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 },
517 { "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 },
518 { "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 },
519 { "enable_localstorage", XT_S_BOOL, 0, &enable_localstorage, NULL, NULL, NULL, set_enable_localstorage, check_enable_localstorage, TT_ENABLE_LOCALSTORAGE },
520 { "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 },
521 { "enable_plugins", XT_S_BOOL, 0, &enable_plugins, NULL, NULL, NULL, set_enable_plugins, check_enable_plugins, TT_ENABLE_PLUGINS },
522 { "enable_scripts", XT_S_BOOL, 0, &enable_scripts, NULL, NULL, NULL, set_enable_scripts, check_enable_scripts, TT_ENABLE_SCRIPTS },
523 { "enable_socket", XT_S_BOOL,XT_SF_RESTART,&enable_socket, NULL, NULL, NULL, NULL, check_enable_socket, TT_ENABLE_SOCKET },
524 { "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 },
525 { "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 },
526 { "encoding", XT_S_STR, 0, NULL, &encoding, NULL, NULL, NULL, check_encoding, TT_ENCODING },
527 { "external_editor", XT_S_STR,0, NULL, &external_editor, NULL, NULL, set_external_editor, check_external_editor, TT_EXTERNAL_EDITOR },
528 { "fancy_bar", XT_S_BOOL,XT_SF_RESTART,&fancy_bar, NULL, NULL, NULL, set_fancy_bar, check_fancy_bar, TT_FANCY_BAR },
529 { "gnutls_priority_string", XT_S_STR, 0, NULL, NULL,&s_gnutls_priority_string, NULL, NULL, check_gnutls_search_string, TT_GNUTLS_PRIORITY_STRING },
530 { "guess_search", XT_S_BOOL, 0, &guess_search, NULL, NULL, NULL, set_guess_search, check_guess_search, TT_GUESS_SEARCH },
531 { "gui_mode", XT_S_STR, 0, NULL, NULL,&s_gui_mode, NULL, NULL, check_gui_mode, TT_GUI_MODE },
532 { "history_autosave", XT_S_BOOL, 0, &history_autosave, NULL, NULL, NULL, NULL, check_history_autosave, TT_HISTORY_AUTOSAVE },
533 { "home", XT_S_STR, 0, NULL, &home, NULL, NULL, set_home, check_home, TT_HOME },
534 { "http_proxy", XT_S_STR, 0, NULL, &http_proxy, NULL, NULL, set_http_proxy, check_http_proxy, TT_HTTP_PROXY },
535 { "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 },
536 { "icon_size", XT_S_INT, 0, &icon_size, NULL, NULL, NULL, NULL, check_icon_size, TT_ICON_SIZE },
537 { "include_config", XT_S_STR, XT_SF_INVISIBLE, NULL, &include_config, NULL, NULL, NULL, NULL },
538 { "max_connections", XT_S_INT, XT_SF_RESTART,&max_connections, NULL, NULL, NULL, NULL, check_max_connections, TT_MAX_CONNECTIONS },
539 { "max_host_connections", XT_S_INT, XT_SF_RESTART,&max_host_connections, NULL, NULL, NULL, NULL, check_max_host_connections, TT_MAX_HOST_CONNECTIONS },
540 { "oops_font", XT_S_STR, 0, NULL, &oops_font_name, NULL, NULL, set_oops_font, check_oops_font, TT_OOPS_FONT },
541 { "preload_strict_transport", XT_S_BOOL, 0, &preload_strict_transport, NULL, NULL, NULL, NULL, NULL, TT_PRELOAD_STRICT_TRANSPORT },
542 { "read_only_cookies", XT_S_BOOL, 0, &read_only_cookies, NULL, NULL, NULL, NULL, check_read_only_cookies, TT_READ_ONLY_COOKIES },
543 { "referer", XT_S_STR, 0, NULL, NULL,&s_referer, NULL, set_referer_rt, check_referer, TT_REFERER },
544 { "refresh_interval", XT_S_INT, 0, &refresh_interval, NULL, NULL, NULL, set_refresh_interval, check_refresh_interval, TT_REFRESH_INTERVAL },
545 { "resource_dir", XT_S_STR, 0, NULL, &resource_dir, NULL, NULL, NULL, check_resource_dir, TT_RESOURCE_DIR },
546 { "save_global_history", XT_S_BOOL,XT_SF_RESTART,&save_global_history, NULL, NULL, NULL, NULL, check_save_global_history, TT_SAVE_GLOBAL_HISTORY },
547 { "save_rejected_cookies", XT_S_BOOL,XT_SF_RESTART,&save_rejected_cookies, NULL, NULL, NULL, NULL, check_save_rejected_cookies, TT_SAVE_REJECTED_COOKIES },
548 { "search_string", XT_S_STR, 0, NULL, &search_string, NULL, NULL, set_search_string, check_search_string, TT_SEARCH_STRING },
549 { "session_autosave", XT_S_BOOL, 0, &session_autosave, NULL, NULL, NULL, set_session_autosave, check_session_autosave, TT_SESSION_AUTOSAVE },
550 { "session_timeout", XT_S_INT, 0, &session_timeout, NULL, NULL, NULL, set_session_timeout, check_session_timeout, TT_SESSION_TIMEOUT },
551 { "show_scrollbars", XT_S_BOOL, 0, &show_scrollbars, NULL, NULL, NULL, set_show_scrollbars, check_show_scrollbars, TT_SHOW_SCROLLBARS },
552 { "show_statusbar", XT_S_BOOL, 0, &show_statusbar, NULL, NULL, NULL, set_show_statusbar, check_show_statusbar, TT_SHOW_STATUSBAR },
553 { "show_tabs", XT_S_BOOL, 0, &show_tabs, NULL, NULL, NULL, set_show_tabs, check_show_tabs, TT_SHOW_TABS },
554 { "show_url", XT_S_BOOL, 0, &show_url, NULL, NULL, NULL, set_show_url, check_show_url, TT_SHOW_URL },
555 { "single_instance", XT_S_BOOL,XT_SF_RESTART,&single_instance, NULL, NULL, NULL, NULL, check_single_instance, TT_SINGLE_INSTANCE },
556 { "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 },
557 { "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 },
558 { "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 },
559 { "statusbar_elems", XT_S_STR, 0, NULL, &statusbar_elems, NULL, NULL, NULL, check_statusbar_elems, TT_STATUSBAR_ELEMS },
560 { "statusbar_font", XT_S_STR, 0, NULL, &statusbar_font_name, NULL, NULL, set_statusbar_font, check_statusbar_font, TT_STATUSBAR_FONT },
561 { "statusbar_style", XT_S_STR, 0, NULL, NULL,&s_statusbar_style, NULL, set_statusbar_style_rt, check_statusbar_style, TT_STATUSBAR_STYLE },
562 { "tab_style", XT_S_STR, 0, NULL, NULL,&s_tab_style, NULL, set_tab_style_rt, check_tab_style, TT_TAB_STYLE },
563 { "tabbar_font", XT_S_STR, 0, NULL, &tabbar_font_name, NULL, NULL, set_tabbar_font, check_tabbar_font, TT_TABBAR_FONT },
564 { "tabless", XT_S_BOOL, 0, &tabless, NULL, NULL, NULL, NULL, check_tabless, TT_TABLESS },
565 { "url_regex", XT_S_STR, 0, NULL, &url_regex, NULL, NULL, set_url_regex, check_url_regex, TT_URL_REGEX },
566 { "userstyle", XT_S_STR, 0, NULL, NULL,&s_userstyle, NULL, set_userstyle_rt, check_userstyle, TT_USERSTYLE },
567 { "userstyle_global", XT_S_BOOL, 0, &userstyle_global, NULL, NULL, NULL, set_userstyle_global, check_userstyle_global, TT_USERSTYLE_GLOBAL },
568 { "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 },
569 { "window_height", XT_S_INT, 0, &window_height, NULL, NULL, NULL, NULL, check_window_height, TT_WINDOW_HEIGHT },
570 { "window_maximize", XT_S_BOOL, 0, &window_maximize, NULL, NULL, NULL, NULL, check_window_maximize, TT_WINDOW_MAXIMIZE },
571 { "window_width", XT_S_INT, 0, &window_width, NULL, NULL, NULL, NULL, check_window_width, TT_WINDOW_WIDTH },
572 { "work_dir", XT_S_STR, 0, NULL, NULL,&s_work_dir, NULL, NULL, check_work_dir, TT_WORK_DIR },
574 /* special settings */
575 { "alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_alias, NULL, NULL },
576 { "cmd_alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cmd_alias, NULL, NULL },
577 { "cookie_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cookie_wl, NULL, NULL },
578 { "custom_uri", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_uri, NULL, NULL },
579 { "force_https", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_force_https, NULL, NULL },
580 { "http_accept", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_http_accept, NULL, NULL },
581 { "js_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_js, NULL, NULL },
582 { "keybinding", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_kb, NULL, NULL },
583 { "mime_type", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_mime, NULL, NULL },
584 { "pl_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_pl, NULL, NULL },
585 { "user_agent", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_ua, NULL, NULL },
589 set_http_proxy(char *proxy)
591 SoupURI *uri;
593 /* see if we need to clear it */
594 if (proxy == NULL || strlen(proxy) == 0) {
595 setup_proxy(NULL);
596 return (0);
599 uri = soup_uri_new(proxy);
600 if (uri == NULL)
601 return (1);
602 if (!SOUP_URI_VALID_FOR_HTTP(uri)) {
603 soup_uri_free(uri);
604 return (1);
607 setup_proxy(proxy);
609 soup_uri_free(uri);
611 return (0);
615 check_http_proxy(char **tt)
617 *tt = g_strdup("Default: (empty)");
618 return (g_strcmp0(http_proxy, NULL));
622 check_http_proxy_starts_enabled(char **tt)
624 *tt = g_strdup("Default: Enabled");
625 return (http_proxy_starts_enabled != 1);
629 check_icon_size(char **tt)
631 *tt = g_strdup_printf("Default: %d", 2);
632 return (icon_size != 2);
636 check_max_connections(char **tt)
638 *tt = g_strdup_printf("Default: %d", 25);
639 return (max_connections != 25);
643 check_max_host_connections(char **tt)
645 *tt = g_strdup_printf("Default: %d", 5);
646 return (max_host_connections != 5);
650 set_default_zoom_level(char *value)
652 struct karg args = {0};
653 struct tab *t;
655 if (value == NULL || strlen(value) == 0)
656 default_zoom_level = XT_DS_DEFAULT_ZOOM_LEVEL;
657 else
658 default_zoom_level = g_strtod(value, NULL);
659 args.i = 100; /* adjust = 100 percent for no additional adjustment */
660 TAILQ_FOREACH(t, &tabs, entry)
661 resizetab(t, &args);
662 return (0);
666 check_default_zoom_level(char **tt)
668 *tt = g_strdup_printf("Default: %f", XT_DS_DEFAULT_ZOOM_LEVEL);
669 return (default_zoom_level != XT_DS_DEFAULT_ZOOM_LEVEL);
673 set_cookies_enabled(char *value)
675 int tmp;
676 const char *errstr;
678 if (value == NULL || strlen(value) == 0)
679 cookies_enabled = XT_DS_COOKIES_ENABLED;
680 else {
681 tmp = strtonum(value, 0, 1, &errstr);
682 if (errstr)
683 return (-1);
684 cookies_enabled = tmp;
686 return (0);
690 check_cookies_enabled(char **tt)
692 *tt = g_strdup_printf("Default: %s",
693 XT_DS_COOKIES_ENABLED ? "Enabled" : "Disabled");
694 return (cookies_enabled != XT_DS_COOKIES_ENABLED);
698 set_append_next(char *value)
700 int tmp;
701 const char *errstr;
703 if (value == NULL || strlen(value) == 0)
704 append_next = XT_DS_APPEND_NEXT;
705 else {
706 tmp = strtonum(value, 0, 1, &errstr);
707 if (errstr)
708 return (-1);
709 append_next = tmp;
711 return (0);
715 check_append_next(char **tt)
717 *tt = g_strdup_printf("Default: %s",
718 XT_DS_APPEND_NEXT ? "Enabled" : "Disabled");
719 return (append_next != XT_DS_APPEND_NEXT);
723 set_cmd_font(char *value)
725 struct tab *t;
727 if (cmd_font_name)
728 g_free(cmd_font_name);
729 if (cmd_font)
730 pango_font_description_free(cmd_font);
731 if (value == NULL || strlen(value) == 0)
732 cmd_font_name = g_strdup(XT_DS_CMD_FONT_NAME);
733 else
734 cmd_font_name = g_strdup(value);
735 cmd_font = pango_font_description_from_string(cmd_font_name);
736 TAILQ_FOREACH(t, &tabs, entry)
737 gtk_widget_modify_font(GTK_WIDGET(t->cmd), cmd_font);
738 return (0);
742 check_cmd_font(char **tt)
744 *tt = g_strdup_printf("Default: %s", XT_DS_CMD_FONT_NAME);
745 return (g_strcmp0(cmd_font_name, XT_DS_CMD_FONT_NAME));
749 set_oops_font(char *value)
751 struct tab *t;
753 if (oops_font_name)
754 g_free(oops_font_name);
755 if (oops_font)
756 pango_font_description_free(oops_font);
757 if (value == NULL || strlen(value) == 0)
758 cmd_font_name = g_strdup(XT_DS_OOPS_FONT_NAME);
759 else
760 oops_font_name = g_strdup(value);
761 oops_font = pango_font_description_from_string(oops_font_name);
762 TAILQ_FOREACH(t, &tabs, entry)
763 gtk_widget_modify_font(GTK_WIDGET(t->oops), oops_font);
764 return (0);
768 check_oops_font(char **tt)
770 *tt = g_strdup_printf("Default: %s", XT_DS_OOPS_FONT_NAME);
771 return (g_strcmp0(oops_font_name, XT_DS_OOPS_FONT_NAME));
775 check_read_only_cookies(char **tt)
777 *tt = g_strdup_printf("Default: %s",
778 XT_DS_READ_ONLY_COOKIES ? "Enabled" : "Disabled");
779 return (read_only_cookies != XT_DS_READ_ONLY_COOKIES);
783 set_statusbar_font(char *value)
785 struct tab *t;
787 if (statusbar_font_name)
788 g_free(statusbar_font_name);
789 if (statusbar_font)
790 pango_font_description_free(statusbar_font);
791 if (value == NULL || strlen(value) == 0)
792 statusbar_font_name = g_strdup(XT_DS_STATUSBAR_FONT_NAME);
793 else
794 statusbar_font_name = g_strdup(value);
795 statusbar_font = pango_font_description_from_string(
796 statusbar_font_name);
797 TAILQ_FOREACH(t, &tabs, entry) {
798 gtk_widget_modify_font(GTK_WIDGET(t->sbe.uri),
799 statusbar_font);
800 gtk_widget_modify_font(GTK_WIDGET(t->sbe.buffercmd),
801 statusbar_font);
802 gtk_widget_modify_font(GTK_WIDGET(t->sbe.zoom),
803 statusbar_font);
804 gtk_widget_modify_font(GTK_WIDGET(t->sbe.position),
805 statusbar_font);
806 gtk_widget_modify_font(GTK_WIDGET(t->sbe.proxy),
807 statusbar_font);
809 return (0);
813 check_statusbar_font(char **tt)
815 *tt = g_strdup_printf("Default: %s", XT_DS_STATUSBAR_FONT_NAME);
816 return (g_strcmp0(statusbar_font_name, XT_DS_STATUSBAR_FONT_NAME));
820 set_tabbar_font(char *value)
822 struct tab *t;
824 if (tabbar_font_name)
825 g_free(tabbar_font_name);
826 if (tabbar_font)
827 pango_font_description_free(tabbar_font);
828 if (value == NULL || strlen(value) == 0)
829 tabbar_font_name = g_strdup(XT_DS_TABBAR_FONT_NAME);
830 else
831 tabbar_font_name = g_strdup(value);
832 tabbar_font = pango_font_description_from_string(tabbar_font_name);
833 TAILQ_FOREACH(t, &tabs, entry)
834 gtk_widget_modify_font(GTK_WIDGET(t->tab_elems.label),
835 tabbar_font);
836 return (0);
840 check_tabbar_font(char **tt)
842 *tt = g_strdup_printf("Default: %s", XT_DS_TABBAR_FONT_NAME);
843 return (g_strcmp0(tabbar_font_name, XT_DS_TABBAR_FONT_NAME));
847 check_tabless(char **tt)
849 *tt = g_strdup_printf("Default: Disabled\n");
850 return (tabless != 0);
854 set_color_visited_uris(char *value)
856 int tmp;
857 const char *errstr;
859 if (value == NULL || strlen(value) == 0)
860 color_visited_uris = XT_DS_COLOR_VISITED_URIS;
861 else {
862 tmp = strtonum(value, 0, 1, &errstr);
863 if (errstr)
864 return (-1);
865 color_visited_uris = tmp;
867 return (0);
871 check_color_visited_uris(char **tt)
873 *tt = g_strdup_printf("Default: %s",
874 XT_DS_COLOR_VISITED_URIS ? "Enabled" : "Disabled");
875 return (color_visited_uris != XT_DS_COLOR_VISITED_URIS);
879 set_home(char *value)
881 if (home)
882 g_free(home);
883 if (value == NULL || strlen(value) == 0)
884 home = g_strdup(XT_DS_HOME);
885 else
886 home = g_strdup(value);
887 return (0);
891 check_home(char **tt)
893 *tt = g_strdup_printf("Default: %s", XT_DS_HOME);
894 return (g_strcmp0(home, XT_DS_HOME));
898 set_search_string(char *value)
900 struct tab *t;
902 if (search_string)
903 g_free(search_string);
904 if (value == NULL || strlen(value) == 0) {
905 search_string = NULL;
906 TAILQ_FOREACH(t, &tabs, entry)
907 gtk_widget_hide(t->search_entry);
908 } else {
909 search_string = g_strdup(value);
910 TAILQ_FOREACH(t, &tabs, entry)
911 gtk_widget_show(t->search_entry);
913 return (0);
917 check_search_string(char **tt)
919 *tt = g_strdup_printf("Default: %s", XT_DS_SEARCH_STRING);
920 return (g_strcmp0(search_string, XT_DS_SEARCH_STRING));
923 size_t
924 get_settings_size(void)
926 return (LENGTH(rs));
929 char *
930 get_setting_name(int i)
932 if (i > LENGTH(rs))
933 return (NULL);
934 return (rs[i].name);
937 char *
938 get_as_string(struct settings *s)
940 char *r = NULL;
942 if (s == NULL)
943 return (NULL);
945 if (s->s && s->s->get)
946 r = s->s->get(s);
947 else if (s->type == XT_S_INT)
948 r = g_strdup_printf("%d", *s->ival);
949 else if (s->type == XT_S_STR)
950 r = g_strdup(*s->sval);
951 else if (s->type == XT_S_FLOAT)
952 r = g_strdup_printf("%f", *s->fval);
953 else if (s->type == XT_S_BOOL)
954 r = g_strdup_printf("%d", *s->ival);
955 else
956 r = g_strdup_printf("INVALID TYPE");
958 return (r);
961 void
962 settings_walk(void (*cb)(struct settings *, char *, void *), void *cb_args)
964 int i;
965 char *s;
967 for (i = 0; i < LENGTH(rs); i++) {
968 if (rs[i].s && rs[i].s->walk)
969 rs[i].s->walk(&rs[i], cb, cb_args);
970 else {
971 s = get_as_string(&rs[i]);
972 cb(&rs[i], s, cb_args);
973 g_free(s);
979 check_allow_volatile_cookies(char **tt)
981 *tt = g_strdup("Default: Disabled");
982 return (allow_volatile_cookies != 0);
986 check_anonymize_headers(char **tt)
988 *tt = g_strdup("Default: Disabled");
989 return (anonymize_headers != 0);
993 set_browser_mode(struct settings *s, char *val)
995 if (!strcmp(val, "whitelist")) {
996 browser_mode = XT_BM_WHITELIST;
997 allow_volatile_cookies = 0;
998 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
999 cookies_enabled = 1;
1000 enable_cookie_whitelist = 1;
1001 enable_plugin_whitelist = 1;
1002 enable_plugins = 0;
1003 read_only_cookies = 0;
1004 save_rejected_cookies = 0;
1005 session_timeout = 3600;
1006 enable_scripts = 0;
1007 enable_js_whitelist = 1;
1008 enable_localstorage = 0;
1009 referer_mode = XT_REFERER_SAME_DOMAIN;
1010 allow_insecure_content = 0;
1011 allow_insecure_scripts = 0;
1012 do_not_track = 1;
1013 } else if (!strcmp(val, "normal")) {
1014 browser_mode = XT_BM_NORMAL;
1015 allow_volatile_cookies = 0;
1016 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1017 cookies_enabled = 1;
1018 enable_cookie_whitelist = 0;
1019 enable_plugin_whitelist = 0;
1020 enable_plugins = 1;
1021 read_only_cookies = 0;
1022 save_rejected_cookies = 0;
1023 session_timeout = 3600;
1024 enable_scripts = 1;
1025 enable_js_whitelist = 0;
1026 enable_localstorage = 1;
1027 referer_mode = XT_REFERER_ALWAYS;
1028 allow_insecure_content = 1;
1029 allow_insecure_scripts = 1;
1030 do_not_track = 0;
1031 } else if (!strcmp(val, "kiosk")) {
1032 browser_mode = XT_BM_KIOSK;
1033 allow_volatile_cookies = 0;
1034 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1035 cookies_enabled = 1;
1036 enable_cookie_whitelist = 0;
1037 enable_plugin_whitelist = 0;
1038 enable_plugins = 1;
1039 read_only_cookies = 0;
1040 save_rejected_cookies = 0;
1041 session_timeout = 3600;
1042 enable_scripts = 1;
1043 enable_js_whitelist = 0;
1044 enable_localstorage = 1;
1045 referer_mode = XT_REFERER_ALWAYS;
1046 allow_insecure_content = 1;
1047 allow_insecure_scripts = 1;
1048 do_not_track = 0;
1049 show_tabs = 0;
1050 tabless = 1;
1051 } else
1052 return (1);
1054 return (0);
1057 char *
1058 get_browser_mode(struct settings *s)
1060 char *r = NULL;
1062 if (browser_mode == XT_BM_WHITELIST)
1063 r = g_strdup("whitelist");
1064 else if (browser_mode == XT_BM_NORMAL)
1065 r = g_strdup("normal");
1066 else if (browser_mode == XT_BM_KIOSK)
1067 r = g_strdup("kiosk");
1068 else
1069 return (NULL);
1071 return (r);
1075 check_browser_mode(char **tt)
1077 *tt = g_strdup("Default: normal");
1078 return (browser_mode != XT_BM_NORMAL);
1082 set_gui_mode(struct settings *s, char *val)
1084 if (!strcmp(val, "classic")) {
1085 fancy_bar = 1;
1086 show_tabs = 1;
1087 tab_style = XT_TABS_NORMAL;
1088 show_url = 1;
1089 show_statusbar = 0;
1090 show_scrollbars = 1;
1091 } else if (!strcmp(val, "minimal")) {
1092 fancy_bar = 0;
1093 show_tabs = 1;
1094 tab_style = XT_TABS_COMPACT;
1095 show_url = 0;
1096 show_statusbar = 1;
1097 show_scrollbars = 0;
1098 } else
1099 return (1);
1101 return (0);
1104 char *
1105 get_gui_mode(struct settings *s)
1107 char *r = NULL;
1109 if (gui_mode == XT_GM_CLASSIC)
1110 r = g_strdup("classic");
1111 else if (browser_mode == XT_GM_MINIMAL)
1112 r = g_strdup("minimal");
1113 else
1114 return (NULL);
1116 return (r);
1120 check_gui_mode(char **tt)
1122 *tt = g_strdup("Default: classic");
1123 return (gui_mode != XT_GM_CLASSIC);
1127 check_history_autosave(char **tt)
1129 *tt = g_strdup("Default: Disabled");
1130 return (history_autosave != 0);
1134 set_cookie_policy(struct settings *s, char *val)
1136 if (!strcmp(val, "no3rdparty"))
1137 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
1138 else if (!strcmp(val, "accept"))
1139 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1140 else if (!strcmp(val, "reject"))
1141 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
1142 else
1143 return (1);
1145 return (0);
1149 set_cookie_policy_rt(char *value)
1151 if (value == NULL || strlen(value) == 0)
1152 cookie_policy = XT_DS_COOKIE_POLICY;
1153 else if (set_cookie_policy(NULL, value))
1154 return (-1);
1155 g_object_set(G_OBJECT(s_cookiejar), SOUP_COOKIE_JAR_ACCEPT_POLICY,
1156 cookie_policy, (void *)NULL);
1157 return (0);
1161 check_cookie_policy(char **tt)
1163 *tt = g_strdup("Default (depends on browser_mode):\n"
1164 "\tnormal:\talways\n"
1165 "\twhitelist:\tno3rdparty\n"
1166 "\tkiosk:\talways");
1167 if (browser_mode == XT_BM_WHITELIST &&
1168 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1169 return (1);
1170 if (browser_mode == XT_BM_NORMAL &&
1171 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1172 return (1);
1173 if (browser_mode == XT_BM_KIOSK &&
1174 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1175 return (1);
1176 return (0);
1179 char *
1180 get_cookie_policy(struct settings *s)
1182 char *r = NULL;
1184 if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1185 r = g_strdup("no3rdparty");
1186 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1187 r = g_strdup("accept");
1188 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
1189 r = g_strdup("reject");
1190 else
1191 return (NULL);
1193 return (r);
1196 char *
1197 get_default_script(struct settings *s)
1199 if (default_script[0] == '\0')
1200 return (0);
1201 return (g_strdup(default_script));
1205 set_default_script(struct settings *s, char *val)
1207 expand_tilde(default_script, sizeof default_script, val);
1208 return (0);
1212 check_default_script(char **tt)
1214 *tt = g_strdup("Default: (empty)");
1215 return (g_strcmp0(default_script, XT_DS_DEFAULT_SCRIPT));
1219 set_default_script_rt(char *value)
1221 if (value == NULL || strlen(value) == 0)
1222 return set_default_script(NULL, "");
1223 return (set_default_script(NULL, value));
1227 set_do_not_track(char *value)
1229 int tmp;
1230 const char *errstr;
1232 if (value == NULL || strlen(value) == 0)
1233 do_not_track = XT_DS_DO_NOT_TRACK;
1234 else {
1235 tmp = strtonum(value, 0, 1, &errstr);
1236 if (errstr)
1237 return (-1);
1238 do_not_track = tmp;
1240 return (0);
1244 check_do_not_track(char **tt)
1246 *tt = g_strdup("Default (depends on browser_mode):\n"
1247 "\tnormal:\tDisabled\n"
1248 "\twhitelist:\tEnabled\n"
1249 "\tkiosk:\tDisabled");
1250 if (browser_mode == XT_BM_WHITELIST && do_not_track != 1)
1251 return (1);
1252 if (browser_mode == XT_BM_NORMAL && do_not_track != 0)
1253 return (1);
1254 if (browser_mode == XT_BM_KIOSK && do_not_track != 0)
1255 return (1);
1256 return (0);
1259 char *
1260 get_download_dir(struct settings *s)
1262 if (download_dir[0] == '\0')
1263 return (0);
1264 return (g_strdup(download_dir));
1268 set_download_dir(struct settings *s, char *val)
1270 expand_tilde(download_dir, sizeof download_dir, val);
1271 return (0);
1275 check_download_dir(char **tt)
1277 struct passwd *pwd;
1278 char buf[PATH_MAX] = {0};
1280 /* XXX this might need some additonal magic on windows */
1281 if ((pwd = getpwuid(getuid())) == NULL)
1282 return (-1);
1283 snprintf(buf, sizeof buf, "%s" PS "downloads", pwd->pw_dir);
1284 *tt = g_strdup_printf("Default: %s", buf);
1285 return (g_strcmp0(download_dir, buf));
1289 add_alias(struct settings *s, char *line)
1291 char *l, *alias;
1292 struct alias *a = NULL;
1294 if (s == NULL || line == NULL) {
1295 show_oops(NULL, "add_alias invalid parameters");
1296 return (1);
1299 l = line;
1300 a = g_malloc(sizeof(*a));
1302 if ((alias = strsep(&l, " \t,")) == NULL || l == NULL) {
1303 show_oops(NULL, "add_alias: incomplete alias definition");
1304 goto bad;
1307 /* Remove additional leading whitespace */
1308 l += (long)strspn(l, " \t");
1310 if (strlen(alias) == 0 || strlen(l) == 0) {
1311 show_oops(NULL, "add_alias: invalid alias definition");
1312 goto bad;
1315 a->a_name = g_strdup(alias);
1316 a->a_uri = g_strdup(l);
1318 DNPRINTF(XT_D_CONFIG, "add_alias: %s for %s\n", a->a_name, a->a_uri);
1320 TAILQ_INSERT_TAIL(&aliases, a, entry);
1322 return (0);
1323 bad:
1324 if (a)
1325 g_free(a);
1326 return (1);
1329 void
1330 walk_alias(struct settings *s,
1331 void (*cb)(struct settings *, char *, void *), void *cb_args)
1333 struct alias *a;
1334 char *str;
1336 if (s == NULL || cb == NULL) {
1337 show_oops(NULL, "walk_alias invalid parameters");
1338 return;
1341 TAILQ_FOREACH(a, &aliases, entry) {
1342 str = g_strdup_printf("%s --> %s", a->a_name, a->a_uri);
1343 cb(s, str, cb_args);
1344 g_free(str);
1349 add_mime_type(struct settings *s, char *line)
1351 char *mime_type;
1352 char *l;
1353 struct mime_type *m = NULL;
1354 int downloadfirst = 0;
1356 /* XXX this could be smarter */
1358 if (line == NULL || strlen(line) == 0) {
1359 show_oops(NULL, "add_mime_type invalid parameters");
1360 return (1);
1363 l = line;
1364 if (*l == '@') {
1365 downloadfirst = 1;
1366 l++;
1368 m = g_malloc(sizeof(*m));
1370 if ((mime_type = strsep(&l, " \t,")) == NULL || l == NULL) {
1371 show_oops(NULL, "add_mime_type: invalid mime_type");
1372 goto bad;
1374 if (mime_type[strlen(mime_type) - 1] == '*') {
1375 mime_type[strlen(mime_type) - 1] = '\0';
1376 m->mt_default = 1;
1377 } else
1378 m->mt_default = 0;
1380 if (strlen(mime_type) == 0 || strlen(l) == 0) {
1381 show_oops(NULL, "add_mime_type: invalid mime_type");
1382 goto bad;
1385 m->mt_type = g_strdup(mime_type);
1386 m->mt_action = g_strdup(l);
1387 m->mt_download = downloadfirst;
1389 DNPRINTF(XT_D_CONFIG, "add_mime_type: type %s action %s default %d\n",
1390 m->mt_type, m->mt_action, m->mt_default);
1392 TAILQ_INSERT_TAIL(&mtl, m, entry);
1394 return (0);
1395 bad:
1396 if (m)
1397 g_free(m);
1398 return (1);
1401 void
1402 walk_mime_type(struct settings *s,
1403 void (*cb)(struct settings *, char *, void *), void *cb_args)
1405 struct mime_type *m;
1406 char *str;
1408 if (s == NULL || cb == NULL) {
1409 show_oops(NULL, "walk_mime_type invalid parameters");
1410 return;
1413 TAILQ_FOREACH(m, &mtl, entry) {
1414 str = g_strdup_printf("%s%s --> %s",
1415 m->mt_type,
1416 m->mt_default ? "*" : "",
1417 m->mt_action);
1418 cb(s, str, cb_args);
1419 g_free(str);
1423 /* inherent to GTK not all keys will be caught at all times */
1424 /* XXX sort key bindings */
1425 struct key_binding keys[] = {
1426 { "command_mode", 0, 1, GDK_Escape },
1427 { "insert_mode", 0, 0, GDK_i },
1428 { "cookiejar", MOD1, 1, GDK_j },
1429 { "downloadmgr", MOD1, 1, GDK_d },
1430 { "history", MOD1, 1, GDK_h },
1431 { "print", CTRL, 1, GDK_p },
1432 { "search", 0, 0, GDK_slash },
1433 { "searchb", 0, 0, GDK_question },
1434 { "statustoggle", CTRL, 1, GDK_n },
1435 { "command", 0, 0, GDK_colon },
1436 { "qa", CTRL, 1, GDK_q },
1437 { "restart", MOD1, 1, GDK_q },
1438 { "js toggle", CTRL, 1, GDK_j },
1439 { "plugin toggle", MOD1, 1, GDK_p },
1440 { "cookie toggle", MOD1, 1, GDK_c },
1441 { "togglesrc", CTRL, 1, GDK_s },
1442 { "yankuri", 0, 0, GDK_y },
1443 { "pasteuricur", 0, 0, GDK_p },
1444 { "pasteurinew", 0, 0, GDK_P },
1445 { "toplevel toggle", 0, 1, GDK_F4 },
1446 { "help", 0, 1, GDK_F1 },
1447 { "run_script", MOD1, 1, GDK_r },
1448 { "proxy toggle", 0, 1, GDK_F2 },
1449 { "editelement", CTRL, 1, GDK_i },
1450 { "passthrough", CTRL, 1, GDK_z },
1451 { "modurl", CTRL, 1, GDK_Return },
1452 { "urlmod plus", MOD1, 1, GDK_a },
1453 { "urlmod min", MOD1, 1, GDK_A },
1455 /* search */
1456 { "searchnext", 0, 0, GDK_n },
1457 { "searchprevious", 0, 0, GDK_N },
1459 /* focus */
1460 { "focusaddress", 0, 1, GDK_F6 },
1461 { "focussearch", 0, 1, GDK_F7 },
1463 /* hinting */
1464 { "hinting", 0, 0, GDK_f },
1465 { "hinting", 0, 0, GDK_period },
1466 { "hinting_newtab", SHFT, 0, GDK_F },
1467 { "hinting_newtab", 0, 0, GDK_comma },
1469 /* custom stylesheet */
1470 { "userstyle", 0, 0, GDK_s },
1471 { "userstyle_global", SHFT, 0, GDK_S },
1473 /* navigation */
1474 { "goback", 0, 0, GDK_BackSpace },
1475 { "goback", MOD1, 1, GDK_Left },
1476 { "goforward", SHFT, 1, GDK_BackSpace },
1477 { "goforward", MOD1, 1, GDK_Right },
1478 { "reload", 0, 1, GDK_F5 },
1479 { "reload", CTRL, 1, GDK_r },
1480 { "reload", CTRL, 1, GDK_l },
1481 { "favorites", MOD1, 1, GDK_f },
1483 /* vertical movement */
1484 { "scrolldown", 0, 0, GDK_j },
1485 { "scrolldown", 0, 0, GDK_Down },
1486 { "scrollup", 0, 0, GDK_Up },
1487 { "scrollup", 0, 0, GDK_k },
1488 { "scrollbottom", 0, 0, GDK_G },
1489 { "scrollbottom", 0, 0, GDK_End },
1490 { "scrolltop", 0, 0, GDK_Home },
1491 { "scrollpagedown", 0, 0, GDK_space },
1492 { "scrollpagedown", CTRL, 1, GDK_f },
1493 { "scrollhalfdown", CTRL, 1, GDK_d },
1494 { "scrollpagedown", 0, 0, GDK_Page_Down },
1495 { "scrollpageup", 0, 0, GDK_Page_Up },
1496 { "scrollpageup", CTRL, 1, GDK_b },
1497 { "scrollhalfup", CTRL, 1, GDK_u },
1498 /* horizontal movement */
1499 { "scrollright", 0, 0, GDK_l },
1500 { "scrollright", 0, 0, GDK_Right },
1501 { "scrollleft", 0, 0, GDK_Left },
1502 { "scrollleft", 0, 0, GDK_h },
1503 { "scrollfarright", 0, 0, GDK_dollar },
1504 { "scrollfarleft", 0, 0, GDK_0 },
1506 /* tabs */
1507 { "tabnew", CTRL, 1, GDK_t },
1508 { "999tabnew", CTRL, 1, GDK_T },
1509 { "tabclose", CTRL, 1, GDK_w },
1510 { "tabundoclose", 0, 0, GDK_U },
1511 { "tabnext 1", CTRL, 1, GDK_1 },
1512 { "tabnext 2", CTRL, 1, GDK_2 },
1513 { "tabnext 3", CTRL, 1, GDK_3 },
1514 { "tabnext 4", CTRL, 1, GDK_4 },
1515 { "tabnext 5", CTRL, 1, GDK_5 },
1516 { "tabnext 6", CTRL, 1, GDK_6 },
1517 { "tabnext 7", CTRL, 1, GDK_7 },
1518 { "tabnext 8", CTRL, 1, GDK_8 },
1519 { "tabnext 9", CTRL, 1, GDK_9 },
1520 { "tabfirst", CTRL, 1, GDK_less },
1521 { "tablast", CTRL, 1, GDK_greater },
1522 { "tabprevious", CTRL, 1, GDK_Left },
1523 { "tabnext", CTRL, 1, GDK_Right },
1524 { "focusout", CTRL, 1, GDK_minus },
1525 { "focusin", CTRL, 1, GDK_plus },
1526 { "focusin", CTRL, 1, GDK_equal },
1527 { "focusreset", CTRL, 1, GDK_0 },
1529 /* command aliases (handy when -S flag is used) */
1530 { ":open ", 0, 1, GDK_F9 },
1531 { ":open <uri>", 0, 1, GDK_F10 },
1532 { ":tabnew ", 0, 1, GDK_F11 },
1533 { ":tabnew <uri>", 0, 1, GDK_F12 },
1536 void
1537 walk_kb(struct settings *s,
1538 void (*cb)(struct settings *, char *, void *), void *cb_args)
1540 struct key_binding *k;
1541 char str[1024];
1543 if (s == NULL || cb == NULL) {
1544 show_oops(NULL, "walk_kb invalid parameters");
1545 return;
1548 TAILQ_FOREACH(k, &kbl, entry) {
1549 if (k->cmd == NULL)
1550 continue;
1551 str[0] = '\0';
1553 /* sanity */
1554 if (gdk_keyval_name(k->key) == NULL)
1555 continue;
1557 strlcat(str, k->cmd, sizeof str);
1558 strlcat(str, ",", sizeof str);
1560 if (k->mask & GDK_SHIFT_MASK)
1561 strlcat(str, "S-", sizeof str);
1562 if (k->mask & GDK_CONTROL_MASK)
1563 strlcat(str, "C-", sizeof str);
1564 if (k->mask & GDK_MOD1_MASK)
1565 strlcat(str, "M1-", sizeof str);
1566 if (k->mask & GDK_MOD2_MASK)
1567 strlcat(str, "M2-", sizeof str);
1568 if (k->mask & GDK_MOD3_MASK)
1569 strlcat(str, "M3-", sizeof str);
1570 if (k->mask & GDK_MOD4_MASK)
1571 strlcat(str, "M4-", sizeof str);
1572 if (k->mask & GDK_MOD5_MASK)
1573 strlcat(str, "M5-", sizeof str);
1575 strlcat(str, gdk_keyval_name(k->key), sizeof str);
1576 cb(s, str, cb_args);
1580 void
1581 init_keybindings(void)
1583 int i;
1584 struct key_binding *k;
1586 for (i = 0; i < LENGTH(keys); i++) {
1587 k = g_malloc0(sizeof *k);
1588 k->cmd = keys[i].cmd;
1589 k->mask = keys[i].mask;
1590 k->use_in_entry = keys[i].use_in_entry;
1591 k->key = keys[i].key;
1592 TAILQ_INSERT_HEAD(&kbl, k, entry);
1594 DNPRINTF(XT_D_KEYBINDING, "init_keybindings: added: %s\n",
1595 k->cmd ? k->cmd : "unnamed key");
1599 void
1600 keybinding_clearall(void)
1602 struct key_binding *k, *next;
1604 for (k = TAILQ_FIRST(&kbl); k; k = next) {
1605 next = TAILQ_NEXT(k, entry);
1606 if (k->cmd == NULL)
1607 continue;
1609 DNPRINTF(XT_D_KEYBINDING, "keybinding_clearall: %s\n",
1610 k->cmd ? k->cmd : "unnamed key");
1611 TAILQ_REMOVE(&kbl, k, entry);
1612 g_free(k);
1617 keybinding_set(char *cmd, char *key, int use_in_entry)
1619 struct key_binding *k;
1620 guint keyval, mask = 0;
1621 int i;
1623 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: %s %s\n", cmd, key);
1625 /* Keys which are to be used in entry have been prefixed with an
1626 * exclamation mark. */
1627 if (use_in_entry)
1628 key++;
1630 /* find modifier keys */
1631 if (strstr(key, "S-"))
1632 mask |= GDK_SHIFT_MASK;
1633 if (strstr(key, "C-"))
1634 mask |= GDK_CONTROL_MASK;
1635 if (strstr(key, "M1-"))
1636 mask |= GDK_MOD1_MASK;
1637 if (strstr(key, "M2-"))
1638 mask |= GDK_MOD2_MASK;
1639 if (strstr(key, "M3-"))
1640 mask |= GDK_MOD3_MASK;
1641 if (strstr(key, "M4-"))
1642 mask |= GDK_MOD4_MASK;
1643 if (strstr(key, "M5-"))
1644 mask |= GDK_MOD5_MASK;
1646 /* find keyname */
1647 for (i = strlen(key) - 1; i > 0; i--)
1648 if (key[i] == '-')
1649 key = &key[i + 1];
1651 /* validate keyname */
1652 keyval = gdk_keyval_from_name(key);
1653 if (keyval == GDK_VoidSymbol) {
1654 warnx("invalid keybinding name %s", key);
1655 return (1);
1657 /* must run this test too, gtk+ doesn't handle 10 for example */
1658 if (gdk_keyval_name(keyval) == NULL) {
1659 warnx("invalid keybinding name %s", key);
1660 return (1);
1663 /* Remove eventual dupes. */
1664 TAILQ_FOREACH(k, &kbl, entry)
1665 if (k->key == keyval && k->mask == mask) {
1666 TAILQ_REMOVE(&kbl, k, entry);
1667 g_free(k);
1668 break;
1671 if (strcmp(cmd, "unbind") == 0) {
1672 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: just unbinding: %s\n",
1673 gdk_keyval_name(keyval));
1674 printf("keybinding_set: just unbinding: %s\n",
1675 gdk_keyval_name(keyval));
1676 return (0);
1679 /* add keyname */
1680 k = g_malloc0(sizeof *k);
1681 k->cmd = g_strdup(cmd);
1682 k->mask = mask;
1683 k->use_in_entry = use_in_entry;
1684 k->key = keyval;
1686 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: %s 0x%x %d 0x%x\n",
1687 k->cmd,
1688 k->mask,
1689 k->use_in_entry,
1690 k->key);
1691 DNPRINTF(XT_D_KEYBINDING, "keybinding_set: adding: %s %s\n",
1692 k->cmd, gdk_keyval_name(keyval));
1694 TAILQ_INSERT_HEAD(&kbl, k, entry);
1696 return (0);
1700 cmd_alias_add(char *alias, char *cmd)
1702 struct cmd_alias *c;
1704 /* XXX */
1705 TAILQ_FOREACH(c, &cal, entry)
1706 if (!strcmp((alias), c->alias)) {
1707 TAILQ_REMOVE(&cal, c, entry);
1708 g_free(c);
1711 c = g_malloc(sizeof (struct cmd_alias));
1712 c->alias = g_strchug(g_strdup(alias));
1713 c->cmd = g_strchug(g_strdup(cmd));
1715 DNPRINTF(XT_D_CUSTOM_URI, "cmd_alias_add: %s %s\n", c->alias, c->cmd);
1717 TAILQ_INSERT_HEAD(&cal, c, entry);
1718 return (0);
1722 custom_uri_add(char *uri, char *cmd)
1724 struct custom_uri *u;
1726 TAILQ_FOREACH(u, &cul, entry)
1727 if (!strcmp((uri), u->uri) && !strcmp(cmd, u->cmd)) {
1728 TAILQ_REMOVE(&cul, u, entry);
1729 g_free(u);
1732 u = g_malloc(sizeof (struct custom_uri));
1733 u->uri = g_strdup(uri);
1734 expand_tilde(u->cmd, sizeof u->cmd, cmd);
1736 DNPRINTF(XT_D_CUSTOM_URI, "custom_uri_add: %s %s\n", u->uri, u->cmd);
1738 /* don't check here if the script is valid, wait until running it */
1739 TAILQ_INSERT_HEAD(&cul, u, entry);
1740 return (0);
1744 add_kb(struct settings *s, char *entry)
1746 char *kb, *key;
1748 DNPRINTF(XT_D_KEYBINDING, "add_kb: %s\n", entry);
1750 /* clearall is special */
1751 if (!strcmp(entry, "clearall")) {
1752 keybinding_clearall();
1753 return (0);
1756 kb = strstr(entry, ",");
1757 if (kb == NULL)
1758 return (1);
1759 *kb = '\0';
1760 key = kb + 1;
1762 return (keybinding_set(entry, key, key[0] == '!'));
1766 add_custom_uri(struct settings *s, char *entry)
1768 char *uri, *cmd;
1770 DNPRINTF(XT_D_CUSTOM_URI, "add_custom_uri: %s\n", entry);
1772 uri = strstr(entry, ",");
1773 if (uri == NULL)
1774 return (1);
1775 *uri = '\0';
1776 cmd = uri + 1;
1778 return (custom_uri_add(entry, cmd));
1781 void
1782 walk_custom_uri(struct settings *s,
1783 void (*cb)(struct settings *, char *, void *), void *cb_args)
1785 struct custom_uri *u;
1786 char buf[1024];
1788 if (s == NULL || cb == NULL) {
1789 show_oops(NULL, "walk_custom_uri invalid parameters");
1790 return;
1793 TAILQ_FOREACH(u, &cul, entry) {
1794 snprintf(buf, sizeof buf, "%s,%s", u->uri, u->cmd);
1795 cb(s, buf, cb_args);
1800 add_ua(struct settings *s, char *value)
1802 struct user_agent *ua;
1803 static int ua_count = 0;
1805 ua = g_malloc(sizeof *ua);
1806 ua->id = ua_count++;
1807 ua->value = g_strdup(value);
1809 RB_INSERT(user_agent_list, &ua_list, ua);
1811 return (0);
1815 void
1816 walk_ua(struct settings *s,
1817 void (*cb)(struct settings *, char *, void *), void *cb_args)
1819 struct user_agent *ua;
1821 if (s == NULL || cb == NULL) {
1822 show_oops(NULL, "walk_ua invalid parameters");
1823 return;
1826 RB_FOREACH(ua, user_agent_list, &ua_list)
1827 cb(s, ua->value, cb_args);
1831 add_force_https(struct settings *s, char *value)
1833 if (g_str_has_prefix(value, "re:")) {
1834 value = &value[3];
1835 wl_add(value, &force_https, XT_WL_PERSISTENT | XT_WL_REGEX);
1836 } else
1837 wl_add(value, &force_https, XT_WL_PERSISTENT);
1838 return (0);
1842 add_http_accept(struct settings *s, char *value)
1844 struct http_accept *ha;
1845 static int ha_count = 0;
1847 ha = g_malloc(sizeof *ha);
1848 ha->id = ha_count++;
1849 ha->value = g_strdup(value);
1851 RB_INSERT(http_accept_list, &ha_list, ha);
1853 return (0);
1856 void
1857 walk_http_accept(struct settings *s,
1858 void (*cb)(struct settings *, char *, void *), void *cb_args)
1860 struct http_accept *ha;
1862 if (s == NULL || cb == NULL) {
1863 show_oops(NULL, "%s: invalid parameters", __func__);
1864 return;
1867 RB_FOREACH(ha, http_accept_list, &ha_list)
1868 cb(s, ha->value, cb_args);
1872 add_cmd_alias(struct settings *s, char *entry)
1874 char *alias, *cmd;
1876 DNPRINTF(XT_D_CMD_ALIAS, "add_cmd_alias: %s\n", entry);
1878 alias = strstr(entry, ",");
1879 if (alias == NULL)
1880 return (1);
1881 *alias = '\0';
1882 cmd = alias + 1;
1884 return (cmd_alias_add(entry, cmd));
1887 void
1888 walk_cmd_alias(struct settings *s,
1889 void (*cb)(struct settings *, char *, void *), void *cb_args)
1891 struct cmd_alias *c;
1892 char buf[1024];
1894 if (s == NULL || cb == NULL) {
1895 show_oops(NULL, "walk_cmd_alias invalid parameters");
1896 return;
1899 TAILQ_FOREACH(c, &cal, entry) {
1900 snprintf(buf, sizeof buf, "%s --> %s", c->alias, c->cmd);
1901 cb(s, buf, cb_args);
1906 set_allow_insecure_content(char *value)
1908 struct tab *t;
1909 int tmp;
1910 const char *errstr;
1912 if (value == NULL || strlen(value) == 0)
1913 allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
1914 else {
1915 tmp = strtonum(value, 0, 1, &errstr);
1916 if (errstr)
1917 return (-1);
1918 allow_insecure_content = tmp;
1920 TAILQ_FOREACH(t, &tabs, entry)
1921 if (is_g_object_setting(G_OBJECT(t->settings),
1922 "enable-display-of-insecure-content")) {
1923 g_object_set(G_OBJECT(t->settings),
1924 "enable-display-of-insecure-content",
1925 allow_insecure_content, (char *)NULL);
1926 webkit_web_view_set_settings(t->wv, t->settings);
1928 return (0);
1932 check_allow_insecure_content(char **tt)
1934 *tt = g_strdup("Default (depends on browser_mode):\n"
1935 "\tnormal:\tEnabled\n"
1936 "\twhitelist:\tDisabled\n"
1937 "\tkiosk:\tEnabled");
1938 if (browser_mode == XT_BM_NORMAL && allow_insecure_content != 1)
1939 return (1);
1940 if (browser_mode == XT_BM_WHITELIST && allow_insecure_content != 0)
1941 return (1);
1942 if (browser_mode == XT_BM_KIOSK && allow_insecure_content != 1)
1943 return (1);
1944 return (0);
1948 set_allow_insecure_scripts(char *value)
1950 struct tab *t;
1951 int tmp;
1952 const char *errstr;
1954 if (value == NULL || strlen(value) == 0)
1955 allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
1956 else {
1957 tmp = strtonum(value, 0, 1, &errstr);
1958 if (errstr)
1959 return (-1);
1960 allow_insecure_scripts = tmp;
1962 TAILQ_FOREACH(t, &tabs, entry)
1963 if (is_g_object_setting(G_OBJECT(t->settings),
1964 "enable-running-of-insecure-content")) {
1965 g_object_set(G_OBJECT(t->settings),
1966 "enable-running-of-insecure-content",
1967 allow_insecure_scripts, (char *)NULL);
1968 webkit_web_view_set_settings(t->wv, t->settings);
1970 return (0);
1974 check_allow_insecure_scripts(char **tt)
1976 *tt = g_strdup("Default (depends on browser_mode):\n"
1977 "\tnormal:\tEnabled\n"
1978 "\twhitelist:\tDisabled\n"
1979 "\tkiosk:\tEnabled");
1980 if (browser_mode == XT_BM_NORMAL && allow_insecure_scripts != 1)
1981 return (1);
1982 if (browser_mode == XT_BM_WHITELIST && allow_insecure_scripts != 0)
1983 return (1);
1984 if (browser_mode == XT_BM_KIOSK && allow_insecure_scripts != 1)
1985 return (1);
1986 return (0);
1990 set_auto_load_images(char *value)
1992 struct tab *t;
1993 int tmp;
1994 const char *errstr;
1996 if (value == NULL || strlen(value) == 0)
1997 auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
1998 else {
1999 tmp = strtonum(value, 0, 1, &errstr);
2000 if (errstr)
2001 return (-1);
2002 auto_load_images = tmp;
2004 TAILQ_FOREACH(t, &tabs, entry) {
2005 g_object_set(G_OBJECT(t->settings),
2006 "auto-load-images", auto_load_images, (char *)NULL);
2007 webkit_web_view_set_settings(t->wv, t->settings);
2009 return (0);
2013 check_auto_load_images(char **tt)
2015 *tt = g_strdup_printf("Default: %s",
2016 XT_DS_AUTO_LOAD_IMAGES ? "Enabled" : "Disabled");
2017 return (auto_load_images != XT_DS_AUTO_LOAD_IMAGES);
2021 set_autofocus_onload(char *value)
2023 int tmp;
2024 const char *errstr;
2026 if (value == NULL || strlen(value) == 0)
2027 autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
2028 else {
2029 tmp = strtonum(value, 0, 1, &errstr);
2030 if (errstr)
2031 return (-1);
2032 autofocus_onload = tmp;
2034 return (0);
2038 check_autofocus_onload(char **tt)
2040 *tt = g_strdup_printf("Default: %s",
2041 XT_DS_AUTOFOCUS_ONLOAD ? "Enabled" : "Disabled");
2042 return (autofocus_onload != XT_DS_AUTOFOCUS_ONLOAD);
2046 set_ctrl_click_focus(char *value)
2048 int tmp;
2049 const char *errstr;
2051 if (value == NULL || strlen(value) == 0)
2052 ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS;
2053 else {
2054 tmp = strtonum(value, 0, 1, &errstr);
2055 if (errstr)
2056 return (-1);
2057 ctrl_click_focus = tmp;
2059 return (0);
2063 check_ctrl_click_focus(char **tt)
2065 *tt = g_strdup_printf("Default: %s",
2066 XT_DS_CTRL_CLICK_FOCUS ? "Enabled" : "Disabled");
2067 return (ctrl_click_focus != XT_DS_CTRL_CLICK_FOCUS);
2071 set_download_notifications(char *value)
2073 int tmp;
2074 const char *errstr;
2076 if (value == NULL || strlen(value) == 0)
2077 download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
2078 else {
2079 tmp = strtonum(value, 0, 1, &errstr);
2080 if (errstr)
2081 return (-1);
2082 download_notifications = tmp;
2084 return (0);
2088 check_download_notifications(char **tt)
2090 *tt = g_strdup_printf("Default: %s",
2091 XT_DS_DOWNLOAD_NOTIFICATIONS ? "Enabled" : "Disabled");
2092 return (download_notifications != XT_DS_DOWNLOAD_NOTIFICATIONS);
2096 set_enable_autoscroll(char *value)
2098 int tmp;
2099 const char *errstr;
2101 if (value == NULL || strlen(value) == 0)
2102 enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
2103 else {
2104 tmp = strtonum(value, 0, 1, &errstr);
2105 if (errstr)
2106 return (-1);
2107 enable_autoscroll = tmp;
2109 return (0);
2113 check_enable_autoscroll(char **tt)
2115 *tt = g_strdup_printf("Default: %s",
2116 XT_DS_ENABLE_AUTOSCROLL ? "Enabled" : "Disabled");
2117 return (enable_autoscroll != XT_DS_ENABLE_AUTOSCROLL);
2121 set_enable_cookie_whitelist(char *value)
2123 int tmp;
2124 const char *errstr;
2126 if (value == NULL || strlen(value) == 0)
2127 enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
2128 else {
2129 tmp = strtonum(value, 0, 1, &errstr);
2130 if (errstr)
2131 return (-1);
2132 enable_cookie_whitelist = tmp;
2134 return (0);
2138 check_enable_cookie_whitelist(char **tt)
2140 *tt = g_strdup("Default (depends on browser_mode):\n"
2141 "\tnormal:\tDisabled\n"
2142 "\twhitelist:\tEnabled\n"
2143 "\tkiosk:\tDisabled");
2144 if (browser_mode == XT_BM_WHITELIST && enable_cookie_whitelist != 1)
2145 return (1);
2146 if (browser_mode == XT_BM_NORMAL && enable_cookie_whitelist != 0)
2147 return (1);
2148 if (browser_mode == XT_BM_KIOSK && enable_cookie_whitelist != 0)
2149 return (1);
2150 return (0);
2154 set_enable_js_autorun(char *value)
2156 int tmp;
2157 const char *errstr;
2159 if (value == NULL || strlen(value) == 0)
2160 enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
2161 else {
2162 tmp = strtonum(value, 0, 1, &errstr);
2163 if (errstr)
2164 return (-1);
2165 enable_js_autorun = tmp;
2167 return (0);
2171 check_enable_js_autorun(char **tt)
2173 *tt = g_strdup_printf("Default: %s",
2174 XT_DS_ENABLE_JS_AUTORUN ? "Enabled" : "Disabled");
2175 return (enable_js_autorun != XT_DS_ENABLE_JS_AUTORUN);
2179 set_enable_js_whitelist(char *value)
2181 int tmp;
2182 const char *errstr;
2184 if (value == NULL || strlen(value) == 0)
2185 enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
2186 else {
2187 tmp = strtonum(value, 0, 1, &errstr);
2188 if (errstr)
2189 return (-1);
2190 enable_js_whitelist = tmp;
2192 return (0);
2196 check_enable_js_whitelist(char **tt)
2198 *tt = g_strdup("Default (depends on browser_mode):\n"
2199 "\tnormal:\tDisabled\n"
2200 "\twhitelist:\tEnabled\n"
2201 "\tkiosk:\tDisabled");
2202 if (browser_mode == XT_BM_WHITELIST && enable_js_whitelist != 1)
2203 return (1);
2204 if (browser_mode == XT_BM_NORMAL && enable_js_whitelist != 0)
2205 return (1);
2206 if (browser_mode == XT_BM_KIOSK && enable_js_whitelist != 0)
2207 return (1);
2208 return (0);
2212 set_enable_favicon_entry(char *value)
2214 int tmp;
2215 const char *errstr;
2217 if (value == NULL || strlen(value) == 0)
2218 enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
2219 else {
2220 tmp = strtonum(value, 0, 1, &errstr);
2221 if (errstr)
2222 return (-1);
2223 enable_favicon_entry = tmp;
2225 return (0);
2229 check_enable_favicon_entry(char **tt)
2231 *tt = g_strdup_printf("Default: %s",
2232 XT_DS_ENABLE_FAVICON_ENTRY ? "Enabled" : "Disabled");
2233 return (enable_favicon_entry != XT_DS_ENABLE_FAVICON_ENTRY);
2237 set_enable_favicon_tabs(char *value)
2239 int tmp;
2240 const char *errstr;
2242 if (value == NULL || strlen(value) == 0)
2243 enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
2244 else {
2245 tmp = strtonum(value, 0, 1, &errstr);
2246 if (errstr)
2247 return (-1);
2248 enable_favicon_tabs = tmp;
2250 return (0);
2254 check_enable_favicon_tabs(char **tt)
2256 *tt = g_strdup_printf("Default: %s",
2257 XT_DS_ENABLE_FAVICON_TABS ? "Enabled" : "Disabled");
2258 return (enable_favicon_tabs != XT_DS_ENABLE_FAVICON_TABS);
2262 set_enable_localstorage(char *value)
2264 struct tab *t;
2265 int tmp;
2266 const char *errstr;
2268 if (value == NULL || strlen(value) == 0)
2269 enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
2270 else {
2271 tmp = strtonum(value, 0, 1, &errstr);
2272 if (errstr)
2273 return (-1);
2274 enable_localstorage = tmp;
2276 TAILQ_FOREACH(t, &tabs, entry)
2277 g_object_set(G_OBJECT(t->settings),
2278 "enable-html5-local-storage", enable_localstorage,
2279 (char *)NULL);
2280 return (0);
2284 check_enable_localstorage(char **tt)
2286 *tt = g_strdup("Default (depends on browser_mode):\n"
2287 "\tnormal:\tEnabled\n"
2288 "\twhitelist:\tDisabled\n"
2289 "\tkiosk:\tEnabled");
2290 if (browser_mode == XT_BM_WHITELIST && enable_localstorage != 0)
2291 return (1);
2292 if (browser_mode == XT_BM_NORMAL && enable_localstorage != 1)
2293 return (1);
2294 if (browser_mode == XT_BM_KIOSK && enable_localstorage != 1)
2295 return (1);
2296 return (0);
2300 set_enable_plugins(char *value)
2302 struct tab *t;
2303 int tmp;
2304 const char *errstr;
2306 if (value == NULL || strlen(value) == 0)
2307 enable_plugins = XT_DS_ENABLE_PLUGINS;
2308 else {
2309 tmp = strtonum(value, 0, 1, &errstr);
2310 if (errstr)
2311 return (-1);
2312 enable_plugins = tmp;
2314 TAILQ_FOREACH(t, &tabs, entry)
2315 g_object_set(G_OBJECT(t->settings), "enable-plugins",
2316 enable_plugins, (char *)NULL);
2317 return (0);
2321 check_enable_plugins(char **tt)
2323 *tt = g_strdup("Default (depends on browser_mode):\n"
2324 "\tnormal:\tEnabled\n"
2325 "\twhitelist:\tDisabled\n"
2326 "\tkiosk:\tEnabled");
2327 if (browser_mode == XT_BM_WHITELIST && enable_plugins != 0)
2328 return (1);
2329 if (browser_mode == XT_BM_NORMAL && enable_plugins != 1)
2330 return (1);
2331 if (browser_mode == XT_BM_KIOSK && enable_plugins != 1)
2332 return (1);
2333 return (0);
2337 set_enable_plugin_whitelist(char *value)
2339 int tmp;
2340 const char *errstr;
2342 if (value == NULL || strlen(value) == 0)
2343 enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
2344 else {
2345 tmp = strtonum(value, 0, 1, &errstr);
2346 if (errstr)
2347 return (-1);
2348 enable_plugin_whitelist = tmp;
2350 return (0);
2354 check_enable_plugin_whitelist(char **tt)
2356 *tt = g_strdup("Default (depends on browser_mode):\n"
2357 "\tnormal:\tDisabled\n"
2358 "\twhitelist:\tEnabled\n"
2359 "\tkiosk:\tDisabled");
2360 if (browser_mode == XT_BM_WHITELIST && enable_plugin_whitelist != 1)
2361 return (1);
2362 if (browser_mode == XT_BM_NORMAL && enable_plugin_whitelist != 0)
2363 return (1);
2364 if (browser_mode == XT_BM_KIOSK && enable_plugin_whitelist != 0)
2365 return (1);
2366 return (0);
2370 set_enable_scripts(char *value)
2372 struct tab *t;
2373 int tmp;
2374 const char *errstr;
2376 if (value == NULL || strlen(value) == 0)
2377 enable_scripts = XT_DS_ENABLE_SCRIPTS;
2378 else {
2379 tmp = strtonum(value, 0, 1, &errstr);
2380 if (errstr)
2381 return (-1);
2382 enable_scripts = tmp;
2384 TAILQ_FOREACH(t, &tabs, entry)
2385 g_object_set(G_OBJECT(t->settings), "enable-scripts",
2386 enable_scripts, (char *)NULL);
2387 return (0);
2391 check_enable_scripts(char **tt)
2393 *tt = g_strdup("Default (depends on browser_mode):\n"
2394 "\tnormal:\tEnabled\n"
2395 "\twhitelist:\tDisabled\n"
2396 "\tkiosk:\tEnabled");
2397 if (browser_mode == XT_BM_WHITELIST && enable_scripts != 0)
2398 return (1);
2399 if (browser_mode == XT_BM_NORMAL && enable_scripts != 1)
2400 return (1);
2401 if (browser_mode == XT_BM_KIOSK && enable_scripts != 1)
2402 return (1);
2403 return (0);
2407 check_enable_socket(char **tt)
2409 *tt = g_strdup("Default: Disabled");
2410 return (enable_socket != 0);
2414 set_enable_spell_checking(char *value)
2416 struct tab *t;
2417 int tmp;
2418 const char *errstr;
2420 if (value == NULL || strlen(value) == 0)
2421 enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
2422 else {
2423 tmp = strtonum(value, 0, 1, &errstr);
2424 if (errstr)
2425 return (-1);
2426 enable_spell_checking = tmp;
2428 TAILQ_FOREACH(t, &tabs, entry)
2429 g_object_set(G_OBJECT(t->settings), "enable_spell_checking",
2430 enable_spell_checking, (char *)NULL);
2431 return (0);
2435 check_enable_spell_checking(char **tt)
2437 *tt = g_strdup_printf("Default: %s",
2438 XT_DS_ENABLE_SPELL_CHECKING ? "Enabled" : "Disabled");
2439 return (enable_spell_checking != XT_DS_ENABLE_SPELL_CHECKING);
2443 set_enable_strict_transport(char *value)
2445 int tmp;
2446 const char *errstr;
2448 if (value == NULL || strlen(value) == 0)
2449 enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
2450 else {
2451 tmp = strtonum(value, 0, 1, &errstr);
2452 if (errstr)
2453 return (-1);
2454 enable_strict_transport = tmp;
2456 return (0);
2460 check_enable_strict_transport(char **tt)
2462 *tt = g_strdup_printf("Default: %s",
2463 XT_DS_ENABLE_STRICT_TRANSPORT ? "Enabled" : "Disabled");
2464 return (enable_strict_transport != XT_DS_ENABLE_STRICT_TRANSPORT);
2467 #if 0
2469 * XXX: this is currently broken. Need to figure out what to do with
2470 * this. Problemm is set_encoding will refresh the tab it's run on, so
2471 * we can either put a big fat warning in the manpage and refresh every
2472 * single open tab with the new encoding or scrap it as a runtime
2473 * setting.
2476 set_encoding_rt(char *value)
2478 struct karg args = {0};
2480 if (value == NULL || strlen(value) == 0)
2481 return (-1);
2482 if (encoding)
2483 g_free(encoding);
2484 encoding = g_strdup(value);
2485 args.s = encoding;
2486 set_encoding(get_current_tab(), &args);
2487 return (0);
2489 #endif
2492 check_encoding(char **tt)
2494 *tt = g_strdup_printf("Default: %s", XT_DS_ENCODING);
2495 return (g_strcmp0(encoding, XT_DS_ENCODING));
2499 check_gnutls_search_string(char **tt)
2501 *tt = g_strdup("Default: (empty)");
2502 return (g_strcmp0(gnutls_priority_string,
2503 XT_DS_GNUTLS_PRIORITY_STRING));
2507 set_gnutls_priority_string(struct settings *s, char *value)
2509 return (!g_setenv("G_TLS_GNUTLS_PRIORITY", value, FALSE));
2512 char *
2513 get_gnutls_priority_string(struct settings *s)
2515 return (g_strdup(g_getenv("G_TLS_GNUTLS_PRIORITY")));
2519 set_guess_search(char *value)
2521 int tmp;
2522 const char *errstr;
2524 if (value == NULL || strlen(value) == 0)
2525 guess_search = XT_DS_GUESS_SEARCH;
2526 else {
2527 tmp = strtonum(value, 0, 1, &errstr);
2528 if (errstr)
2529 return (-1);
2530 guess_search = tmp;
2532 return (0);
2536 check_guess_search(char **tt)
2538 *tt = g_strdup_printf("Default: %s",
2539 XT_DS_GUESS_SEARCH ? "Enabled" : "Disabled");
2540 return (guess_search != XT_DS_GUESS_SEARCH);
2543 char *
2544 get_referer(struct settings *s)
2546 if (referer_mode == XT_REFERER_ALWAYS)
2547 return (g_strdup("always"));
2548 if (referer_mode == XT_REFERER_NEVER)
2549 return (g_strdup("never"));
2550 if (referer_mode == XT_REFERER_SAME_DOMAIN)
2551 return (g_strdup("same-domain"));
2552 if (referer_mode == XT_REFERER_SAME_FQDN)
2553 return (g_strdup("same-fqdn"));
2554 if (referer_mode == XT_REFERER_CUSTOM)
2555 return (g_strdup(referer_custom));
2556 return (NULL);
2560 set_referer(struct settings *s, char *value)
2562 if (referer_custom) {
2563 g_free(referer_custom);
2564 referer_custom = NULL;
2567 if (!strcmp(value, "always"))
2568 referer_mode = XT_REFERER_ALWAYS;
2569 else if (!strcmp(value, "never"))
2570 referer_mode = XT_REFERER_NEVER;
2571 else if (!strcmp(value, "same-domain"))
2572 referer_mode = XT_REFERER_SAME_DOMAIN;
2573 else if (!strcmp(value, "same-fqdn"))
2574 referer_mode = XT_REFERER_SAME_FQDN;
2575 else if (!valid_url_type(value)) {
2576 referer_mode = XT_REFERER_CUSTOM;
2577 referer_custom = g_strdup(value);
2578 } else {
2579 /* we've already free'd the custom referer */
2580 if (referer_mode == XT_REFERER_CUSTOM)
2581 referer_mode = XT_REFERER_NEVER;
2582 return (1);
2585 return (0);
2589 set_referer_rt(char *value)
2591 if (value == NULL || strlen(value) == 0) {
2592 if (referer_custom)
2593 g_free(referer_custom);
2594 referer_custom = g_strdup(XT_DS_REFERER_CUSTOM);
2595 referer_mode = XT_DS_REFERER_MODE;
2596 return (0);
2598 return (set_referer(NULL, value));
2602 check_referer(char **tt)
2604 *tt = g_strdup("Default (depends on browser_mode):\n"
2605 "\tnormal:\talways\n"
2606 "\twhitelist:\tsame-domain\n"
2607 "\tkiosk:\talways");
2608 if (browser_mode == XT_BM_WHITELIST &&
2609 referer_mode != XT_REFERER_SAME_DOMAIN)
2610 return (1);
2611 if (browser_mode == XT_BM_NORMAL && referer_mode != XT_REFERER_ALWAYS)
2612 return (1);
2613 if (browser_mode == XT_BM_KIOSK && referer_mode != XT_REFERER_ALWAYS)
2614 return (1);
2615 return (0);
2618 char *
2619 get_ssl_ca_file(struct settings *s)
2621 if (strlen(ssl_ca_file) == 0)
2622 return (NULL);
2623 return (g_strdup(ssl_ca_file));
2627 set_refresh_interval(char *value)
2629 int tmp;
2630 const char *errstr;
2632 if (value == NULL || strlen(value) == 0)
2633 refresh_interval = XT_DS_REFRESH_INTERVAL;
2634 else {
2635 tmp = strtonum(value, 0, INT_MAX, &errstr);
2636 if (errstr)
2637 return (-1);
2638 refresh_interval = tmp;
2640 return (0);
2644 check_resource_dir(char **tt)
2646 *tt = g_strdup_printf("Default: %s", XT_DS_RESOURCE_DIR);
2647 return (g_strcmp0(resource_dir, XT_DS_RESOURCE_DIR));
2651 check_save_global_history(char **tt)
2653 *tt = g_strdup("Default: Disabled");
2654 return (save_global_history != 0);
2658 check_save_rejected_cookies(char **tt)
2660 *tt = g_strdup("Default: Disabled");
2661 return (save_rejected_cookies != 0);
2665 check_refresh_interval(char **tt)
2667 *tt = g_strdup_printf("Default: %d", XT_DS_REFRESH_INTERVAL);
2668 return (refresh_interval != XT_DS_REFRESH_INTERVAL);
2672 set_session_autosave(char *value)
2674 int tmp;
2675 const char *errstr;
2677 if (value == NULL || strlen(value) == 0)
2678 session_autosave = XT_DS_SESSION_AUTOSAVE;
2679 else {
2680 tmp = strtonum(value, 0, 1, &errstr);
2681 if (errstr)
2682 return (-1);
2683 session_autosave = tmp;
2685 return (0);
2689 check_session_autosave(char **tt)
2691 *tt = g_strdup_printf("Default: %s",
2692 XT_DS_SESSION_AUTOSAVE ? "Enabled" : "Disabled");
2693 return (session_autosave != XT_DS_SESSION_AUTOSAVE);
2697 set_session_timeout(char *value)
2699 int tmp;
2700 const char *errstr;
2702 if (value == NULL || strlen(value) == 0)
2703 session_timeout = XT_DS_SESSION_TIMEOUT;
2704 else {
2705 tmp = strtonum(value, 0, INT_MAX, &errstr);
2706 if (errstr)
2707 return (-1);
2708 session_timeout = tmp;
2710 return (0);
2714 check_session_timeout(char **tt)
2716 *tt = g_strdup_printf("Default: %d", XT_DS_SESSION_TIMEOUT);
2717 return (session_timeout != XT_DS_SESSION_TIMEOUT);
2721 set_show_scrollbars(char *value)
2723 struct tab *t;
2724 int tmp;
2725 const char *errstr;
2727 if (value == NULL || strlen(value) == 0)
2728 tmp = XT_DS_SHOW_SCROLLBARS;
2729 else {
2730 tmp = strtonum(value, 0, 1, &errstr);
2731 if (errstr)
2732 return (-1);
2734 show_scrollbars = tmp;
2735 TAILQ_FOREACH(t, &tabs, entry)
2736 if (set_scrollbar_visibility(t, show_scrollbars))
2737 return (-1);
2738 return (0);
2742 check_show_scrollbars(char **tt)
2744 *tt = g_strdup("Default (depends on gui_mode):\n"
2745 "\tclassic:\tEnabled\n"
2746 "\tminimal:\tDisabled");
2747 if (gui_mode == XT_GM_CLASSIC && show_scrollbars != 1)
2748 return (1);
2749 if (gui_mode == XT_GM_MINIMAL && show_scrollbars != 0)
2750 return (1);
2751 return (0);
2755 set_show_statusbar(char *value)
2757 int tmp;
2758 const char *errstr;
2760 if (value == NULL || strlen(value) == 0)
2761 tmp = XT_DS_SHOW_STATUSBAR;
2762 else {
2763 tmp = strtonum(value, 0, 1, &errstr);
2764 if (errstr)
2765 return (-1);
2767 show_statusbar = tmp;
2768 statusbar_set_visibility();
2769 return (0);
2773 check_show_statusbar(char **tt)
2775 *tt = g_strdup("Default (depends on gui_mode):\n"
2776 "\tclassic:\tDisabled\n"
2777 "\tminimal:\tEnabled");
2778 if (gui_mode == XT_GM_CLASSIC && show_statusbar != 0)
2779 return (1);
2780 if (gui_mode == XT_GM_MINIMAL && show_statusbar != 1)
2781 return (1);
2782 return (0);
2786 set_show_tabs(char *value)
2788 struct karg args = {0};
2789 int val;
2790 const char *errstr;
2792 if (value == NULL || strlen(value) == 0)
2793 val = XT_DS_SHOW_TABS;
2794 else {
2795 val = strtonum(value, 0, 1, &errstr);
2796 if (errstr)
2797 return (-1);
2799 args.i = val ? XT_TAB_SHOW : XT_TAB_HIDE;
2800 tabaction(get_current_tab(), &args);
2801 return (0);
2805 check_show_tabs(char **tt)
2807 *tt = g_strdup("Default (depends on gui_mode):\n"
2808 "\tclassic:\tEnabled\n"
2809 "\tminimal:\tDisabled");
2810 if (gui_mode == XT_GM_CLASSIC && show_tabs != 1)
2811 return (1);
2812 if (gui_mode == XT_GM_MINIMAL && show_tabs != 0)
2813 return (1);
2814 return (0);
2818 set_show_url(char *value)
2820 struct karg args = {0};
2821 int val;
2822 const char *errstr;
2824 if (value == NULL || strlen(value) == 0)
2825 val = XT_DS_SHOW_URL;
2826 else {
2827 val = strtonum(value, 0, 1, &errstr);
2828 if (errstr)
2829 return (-1);
2831 args.i = val ? XT_URL_SHOW : XT_URL_HIDE;
2832 urlaction(get_current_tab(), &args);
2833 return (0);
2837 check_show_url(char **tt)
2839 *tt = g_strdup("Default (depends on gui_mode):\n"
2840 "\tclassic:\tEnabled\n"
2841 "\tminimal:\tDisabled");
2842 if (gui_mode == XT_GM_CLASSIC && show_url != 1)
2843 return (1);
2844 if (gui_mode == XT_GM_MINIMAL && show_url != 0)
2845 return (1);
2846 return (0);
2850 check_single_instance(char **tt)
2852 *tt = g_strdup("Default: Disabled");
2853 return (single_instance != 0);
2857 set_spell_check_languages(char *value)
2859 struct tab *t;
2861 if (spell_check_languages)
2862 g_free(spell_check_languages);
2863 if (value == NULL || strlen(value) == 0)
2864 spell_check_languages = g_strdup(XT_DS_SPELL_CHECK_LANGUAGES);
2865 else
2866 spell_check_languages = g_strdup(value);
2867 TAILQ_FOREACH(t, &tabs, entry)
2868 g_object_set(G_OBJECT(t->settings), "spell_checking_languages",
2869 spell_check_languages, (char *)NULL);
2870 return (0);
2874 check_spell_check_languages(char **tt)
2876 *tt = g_strdup_printf("Default: %s", XT_DS_SPELL_CHECK_LANGUAGES);
2877 return (g_strcmp0(spell_check_languages, XT_DS_SPELL_CHECK_LANGUAGES));
2881 check_valid_file(char *name)
2883 struct stat sb;
2885 if (name == NULL || stat(name, &sb))
2886 return (-1);
2887 return (0);
2891 set_ssl_ca_file_rt(char *value)
2893 if (value == NULL || strlen(value) == 0) {
2894 strlcpy(ssl_ca_file, XT_DS_SSL_CA_FILE, sizeof ssl_ca_file);
2895 g_object_set(session, SOUP_SESSION_SSL_CA_FILE, "", NULL);
2896 return (0);
2897 } else
2898 return (set_ssl_ca_file(NULL, value));
2902 check_ssl_ca_file(char **tt)
2904 *tt = g_strdup("Default: (empty)");
2905 return (g_strcmp0(ssl_ca_file, XT_DS_SSL_CA_FILE));
2909 set_ssl_strict_certs(char *value)
2911 int tmp;
2912 const char *errstr;
2914 if (value == NULL || strlen(value) == 0)
2915 ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
2916 else {
2917 tmp = strtonum(value, 0, 1, &errstr);
2918 if (errstr)
2919 return (-1);
2920 ssl_strict_certs = tmp;
2922 g_object_set(session, SOUP_SESSION_SSL_STRICT, ssl_strict_certs, NULL);
2923 return (0);
2927 check_ssl_strict_certs(char **tt)
2929 *tt = g_strdup_printf("Default: %s",
2930 XT_DS_SSL_STRICT_CERTS ? "Enabled" : "Disabled");
2931 return (ssl_strict_certs != XT_DS_SSL_STRICT_CERTS);
2935 check_statusbar_elems(char **tt)
2937 *tt = g_strdup("Default: BP");
2938 return (g_strcmp0(statusbar_elems, "BP"));
2942 set_external_editor(char *editor)
2944 if (external_editor)
2945 g_free(external_editor);
2946 if (editor == NULL || strlen(editor) == 0)
2947 external_editor = NULL;
2948 else
2949 external_editor = g_strdup(editor);
2950 return (0);
2954 check_external_editor(char **tt)
2956 *tt = g_strdup("Default: (empty)");
2957 return (g_strcmp0(external_editor, NULL));
2961 set_fancy_bar(char *value)
2963 struct tab *t;
2964 int tmp;
2965 const char *errstr;
2967 if (value == NULL || strlen(value) == 0)
2968 fancy_bar = 1; /* XXX */
2969 else {
2970 tmp = strtonum(value, 0, 1, &errstr);
2971 if (errstr)
2972 return (-1);
2973 fancy_bar = tmp;
2975 TAILQ_FOREACH(t, &tabs, entry)
2976 if (fancy_bar) {
2977 gtk_widget_show(t->backward);
2978 gtk_widget_show(t->forward);
2979 gtk_widget_show(t->stop);
2980 gtk_widget_show(t->js_toggle);
2981 if (search_string && strlen(search_string))
2982 gtk_widget_show(t->search_entry);
2983 } else {
2984 gtk_widget_hide(t->backward);
2985 gtk_widget_hide(t->forward);
2986 gtk_widget_hide(t->stop);
2987 gtk_widget_hide(t->js_toggle);
2988 gtk_widget_hide(t->search_entry);
2990 return (0);
2994 check_fancy_bar(char **tt)
2996 *tt = g_strdup("Default (depends on gui_mode):\n"
2997 "\tclassic:\tEnabled\n"
2998 "\tminimal:\tDisabled");
2999 if (gui_mode == XT_GM_CLASSIC && fancy_bar != 1)
3000 return (1);
3001 if (gui_mode == XT_GM_MINIMAL && fancy_bar != 0)
3002 return (1);
3003 return (0);
3006 void
3007 setup_proxy(char *uri)
3009 struct tab *t;
3011 if (proxy_uri) {
3012 g_object_set(session, "proxy_uri", NULL, (char *)NULL);
3013 soup_uri_free(proxy_uri);
3014 proxy_uri = NULL;
3015 TAILQ_FOREACH(t, &tabs, entry)
3016 gtk_label_set_text(GTK_LABEL(t->sbe.proxy), "");
3018 if (http_proxy) {
3019 if (http_proxy != uri) {
3020 g_free(http_proxy);
3021 http_proxy = NULL;
3025 if (uri) {
3026 http_proxy = g_strdup(uri);
3027 DNPRINTF(XT_D_CONFIG, "setup_proxy: %s\n", uri);
3028 proxy_uri = soup_uri_new(http_proxy);
3029 if (proxy_uri != NULL && SOUP_URI_VALID_FOR_HTTP(proxy_uri)) {
3030 g_object_set(session, "proxy-uri", proxy_uri,
3031 (char *)NULL);
3032 TAILQ_FOREACH(t, &tabs, entry) {
3033 gtk_label_set_text(GTK_LABEL(t->sbe.proxy),
3034 "proxy");
3035 gtk_widget_show(t->proxy_toggle);
3036 button_set_file(t->proxy_toggle,
3037 "torenabled.ico");
3040 } else {
3041 TAILQ_FOREACH(t, &tabs, entry)
3042 button_set_file(t->proxy_toggle, "tordisabled.ico");
3046 char *
3047 get_tab_style(struct settings *s)
3049 if (tab_style == XT_TABS_NORMAL)
3050 return (g_strdup("normal"));
3051 else
3052 return (g_strdup("compact"));
3056 set_tab_style(struct settings *s, char *val)
3058 if (!strcmp(val, "normal"))
3059 tab_style = XT_TABS_NORMAL;
3060 else if (!strcmp(val, "compact"))
3061 tab_style = XT_TABS_COMPACT;
3062 else
3063 return (1);
3065 return (0);
3069 check_tab_style(char **tt)
3071 *tt = g_strdup("Default (depends on gui_mode):\n"
3072 "\tclassic:\tnormal\n"
3073 "\tminimal:\tcompact");
3074 if (gui_mode == XT_GM_CLASSIC && tab_style != XT_TABS_NORMAL)
3075 return (1);
3076 if (gui_mode == XT_GM_MINIMAL && tab_style != XT_TABS_COMPACT)
3077 return (1);
3078 return (0);
3082 set_tab_style_rt(char *value)
3084 struct karg args = {0};
3085 int old_tab_style;
3087 if (value == NULL || strlen(value) == 0) {
3088 if (tab_style == XT_DS_TAB_STYLE)
3089 return (0);
3090 tab_style = XT_TABS_COMPACT;
3091 args.i = XT_TAB_NEXTSTYLE;
3092 } else {
3093 old_tab_style = tab_style;
3094 if (set_tab_style(NULL, value))
3095 return (-1);
3096 if (old_tab_style != tab_style) {
3097 tab_style = old_tab_style;
3098 args.i = XT_TAB_NEXTSTYLE;
3101 tabaction(get_current_tab(), &args);
3102 return (0);
3105 char *
3106 get_statusbar_style(struct settings *s)
3108 if (statusbar_style == XT_STATUSBAR_URL)
3109 return (g_strdup("url"));
3110 else
3111 return (g_strdup("title"));
3115 set_statusbar_style(struct settings *s, char *val)
3117 if (!strcmp(val, "url"))
3118 statusbar_style = XT_STATUSBAR_URL;
3119 else if (!strcmp(val, "title"))
3120 statusbar_style = XT_STATUSBAR_TITLE;
3121 else
3122 return (1);
3124 return (0);
3128 set_statusbar_style_rt(char *value)
3130 struct tab *t;
3131 const gchar *page_uri;
3133 if (value == NULL || strlen(value) == 0) {
3134 if (statusbar_style == XT_DS_STATUSBAR_STYLE)
3135 return (0);
3136 statusbar_style = XT_DS_STATUSBAR_STYLE;
3137 } else {
3138 if (!strcmp(value, "url"))
3139 statusbar_style = XT_STATUSBAR_URL;
3140 else if (!strcmp(value, "title"))
3141 statusbar_style = XT_STATUSBAR_TITLE;
3144 /* apply changes */
3145 TAILQ_FOREACH(t, &tabs, entry) {
3146 if (statusbar_style == XT_STATUSBAR_TITLE)
3147 set_status(t, "%s", get_title(t, FALSE));
3148 else if ((page_uri = get_uri(t)) != NULL)
3149 set_status(t, "%s", page_uri);
3152 return (0);
3156 check_statusbar_style(char **tt)
3158 *tt = g_strdup("Default: url");
3159 return (statusbar_style != XT_DS_STATUSBAR_STYLE);
3163 set_url_regex(char *value)
3165 if (value == NULL || strlen(value) == 0) {
3166 if (url_regex)
3167 g_free(url_regex);
3168 url_regex = g_strdup(XT_DS_URL_REGEX);
3169 } else {
3170 if (regcomp(&url_re, value, REG_EXTENDED | REG_NOSUB))
3171 return (-1);
3172 if (url_regex)
3173 g_free(url_regex);
3174 url_regex = g_strdup(value);
3176 return (0);
3180 check_url_regex(char **tt)
3182 *tt = g_strdup_printf("Default: %s", XT_DS_URL_REGEX);
3183 return (g_strcmp0(url_regex, XT_DS_URL_REGEX));
3187 set_userstyle(struct settings *s, char *value)
3189 int rv = 0;
3190 char script[PATH_MAX] = {'\0'};
3191 char *tmp;
3193 if (value == NULL || strlen(value) == 0) {
3194 snprintf(script, sizeof script, "%s" PS "style.css", resource_dir);
3195 tmp = g_filename_to_uri(script, NULL, NULL);
3196 if (tmp == NULL)
3197 rv = -1;
3198 else {
3199 if (userstyle)
3200 g_free(userstyle);
3201 userstyle = tmp;
3203 } else {
3204 expand_tilde(script, sizeof script, value);
3205 tmp = g_filename_to_uri(script, NULL, NULL);
3206 if (tmp == NULL)
3207 rv = -1;
3208 else {
3209 if (userstyle)
3210 g_free(userstyle);
3211 userstyle = tmp;
3214 if (stylesheet)
3215 g_free(stylesheet);
3216 stylesheet = g_strdup(userstyle);
3217 return (rv);
3220 char *
3221 get_userstyle(struct settings *s)
3223 if (userstyle)
3224 return (g_filename_from_uri(userstyle, NULL, NULL));
3225 return (NULL);
3229 set_userstyle_rt(char *value)
3231 return (set_userstyle(NULL, value));
3235 check_userstyle(char **tt)
3237 int rv = 0;
3238 char buf[PATH_MAX];
3239 char *file = NULL;
3241 snprintf(buf, sizeof buf, "%s" PS "%s", resource_dir, "style.css");
3242 *tt = g_strdup_printf("Default: %s", buf);
3243 file = g_filename_from_uri(userstyle, NULL, NULL);
3244 rv = g_strcmp0(file, buf);
3245 if (file)
3246 g_free(file);
3247 return (rv);
3251 set_userstyle_global(char *value)
3253 struct karg args = {0};
3254 int tmp, old_style;
3255 const char *errstr;
3257 if (value == NULL || strlen(value) == 0) {
3258 if (userstyle_global == XT_DS_USERSTYLE_GLOBAL)
3259 return (0);
3260 userstyle_global = 1;
3261 args.i = XT_STYLE_GLOBAL;
3262 userstyle_cmd(get_current_tab(), &args);
3263 } else {
3264 old_style = userstyle_global;
3265 tmp = strtonum(value, 0, 1, &errstr);
3266 if (errstr)
3267 return (-1);
3268 if (tmp != old_style) {
3269 args.i = XT_STYLE_GLOBAL;
3270 userstyle_cmd(get_current_tab(), &args);
3273 return (0);
3277 check_userstyle_global(char **tt)
3279 *tt = g_strdup_printf("Default: %s",
3280 XT_DS_USERSTYLE_GLOBAL ? "Enabled" : "Disabled");
3281 return (userstyle_global != XT_DS_USERSTYLE_GLOBAL);
3285 set_warn_cert_changes(char *value)
3287 int tmp;
3288 const char *errstr;
3290 if (value == NULL || strlen(value) == 0)
3291 warn_cert_changes = XT_DS_WARN_CERT_CHANGES;
3292 else {
3293 tmp = strtonum(value, 0, 1, &errstr);
3294 if (errstr)
3295 return (-1);
3296 warn_cert_changes = tmp;
3298 return (0);
3302 check_warn_cert_changes(char **tt)
3304 *tt = g_strdup_printf("Default: %s",
3305 XT_DS_WARN_CERT_CHANGES ? "Enabled" : "Disabled");
3306 return (warn_cert_changes != XT_DS_WARN_CERT_CHANGES);
3310 check_window_height(char **tt)
3312 *tt = g_strdup_printf("Default: %d", 768);
3313 return (window_height != 768);
3317 check_window_maximize(char **tt)
3319 *tt = g_strdup("Default: Disabled");
3320 return (window_maximize != 0);
3324 check_window_width(char **tt)
3326 *tt = g_strdup_printf("Default: %d", 768);
3327 return (window_width != 1024);
3331 check_work_dir(char **tt)
3333 struct passwd *pwd;
3334 char buf[PATH_MAX];
3336 if ((pwd = getpwuid(getuid())) == NULL)
3337 return (-1);
3338 snprintf(buf, sizeof buf, "%s" PS ".xombrero", pwd->pw_dir);
3339 *tt = g_strdup_printf("Default: %s", buf);
3340 return (g_strcmp0(work_dir, buf));
3343 char *
3344 get_edit_mode(struct settings *s)
3346 if (edit_mode == XT_EM_HYBRID)
3347 return (g_strdup("hybrid"));
3348 else
3349 return (g_strdup("vi"));
3353 set_edit_mode(struct settings *s, char *val)
3355 if (!strcmp(val, "hybrid"))
3356 edit_mode = XT_EM_HYBRID;
3357 else if (!strcmp(val, "vi"))
3358 edit_mode = XT_EM_VI;
3359 else
3360 return (1);
3362 return (0);
3366 check_edit_mode(char **tt)
3368 *tt = g_strdup("Default: hybrid");
3369 return (edit_mode != XT_EM_HYBRID);
3372 char *
3373 get_download_mode(struct settings *s)
3375 switch (download_mode) {
3376 case XT_DM_START:
3377 return (g_strdup("start"));
3378 break;
3379 case XT_DM_ASK:
3380 return (g_strdup("ask"));
3381 break;
3382 case XT_DM_ADD:
3383 return (g_strdup("add"));
3384 break;
3386 return (g_strdup("unknown"));
3390 set_download_mode(struct settings *s, char *val)
3392 if (val == NULL || strlen(val) == 0 || !strcmp(val, "start"))
3393 download_mode = XT_DM_START;
3394 else if (!strcmp(val, "ask"))
3395 download_mode = XT_DM_ASK;
3396 else if (!strcmp(val, "add"))
3397 download_mode = XT_DM_ADD;
3398 else
3399 return (1);
3401 return (0);
3405 set_download_mode_rt(char *val)
3407 return (set_download_mode(NULL, val));
3411 check_download_mode(char **tt)
3413 *tt = g_strdup("Default: start");
3414 return (download_mode != XT_DM_START);
3417 char *
3418 get_work_dir(struct settings *s)
3420 if (work_dir[0] == '\0')
3421 return (0);
3422 return (g_strdup(work_dir));
3426 set_work_dir(struct settings *s, char *val)
3428 expand_tilde(work_dir, sizeof work_dir, val);
3429 return (0);
3432 void
3433 walk_cookie_wl(struct settings *s,
3434 void (*cb)(struct settings *, char *, void *), void *cb_args)
3436 struct wl_entry *w;
3438 if (s == NULL || cb == NULL) {
3439 show_oops(NULL, "walk_cookie_wl invalid parameters");
3440 return;
3443 TAILQ_FOREACH_REVERSE(w, &c_wl, wl_list, entry)
3444 cb(s, w->pat, cb_args);
3447 void
3448 walk_js_wl(struct settings *s,
3449 void (*cb)(struct settings *, char *, void *), void *cb_args)
3451 struct wl_entry *w;
3453 if (s == NULL || cb == NULL) {
3454 show_oops(NULL, "walk_js_wl invalid parameters");
3455 return;
3458 TAILQ_FOREACH_REVERSE(w, &js_wl, wl_list, entry)
3459 cb(s, w->pat, cb_args);
3462 void
3463 walk_pl_wl(struct settings *s,
3464 void (*cb)(struct settings *, char *, void *), void *cb_args)
3466 struct wl_entry *w;
3468 if (s == NULL || cb == NULL) {
3469 show_oops(NULL, "walk_pl_wl invalid parameters");
3470 return;
3473 TAILQ_FOREACH_REVERSE(w, &pl_wl, wl_list, entry)
3474 cb(s, w->pat, cb_args);
3477 void
3478 walk_force_https(struct settings *s,
3479 void (*cb)(struct settings *, char *, void *), void *cb_args)
3481 struct wl_entry *w;
3483 if (s == NULL || cb == NULL) {
3484 show_oops(NULL, "walk_force_https invalid parameters");
3485 return;
3488 TAILQ_FOREACH_REVERSE(w, &force_https, wl_list, entry)
3489 cb(s, w->pat, cb_args);
3493 settings_add(char *var, char *val)
3495 int i, rv, *p;
3496 gfloat *f;
3497 char c[PATH_MAX], **s;
3499 /* get settings */
3500 for (i = 0, rv = 0; i < LENGTH(rs); i++) {
3501 if (strcmp(var, rs[i].name))
3502 continue;
3504 if (!strcmp(var, "include_config")) {
3505 expand_tilde(c, sizeof c, val);
3506 config_parse(c, 0);
3507 rv = 1;
3508 break;
3511 if (rs[i].s) {
3512 if (rs[i].s->set(&rs[i], val))
3513 startpage_add("invalid value for %s: %s", var,
3514 val);
3515 rv = 1;
3516 break;
3517 } else
3518 switch (rs[i].type) {
3519 case XT_S_INT: /* FALLTHROUGH */
3520 case XT_S_BOOL:
3521 p = rs[i].ival;
3522 *p = atoi(val);
3523 rv = 1;
3524 break;
3525 case XT_S_STR:
3526 s = rs[i].sval;
3527 if (s == NULL)
3528 errx(1, "invalid sval for %s",
3529 rs[i].name);
3530 if (*s)
3531 g_free(*s);
3532 *s = g_strdup(val);
3533 rv = 1;
3534 break;
3535 case XT_S_FLOAT:
3536 f = rs[i].fval;
3537 *f = atof(val);
3538 rv = 1;
3539 break;
3540 case XT_S_INVALID:
3541 default:
3542 errx(1, "invalid type for %s", var);
3544 break;
3546 return (rv);
3549 #define WS "\n= \t"
3550 void
3551 config_parse(char *filename, int runtime)
3553 FILE *config, *f;
3554 char *line, *cp, *var, *val;
3555 size_t len, lineno = 0;
3556 int handled;
3557 char file[PATH_MAX];
3558 struct stat sb;
3560 DNPRINTF(XT_D_CONFIG, "config_parse: filename %s\n", filename);
3562 if (filename == NULL)
3563 return;
3565 if (runtime && runtime_settings[0] != '\0') {
3566 snprintf(file, sizeof file, "%s" PS "%s",
3567 work_dir, runtime_settings);
3568 if (stat(file, &sb)) {
3569 warnx("runtime file doesn't exist, creating it");
3570 if ((f = fopen(file, "w")) == NULL)
3571 err(1, "runtime");
3572 fprintf(f, "# AUTO GENERATED, DO NOT EDIT\n");
3573 fclose(f);
3575 } else
3576 strlcpy(file, filename, sizeof file);
3578 if ((config = fopen(file, "r")) == NULL) {
3579 warn("config_parse: cannot open %s", filename);
3580 return;
3583 for (;;) {
3584 if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL)
3585 if (feof(config) || ferror(config))
3586 break;
3588 cp = line;
3589 cp += (long)strspn(cp, WS);
3590 if (cp[0] == '\0') {
3591 /* empty line */
3592 free(line);
3593 continue;
3596 if ((var = strsep(&cp, WS)) == NULL || cp == NULL)
3597 startpage_add("invalid configuration file entry: %s",
3598 line);
3599 else {
3600 cp += (long)strspn(cp, WS);
3602 if ((val = strsep(&cp, "\0")) == NULL)
3603 break;
3605 DNPRINTF(XT_D_CONFIG, "config_parse: %s=%s\n",
3606 var, val);
3607 handled = settings_add(var, val);
3609 if (handled == 0)
3610 startpage_add("invalid configuration file entry"
3611 ": %s=%s", var, val);
3614 free(line);
3617 fclose(config);
3620 struct settings_args {
3621 char **body;
3622 int i;
3625 void
3626 print_setting(struct settings *s, char *val, void *cb_args)
3628 char *enc_val, *tmp, *color;
3629 struct settings_args *sa = cb_args;
3631 if (sa == NULL || s->flags & XT_SF_INVISIBLE)
3632 return;
3634 if (s->flags & XT_SF_RUNTIME)
3635 color = "#22cc22";
3636 else
3637 color = "#cccccc";
3639 enc_val = html_escape(val);
3640 tmp = *sa->body;
3641 *sa->body = g_strdup_printf(
3642 "%s\n<tr>"
3643 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
3644 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
3645 *sa->body,
3646 color,
3647 s->name,
3648 color,
3649 enc_val == NULL ? "" : enc_val
3651 g_free(tmp);
3652 if (enc_val)
3653 g_free(enc_val);
3654 sa->i++;
3657 void
3658 print_runtime_setting(struct settings *s, char *val, void *cb_args)
3660 char *tmp, *tt = NULL;
3661 struct settings_args *sa = cb_args;
3662 int modified = 0;
3663 int i;
3665 if (sa == NULL)
3666 return;
3668 if (s == NULL || s->flags & XT_SF_INVISIBLE || s->activate == NULL)
3669 return;
3671 tmp = *sa->body;
3672 if (s->ismodified)
3673 modified = s->ismodified(&tt);
3674 *sa->body = g_strdup_printf(
3675 "%s\n<tr %s>"
3676 "<td title=\"%s\" style='width: 240px;'><div style='width: 100%%;'>%s</div></td>"
3677 "<td title=\"%s\"><div style='width: 100%%; word-break:break-all'>",
3678 *sa->body,
3679 modified ? "id='modified'" : "",
3680 s->tt ? s->tt : "",
3681 s->name,
3682 tt);
3683 g_free(tmp);
3684 g_free(tt);
3686 tmp = *sa->body;
3687 if (s->type == XT_S_STR && s->s && s->s->valid_options[0]) {
3688 *sa->body = g_strdup_printf("%s<select name='%s'>",
3689 *sa->body,
3690 s->name);
3691 for (i = 0; s->s->valid_options[i]; ++i) {
3692 g_free(tmp);
3693 tmp = *sa->body;
3694 *sa->body = g_strdup_printf("%s"
3695 "<option value='%s' %s>%s</option>",
3696 *sa->body,
3697 s->s->valid_options[i],
3698 !strcmp(s->s->valid_options[i], val) ? "selected" : "",
3699 s->s->valid_options[i]);
3701 } else if (s->type == XT_S_STR)
3702 *sa->body = g_strdup_printf(
3703 "%s<input style='width: 98%%' type='text' name='%s' value='%s'>"
3704 "</div></td></tr>",
3705 *sa->body,
3706 s->name,
3707 val ? val : "");
3708 else if (s->type == XT_S_INT)
3709 *sa->body = g_strdup_printf(
3710 "%s<input type='number' name='%s' value='%s'>"
3711 "</div></td></tr>",
3712 *sa->body,
3713 s->name,
3714 val);
3715 else if (s->type == XT_S_FLOAT)
3716 *sa->body = g_strdup_printf(
3717 "%s<input type='number' step='0.000001' name='%s' value='%s'>"
3718 "</div></td></tr>",
3719 *sa->body,
3720 s->name,
3721 val);
3722 else if (s->type == XT_S_BOOL)
3723 *sa->body = g_strdup_printf(
3724 "%s<input type='hidden' name='%s' value='0'>"
3725 "<input type='checkbox' name='%s' value='1''%s>"
3726 "</div></td></tr>",
3727 *sa->body,
3728 s->name,
3729 s->name,
3730 atoi(val) ? " checked='checked'" : "");
3731 else {
3732 *sa->body = g_strdup(*sa->body);
3733 warnx("Did not print setting %s", s->name);
3735 g_free(tmp);
3736 sa->i++;
3739 char *
3740 print_set_rejects(void)
3742 struct set_reject *sr, *st;
3743 char *body = NULL, *tmp;
3745 if (TAILQ_EMPTY(&srl))
3746 return (NULL);
3748 body = g_strdup_printf("The following settings were invalid and could "
3749 "not be set:<br><div align='center'><table id='settings'>"
3750 "<th align='left'>Setting</th>"
3751 "<th align='left'>Value</th>");
3752 TAILQ_FOREACH_SAFE(sr, &srl, entry, st) {
3753 tmp = body;
3754 body = g_strdup_printf("%s\n<tr>"
3755 "<td style='width:240px'><div>%s</div></td>"
3756 "<td><div style='word-break:break-all'>%s</div></td></tr>",
3757 body,
3758 sr->name,
3759 sr->value);
3760 g_free(tmp);
3761 TAILQ_REMOVE(&srl, sr, entry);
3762 g_free(sr->name);
3763 g_free(sr->value);
3764 g_free(sr);
3766 tmp = body;
3767 body = g_strdup_printf("%s</table></div><br>", body);
3768 g_free(tmp);
3769 return (body);
3773 xtp_page_set(struct tab *t, struct karg *args)
3775 char *body, *page, *tmp;
3776 int i = 1;
3777 struct settings_args sa;
3779 bzero(&sa, sizeof sa);
3780 sa.body = &body;
3782 /* body */
3783 body = g_strdup_printf("<div align='center'><table><tr>"
3784 "<th align='left'>Setting</th>"
3785 "<th align='left'>Value</th></tr>\n");
3787 settings_walk(print_setting, &sa);
3788 i = sa.i;
3790 /* small message if there are none */
3791 if (i == 1) {
3792 tmp = body;
3793 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3794 "colspan='2'>No settings</td></tr>\n", body);
3795 g_free(tmp);
3798 tmp = body;
3799 body = g_strdup_printf("%s</table></div>", body);
3800 g_free(tmp);
3802 page = get_html_page("Settings", body, "", 0);
3804 g_free(body);
3806 load_webkit_string(t, page, XT_URI_ABOUT_SET, 0);
3808 g_free(page);
3810 return (XT_CB_PASSTHROUGH);
3814 xtp_page_rt(struct tab *t, struct karg *args)
3816 char *body = NULL, *page, *tmp;
3817 int i = 1;
3818 struct settings_args sa;
3820 generate_xtp_session_key(&t->session_key);
3822 bzero(&sa, sizeof sa);
3823 sa.body = &body;
3825 /* body */
3826 body = print_set_rejects();
3828 tmp = body;
3829 body = g_strdup_printf("%s<div align='center'>"
3830 "<form method='GET' action='%s%d/%s/%d'>"
3831 "<input type='submit' value='Save Settings'>"
3832 "<table id='settings'>"
3833 "<th align='left'>Setting</th>"
3834 "<th align='left'>Value</th>\n",
3835 body ? body : "",
3836 XT_XTP_STR,
3837 XT_XTP_RT,
3838 t->session_key,
3839 XT_XTP_RT_SAVE);
3840 g_free(tmp);
3842 settings_walk(print_runtime_setting, &sa);
3843 i = sa.i;
3845 /* small message if there are none */
3846 if (i == 1) {
3847 tmp = body;
3848 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3849 "colspan='2'>No settings</td></tr>\n", body);
3850 g_free(tmp);
3853 tmp = body;
3854 body = g_strdup_printf("%s</table>"
3855 "<input type='submit' value='Save Settings'></form></div>", body);
3856 g_free(tmp);
3858 page = get_html_page("Runtime Settings", body, "", 1);
3860 g_free(body);
3862 load_webkit_string(t, page, XT_URI_ABOUT_RUNTIME, 0);
3864 g_free(page);
3866 return (XT_CB_PASSTHROUGH);
3870 set(struct tab *t, struct karg *args)
3872 char *p, *val;
3873 int i;
3875 if (args == NULL || args->s == NULL)
3876 return (xtp_page_set(t, args));
3878 /* strip spaces */
3879 p = g_strstrip(args->s);
3881 if (strlen(p) == 0)
3882 return (xtp_page_set(t, args));
3884 /* we got some sort of string */
3885 val = g_strstr_len(p, strlen(p), "=");
3886 if (val) {
3887 *val++ = '\0';
3888 val = g_strstrip(val);
3889 p = g_strchomp(p);
3891 for (i = 0; i < get_settings_size(); i++) {
3892 if (strcmp(rs[i].name, p))
3893 continue;
3895 if (rs[i].activate) {
3896 if (rs[i].activate(val))
3897 show_oops(t, "%s invalid value %s",
3898 p, val);
3899 else
3900 show_oops(t, ":set %s = %s", p, val);
3901 goto done;
3902 } else {
3903 show_oops(t, "not a runtime option: %s", p);
3904 goto done;
3907 show_oops(t, "unknown option: %s", p);
3908 } else {
3909 p = g_strchomp(p);
3911 for (i = 0; i < get_settings_size(); i++) {
3912 if (strcmp(rs[i].name, p))
3913 continue;
3915 /* XXX this could use some cleanup */
3916 switch (rs[i].type) {
3917 case XT_S_INT: /* FALLTHROUGH */
3918 case XT_S_BOOL:
3919 if (rs[i].ival)
3920 show_oops(t, "%s = %d",
3921 rs[i].name, *rs[i].ival);
3922 else if (rs[i].s && rs[i].s->get)
3923 show_oops(t, "%s = %s",
3924 rs[i].name,
3925 rs[i].s->get(&rs[i]));
3926 else if (rs[i].s && rs[i].s->get == NULL)
3927 show_oops(t, "%s = ...", rs[i].name);
3928 else
3929 show_oops(t, "%s = ", rs[i].name);
3930 break;
3931 case XT_S_FLOAT:
3932 if (rs[i].fval)
3933 show_oops(t, "%s = %f",
3934 rs[i].name, *rs[i].fval);
3935 else if (rs[i].s && rs[i].s->get)
3936 show_oops(t, "%s = %s",
3937 rs[i].name,
3938 rs[i].s->get(&rs[i]));
3939 else if (rs[i].s && rs[i].s->get == NULL)
3940 show_oops(t, "%s = ...", rs[i].name);
3941 else
3942 show_oops(t, "%s = ", rs[i].name);
3943 break;
3944 case XT_S_STR:
3945 if (rs[i].sval && *rs[i].sval)
3946 show_oops(t, "%s = %s",
3947 rs[i].name, *rs[i].sval);
3948 else if (rs[i].s && rs[i].s->get)
3949 show_oops(t, "%s = %s",
3950 rs[i].name,
3951 rs[i].s->get(&rs[i]));
3952 else if (rs[i].s && rs[i].s->get == NULL)
3953 show_oops(t, "%s = ...", rs[i].name);
3954 else
3955 show_oops(t, "%s = ", rs[i].name);
3956 break;
3957 default:
3958 show_oops(t, "unknown type for %s", rs[i].name);
3959 goto done;
3962 goto done;
3964 show_oops(t, "unknown option: %s", p);
3966 done:
3967 return (XT_CB_PASSTHROUGH);