Add a favedit command and remove rm links from :fav
[xombrero.git] / settings.c
blobe697e20384c57c435758fcd9efe1b2d554fb1c3f
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 int tabless = 0; /* allow only 1 tab */
35 char search_file[PATH_MAX];
36 char command_file[PATH_MAX];
37 char runtime_settings[PATH_MAX]; /* override of settings */
39 /* settings that require restart */
40 int enable_socket = 0;
41 int single_instance = 0; /* only allow one xombrero to run */
42 int fancy_bar = 1; /* fancy toolbar */
43 int browser_mode = XT_BM_NORMAL;
44 int gui_mode = XT_GM_CLASSIC;
45 char *statusbar_elems = NULL;
46 int window_height = 768;
47 int window_width = 1024;
48 int window_maximize = 0;
49 int icon_size = 2; /* 1 = smallest, 2+ = bigger */
50 char *resource_dir = NULL;
51 char download_dir[PATH_MAX];
52 int allow_volatile_cookies = 0;
53 int save_global_history = 0; /* save global history to disk */
54 struct user_agent *user_agent = NULL;
55 struct http_accept *http_accept = NULL;
56 int save_rejected_cookies = 0;
57 gint max_connections = 25;
58 gint max_host_connections = 5;
59 int history_autosave = 0;
60 int edit_mode = XT_EM_HYBRID;
61 char *include_config = NULL;
63 /* runtime settings */
64 int show_tabs = XT_DS_SHOW_TABS; /* show tabs on notebook */
65 int tab_style = XT_DS_TAB_STYLE; /* tab bar style */
66 int statusbar_style = XT_DS_STATUSBAR_STYLE; /* status bar style */
67 int show_url = XT_DS_SHOW_URL; /* show url toolbar on notebook */
68 int show_scrollbars = XT_DS_SHOW_SCROLLBARS;
69 int show_statusbar = XT_DS_SHOW_STATUSBAR; /* vimperator style status bar */
70 int ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS; /* ctrl click gets focus */
71 int cookies_enabled = XT_DS_COOKIES_ENABLED; /* enable cookies */
72 int read_only_cookies = XT_DS_READ_ONLY_COOKIES; /* enable to not write cookies */
73 int enable_scripts = XT_DS_ENABLE_SCRIPTS;
74 int enable_plugins = XT_DS_ENABLE_PLUGINS;
75 gfloat default_zoom_level = XT_DS_DEFAULT_ZOOM_LEVEL;
76 char default_script[PATH_MAX]; /* special setting - is never g_free'd */
77 int refresh_interval = XT_DS_REFRESH_INTERVAL; /* download refresh interval */
78 int enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
79 int enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
80 int enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
81 int enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
82 int session_timeout = XT_DS_SESSION_TIMEOUT; /* cookie session timeout */
83 int cookie_policy = XT_DS_COOKIE_POLICY;
84 char ssl_ca_file[PATH_MAX]; /* special setting - is never g_free'd */
85 gboolean ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
86 gboolean enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
87 int append_next = XT_DS_APPEND_NEXT; /* append tab after current tab */
88 char *home = NULL; /* allocated/set at startup */
89 char *search_string = NULL; /* allocated/set at startup */
90 char *http_proxy = NULL;
91 int http_proxy_starts_enabled = 1;
92 int download_mode = XT_DM_START;
93 int color_visited_uris = XT_DS_COLOR_VISITED_URIS;
94 int session_autosave = XT_DS_SESSION_AUTOSAVE;
95 int guess_search = XT_DS_GUESS_SEARCH;
96 gint enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
97 char *spell_check_languages = NULL; /* allocated/set at startup */
98 char *url_regex = NULL; /* allocated/set at startup */
99 char *encoding = NULL; /* allocated/set at startup */
100 int autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
101 int enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
102 char *userstyle = NULL; /* allocated/set at startup */
103 int userstyle_global = XT_DS_USERSTYLE_GLOBAL;
104 int auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
105 int enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
106 int enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
107 int enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
108 char *external_editor = NULL;
109 int referer_mode = XT_DS_REFERER_MODE;
110 char *referer_custom = NULL;
111 int download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
112 int warn_cert_changes = 0;
113 int allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
114 int allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
115 int do_not_track = XT_DS_DO_NOT_TRACK;
116 int preload_strict_transport = XT_DS_PRELOAD_STRICT_TRANSPORT;
117 char *gnutls_priority_string = XT_DS_GNUTLS_PRIORITY_STRING;
119 char *cmd_font_name = NULL; /* these are all set at startup */
120 char *oops_font_name = NULL;
121 char *statusbar_font_name = NULL;
122 char *tabbar_font_name = NULL;
124 char *get_download_dir(struct settings *);
125 char *get_default_script(struct settings *);
126 char *get_runtime_dir(struct settings *);
127 char *get_tab_style(struct settings *);
128 char *get_statusbar_style(struct settings *);
129 char *get_edit_mode(struct settings *);
130 char *get_download_mode(struct settings *);
131 char *get_work_dir(struct settings *);
132 char *get_referer(struct settings *);
133 char *get_ssl_ca_file(struct settings *);
134 char *get_userstyle(struct settings *);
135 char *get_gnutls_priority_string(struct settings *);
137 int add_cookie_wl(struct settings *, char *);
138 int add_js_wl(struct settings *, char *);
139 int add_pl_wl(struct settings *, char *);
140 int add_mime_type(struct settings *, char *);
141 int add_alias(struct settings *, char *);
142 int add_kb(struct settings *, char *);
143 int add_ua(struct settings *, char *);
144 int add_http_accept(struct settings *, char *);
145 int add_cmd_alias(struct settings *, char *);
146 int add_custom_uri(struct settings *, char *);
147 int add_force_https(struct settings *, char *);
149 int set_append_next(char *);
150 int set_autofocus_onload(char *);
151 int set_cmd_font(char *);
152 int set_color_visited_uris(char *);
153 int set_cookie_policy_rt(char *);
154 int set_cookies_enabled(char *);
155 int set_ctrl_click_focus(char *);
156 int set_fancy_bar(char *);
157 int set_home(char *);
158 int set_download_dir(struct settings *, char *);
159 int set_download_notifications(char *);
160 int set_default_script(struct settings *, char *);
161 int set_default_script_rt(char *);
162 int set_default_zoom_level(char *);
163 int set_enable_cookie_whitelist(char *);
164 int set_enable_js_autorun(char *);
165 int set_enable_js_whitelist(char *);
166 int set_enable_localstorage(char *);
167 int set_enable_plugins(char *);
168 int set_enable_plugin_whitelist(char *);
169 int set_enable_scripts(char *);
170 int set_enable_spell_checking(char *);
171 int set_enable_strict_transport(char *);
172 int set_encoding_rt(char *);
173 int set_runtime_dir(struct settings *, char *);
174 int set_tabbar_font(char *value);
175 int set_tab_style(struct settings *, char *);
176 int set_tab_style_rt(char *);
177 int set_statusbar_style(struct settings *, char *);
178 int set_statusbar_style_rt(char *);
179 int set_edit_mode(struct settings *, char *);
180 int set_work_dir(struct settings *, char *);
181 int set_auto_load_images(char *);
182 int set_enable_autoscroll(char *);
183 int set_enable_favicon_entry(char *);
184 int set_enable_favicon_tabs(char *);
185 int set_guess_search(char *);
186 int set_download_mode(struct settings *, char *);
187 int set_download_mode_rt(char *);
188 int set_oops_font(char *);
189 int set_read_only_cookies(char *);
190 int set_referer(struct settings *, char *);
191 int set_referer_rt(char *);
192 int set_refresh_interval(char *);
193 int set_search_string(char *s);
194 int set_session_autosave(char *);
195 int set_session_timeout(char *);
196 int set_show_scrollbars(char *);
197 int set_show_statusbar(char *);
198 int set_show_tabs(char *);
199 int set_show_url(char *);
200 int set_spell_check_languages(char *);
201 int set_ssl_ca_file_rt(char *);
202 int set_ssl_strict_certs(char *);
203 int set_statusbar_font(char *);
204 int set_url_regex(char *);
205 int set_userstyle(struct settings *, char *);
206 int set_userstyle_rt(char *);
207 int set_userstyle_global(char *);
208 int set_external_editor(char *);
209 int set_warn_cert_changes(char *);
210 int set_allow_insecure_content(char *);
211 int set_allow_insecure_scripts(char *);
212 int set_http_proxy(char *);
213 int set_do_not_track(char *);
214 int set_gnutls_priority_string(struct settings *, char *);
216 int check_allow_insecure_content(char **);
217 int check_allow_insecure_scripts(char **);
218 int check_allow_volatile_cookies(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_tabbar_font(char **);
283 int check_url_regex(char **);
284 int check_userstyle(char **);
285 int check_userstyle_global(char **);
286 int check_warn_cert_changes(char **);
287 int check_window_height(char **);
288 int check_window_maximize(char **);
289 int check_window_width(char **);
290 int check_work_dir(char **);
291 int check_do_not_track(char **);
293 void walk_mime_type(struct settings *, void (*)(struct settings *,
294 char *, void *), void *);
295 void walk_alias(struct settings *, void (*)(struct settings *,
296 char *, void *), void *);
297 void walk_cookie_wl(struct settings *, void (*)(struct settings *,
298 char *, void *), void *);
299 void walk_js_wl(struct settings *, void (*)(struct settings *,
300 char *, void *), void *);
301 void walk_pl_wl(struct settings *, void (*)(struct settings *,
302 char *, void *), void *);
303 void walk_kb(struct settings *, void (*)(struct settings *, char *,
304 void *), void *);
305 void walk_ua(struct settings *, void (*)(struct settings *, char *,
306 void *), void *);
307 void walk_http_accept(struct settings *, void (*)(struct settings *,
308 char *, void *), void *);
309 void walk_cmd_alias(struct settings *, void (*)(struct settings *,
310 char *, void *), void *);
311 void walk_custom_uri(struct settings *, void (*)(struct settings *,
312 char *, void *), void *);
313 void walk_force_https(struct settings *, void (*)(struct settings *,
314 char *, void *), void *);
316 struct special s_browser_mode = {
317 set_browser_mode,
318 get_browser_mode,
319 NULL,
320 { "kiosk", "normal", "whitelist", NULL }
323 struct special s_gui_mode = {
324 set_gui_mode,
325 get_gui_mode,
326 NULL,
327 { "classic", "minimal", NULL }
330 struct special s_cookie = {
331 set_cookie_policy,
332 get_cookie_policy,
333 NULL,
334 { "accept", "no3rdparty", "reject", NULL }
337 struct special s_alias = {
338 add_alias,
339 NULL,
340 walk_alias,
341 { NULL }
344 struct special s_cmd_alias = {
345 add_cmd_alias,
346 NULL,
347 walk_cmd_alias,
348 { NULL }
351 struct special s_mime = {
352 add_mime_type,
353 NULL,
354 walk_mime_type,
355 { NULL }
358 struct special s_js = {
359 add_js_wl,
360 NULL,
361 walk_js_wl,
362 { NULL }
365 struct special s_pl = {
366 add_pl_wl,
367 NULL,
368 walk_pl_wl,
369 { NULL }
372 struct special s_kb = {
373 add_kb,
374 NULL,
375 walk_kb,
376 { NULL }
379 struct special s_cookie_wl = {
380 add_cookie_wl,
381 NULL,
382 walk_cookie_wl,
383 { NULL }
386 struct special s_uri = {
387 add_custom_uri,
388 NULL,
389 walk_custom_uri,
390 { NULL }
393 struct special s_default_script = {
394 set_default_script,
395 get_default_script,
396 NULL,
397 { NULL }
400 struct special s_ssl_ca_file = {
401 set_ssl_ca_file,
402 get_ssl_ca_file,
403 NULL,
404 { NULL }
407 struct special s_download_dir = {
408 set_download_dir,
409 get_download_dir,
410 NULL,
411 { NULL }
414 struct special s_work_dir = {
415 set_work_dir,
416 get_work_dir,
417 NULL,
418 { NULL }
421 struct special s_tab_style = {
422 set_tab_style,
423 get_tab_style,
424 NULL,
425 { "compact", "normal", NULL }
428 struct special s_statusbar_style = {
429 set_statusbar_style,
430 get_statusbar_style,
431 NULL,
432 { "title", "url", NULL }
435 struct special s_edit_mode = {
436 set_edit_mode,
437 get_edit_mode,
438 NULL,
439 { "hybrid", "vi", NULL }
442 struct special s_download_mode = {
443 set_download_mode,
444 get_download_mode,
445 NULL,
446 { "add", "ask", "start", NULL }
449 struct special s_ua = {
450 add_ua,
451 NULL,
452 walk_ua,
453 { NULL }
456 struct special s_http_accept = {
457 add_http_accept,
458 NULL,
459 walk_http_accept,
460 { NULL }
463 struct special s_referer = {
464 set_referer,
465 get_referer,
466 NULL,
467 { "always", "never", "same-domain", "same-fqdn", NULL }
470 struct special s_userstyle = {
471 set_userstyle,
472 get_userstyle,
473 NULL,
474 { NULL }
477 struct special s_force_https = {
478 add_force_https,
479 NULL,
480 walk_force_https,
481 { NULL }
484 struct special s_gnutls_priority_string = {
485 set_gnutls_priority_string,
486 get_gnutls_priority_string,
487 NULL,
488 { NULL }
491 struct settings rs[] = {
492 { "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 },
493 { "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},
494 { "allow_volatile_cookies", XT_S_BOOL, 0, &allow_volatile_cookies, NULL, NULL, NULL, NULL, check_allow_volatile_cookies, TT_ALLOW_VOLATILE_COOKIES},
495 { "append_next", XT_S_BOOL, 0, &append_next, NULL, NULL, NULL, set_append_next, check_append_next, TT_APPEND_NEXT},
496 { "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 },
497 { "autofocus_onload", XT_S_BOOL, 0, &autofocus_onload, NULL, NULL, NULL, set_autofocus_onload, check_autofocus_onload, TT_AUTOFOCUS_ONLOAD },
498 { "browser_mode", XT_S_STR, 0, NULL, NULL,&s_browser_mode, NULL, NULL, check_browser_mode, TT_BROWSER_MODE },
499 { "cmd_font", XT_S_STR, 0, NULL, &cmd_font_name, NULL, NULL, set_cmd_font, check_cmd_font, TT_CMD_FONT},
500 { "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 },
501 { "cookie_policy", XT_S_STR, 0, NULL, NULL,&s_cookie, NULL, set_cookie_policy_rt, check_cookie_policy, TT_COOKIE_POLICY},
502 { "cookies_enabled", XT_S_BOOL, 0, &cookies_enabled, NULL, NULL, NULL, set_cookies_enabled, check_cookies_enabled, TT_COOKIES_ENABLED },
503 { "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 },
504 { "default_script", XT_S_STR, 1, NULL, NULL,&s_default_script, NULL, set_default_script_rt, check_default_script, TT_DEFAULT_SCRIPT },
505 { "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 },
506 { "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 },
507 { "download_dir", XT_S_STR, 0, NULL, NULL,&s_download_dir, NULL, NULL, check_download_dir, TT_DOWNLOAD_DIR },
508 { "download_mode", XT_S_STR, 0, NULL, NULL,&s_download_mode, NULL, set_download_mode_rt, check_download_mode, TT_DOWNLOAD_MODE },
509 { "download_notifications", XT_S_BOOL, 0, &download_notifications, NULL, NULL, NULL, set_download_notifications, check_download_notifications, TT_DOWNLOAD_NOTIFICATIONS },
510 { "edit_mode", XT_S_STR, 0, NULL, NULL,&s_edit_mode, NULL, NULL, check_edit_mode, NULL },
511 { "enable_autoscroll", XT_S_BOOL, 0, &enable_autoscroll, NULL, NULL, NULL, set_enable_autoscroll, check_enable_autoscroll, TT_ENABLE_AUTOSCROLL },
512 { "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 },
513 { "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 },
514 { "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 },
515 { "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 },
516 { "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 },
517 { "enable_localstorage", XT_S_BOOL, 0, &enable_localstorage, NULL, NULL, NULL, set_enable_localstorage, check_enable_localstorage, TT_ENABLE_LOCALSTORAGE },
518 { "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 },
519 { "enable_plugins", XT_S_BOOL, 0, &enable_plugins, NULL, NULL, NULL, set_enable_plugins, check_enable_plugins, TT_ENABLE_PLUGINS },
520 { "enable_scripts", XT_S_BOOL, 0, &enable_scripts, NULL, NULL, NULL, set_enable_scripts, check_enable_scripts, TT_ENABLE_SCRIPTS },
521 { "enable_socket", XT_S_BOOL,XT_SF_RESTART,&enable_socket, NULL, NULL, NULL, NULL, check_enable_socket, TT_ENABLE_SOCKET },
522 { "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 },
523 { "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 },
524 { "encoding", XT_S_STR, 0, NULL, &encoding, NULL, NULL, NULL, check_encoding, TT_ENCODING },
525 { "external_editor", XT_S_STR,0, NULL, &external_editor, NULL, NULL, set_external_editor, check_external_editor, TT_EXTERNAL_EDITOR },
526 { "fancy_bar", XT_S_BOOL,XT_SF_RESTART,&fancy_bar, NULL, NULL, NULL, set_fancy_bar, check_fancy_bar, TT_FANCY_BAR },
527 { "gnutls_priority_string", XT_S_STR, 0, NULL, NULL,&s_gnutls_priority_string, NULL, NULL, check_gnutls_search_string, TT_GNUTLS_PRIORITY_STRING },
528 { "guess_search", XT_S_BOOL, 0, &guess_search, NULL, NULL, NULL, set_guess_search, check_guess_search, TT_GUESS_SEARCH },
529 { "gui_mode", XT_S_STR, 0, NULL, NULL,&s_gui_mode, NULL, NULL, check_gui_mode, TT_GUI_MODE },
530 { "history_autosave", XT_S_BOOL, 0, &history_autosave, NULL, NULL, NULL, NULL, check_history_autosave, TT_HISTORY_AUTOSAVE },
531 { "home", XT_S_STR, 0, NULL, &home, NULL, NULL, set_home, check_home, TT_HOME },
532 { "http_proxy", XT_S_STR, 0, NULL, &http_proxy, NULL, NULL, set_http_proxy, check_http_proxy, TT_HTTP_PROXY },
533 { "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 },
534 { "icon_size", XT_S_INT, 0, &icon_size, NULL, NULL, NULL, NULL, check_icon_size, TT_ICON_SIZE },
535 { "include_config", XT_S_STR, XT_SF_INVISIBLE, NULL, &include_config, NULL, NULL, NULL, NULL },
536 { "max_connections", XT_S_INT, XT_SF_RESTART,&max_connections, NULL, NULL, NULL, NULL, check_max_connections, TT_MAX_CONNECTIONS },
537 { "max_host_connections", XT_S_INT, XT_SF_RESTART,&max_host_connections, NULL, NULL, NULL, NULL, check_max_host_connections, TT_MAX_HOST_CONNECTIONS },
538 { "oops_font", XT_S_STR, 0, NULL, &oops_font_name, NULL, NULL, set_oops_font, check_oops_font, TT_OOPS_FONT },
539 { "preload_strict_transport", XT_S_BOOL, 0, &preload_strict_transport, NULL, NULL, NULL, NULL, NULL, TT_PRELOAD_STRICT_TRANSPORT },
540 { "read_only_cookies", XT_S_BOOL, 0, &read_only_cookies, NULL, NULL, NULL, NULL, check_read_only_cookies, TT_READ_ONLY_COOKIES },
541 { "referer", XT_S_STR, 0, NULL, NULL,&s_referer, NULL, set_referer_rt, check_referer, TT_REFERER },
542 { "refresh_interval", XT_S_INT, 0, &refresh_interval, NULL, NULL, NULL, set_refresh_interval, check_refresh_interval, TT_REFRESH_INTERVAL },
543 { "resource_dir", XT_S_STR, 0, NULL, &resource_dir, NULL, NULL, NULL, check_resource_dir, TT_RESOURCE_DIR },
544 { "save_global_history", XT_S_BOOL,XT_SF_RESTART,&save_global_history, NULL, NULL, NULL, NULL, check_save_global_history, TT_SAVE_GLOBAL_HISTORY },
545 { "save_rejected_cookies", XT_S_BOOL,XT_SF_RESTART,&save_rejected_cookies, NULL, NULL, NULL, NULL, check_save_rejected_cookies, TT_SAVE_REJECTED_COOKIES },
546 { "search_string", XT_S_STR, 0, NULL, &search_string, NULL, NULL, set_search_string, check_search_string, TT_SEARCH_STRING },
547 { "session_autosave", XT_S_BOOL, 0, &session_autosave, NULL, NULL, NULL, set_session_autosave, check_session_autosave, TT_SESSION_AUTOSAVE },
548 { "session_timeout", XT_S_INT, 0, &session_timeout, NULL, NULL, NULL, set_session_timeout, check_session_timeout, TT_SESSION_TIMEOUT },
549 { "show_scrollbars", XT_S_BOOL, 0, &show_scrollbars, NULL, NULL, NULL, set_show_scrollbars, check_show_scrollbars, TT_SHOW_SCROLLBARS },
550 { "show_statusbar", XT_S_BOOL, 0, &show_statusbar, NULL, NULL, NULL, set_show_statusbar, check_show_statusbar, TT_SHOW_STATUSBAR },
551 { "show_tabs", XT_S_BOOL, 0, &show_tabs, NULL, NULL, NULL, set_show_tabs, check_show_tabs, TT_SHOW_TABS },
552 { "show_url", XT_S_BOOL, 0, &show_url, NULL, NULL, NULL, set_show_url, check_show_url, TT_SHOW_URL },
553 { "single_instance", XT_S_BOOL,XT_SF_RESTART,&single_instance, NULL, NULL, NULL, NULL, check_single_instance, TT_SINGLE_INSTANCE },
554 { "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 },
555 { "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 },
556 { "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 },
557 { "statusbar_elems", XT_S_STR, 0, NULL, &statusbar_elems, NULL, NULL, NULL, check_statusbar_elems, TT_STATUSBAR_ELEMS },
558 { "statusbar_font", XT_S_STR, 0, NULL, &statusbar_font_name, NULL, NULL, set_statusbar_font, check_statusbar_font, TT_STATUSBAR_FONT },
559 { "statusbar_style", XT_S_STR, 0, NULL, NULL,&s_statusbar_style, NULL, set_statusbar_style_rt, check_statusbar_style, TT_STATUSBAR_STYLE },
560 { "tab_style", XT_S_STR, 0, NULL, NULL,&s_tab_style, NULL, set_tab_style_rt, check_tab_style, TT_TAB_STYLE },
561 { "tabbar_font", XT_S_STR, 0, NULL, &tabbar_font_name, NULL, NULL, set_tabbar_font, check_tabbar_font, TT_TABBAR_FONT },
562 { "url_regex", XT_S_STR, 0, NULL, &url_regex, NULL, NULL, set_url_regex, check_url_regex, TT_URL_REGEX },
563 { "userstyle", XT_S_STR, 0, NULL, NULL,&s_userstyle, NULL, set_userstyle_rt, check_userstyle, TT_USERSTYLE },
564 { "userstyle_global", XT_S_BOOL, 0, &userstyle_global, NULL, NULL, NULL, set_userstyle_global, check_userstyle_global, TT_USERSTYLE_GLOBAL },
565 { "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 },
566 { "window_height", XT_S_INT, 0, &window_height, NULL, NULL, NULL, NULL, check_window_height, TT_WINDOW_HEIGHT },
567 { "window_maximize", XT_S_BOOL, 0, &window_maximize, NULL, NULL, NULL, NULL, check_window_maximize, TT_WINDOW_MAXIMIZE },
568 { "window_width", XT_S_INT, 0, &window_width, NULL, NULL, NULL, NULL, check_window_width, TT_WINDOW_WIDTH },
569 { "work_dir", XT_S_STR, 0, NULL, NULL,&s_work_dir, NULL, NULL, check_work_dir, TT_WORK_DIR },
571 /* special settings */
572 { "alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_alias, NULL, NULL },
573 { "cmd_alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cmd_alias, NULL, NULL },
574 { "cookie_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cookie_wl, NULL, NULL },
575 { "custom_uri", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_uri, NULL, NULL },
576 { "force_https", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_force_https, NULL, NULL },
577 { "http_accept", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_http_accept, NULL, NULL },
578 { "js_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_js, NULL, NULL },
579 { "keybinding", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_kb, NULL, NULL },
580 { "mime_type", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_mime, NULL, NULL },
581 { "pl_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_pl, NULL, NULL },
582 { "user_agent", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_ua, NULL, NULL },
586 set_http_proxy(char *proxy)
588 SoupURI *uri;
590 /* see if we need to clear it */
591 if (proxy == NULL || strlen(proxy) == 0) {
592 setup_proxy(NULL);
593 return (0);
596 uri = soup_uri_new(proxy);
597 if (uri == NULL || !SOUP_URI_VALID_FOR_HTTP(uri))
598 return (1);
600 setup_proxy(proxy);
602 soup_uri_free(uri);
604 return (0);
608 check_http_proxy(char **tt)
610 *tt = g_strdup("Default: (empty)");
611 return (g_strcmp0(http_proxy, NULL));
615 check_http_proxy_starts_enabled(char **tt)
617 *tt = g_strdup("Default: Enabled");
618 return (http_proxy_starts_enabled != 1);
622 check_icon_size(char **tt)
624 *tt = g_strdup_printf("Default: %d", 2);
625 return (icon_size != 2);
629 check_max_connections(char **tt)
631 *tt = g_strdup_printf("Default: %d", 25);
632 return (max_connections != 25);
636 check_max_host_connections(char **tt)
638 *tt = g_strdup_printf("Default: %d", 5);
639 return (max_host_connections != 5);
643 set_default_zoom_level(char *value)
645 struct karg args = {0};
646 struct tab *t;
648 if (value == NULL || strlen(value) == 0)
649 default_zoom_level = XT_DS_DEFAULT_ZOOM_LEVEL;
650 else
651 default_zoom_level = g_strtod(value, NULL);
652 args.i = 100; /* adjust = 100 percent for no additional adjustment */
653 TAILQ_FOREACH(t, &tabs, entry)
654 resizetab(t, &args);
655 return (0);
659 check_default_zoom_level(char **tt)
661 *tt = g_strdup_printf("Default: %f", XT_DS_DEFAULT_ZOOM_LEVEL);
662 return (default_zoom_level != XT_DS_DEFAULT_ZOOM_LEVEL);
666 set_cookies_enabled(char *value)
668 int tmp;
669 const char *errstr;
671 if (value == NULL || strlen(value) == 0)
672 cookies_enabled = XT_DS_COOKIES_ENABLED;
673 else {
674 tmp = strtonum(value, 0, 1, &errstr);
675 if (errstr)
676 return (-1);
677 cookies_enabled = tmp;
679 return (0);
683 check_cookies_enabled(char **tt)
685 *tt = g_strdup_printf("Default: %s",
686 XT_DS_COOKIES_ENABLED ? "Enabled" : "Disabled");
687 return (cookies_enabled != XT_DS_COOKIES_ENABLED);
691 set_append_next(char *value)
693 int tmp;
694 const char *errstr;
696 if (value == NULL || strlen(value) == 0)
697 append_next = XT_DS_APPEND_NEXT;
698 else {
699 tmp = strtonum(value, 0, 1, &errstr);
700 if (errstr)
701 return (-1);
702 append_next = tmp;
704 return (0);
708 check_append_next(char **tt)
710 *tt = g_strdup_printf("Default: %s",
711 XT_DS_APPEND_NEXT ? "Enabled" : "Disabled");
712 return (append_next != XT_DS_APPEND_NEXT);
716 set_cmd_font(char *value)
718 struct tab *t;
720 if (cmd_font_name)
721 g_free(cmd_font_name);
722 if (cmd_font)
723 pango_font_description_free(cmd_font);
724 if (value == NULL || strlen(value) == 0)
725 cmd_font_name = g_strdup(XT_DS_CMD_FONT_NAME);
726 else
727 cmd_font_name = g_strdup(value);
728 cmd_font = pango_font_description_from_string(cmd_font_name);
729 TAILQ_FOREACH(t, &tabs, entry)
730 gtk_widget_modify_font(GTK_WIDGET(t->cmd), cmd_font);
731 return (0);
735 check_cmd_font(char **tt)
737 *tt = g_strdup_printf("Default: %s", XT_DS_CMD_FONT_NAME);
738 return (g_strcmp0(cmd_font_name, XT_DS_CMD_FONT_NAME));
742 set_oops_font(char *value)
744 struct tab *t;
746 if (oops_font_name)
747 g_free(oops_font_name);
748 if (oops_font)
749 pango_font_description_free(oops_font);
750 if (value == NULL || strlen(value) == 0)
751 cmd_font_name = g_strdup(XT_DS_OOPS_FONT_NAME);
752 else
753 oops_font_name = g_strdup(value);
754 oops_font = pango_font_description_from_string(oops_font_name);
755 TAILQ_FOREACH(t, &tabs, entry)
756 gtk_widget_modify_font(GTK_WIDGET(t->oops), oops_font);
757 return (0);
761 check_oops_font(char **tt)
763 *tt = g_strdup_printf("Default: %s", XT_DS_OOPS_FONT_NAME);
764 return (g_strcmp0(oops_font_name, XT_DS_OOPS_FONT_NAME));
768 check_read_only_cookies(char **tt)
770 *tt = g_strdup_printf("Default: %s",
771 XT_DS_READ_ONLY_COOKIES ? "Enabled" : "Disabled");
772 return (read_only_cookies != XT_DS_READ_ONLY_COOKIES);
776 set_statusbar_font(char *value)
778 struct tab *t;
780 if (statusbar_font_name)
781 g_free(statusbar_font_name);
782 if (statusbar_font)
783 pango_font_description_free(statusbar_font);
784 if (value == NULL || strlen(value) == 0)
785 statusbar_font_name = g_strdup(XT_DS_STATUSBAR_FONT_NAME);
786 else
787 statusbar_font_name = g_strdup(value);
788 statusbar_font = pango_font_description_from_string(
789 statusbar_font_name);
790 TAILQ_FOREACH(t, &tabs, entry) {
791 gtk_widget_modify_font(GTK_WIDGET(t->sbe.uri),
792 statusbar_font);
793 gtk_widget_modify_font(GTK_WIDGET(t->sbe.buffercmd),
794 statusbar_font);
795 gtk_widget_modify_font(GTK_WIDGET(t->sbe.zoom),
796 statusbar_font);
797 gtk_widget_modify_font(GTK_WIDGET(t->sbe.position),
798 statusbar_font);
799 gtk_widget_modify_font(GTK_WIDGET(t->sbe.proxy),
800 statusbar_font);
802 return (0);
806 check_statusbar_font(char **tt)
808 *tt = g_strdup_printf("Default: %s", XT_DS_STATUSBAR_FONT_NAME);
809 return (g_strcmp0(statusbar_font_name, XT_DS_STATUSBAR_FONT_NAME));
813 set_tabbar_font(char *value)
815 struct tab *t;
817 if (tabbar_font_name)
818 g_free(tabbar_font_name);
819 if (tabbar_font)
820 pango_font_description_free(tabbar_font);
821 if (value == NULL || strlen(value) == 0)
822 tabbar_font_name = g_strdup(XT_DS_TABBAR_FONT_NAME);
823 else
824 tabbar_font_name = g_strdup(value);
825 tabbar_font = pango_font_description_from_string(tabbar_font_name);
826 TAILQ_FOREACH(t, &tabs, entry)
827 gtk_widget_modify_font(GTK_WIDGET(t->tab_elems.label),
828 tabbar_font);
829 return (0);
833 check_tabbar_font(char **tt)
835 *tt = g_strdup_printf("Default: %s", XT_DS_TABBAR_FONT_NAME);
836 return (g_strcmp0(tabbar_font_name, XT_DS_TABBAR_FONT_NAME));
840 set_color_visited_uris(char *value)
842 int tmp;
843 const char *errstr;
845 if (value == NULL || strlen(value) == 0)
846 color_visited_uris = XT_DS_COLOR_VISITED_URIS;
847 else {
848 tmp = strtonum(value, 0, 1, &errstr);
849 if (errstr)
850 return (-1);
851 color_visited_uris = tmp;
853 return (0);
857 check_color_visited_uris(char **tt)
859 *tt = g_strdup_printf("Default: %s",
860 XT_DS_COLOR_VISITED_URIS ? "Enabled" : "Disabled");
861 return (color_visited_uris != XT_DS_COLOR_VISITED_URIS);
865 set_home(char *value)
867 if (home)
868 g_free(home);
869 if (value == NULL || strlen(value) == 0)
870 home = g_strdup(XT_DS_HOME);
871 else
872 home = g_strdup(value);
873 return (0);
877 check_home(char **tt)
879 *tt = g_strdup_printf("Default: %s", XT_DS_HOME);
880 return (g_strcmp0(home, XT_DS_HOME));
884 set_search_string(char *value)
886 struct tab *t;
888 if (search_string)
889 g_free(search_string);
890 if (value == NULL || strlen(value) == 0) {
891 search_string = NULL;
892 TAILQ_FOREACH(t, &tabs, entry)
893 gtk_widget_hide(t->search_entry);
894 } else {
895 search_string = g_strdup(value);
896 TAILQ_FOREACH(t, &tabs, entry)
897 gtk_widget_show(t->search_entry);
899 return (0);
903 check_search_string(char **tt)
905 *tt = g_strdup_printf("Default: %s", XT_DS_SEARCH_STRING);
906 return (g_strcmp0(search_string, XT_DS_SEARCH_STRING));
909 size_t
910 get_settings_size(void)
912 return (LENGTH(rs));
915 char *
916 get_setting_name(int i)
918 if (i > LENGTH(rs))
919 return (NULL);
920 return (rs[i].name);
923 char *
924 get_as_string(struct settings *s)
926 char *r = NULL;
928 if (s == NULL)
929 return (NULL);
931 if (s->s && s->s->get)
932 r = s->s->get(s);
933 else if (s->type == XT_S_INT)
934 r = g_strdup_printf("%d", *s->ival);
935 else if (s->type == XT_S_STR)
936 r = g_strdup(*s->sval);
937 else if (s->type == XT_S_FLOAT)
938 r = g_strdup_printf("%f", *s->fval);
939 else if (s->type == XT_S_BOOL)
940 r = g_strdup_printf("%d", *s->ival);
941 else
942 r = g_strdup_printf("INVALID TYPE");
944 return (r);
947 void
948 settings_walk(void (*cb)(struct settings *, char *, void *), void *cb_args)
950 int i;
951 char *s;
953 for (i = 0; i < LENGTH(rs); i++) {
954 if (rs[i].s && rs[i].s->walk)
955 rs[i].s->walk(&rs[i], cb, cb_args);
956 else {
957 s = get_as_string(&rs[i]);
958 cb(&rs[i], s, cb_args);
959 g_free(s);
965 check_allow_volatile_cookies(char **tt)
967 *tt = g_strdup("Default: Disabled");
968 return (allow_volatile_cookies != 0);
972 set_browser_mode(struct settings *s, char *val)
974 if (!strcmp(val, "whitelist")) {
975 browser_mode = XT_BM_WHITELIST;
976 allow_volatile_cookies = 0;
977 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
978 cookies_enabled = 1;
979 enable_cookie_whitelist = 1;
980 enable_plugin_whitelist = 1;
981 enable_plugins = 0;
982 read_only_cookies = 0;
983 save_rejected_cookies = 0;
984 session_timeout = 3600;
985 enable_scripts = 0;
986 enable_js_whitelist = 1;
987 enable_localstorage = 0;
988 referer_mode = XT_REFERER_SAME_DOMAIN;
989 allow_insecure_content = 0;
990 allow_insecure_scripts = 0;
991 do_not_track = 1;
992 } else if (!strcmp(val, "normal")) {
993 browser_mode = XT_BM_NORMAL;
994 allow_volatile_cookies = 0;
995 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
996 cookies_enabled = 1;
997 enable_cookie_whitelist = 0;
998 enable_plugin_whitelist = 0;
999 enable_plugins = 1;
1000 read_only_cookies = 0;
1001 save_rejected_cookies = 0;
1002 session_timeout = 3600;
1003 enable_scripts = 1;
1004 enable_js_whitelist = 0;
1005 enable_localstorage = 1;
1006 referer_mode = XT_REFERER_ALWAYS;
1007 allow_insecure_content = 1;
1008 allow_insecure_scripts = 1;
1009 do_not_track = 0;
1010 } else if (!strcmp(val, "kiosk")) {
1011 browser_mode = XT_BM_KIOSK;
1012 allow_volatile_cookies = 0;
1013 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1014 cookies_enabled = 1;
1015 enable_cookie_whitelist = 0;
1016 enable_plugin_whitelist = 0;
1017 enable_plugins = 1;
1018 read_only_cookies = 0;
1019 save_rejected_cookies = 0;
1020 session_timeout = 3600;
1021 enable_scripts = 1;
1022 enable_js_whitelist = 0;
1023 enable_localstorage = 1;
1024 referer_mode = XT_REFERER_ALWAYS;
1025 allow_insecure_content = 1;
1026 allow_insecure_scripts = 1;
1027 do_not_track = 0;
1028 show_tabs = 0;
1029 tabless = 1;
1030 } else
1031 return (1);
1033 return (0);
1036 char *
1037 get_browser_mode(struct settings *s)
1039 char *r = NULL;
1041 if (browser_mode == XT_BM_WHITELIST)
1042 r = g_strdup("whitelist");
1043 else if (browser_mode == XT_BM_NORMAL)
1044 r = g_strdup("normal");
1045 else if (browser_mode == XT_BM_KIOSK)
1046 r = g_strdup("kiosk");
1047 else
1048 return (NULL);
1050 return (r);
1054 check_browser_mode(char **tt)
1056 *tt = g_strdup("Default: normal");
1057 return (browser_mode != XT_BM_NORMAL);
1061 set_gui_mode(struct settings *s, char *val)
1063 if (!strcmp(val, "classic")) {
1064 fancy_bar = 1;
1065 show_tabs = 1;
1066 tab_style = XT_TABS_NORMAL;
1067 show_url = 1;
1068 show_statusbar = 0;
1069 show_scrollbars = 1;
1070 } else if (!strcmp(val, "minimal")) {
1071 fancy_bar = 0;
1072 show_tabs = 1;
1073 tab_style = XT_TABS_COMPACT;
1074 show_url = 0;
1075 show_statusbar = 1;
1076 show_scrollbars = 0;
1077 } else
1078 return (1);
1080 return (0);
1083 char *
1084 get_gui_mode(struct settings *s)
1086 char *r = NULL;
1088 if (gui_mode == XT_GM_CLASSIC)
1089 r = g_strdup("classic");
1090 else if (browser_mode == XT_GM_MINIMAL)
1091 r = g_strdup("minimal");
1092 else
1093 return (NULL);
1095 return (r);
1099 check_gui_mode(char **tt)
1101 *tt = g_strdup("Default: classic");
1102 return (gui_mode != XT_GM_CLASSIC);
1106 check_history_autosave(char **tt)
1108 *tt = g_strdup("Default: Disabled");
1109 return (history_autosave != 0);
1113 set_cookie_policy(struct settings *s, char *val)
1115 if (!strcmp(val, "no3rdparty"))
1116 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
1117 else if (!strcmp(val, "accept"))
1118 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
1119 else if (!strcmp(val, "reject"))
1120 cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
1121 else
1122 return (1);
1124 return (0);
1128 set_cookie_policy_rt(char *value)
1130 if (value == NULL || strlen(value) == 0)
1131 cookie_policy = XT_DS_COOKIE_POLICY;
1132 else if (set_cookie_policy(NULL, value))
1133 return (-1);
1134 g_object_set(G_OBJECT(s_cookiejar), SOUP_COOKIE_JAR_ACCEPT_POLICY,
1135 cookie_policy, (void *)NULL);
1136 return (0);
1140 check_cookie_policy(char **tt)
1142 *tt = g_strdup("Default (depends on browser_mode):\n"
1143 "\tnormal:\talways\n"
1144 "\twhitelist:\tno3rdparty\n"
1145 "\tkiosk:\talways");
1146 if (browser_mode == XT_BM_WHITELIST &&
1147 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1148 return (1);
1149 if (browser_mode == XT_BM_NORMAL &&
1150 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1151 return (1);
1152 if (browser_mode == XT_BM_KIOSK &&
1153 cookie_policy != SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1154 return (1);
1155 return (0);
1158 char *
1159 get_cookie_policy(struct settings *s)
1161 char *r = NULL;
1163 if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY)
1164 r = g_strdup("no3rdparty");
1165 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
1166 r = g_strdup("accept");
1167 else if (cookie_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
1168 r = g_strdup("reject");
1169 else
1170 return (NULL);
1172 return (r);
1175 char *
1176 get_default_script(struct settings *s)
1178 if (default_script[0] == '\0')
1179 return (0);
1180 return (g_strdup(default_script));
1184 set_default_script(struct settings *s, char *val)
1186 expand_tilde(default_script, sizeof default_script, val);
1187 return (0);
1191 check_default_script(char **tt)
1193 *tt = g_strdup("Default: (empty)");
1194 return (g_strcmp0(default_script, XT_DS_DEFAULT_SCRIPT));
1198 set_default_script_rt(char *value)
1200 if (value == NULL || strlen(value) == 0)
1201 return set_default_script(NULL, "");
1202 return (set_default_script(NULL, value));
1206 set_do_not_track(char *value)
1208 int tmp;
1209 const char *errstr;
1211 if (value == NULL || strlen(value) == 0)
1212 do_not_track = XT_DS_DO_NOT_TRACK;
1213 else {
1214 tmp = strtonum(value, 0, 1, &errstr);
1215 if (errstr)
1216 return (-1);
1217 do_not_track = tmp;
1219 return (0);
1223 check_do_not_track(char **tt)
1225 *tt = g_strdup("Default (depends on browser_mode):\n"
1226 "\tnormal:\tDisabled\n"
1227 "\twhitelist:\tEnabled\n"
1228 "\tkiosk:\tDisabled");
1229 if (browser_mode == XT_BM_WHITELIST && do_not_track != 1)
1230 return (1);
1231 if (browser_mode == XT_BM_NORMAL && do_not_track != 0)
1232 return (1);
1233 if (browser_mode == XT_BM_KIOSK && do_not_track != 0)
1234 return (1);
1235 return (0);
1238 char *
1239 get_download_dir(struct settings *s)
1241 if (download_dir[0] == '\0')
1242 return (0);
1243 return (g_strdup(download_dir));
1247 set_download_dir(struct settings *s, char *val)
1249 expand_tilde(download_dir, sizeof download_dir, val);
1250 return (0);
1254 check_download_dir(char **tt)
1256 struct passwd *pwd;
1257 char buf[PATH_MAX] = {0};
1259 /* XXX this might need some additonal magic on windows */
1260 if ((pwd = getpwuid(getuid())) == NULL)
1261 return (-1);
1262 snprintf(buf, sizeof buf, "%s" PS "downloads", pwd->pw_dir);
1263 *tt = g_strdup_printf("Default: %s", buf);
1264 return (g_strcmp0(download_dir, buf));
1268 add_alias(struct settings *s, char *line)
1270 char *l, *alias;
1271 struct alias *a = NULL;
1273 if (s == NULL || line == NULL) {
1274 show_oops(NULL, "add_alias invalid parameters");
1275 return (1);
1278 l = line;
1279 a = g_malloc(sizeof(*a));
1281 if ((alias = strsep(&l, " \t,")) == NULL || l == NULL) {
1282 show_oops(NULL, "add_alias: incomplete alias definition");
1283 goto bad;
1285 if (strlen(alias) == 0 || strlen(l) == 0) {
1286 show_oops(NULL, "add_alias: invalid alias definition");
1287 goto bad;
1290 a->a_name = g_strdup(alias);
1291 a->a_uri = g_strdup(l);
1293 DNPRINTF(XT_D_CONFIG, "add_alias: %s for %s\n", a->a_name, a->a_uri);
1295 TAILQ_INSERT_TAIL(&aliases, a, entry);
1297 return (0);
1298 bad:
1299 if (a)
1300 g_free(a);
1301 return (1);
1304 void
1305 walk_alias(struct settings *s,
1306 void (*cb)(struct settings *, char *, void *), void *cb_args)
1308 struct alias *a;
1309 char *str;
1311 if (s == NULL || cb == NULL) {
1312 show_oops(NULL, "walk_alias invalid parameters");
1313 return;
1316 TAILQ_FOREACH(a, &aliases, entry) {
1317 str = g_strdup_printf("%s --> %s", a->a_name, a->a_uri);
1318 cb(s, str, cb_args);
1319 g_free(str);
1324 add_mime_type(struct settings *s, char *line)
1326 char *mime_type;
1327 char *l;
1328 struct mime_type *m = NULL;
1329 int downloadfirst = 0;
1331 /* XXX this could be smarter */
1333 if (line == NULL || strlen(line) == 0) {
1334 show_oops(NULL, "add_mime_type invalid parameters");
1335 return (1);
1338 l = line;
1339 if (*l == '@') {
1340 downloadfirst = 1;
1341 l++;
1343 m = g_malloc(sizeof(*m));
1345 if ((mime_type = strsep(&l, " \t,")) == NULL || l == NULL) {
1346 show_oops(NULL, "add_mime_type: invalid mime_type");
1347 goto bad;
1349 if (mime_type[strlen(mime_type) - 1] == '*') {
1350 mime_type[strlen(mime_type) - 1] = '\0';
1351 m->mt_default = 1;
1352 } else
1353 m->mt_default = 0;
1355 if (strlen(mime_type) == 0 || strlen(l) == 0) {
1356 show_oops(NULL, "add_mime_type: invalid mime_type");
1357 goto bad;
1360 m->mt_type = g_strdup(mime_type);
1361 m->mt_action = g_strdup(l);
1362 m->mt_download = downloadfirst;
1364 DNPRINTF(XT_D_CONFIG, "add_mime_type: type %s action %s default %d\n",
1365 m->mt_type, m->mt_action, m->mt_default);
1367 TAILQ_INSERT_TAIL(&mtl, m, entry);
1369 return (0);
1370 bad:
1371 if (m)
1372 g_free(m);
1373 return (1);
1376 void
1377 walk_mime_type(struct settings *s,
1378 void (*cb)(struct settings *, char *, void *), void *cb_args)
1380 struct mime_type *m;
1381 char *str;
1383 if (s == NULL || cb == NULL) {
1384 show_oops(NULL, "walk_mime_type invalid parameters");
1385 return;
1388 TAILQ_FOREACH(m, &mtl, entry) {
1389 str = g_strdup_printf("%s%s --> %s",
1390 m->mt_type,
1391 m->mt_default ? "*" : "",
1392 m->mt_action);
1393 cb(s, str, cb_args);
1394 g_free(str);
1398 /* inherent to GTK not all keys will be caught at all times */
1399 /* XXX sort key bindings */
1400 struct key_binding keys[] = {
1401 { "command_mode", 0, 1, GDK_Escape },
1402 { "insert_mode", 0, 0, GDK_i },
1403 { "cookiejar", MOD1, 1, GDK_j },
1404 { "downloadmgr", MOD1, 1, GDK_d },
1405 { "history", MOD1, 1, GDK_h },
1406 { "print", CTRL, 1, GDK_p },
1407 { "search", 0, 0, GDK_slash },
1408 { "searchb", 0, 0, GDK_question },
1409 { "statustoggle", CTRL, 1, GDK_n },
1410 { "command", 0, 0, GDK_colon },
1411 { "qa", CTRL, 1, GDK_q },
1412 { "restart", MOD1, 1, GDK_q },
1413 { "js toggle", CTRL, 1, GDK_j },
1414 { "plugin toggle", MOD1, 1, GDK_p },
1415 { "cookie toggle", MOD1, 1, GDK_c },
1416 { "togglesrc", CTRL, 1, GDK_s },
1417 { "yankuri", 0, 0, GDK_y },
1418 { "pasteuricur", 0, 0, GDK_p },
1419 { "pasteurinew", 0, 0, GDK_P },
1420 { "toplevel toggle", 0, 1, GDK_F4 },
1421 { "help", 0, 1, GDK_F1 },
1422 { "run_script", MOD1, 1, GDK_r },
1423 { "proxy toggle", 0, 1, GDK_F2 },
1424 { "editelement", CTRL, 1, GDK_i },
1425 { "passthrough", CTRL, 1, GDK_z },
1426 { "modurl", CTRL, 1, GDK_Return },
1428 /* search */
1429 { "searchnext", 0, 0, GDK_n },
1430 { "searchprevious", 0, 0, GDK_N },
1432 /* focus */
1433 { "focusaddress", 0, 1, GDK_F6 },
1434 { "focussearch", 0, 1, GDK_F7 },
1436 /* hinting */
1437 { "hinting", 0, 0, GDK_f },
1438 { "hinting", 0, 0, GDK_period },
1439 { "hinting_newtab", SHFT, 0, GDK_F },
1440 { "hinting_newtab", 0, 0, GDK_comma },
1442 /* custom stylesheet */
1443 { "userstyle", 0, 0, GDK_s },
1444 { "userstyle_global", SHFT, 0, GDK_S },
1446 /* navigation */
1447 { "goback", 0, 0, GDK_BackSpace },
1448 { "goback", MOD1, 1, GDK_Left },
1449 { "goforward", SHFT, 1, GDK_BackSpace },
1450 { "goforward", MOD1, 1, GDK_Right },
1451 { "reload", 0, 1, GDK_F5 },
1452 { "reload", CTRL, 1, GDK_r },
1453 { "reload", CTRL, 1, GDK_l },
1454 { "favorites", MOD1, 1, GDK_f },
1456 /* vertical movement */
1457 { "scrolldown", 0, 0, GDK_j },
1458 { "scrolldown", 0, 0, GDK_Down },
1459 { "scrollup", 0, 0, GDK_Up },
1460 { "scrollup", 0, 0, GDK_k },
1461 { "scrollbottom", 0, 0, GDK_G },
1462 { "scrollbottom", 0, 0, GDK_End },
1463 { "scrolltop", 0, 0, GDK_Home },
1464 { "scrollpagedown", 0, 0, GDK_space },
1465 { "scrollpagedown", CTRL, 1, GDK_f },
1466 { "scrollhalfdown", CTRL, 1, GDK_d },
1467 { "scrollpagedown", 0, 0, GDK_Page_Down },
1468 { "scrollpageup", 0, 0, GDK_Page_Up },
1469 { "scrollpageup", CTRL, 1, GDK_b },
1470 { "scrollhalfup", CTRL, 1, GDK_u },
1471 /* horizontal movement */
1472 { "scrollright", 0, 0, GDK_l },
1473 { "scrollright", 0, 0, GDK_Right },
1474 { "scrollleft", 0, 0, GDK_Left },
1475 { "scrollleft", 0, 0, GDK_h },
1476 { "scrollfarright", 0, 0, GDK_dollar },
1477 { "scrollfarleft", 0, 0, GDK_0 },
1479 /* tabs */
1480 { "tabnew", CTRL, 1, GDK_t },
1481 { "999tabnew", CTRL, 1, GDK_T },
1482 { "tabclose", CTRL, 1, GDK_w },
1483 { "tabundoclose", 0, 0, GDK_U },
1484 { "tabnext 1", CTRL, 1, GDK_1 },
1485 { "tabnext 2", CTRL, 1, GDK_2 },
1486 { "tabnext 3", CTRL, 1, GDK_3 },
1487 { "tabnext 4", CTRL, 1, GDK_4 },
1488 { "tabnext 5", CTRL, 1, GDK_5 },
1489 { "tabnext 6", CTRL, 1, GDK_6 },
1490 { "tabnext 7", CTRL, 1, GDK_7 },
1491 { "tabnext 8", CTRL, 1, GDK_8 },
1492 { "tabnext 9", CTRL, 1, GDK_9 },
1493 { "tabfirst", CTRL, 1, GDK_less },
1494 { "tablast", CTRL, 1, GDK_greater },
1495 { "tabprevious", CTRL, 1, GDK_Left },
1496 { "tabnext", CTRL, 1, GDK_Right },
1497 { "focusout", CTRL, 1, GDK_minus },
1498 { "focusin", CTRL, 1, GDK_plus },
1499 { "focusin", CTRL, 1, GDK_equal },
1500 { "focusreset", CTRL, 1, GDK_0 },
1502 /* command aliases (handy when -S flag is used) */
1503 { ":open ", 0, 1, GDK_F9 },
1504 { ":open <uri>", 0, 1, GDK_F10 },
1505 { ":tabnew ", 0, 1, GDK_F11 },
1506 { ":tabnew <uri>", 0, 1, GDK_F12 },
1509 void
1510 walk_kb(struct settings *s,
1511 void (*cb)(struct settings *, char *, void *), void *cb_args)
1513 struct key_binding *k;
1514 char str[1024];
1516 if (s == NULL || cb == NULL) {
1517 show_oops(NULL, "walk_kb invalid parameters");
1518 return;
1521 TAILQ_FOREACH(k, &kbl, entry) {
1522 if (k->cmd == NULL)
1523 continue;
1524 str[0] = '\0';
1526 /* sanity */
1527 if (gdk_keyval_name(k->key) == NULL)
1528 continue;
1530 strlcat(str, k->cmd, sizeof str);
1531 strlcat(str, ",", sizeof str);
1533 if (k->mask & GDK_SHIFT_MASK)
1534 strlcat(str, "S-", sizeof str);
1535 if (k->mask & GDK_CONTROL_MASK)
1536 strlcat(str, "C-", sizeof str);
1537 if (k->mask & GDK_MOD1_MASK)
1538 strlcat(str, "M1-", sizeof str);
1539 if (k->mask & GDK_MOD2_MASK)
1540 strlcat(str, "M2-", sizeof str);
1541 if (k->mask & GDK_MOD3_MASK)
1542 strlcat(str, "M3-", sizeof str);
1543 if (k->mask & GDK_MOD4_MASK)
1544 strlcat(str, "M4-", sizeof str);
1545 if (k->mask & GDK_MOD5_MASK)
1546 strlcat(str, "M5-", sizeof str);
1548 strlcat(str, gdk_keyval_name(k->key), sizeof str);
1549 cb(s, str, cb_args);
1553 void
1554 init_keybindings(void)
1556 int i;
1557 struct key_binding *k;
1559 for (i = 0; i < LENGTH(keys); i++) {
1560 k = g_malloc0(sizeof *k);
1561 k->cmd = keys[i].cmd;
1562 k->mask = keys[i].mask;
1563 k->use_in_entry = keys[i].use_in_entry;
1564 k->key = keys[i].key;
1565 TAILQ_INSERT_HEAD(&kbl, k, entry);
1567 DNPRINTF(XT_D_KEYBINDING, "init_keybindings: added: %s\n",
1568 k->cmd ? k->cmd : "unnamed key");
1572 void
1573 keybinding_clearall(void)
1575 struct key_binding *k, *next;
1577 for (k = TAILQ_FIRST(&kbl); k; k = next) {
1578 next = TAILQ_NEXT(k, entry);
1579 if (k->cmd == NULL)
1580 continue;
1582 DNPRINTF(XT_D_KEYBINDING, "keybinding_clearall: %s\n",
1583 k->cmd ? k->cmd : "unnamed key");
1584 TAILQ_REMOVE(&kbl, k, entry);
1585 g_free(k);
1590 keybinding_add(char *cmd, char *key, int use_in_entry)
1592 struct key_binding *k;
1593 guint keyval, mask = 0;
1594 int i;
1596 DNPRINTF(XT_D_KEYBINDING, "keybinding_add: %s %s\n", cmd, key);
1598 /* Keys which are to be used in entry have been prefixed with an
1599 * exclamation mark. */
1600 if (use_in_entry)
1601 key++;
1603 /* find modifier keys */
1604 if (strstr(key, "S-"))
1605 mask |= GDK_SHIFT_MASK;
1606 if (strstr(key, "C-"))
1607 mask |= GDK_CONTROL_MASK;
1608 if (strstr(key, "M1-"))
1609 mask |= GDK_MOD1_MASK;
1610 if (strstr(key, "M2-"))
1611 mask |= GDK_MOD2_MASK;
1612 if (strstr(key, "M3-"))
1613 mask |= GDK_MOD3_MASK;
1614 if (strstr(key, "M4-"))
1615 mask |= GDK_MOD4_MASK;
1616 if (strstr(key, "M5-"))
1617 mask |= GDK_MOD5_MASK;
1619 /* find keyname */
1620 for (i = strlen(key) - 1; i > 0; i--)
1621 if (key[i] == '-')
1622 key = &key[i + 1];
1624 /* validate keyname */
1625 keyval = gdk_keyval_from_name(key);
1626 if (keyval == GDK_VoidSymbol) {
1627 warnx("invalid keybinding name %s", key);
1628 return (1);
1630 /* must run this test too, gtk+ doesn't handle 10 for example */
1631 if (gdk_keyval_name(keyval) == NULL) {
1632 warnx("invalid keybinding name %s", key);
1633 return (1);
1636 /* Remove eventual dupes. */
1637 TAILQ_FOREACH(k, &kbl, entry)
1638 if (k->key == keyval && k->mask == mask) {
1639 TAILQ_REMOVE(&kbl, k, entry);
1640 g_free(k);
1641 break;
1644 /* add keyname */
1645 k = g_malloc0(sizeof *k);
1646 k->cmd = g_strdup(cmd);
1647 k->mask = mask;
1648 k->use_in_entry = use_in_entry;
1649 k->key = keyval;
1651 DNPRINTF(XT_D_KEYBINDING, "keybinding_add: %s 0x%x %d 0x%x\n",
1652 k->cmd,
1653 k->mask,
1654 k->use_in_entry,
1655 k->key);
1656 DNPRINTF(XT_D_KEYBINDING, "keybinding_add: adding: %s %s\n",
1657 k->cmd, gdk_keyval_name(keyval));
1659 TAILQ_INSERT_HEAD(&kbl, k, entry);
1661 return (0);
1665 cmd_alias_add(char *alias, char *cmd)
1667 struct cmd_alias *c;
1669 /* XXX */
1670 TAILQ_FOREACH(c, &cal, entry)
1671 if (!strcmp((alias), c->alias)) {
1672 TAILQ_REMOVE(&cal, c, entry);
1673 g_free(c);
1676 c = g_malloc(sizeof (struct cmd_alias));
1677 c->alias = g_strchug(g_strdup(alias));
1678 c->cmd = g_strchug(g_strdup(cmd));
1680 DNPRINTF(XT_D_CUSTOM_URI, "cmd_alias_add: %s %s\n", c->alias, c->cmd);
1682 TAILQ_INSERT_HEAD(&cal, c, entry);
1683 return (0);
1687 custom_uri_add(char *uri, char *cmd)
1689 struct custom_uri *u;
1691 TAILQ_FOREACH(u, &cul, entry)
1692 if (!strcmp((uri), u->uri) && !strcmp(cmd, u->cmd)) {
1693 TAILQ_REMOVE(&cul, u, entry);
1694 g_free(u);
1697 u = g_malloc(sizeof (struct custom_uri));
1698 u->uri = g_strdup(uri);
1699 expand_tilde(u->cmd, sizeof u->cmd, cmd);
1701 DNPRINTF(XT_D_CUSTOM_URI, "custom_uri_add: %s %s\n", u->uri, u->cmd);
1703 /* don't check here if the script is valid, wait until running it */
1704 TAILQ_INSERT_HEAD(&cul, u, entry);
1705 return (0);
1709 add_kb(struct settings *s, char *entry)
1711 char *kb, *key;
1713 DNPRINTF(XT_D_KEYBINDING, "add_kb: %s\n", entry);
1715 /* clearall is special */
1716 if (!strcmp(entry, "clearall")) {
1717 keybinding_clearall();
1718 return (0);
1721 kb = strstr(entry, ",");
1722 if (kb == NULL)
1723 return (1);
1724 *kb = '\0';
1725 key = kb + 1;
1727 return (keybinding_add(entry, key, key[0] == '!'));
1731 add_custom_uri(struct settings *s, char *entry)
1733 char *uri, *cmd;
1735 DNPRINTF(XT_D_CUSTOM_URI, "add_custom_uri: %s\n", entry);
1737 uri = strstr(entry, ",");
1738 if (uri == NULL)
1739 return (1);
1740 *uri = '\0';
1741 cmd = uri + 1;
1743 return (custom_uri_add(entry, cmd));
1746 void
1747 walk_custom_uri(struct settings *s,
1748 void (*cb)(struct settings *, char *, void *), void *cb_args)
1750 struct custom_uri *u;
1751 char buf[1024];
1753 if (s == NULL || cb == NULL) {
1754 show_oops(NULL, "walk_custom_uri invalid parameters");
1755 return;
1758 TAILQ_FOREACH(u, &cul, entry) {
1759 snprintf(buf, sizeof buf, "%s,%s", u->uri, u->cmd);
1760 cb(s, buf, cb_args);
1765 add_ua(struct settings *s, char *value)
1767 struct user_agent *ua;
1768 static int ua_count = 0;
1770 ua = g_malloc(sizeof *ua);
1771 ua->id = ua_count++;
1772 ua->value = g_strdup(value);
1774 RB_INSERT(user_agent_list, &ua_list, ua);
1776 return (0);
1780 void
1781 walk_ua(struct settings *s,
1782 void (*cb)(struct settings *, char *, void *), void *cb_args)
1784 struct user_agent *ua;
1786 if (s == NULL || cb == NULL) {
1787 show_oops(NULL, "walk_ua invalid parameters");
1788 return;
1791 RB_FOREACH(ua, user_agent_list, &ua_list)
1792 cb(s, ua->value, cb_args);
1796 add_force_https(struct settings *s, char *value)
1798 wl_add(value, &force_https, XT_WL_PERSISTENT);
1799 return (0);
1803 add_http_accept(struct settings *s, char *value)
1805 struct http_accept *ha;
1806 static int ha_count = 0;
1808 ha = g_malloc(sizeof *ha);
1809 ha->id = ha_count++;
1810 ha->value = g_strdup(value);
1812 RB_INSERT(http_accept_list, &ha_list, ha);
1814 return (0);
1817 void
1818 walk_http_accept(struct settings *s,
1819 void (*cb)(struct settings *, char *, void *), void *cb_args)
1821 struct http_accept *ha;
1823 if (s == NULL || cb == NULL) {
1824 show_oops(NULL, "%s: invalid parameters", __func__);
1825 return;
1828 RB_FOREACH(ha, http_accept_list, &ha_list)
1829 cb(s, ha->value, cb_args);
1833 add_cmd_alias(struct settings *s, char *entry)
1835 char *alias, *cmd;
1837 DNPRINTF(XT_D_CMD_ALIAS, "add_cmd_alias: %s\n", entry);
1839 alias = strstr(entry, ",");
1840 if (alias == NULL)
1841 return (1);
1842 *alias = '\0';
1843 cmd = alias + 1;
1845 return (cmd_alias_add(entry, cmd));
1848 void
1849 walk_cmd_alias(struct settings *s,
1850 void (*cb)(struct settings *, char *, void *), void *cb_args)
1852 struct cmd_alias *c;
1853 char buf[1024];
1855 if (s == NULL || cb == NULL) {
1856 show_oops(NULL, "walk_cmd_alias invalid parameters");
1857 return;
1860 TAILQ_FOREACH(c, &cal, entry) {
1861 snprintf(buf, sizeof buf, "%s --> %s", c->alias, c->cmd);
1862 cb(s, buf, cb_args);
1867 set_allow_insecure_content(char *value)
1869 struct tab *t;
1870 int tmp;
1871 const char *errstr;
1873 if (value == NULL || strlen(value) == 0)
1874 allow_insecure_content = XT_DS_ALLOW_INSECURE_CONTENT;
1875 else {
1876 tmp = strtonum(value, 0, 1, &errstr);
1877 if (errstr)
1878 return (-1);
1879 allow_insecure_content = tmp;
1881 TAILQ_FOREACH(t, &tabs, entry)
1882 if (is_g_object_setting(G_OBJECT(t->settings),
1883 "enable-display-of-insecure-content")) {
1884 g_object_set(G_OBJECT(t->settings),
1885 "enable-display-of-insecure-content",
1886 allow_insecure_content, (char *)NULL);
1887 webkit_web_view_set_settings(t->wv, t->settings);
1889 return (0);
1893 check_allow_insecure_content(char **tt)
1895 *tt = g_strdup("Default (depends on browser_mode):\n"
1896 "\tnormal:\tEnabled\n"
1897 "\twhitelist:\tDisabled\n"
1898 "\tkiosk:\tEnabled");
1899 if (browser_mode == XT_BM_NORMAL && allow_insecure_content != 1)
1900 return (1);
1901 if (browser_mode == XT_BM_WHITELIST && allow_insecure_content != 0)
1902 return (1);
1903 if (browser_mode == XT_BM_KIOSK && allow_insecure_content != 1)
1904 return (1);
1905 return (0);
1909 set_allow_insecure_scripts(char *value)
1911 struct tab *t;
1912 int tmp;
1913 const char *errstr;
1915 if (value == NULL || strlen(value) == 0)
1916 allow_insecure_scripts = XT_DS_ALLOW_INSECURE_SCRIPTS;
1917 else {
1918 tmp = strtonum(value, 0, 1, &errstr);
1919 if (errstr)
1920 return (-1);
1921 allow_insecure_scripts = tmp;
1923 TAILQ_FOREACH(t, &tabs, entry)
1924 if (is_g_object_setting(G_OBJECT(t->settings),
1925 "enable-running-of-insecure-content")) {
1926 g_object_set(G_OBJECT(t->settings),
1927 "enable-running-of-insecure-content",
1928 allow_insecure_scripts, (char *)NULL);
1929 webkit_web_view_set_settings(t->wv, t->settings);
1931 return (0);
1935 check_allow_insecure_scripts(char **tt)
1937 *tt = g_strdup("Default (depends on browser_mode):\n"
1938 "\tnormal:\tEnabled\n"
1939 "\twhitelist:\tDisabled\n"
1940 "\tkiosk:\tEnabled");
1941 if (browser_mode == XT_BM_NORMAL && allow_insecure_scripts != 1)
1942 return (1);
1943 if (browser_mode == XT_BM_WHITELIST && allow_insecure_scripts != 0)
1944 return (1);
1945 if (browser_mode == XT_BM_KIOSK && allow_insecure_scripts != 1)
1946 return (1);
1947 return (0);
1951 set_auto_load_images(char *value)
1953 struct tab *t;
1954 int tmp;
1955 const char *errstr;
1957 if (value == NULL || strlen(value) == 0)
1958 auto_load_images = XT_DS_AUTO_LOAD_IMAGES;
1959 else {
1960 tmp = strtonum(value, 0, 1, &errstr);
1961 if (errstr)
1962 return (-1);
1963 auto_load_images = tmp;
1965 TAILQ_FOREACH(t, &tabs, entry) {
1966 g_object_set(G_OBJECT(t->settings),
1967 "auto-load-images", auto_load_images, (char *)NULL);
1968 webkit_web_view_set_settings(t->wv, t->settings);
1970 return (0);
1974 check_auto_load_images(char **tt)
1976 *tt = g_strdup_printf("Default: %s",
1977 XT_DS_AUTO_LOAD_IMAGES ? "Enabled" : "Disabled");
1978 return (auto_load_images != XT_DS_AUTO_LOAD_IMAGES);
1982 set_autofocus_onload(char *value)
1984 int tmp;
1985 const char *errstr;
1987 if (value == NULL || strlen(value) == 0)
1988 autofocus_onload = XT_DS_AUTOFOCUS_ONLOAD;
1989 else {
1990 tmp = strtonum(value, 0, 1, &errstr);
1991 if (errstr)
1992 return (-1);
1993 autofocus_onload = tmp;
1995 return (0);
1999 check_autofocus_onload(char **tt)
2001 *tt = g_strdup_printf("Default: %s",
2002 XT_DS_AUTOFOCUS_ONLOAD ? "Enabled" : "Disabled");
2003 return (autofocus_onload != XT_DS_AUTOFOCUS_ONLOAD);
2007 set_ctrl_click_focus(char *value)
2009 int tmp;
2010 const char *errstr;
2012 if (value == NULL || strlen(value) == 0)
2013 ctrl_click_focus = XT_DS_CTRL_CLICK_FOCUS;
2014 else {
2015 tmp = strtonum(value, 0, 1, &errstr);
2016 if (errstr)
2017 return (-1);
2018 ctrl_click_focus = tmp;
2020 return (0);
2024 check_ctrl_click_focus(char **tt)
2026 *tt = g_strdup_printf("Default: %s",
2027 XT_DS_CTRL_CLICK_FOCUS ? "Enabled" : "Disabled");
2028 return (ctrl_click_focus != XT_DS_CTRL_CLICK_FOCUS);
2032 set_download_notifications(char *value)
2034 int tmp;
2035 const char *errstr;
2037 if (value == NULL || strlen(value) == 0)
2038 download_notifications = XT_DS_DOWNLOAD_NOTIFICATIONS;
2039 else {
2040 tmp = strtonum(value, 0, 1, &errstr);
2041 if (errstr)
2042 return (-1);
2043 download_notifications = tmp;
2045 return (0);
2049 check_download_notifications(char **tt)
2051 *tt = g_strdup_printf("Default: %s",
2052 XT_DS_DOWNLOAD_NOTIFICATIONS ? "Enabled" : "Disabled");
2053 return (download_notifications != XT_DS_DOWNLOAD_NOTIFICATIONS);
2057 set_enable_autoscroll(char *value)
2059 int tmp;
2060 const char *errstr;
2062 if (value == NULL || strlen(value) == 0)
2063 enable_autoscroll = XT_DS_ENABLE_AUTOSCROLL;
2064 else {
2065 tmp = strtonum(value, 0, 1, &errstr);
2066 if (errstr)
2067 return (-1);
2068 enable_autoscroll = tmp;
2070 return (0);
2074 check_enable_autoscroll(char **tt)
2076 *tt = g_strdup_printf("Default: %s",
2077 XT_DS_ENABLE_AUTOSCROLL ? "Enabled" : "Disabled");
2078 return (enable_autoscroll != XT_DS_ENABLE_AUTOSCROLL);
2082 set_enable_cookie_whitelist(char *value)
2084 int tmp;
2085 const char *errstr;
2087 if (value == NULL || strlen(value) == 0)
2088 enable_cookie_whitelist = XT_DS_ENABLE_COOKIE_WHITELIST;
2089 else {
2090 tmp = strtonum(value, 0, 1, &errstr);
2091 if (errstr)
2092 return (-1);
2093 enable_cookie_whitelist = tmp;
2095 return (0);
2099 check_enable_cookie_whitelist(char **tt)
2101 *tt = g_strdup("Default (depends on browser_mode):\n"
2102 "\tnormal:\tDisabled\n"
2103 "\twhitelist:\tEnabled\n"
2104 "\tkiosk:\tDisabled");
2105 if (browser_mode == XT_BM_WHITELIST && enable_cookie_whitelist != 1)
2106 return (1);
2107 if (browser_mode == XT_BM_NORMAL && enable_cookie_whitelist != 0)
2108 return (1);
2109 if (browser_mode == XT_BM_KIOSK && enable_cookie_whitelist != 0)
2110 return (1);
2111 return (0);
2115 set_enable_js_autorun(char *value)
2117 int tmp;
2118 const char *errstr;
2120 if (value == NULL || strlen(value) == 0)
2121 enable_js_autorun = XT_DS_ENABLE_JS_AUTORUN;
2122 else {
2123 tmp = strtonum(value, 0, 1, &errstr);
2124 if (errstr)
2125 return (-1);
2126 enable_js_autorun = tmp;
2128 return (0);
2132 check_enable_js_autorun(char **tt)
2134 *tt = g_strdup_printf("Default: %s",
2135 XT_DS_ENABLE_JS_AUTORUN ? "Enabled" : "Disabled");
2136 return (enable_js_autorun != XT_DS_ENABLE_JS_AUTORUN);
2140 set_enable_js_whitelist(char *value)
2142 int tmp;
2143 const char *errstr;
2145 if (value == NULL || strlen(value) == 0)
2146 enable_js_whitelist = XT_DS_ENABLE_JS_WHITELIST;
2147 else {
2148 tmp = strtonum(value, 0, 1, &errstr);
2149 if (errstr)
2150 return (-1);
2151 enable_js_whitelist = tmp;
2153 return (0);
2157 check_enable_js_whitelist(char **tt)
2159 *tt = g_strdup("Default (depends on browser_mode):\n"
2160 "\tnormal:\tDisabled\n"
2161 "\twhitelist:\tEnabled\n"
2162 "\tkiosk:\tDisabled");
2163 if (browser_mode == XT_BM_WHITELIST && enable_js_whitelist != 1)
2164 return (1);
2165 if (browser_mode == XT_BM_NORMAL && enable_js_whitelist != 0)
2166 return (1);
2167 if (browser_mode == XT_BM_KIOSK && enable_js_whitelist != 0)
2168 return (1);
2169 return (0);
2173 set_enable_favicon_entry(char *value)
2175 int tmp;
2176 const char *errstr;
2178 if (value == NULL || strlen(value) == 0)
2179 enable_favicon_entry = XT_DS_ENABLE_FAVICON_ENTRY;
2180 else {
2181 tmp = strtonum(value, 0, 1, &errstr);
2182 if (errstr)
2183 return (-1);
2184 enable_favicon_entry = tmp;
2186 return (0);
2190 check_enable_favicon_entry(char **tt)
2192 *tt = g_strdup_printf("Default: %s",
2193 XT_DS_ENABLE_FAVICON_ENTRY ? "Enabled" : "Disabled");
2194 return (enable_favicon_entry != XT_DS_ENABLE_FAVICON_ENTRY);
2198 set_enable_favicon_tabs(char *value)
2200 int tmp;
2201 const char *errstr;
2203 if (value == NULL || strlen(value) == 0)
2204 enable_favicon_tabs = XT_DS_ENABLE_FAVICON_TABS;
2205 else {
2206 tmp = strtonum(value, 0, 1, &errstr);
2207 if (errstr)
2208 return (-1);
2209 enable_favicon_tabs = tmp;
2211 return (0);
2215 check_enable_favicon_tabs(char **tt)
2217 *tt = g_strdup_printf("Default: %s",
2218 XT_DS_ENABLE_FAVICON_TABS ? "Enabled" : "Disabled");
2219 return (enable_favicon_tabs != XT_DS_ENABLE_FAVICON_TABS);
2223 set_enable_localstorage(char *value)
2225 struct tab *t;
2226 int tmp;
2227 const char *errstr;
2229 if (value == NULL || strlen(value) == 0)
2230 enable_localstorage = XT_DS_ENABLE_LOCALSTORAGE;
2231 else {
2232 tmp = strtonum(value, 0, 1, &errstr);
2233 if (errstr)
2234 return (-1);
2235 enable_localstorage = tmp;
2237 TAILQ_FOREACH(t, &tabs, entry)
2238 g_object_set(G_OBJECT(t->settings),
2239 "enable-html5-local-storage", enable_localstorage,
2240 (char *)NULL);
2241 return (0);
2245 check_enable_localstorage(char **tt)
2247 *tt = g_strdup("Default (depends on browser_mode):\n"
2248 "\tnormal:\tEnabled\n"
2249 "\twhitelist:\tDisabled\n"
2250 "\tkiosk:\tEnabled");
2251 if (browser_mode == XT_BM_WHITELIST && enable_localstorage != 0)
2252 return (1);
2253 if (browser_mode == XT_BM_NORMAL && enable_localstorage != 1)
2254 return (1);
2255 if (browser_mode == XT_BM_KIOSK && enable_localstorage != 1)
2256 return (1);
2257 return (0);
2261 set_enable_plugins(char *value)
2263 struct tab *t;
2264 int tmp;
2265 const char *errstr;
2267 if (value == NULL || strlen(value) == 0)
2268 enable_plugins = XT_DS_ENABLE_PLUGINS;
2269 else {
2270 tmp = strtonum(value, 0, 1, &errstr);
2271 if (errstr)
2272 return (-1);
2273 enable_plugins = tmp;
2275 TAILQ_FOREACH(t, &tabs, entry)
2276 g_object_set(G_OBJECT(t->settings), "enable-plugins",
2277 enable_plugins, (char *)NULL);
2278 return (0);
2282 check_enable_plugins(char **tt)
2284 *tt = g_strdup("Default (depends on browser_mode):\n"
2285 "\tnormal:\tEnabled\n"
2286 "\twhitelist:\tDisabled\n"
2287 "\tkiosk:\tEnabled");
2288 if (browser_mode == XT_BM_WHITELIST && enable_plugins != 0)
2289 return (1);
2290 if (browser_mode == XT_BM_NORMAL && enable_plugins != 1)
2291 return (1);
2292 if (browser_mode == XT_BM_KIOSK && enable_plugins != 1)
2293 return (1);
2294 return (0);
2298 set_enable_plugin_whitelist(char *value)
2300 int tmp;
2301 const char *errstr;
2303 if (value == NULL || strlen(value) == 0)
2304 enable_plugin_whitelist = XT_DS_ENABLE_PLUGIN_WHITELIST;
2305 else {
2306 tmp = strtonum(value, 0, 1, &errstr);
2307 if (errstr)
2308 return (-1);
2309 enable_plugin_whitelist = tmp;
2311 return (0);
2315 check_enable_plugin_whitelist(char **tt)
2317 *tt = g_strdup("Default (depends on browser_mode):\n"
2318 "\tnormal:\tDisabled\n"
2319 "\twhitelist:\tEnabled\n"
2320 "\tkiosk:\tDisabled");
2321 if (browser_mode == XT_BM_WHITELIST && enable_plugin_whitelist != 1)
2322 return (1);
2323 if (browser_mode == XT_BM_NORMAL && enable_plugin_whitelist != 0)
2324 return (1);
2325 if (browser_mode == XT_BM_KIOSK && enable_plugin_whitelist != 0)
2326 return (1);
2327 return (0);
2331 set_enable_scripts(char *value)
2333 struct tab *t;
2334 int tmp;
2335 const char *errstr;
2337 if (value == NULL || strlen(value) == 0)
2338 enable_scripts = XT_DS_ENABLE_SCRIPTS;
2339 else {
2340 tmp = strtonum(value, 0, 1, &errstr);
2341 if (errstr)
2342 return (-1);
2343 enable_scripts = tmp;
2345 TAILQ_FOREACH(t, &tabs, entry)
2346 g_object_set(G_OBJECT(t->settings), "enable-scripts",
2347 enable_scripts, (char *)NULL);
2348 return (0);
2352 check_enable_scripts(char **tt)
2354 *tt = g_strdup("Default (depends on browser_mode):\n"
2355 "\tnormal:\tEnabled\n"
2356 "\twhitelist:\tDisabled\n"
2357 "\tkiosk:\tEnabled");
2358 if (browser_mode == XT_BM_WHITELIST && enable_scripts != 0)
2359 return (1);
2360 if (browser_mode == XT_BM_NORMAL && enable_scripts != 1)
2361 return (1);
2362 if (browser_mode == XT_BM_KIOSK && enable_scripts != 1)
2363 return (1);
2364 return (0);
2368 check_enable_socket(char **tt)
2370 *tt = g_strdup("Default: Disabled");
2371 return (enable_socket != 0);
2375 set_enable_spell_checking(char *value)
2377 struct tab *t;
2378 int tmp;
2379 const char *errstr;
2381 if (value == NULL || strlen(value) == 0)
2382 enable_spell_checking = XT_DS_ENABLE_SPELL_CHECKING;
2383 else {
2384 tmp = strtonum(value, 0, 1, &errstr);
2385 if (errstr)
2386 return (-1);
2387 enable_spell_checking = tmp;
2389 TAILQ_FOREACH(t, &tabs, entry)
2390 g_object_set(G_OBJECT(t->settings), "enable_spell_checking",
2391 enable_spell_checking, (char *)NULL);
2392 return (0);
2396 check_enable_spell_checking(char **tt)
2398 *tt = g_strdup_printf("Default: %s",
2399 XT_DS_ENABLE_SPELL_CHECKING ? "Enabled" : "Disabled");
2400 return (enable_spell_checking != XT_DS_ENABLE_SPELL_CHECKING);
2404 set_enable_strict_transport(char *value)
2406 int tmp;
2407 const char *errstr;
2409 if (value == NULL || strlen(value) == 0)
2410 enable_strict_transport = XT_DS_ENABLE_STRICT_TRANSPORT;
2411 else {
2412 tmp = strtonum(value, 0, 1, &errstr);
2413 if (errstr)
2414 return (-1);
2415 enable_strict_transport = tmp;
2417 return (0);
2421 check_enable_strict_transport(char **tt)
2423 *tt = g_strdup_printf("Default: %s",
2424 XT_DS_ENABLE_STRICT_TRANSPORT ? "Enabled" : "Disabled");
2425 return (enable_strict_transport != XT_DS_ENABLE_STRICT_TRANSPORT);
2428 #if 0
2430 * XXX: this is currently broken. Need to figure out what to do with
2431 * this. Problemm is set_encoding will refresh the tab it's run on, so
2432 * we can either put a big fat warning in the manpage and refresh every
2433 * single open tab with the new encoding or scrap it as a runtime
2434 * setting.
2437 set_encoding_rt(char *value)
2439 struct karg args = {0};
2441 if (value == NULL || strlen(value) == 0)
2442 return (-1);
2443 if (encoding)
2444 g_free(encoding);
2445 encoding = g_strdup(value);
2446 args.s = encoding;
2447 set_encoding(get_current_tab(), &args);
2448 return (0);
2450 #endif
2453 check_encoding(char **tt)
2455 *tt = g_strdup_printf("Default: %s", XT_DS_ENCODING);
2456 return (g_strcmp0(encoding, XT_DS_ENCODING));
2460 check_gnutls_search_string(char **tt)
2462 *tt = g_strdup("Default: (empty)");
2463 return (g_strcmp0(gnutls_priority_string,
2464 XT_DS_GNUTLS_PRIORITY_STRING));
2468 set_gnutls_priority_string(struct settings *s, char *value)
2470 return (!g_setenv("G_TLS_GNUTLS_PRIORITY", value, FALSE));
2473 char *
2474 get_gnutls_priority_string(struct settings *s)
2476 return (g_strdup(g_getenv("G_TLS_GNUTLS_PRIORITY")));
2480 set_guess_search(char *value)
2482 int tmp;
2483 const char *errstr;
2485 if (value == NULL || strlen(value) == 0)
2486 guess_search = XT_DS_GUESS_SEARCH;
2487 else {
2488 tmp = strtonum(value, 0, 1, &errstr);
2489 if (errstr)
2490 return (-1);
2491 guess_search = tmp;
2493 return (0);
2497 check_guess_search(char **tt)
2499 *tt = g_strdup_printf("Default: %s",
2500 XT_DS_GUESS_SEARCH ? "Enabled" : "Disabled");
2501 return (guess_search != XT_DS_GUESS_SEARCH);
2504 char *
2505 get_referer(struct settings *s)
2507 if (referer_mode == XT_REFERER_ALWAYS)
2508 return (g_strdup("always"));
2509 if (referer_mode == XT_REFERER_NEVER)
2510 return (g_strdup("never"));
2511 if (referer_mode == XT_REFERER_SAME_DOMAIN)
2512 return (g_strdup("same-domain"));
2513 if (referer_mode == XT_REFERER_SAME_FQDN)
2514 return (g_strdup("same-fqdn"));
2515 if (referer_mode == XT_REFERER_CUSTOM)
2516 return (g_strdup(referer_custom));
2517 return (NULL);
2521 set_referer(struct settings *s, char *value)
2523 if (referer_custom) {
2524 g_free(referer_custom);
2525 referer_custom = NULL;
2528 if (!strcmp(value, "always"))
2529 referer_mode = XT_REFERER_ALWAYS;
2530 else if (!strcmp(value, "never"))
2531 referer_mode = XT_REFERER_NEVER;
2532 else if (!strcmp(value, "same-domain"))
2533 referer_mode = XT_REFERER_SAME_DOMAIN;
2534 else if (!strcmp(value, "same-fqdn"))
2535 referer_mode = XT_REFERER_SAME_FQDN;
2536 else if (!valid_url_type(value)) {
2537 referer_mode = XT_REFERER_CUSTOM;
2538 referer_custom = g_strdup(value);
2539 } else {
2540 /* we've already free'd the custom referer */
2541 if (referer_mode == XT_REFERER_CUSTOM)
2542 referer_mode = XT_REFERER_NEVER;
2543 return (1);
2546 return (0);
2550 set_referer_rt(char *value)
2552 if (value == NULL || strlen(value) == 0) {
2553 if (referer_custom)
2554 g_free(referer_custom);
2555 referer_custom = g_strdup(XT_DS_REFERER_CUSTOM);
2556 referer_mode = XT_DS_REFERER_MODE;
2557 return (0);
2559 return (set_referer(NULL, value));
2563 check_referer(char **tt)
2565 *tt = g_strdup("Default (depends on browser_mode):\n"
2566 "\tnormal:\talways\n"
2567 "\twhitelist:\tsame-domain\n"
2568 "\tkiosk:\talways");
2569 if (browser_mode == XT_BM_WHITELIST &&
2570 referer_mode != XT_REFERER_SAME_DOMAIN)
2571 return (1);
2572 if (browser_mode == XT_BM_NORMAL && referer_mode != XT_REFERER_ALWAYS)
2573 return (1);
2574 if (browser_mode == XT_BM_KIOSK && referer_mode != XT_REFERER_ALWAYS)
2575 return (1);
2576 return (0);
2579 char *
2580 get_ssl_ca_file(struct settings *s)
2582 if (strlen(ssl_ca_file) == 0)
2583 return (NULL);
2584 return (g_strdup(ssl_ca_file));
2588 set_refresh_interval(char *value)
2590 int tmp;
2591 const char *errstr;
2593 if (value == NULL || strlen(value) == 0)
2594 refresh_interval = XT_DS_REFRESH_INTERVAL;
2595 else {
2596 tmp = strtonum(value, 0, INT_MAX, &errstr);
2597 if (errstr)
2598 return (-1);
2599 refresh_interval = tmp;
2601 return (0);
2605 check_resource_dir(char **tt)
2607 *tt = g_strdup_printf("Default: %s", XT_DS_RESOURCE_DIR);
2608 return (g_strcmp0(resource_dir, XT_DS_RESOURCE_DIR));
2612 check_save_global_history(char **tt)
2614 *tt = g_strdup("Default: Disabled");
2615 return (save_global_history != 0);
2619 check_save_rejected_cookies(char **tt)
2621 *tt = g_strdup("Default: Disabled");
2622 return (save_rejected_cookies != 0);
2626 check_refresh_interval(char **tt)
2628 *tt = g_strdup_printf("Default: %d", XT_DS_REFRESH_INTERVAL);
2629 return (refresh_interval != XT_DS_REFRESH_INTERVAL);
2633 set_session_autosave(char *value)
2635 int tmp;
2636 const char *errstr;
2638 if (value == NULL || strlen(value) == 0)
2639 session_autosave = XT_DS_SESSION_AUTOSAVE;
2640 else {
2641 tmp = strtonum(value, 0, 1, &errstr);
2642 if (errstr)
2643 return (-1);
2644 session_autosave = tmp;
2646 return (0);
2650 check_session_autosave(char **tt)
2652 *tt = g_strdup_printf("Default: %s",
2653 XT_DS_SESSION_AUTOSAVE ? "Enabled" : "Disabled");
2654 return (session_autosave != XT_DS_SESSION_AUTOSAVE);
2658 set_session_timeout(char *value)
2660 int tmp;
2661 const char *errstr;
2663 if (value == NULL || strlen(value) == 0)
2664 session_timeout = XT_DS_SESSION_TIMEOUT;
2665 else {
2666 tmp = strtonum(value, 0, INT_MAX, &errstr);
2667 if (errstr)
2668 return (-1);
2669 session_timeout = tmp;
2671 return (0);
2675 check_session_timeout(char **tt)
2677 *tt = g_strdup_printf("Default: %d", XT_DS_SESSION_TIMEOUT);
2678 return (session_timeout != XT_DS_SESSION_TIMEOUT);
2682 set_show_scrollbars(char *value)
2684 struct tab *t;
2685 int tmp;
2686 const char *errstr;
2688 if (value == NULL || strlen(value) == 0)
2689 tmp = XT_DS_SHOW_SCROLLBARS;
2690 else {
2691 tmp = strtonum(value, 0, 1, &errstr);
2692 if (errstr)
2693 return (-1);
2695 show_scrollbars = tmp;
2696 TAILQ_FOREACH(t, &tabs, entry)
2697 if (set_scrollbar_visibility(t, show_scrollbars))
2698 return (-1);
2699 return (0);
2703 check_show_scrollbars(char **tt)
2705 *tt = g_strdup("Default (depends on gui_mode):\n"
2706 "\tclassic:\tEnabled\n"
2707 "\tminimal:\tDisabled");
2708 if (gui_mode == XT_GM_CLASSIC && show_scrollbars != 1)
2709 return (1);
2710 if (gui_mode == XT_GM_MINIMAL && show_scrollbars != 0)
2711 return (1);
2712 return (0);
2716 set_show_statusbar(char *value)
2718 int tmp;
2719 const char *errstr;
2721 if (value == NULL || strlen(value) == 0)
2722 tmp = XT_DS_SHOW_STATUSBAR;
2723 else {
2724 tmp = strtonum(value, 0, 1, &errstr);
2725 if (errstr)
2726 return (-1);
2728 show_statusbar = tmp;
2729 statusbar_set_visibility();
2730 return (0);
2734 check_show_statusbar(char **tt)
2736 *tt = g_strdup("Default (depends on gui_mode):\n"
2737 "\tclassic:\tDisabled\n"
2738 "\tminimal:\tEnabled");
2739 if (gui_mode == XT_GM_CLASSIC && show_statusbar != 0)
2740 return (1);
2741 if (gui_mode == XT_GM_MINIMAL && show_statusbar != 1)
2742 return (1);
2743 return (0);
2747 set_show_tabs(char *value)
2749 struct karg args = {0};
2750 int val;
2751 const char *errstr;
2753 if (value == NULL || strlen(value) == 0)
2754 val = XT_DS_SHOW_TABS;
2755 else {
2756 val = strtonum(value, 0, 1, &errstr);
2757 if (errstr)
2758 return (-1);
2760 args.i = val ? XT_TAB_SHOW : XT_TAB_HIDE;
2761 tabaction(get_current_tab(), &args);
2762 return (0);
2766 check_show_tabs(char **tt)
2768 *tt = g_strdup("Default (depends on gui_mode):\n"
2769 "\tclassic:\tEnabled\n"
2770 "\tminimal:\tDisabled");
2771 if (gui_mode == XT_GM_CLASSIC && show_tabs != 1)
2772 return (1);
2773 if (gui_mode == XT_GM_MINIMAL && show_tabs != 0)
2774 return (1);
2775 return (0);
2779 set_show_url(char *value)
2781 struct karg args = {0};
2782 int val;
2783 const char *errstr;
2785 if (value == NULL || strlen(value) == 0)
2786 val = XT_DS_SHOW_URL;
2787 else {
2788 val = strtonum(value, 0, 1, &errstr);
2789 if (errstr)
2790 return (-1);
2792 args.i = val ? XT_URL_SHOW : XT_URL_HIDE;
2793 urlaction(get_current_tab(), &args);
2794 return (0);
2798 check_show_url(char **tt)
2800 *tt = g_strdup("Default (depends on gui_mode):\n"
2801 "\tclassic:\tEnabled\n"
2802 "\tminimal:\tDisabled");
2803 if (gui_mode == XT_GM_CLASSIC && show_url != 1)
2804 return (1);
2805 if (gui_mode == XT_GM_MINIMAL && show_url != 0)
2806 return (1);
2807 return (0);
2811 check_single_instance(char **tt)
2813 *tt = g_strdup("Default: Disabled");
2814 return (single_instance != 0);
2818 set_spell_check_languages(char *value)
2820 struct tab *t;
2822 if (spell_check_languages)
2823 g_free(spell_check_languages);
2824 if (value == NULL || strlen(value) == 0)
2825 spell_check_languages = g_strdup(XT_DS_SPELL_CHECK_LANGUAGES);
2826 else
2827 spell_check_languages = g_strdup(value);
2828 TAILQ_FOREACH(t, &tabs, entry)
2829 g_object_set(G_OBJECT(t->settings), "spell_checking_languages",
2830 spell_check_languages, (char *)NULL);
2831 return (0);
2835 check_spell_check_languages(char **tt)
2837 *tt = g_strdup_printf("Default: %s", XT_DS_SPELL_CHECK_LANGUAGES);
2838 return (g_strcmp0(spell_check_languages, XT_DS_SPELL_CHECK_LANGUAGES));
2842 check_valid_file(char *name)
2844 struct stat sb;
2846 if (name == NULL || stat(name, &sb))
2847 return (-1);
2848 return (0);
2852 set_ssl_ca_file_rt(char *value)
2854 if (value == NULL || strlen(value) == 0) {
2855 strlcpy(ssl_ca_file, XT_DS_SSL_CA_FILE, sizeof ssl_ca_file);
2856 g_object_set(session, SOUP_SESSION_SSL_CA_FILE, "", NULL);
2857 return (0);
2858 } else
2859 return (set_ssl_ca_file(NULL, value));
2863 check_ssl_ca_file(char **tt)
2865 *tt = g_strdup("Default: (empty)");
2866 return (g_strcmp0(ssl_ca_file, XT_DS_SSL_CA_FILE));
2870 set_ssl_strict_certs(char *value)
2872 int tmp;
2873 const char *errstr;
2875 if (value == NULL || strlen(value) == 0)
2876 ssl_strict_certs = XT_DS_SSL_STRICT_CERTS;
2877 else {
2878 tmp = strtonum(value, 0, 1, &errstr);
2879 if (errstr)
2880 return (-1);
2881 ssl_strict_certs = tmp;
2883 g_object_set(session, SOUP_SESSION_SSL_STRICT, ssl_strict_certs, NULL);
2884 return (0);
2888 check_ssl_strict_certs(char **tt)
2890 *tt = g_strdup_printf("Default: %s",
2891 XT_DS_SSL_STRICT_CERTS ? "Enabled" : "Disabled");
2892 return (ssl_strict_certs != XT_DS_SSL_STRICT_CERTS);
2896 check_statusbar_elems(char **tt)
2898 *tt = g_strdup("Default: BP");
2899 return (g_strcmp0(statusbar_elems, "BP"));
2903 set_external_editor(char *editor)
2905 if (external_editor)
2906 g_free(external_editor);
2907 if (editor == NULL || strlen(editor) == 0)
2908 external_editor = NULL;
2909 else
2910 external_editor = g_strdup(editor);
2911 return (0);
2915 check_external_editor(char **tt)
2917 *tt = g_strdup("Default: (empty)");
2918 return (g_strcmp0(external_editor, NULL));
2922 set_fancy_bar(char *value)
2924 struct tab *t;
2925 int tmp;
2926 const char *errstr;
2928 if (value == NULL || strlen(value) == 0)
2929 fancy_bar = 1; /* XXX */
2930 else {
2931 tmp = strtonum(value, 0, 1, &errstr);
2932 if (errstr)
2933 return (-1);
2934 fancy_bar = tmp;
2936 TAILQ_FOREACH(t, &tabs, entry)
2937 if (fancy_bar) {
2938 gtk_widget_show(t->backward);
2939 gtk_widget_show(t->forward);
2940 gtk_widget_show(t->stop);
2941 gtk_widget_show(t->js_toggle);
2942 if (search_string && strlen(search_string))
2943 gtk_widget_show(t->search_entry);
2944 } else {
2945 gtk_widget_hide(t->backward);
2946 gtk_widget_hide(t->forward);
2947 gtk_widget_hide(t->stop);
2948 gtk_widget_hide(t->js_toggle);
2949 gtk_widget_hide(t->search_entry);
2951 return (0);
2955 check_fancy_bar(char **tt)
2957 *tt = g_strdup("Default (depends on gui_mode):\n"
2958 "\tclassic:\tEnabled\n"
2959 "\tminimal:\tDisabled");
2960 if (gui_mode == XT_GM_CLASSIC && fancy_bar != 1)
2961 return (1);
2962 if (gui_mode == XT_GM_MINIMAL && fancy_bar != 0)
2963 return (1);
2964 return (0);
2967 void
2968 setup_proxy(char *uri)
2970 struct tab *t;
2972 if (proxy_uri) {
2973 g_object_set(session, "proxy_uri", NULL, (char *)NULL);
2974 soup_uri_free(proxy_uri);
2975 proxy_uri = NULL;
2976 TAILQ_FOREACH(t, &tabs, entry)
2977 gtk_label_set_text(GTK_LABEL(t->sbe.proxy), "");
2979 if (http_proxy) {
2980 if (http_proxy != uri) {
2981 g_free(http_proxy);
2982 http_proxy = NULL;
2986 if (uri) {
2987 http_proxy = g_strdup(uri);
2988 DNPRINTF(XT_D_CONFIG, "setup_proxy: %s\n", uri);
2989 proxy_uri = soup_uri_new(http_proxy);
2990 if (proxy_uri != NULL && SOUP_URI_VALID_FOR_HTTP(proxy_uri)) {
2991 g_object_set(session, "proxy-uri", proxy_uri,
2992 (char *)NULL);
2993 TAILQ_FOREACH(t, &tabs, entry)
2994 gtk_label_set_text(GTK_LABEL(t->sbe.proxy),
2995 "proxy");
3000 char *
3001 get_tab_style(struct settings *s)
3003 if (tab_style == XT_TABS_NORMAL)
3004 return (g_strdup("normal"));
3005 else
3006 return (g_strdup("compact"));
3010 set_tab_style(struct settings *s, char *val)
3012 if (!strcmp(val, "normal"))
3013 tab_style = XT_TABS_NORMAL;
3014 else if (!strcmp(val, "compact"))
3015 tab_style = XT_TABS_COMPACT;
3016 else
3017 return (1);
3019 return (0);
3023 check_tab_style(char **tt)
3025 *tt = g_strdup("Default (depends on gui_mode):\n"
3026 "\tclassic:\tnormal\n"
3027 "\tminimal:\tcompact");
3028 if (gui_mode == XT_GM_CLASSIC && tab_style != XT_TABS_NORMAL)
3029 return (1);
3030 if (gui_mode == XT_GM_MINIMAL && tab_style != XT_TABS_COMPACT)
3031 return (1);
3032 return (0);
3036 set_tab_style_rt(char *value)
3038 struct karg args = {0};
3039 int old_tab_style;
3041 if (value == NULL || strlen(value) == 0) {
3042 if (tab_style == XT_DS_TAB_STYLE)
3043 return (0);
3044 tab_style = XT_TABS_COMPACT;
3045 args.i = XT_TAB_NEXTSTYLE;
3046 } else {
3047 old_tab_style = tab_style;
3048 if (set_tab_style(NULL, value))
3049 return (-1);
3050 if (old_tab_style != tab_style) {
3051 tab_style = old_tab_style;
3052 args.i = XT_TAB_NEXTSTYLE;
3055 tabaction(get_current_tab(), &args);
3056 return (0);
3059 char *
3060 get_statusbar_style(struct settings *s)
3062 if (statusbar_style == XT_STATUSBAR_URL)
3063 return (g_strdup("url"));
3064 else
3065 return (g_strdup("title"));
3069 set_statusbar_style(struct settings *s, char *val)
3071 if (!strcmp(val, "url"))
3072 statusbar_style = XT_STATUSBAR_URL;
3073 else if (!strcmp(val, "title"))
3074 statusbar_style = XT_STATUSBAR_TITLE;
3075 else
3076 return (1);
3078 return (0);
3082 set_statusbar_style_rt(char *value)
3084 struct tab *t;
3085 const gchar *page_uri;
3087 if (value == NULL || strlen(value) == 0) {
3088 if (statusbar_style == XT_DS_STATUSBAR_STYLE)
3089 return (0);
3090 statusbar_style = XT_DS_STATUSBAR_STYLE;
3091 } else {
3092 if (!strcmp(value, "url"))
3093 statusbar_style = XT_STATUSBAR_URL;
3094 else if (!strcmp(value, "title"))
3095 statusbar_style = XT_STATUSBAR_TITLE;
3098 /* apply changes */
3099 TAILQ_FOREACH(t, &tabs, entry) {
3100 if (statusbar_style == XT_STATUSBAR_TITLE)
3101 set_status(t, "%s", get_title(t, FALSE));
3102 else if ((page_uri = get_uri(t)) != NULL)
3103 set_status(t, "%s", page_uri);
3106 return (0);
3110 check_statusbar_style(char **tt)
3112 *tt = g_strdup("Default: url");
3113 return (statusbar_style != XT_DS_STATUSBAR_STYLE);
3117 set_url_regex(char *value)
3119 if (value == NULL || strlen(value) == 0) {
3120 if (url_regex)
3121 g_free(url_regex);
3122 url_regex = g_strdup(XT_DS_URL_REGEX);
3123 } else {
3124 if (regcomp(&url_re, value, REG_EXTENDED | REG_NOSUB))
3125 return (-1);
3126 if (url_regex)
3127 g_free(url_regex);
3128 url_regex = g_strdup(value);
3130 return (0);
3134 check_url_regex(char **tt)
3136 *tt = g_strdup_printf("Default: %s", XT_DS_URL_REGEX);
3137 return (g_strcmp0(url_regex, XT_DS_URL_REGEX));
3141 set_userstyle(struct settings *s, char *value)
3143 int rv = 0;
3144 char script[PATH_MAX] = {'\0'};
3145 char *tmp;
3147 if (value == NULL || strlen(value) == 0) {
3148 snprintf(script, sizeof script, "%s" PS "style.css", resource_dir);
3149 tmp = g_filename_to_uri(script, NULL, NULL);
3150 if (tmp == NULL)
3151 rv = -1;
3152 else {
3153 if (userstyle)
3154 g_free(userstyle);
3155 userstyle = tmp;
3157 } else {
3158 expand_tilde(script, sizeof script, value);
3159 tmp = g_filename_to_uri(script, NULL, NULL);
3160 if (tmp == NULL)
3161 rv = -1;
3162 else {
3163 if (userstyle)
3164 g_free(userstyle);
3165 userstyle = tmp;
3168 if (stylesheet)
3169 g_free(stylesheet);
3170 stylesheet = g_strdup(userstyle);
3171 return (rv);
3174 char *
3175 get_userstyle(struct settings *s)
3177 if (userstyle)
3178 return (g_filename_from_uri(userstyle, NULL, NULL));
3179 return (NULL);
3183 set_userstyle_rt(char *value)
3185 return (set_userstyle(NULL, value));
3189 check_userstyle(char **tt)
3191 int rv = 0;
3192 char buf[PATH_MAX];
3193 char *file = NULL;
3195 snprintf(buf, sizeof buf, "%s" PS "%s", resource_dir, "style.css");
3196 *tt = g_strdup_printf("Default: %s", buf);
3197 file = g_filename_from_uri(userstyle, NULL, NULL);
3198 rv = g_strcmp0(file, buf);
3199 if (file)
3200 g_free(file);
3201 return (rv);
3205 set_userstyle_global(char *value)
3207 struct karg args = {0};
3208 int tmp, old_style;
3209 const char *errstr;
3211 if (value == NULL || strlen(value) == 0) {
3212 if (userstyle_global == XT_DS_USERSTYLE_GLOBAL)
3213 return (0);
3214 userstyle_global = 1;
3215 args.i = XT_STYLE_GLOBAL;
3216 userstyle_cmd(get_current_tab(), &args);
3217 } else {
3218 old_style = userstyle_global;
3219 tmp = strtonum(value, 0, 1, &errstr);
3220 if (errstr)
3221 return (-1);
3222 if (tmp != old_style) {
3223 args.i = XT_STYLE_GLOBAL;
3224 userstyle_cmd(get_current_tab(), &args);
3227 return (0);
3231 check_userstyle_global(char **tt)
3233 *tt = g_strdup_printf("Default: %s",
3234 XT_DS_USERSTYLE_GLOBAL ? "Enabled" : "Disabled");
3235 return (userstyle_global != XT_DS_USERSTYLE_GLOBAL);
3239 set_warn_cert_changes(char *value)
3241 int tmp;
3242 const char *errstr;
3244 if (value == NULL || strlen(value) == 0)
3245 warn_cert_changes = XT_DS_WARN_CERT_CHANGES;
3246 else {
3247 tmp = strtonum(value, 0, 1, &errstr);
3248 if (errstr)
3249 return (-1);
3250 warn_cert_changes = tmp;
3252 return (0);
3256 check_warn_cert_changes(char **tt)
3258 *tt = g_strdup_printf("Default: %s",
3259 XT_DS_WARN_CERT_CHANGES ? "Enabled" : "Disabled");
3260 return (warn_cert_changes != XT_DS_WARN_CERT_CHANGES);
3264 check_window_height(char **tt)
3266 *tt = g_strdup_printf("Default: %d", 768);
3267 return (window_height != 768);
3271 check_window_maximize(char **tt)
3273 *tt = g_strdup("Default: Disabled");
3274 return (window_maximize != 0);
3278 check_window_width(char **tt)
3280 *tt = g_strdup_printf("Default: %d", 768);
3281 return (window_width != 1024);
3285 check_work_dir(char **tt)
3287 struct passwd *pwd;
3288 char buf[PATH_MAX];
3290 if ((pwd = getpwuid(getuid())) == NULL)
3291 return (-1);
3292 snprintf(buf, sizeof buf, "%s" PS ".xombrero", pwd->pw_dir);
3293 *tt = g_strdup_printf("Default: %s", buf);
3294 return (g_strcmp0(work_dir, buf));
3297 char *
3298 get_edit_mode(struct settings *s)
3300 if (edit_mode == XT_EM_HYBRID)
3301 return (g_strdup("hybrid"));
3302 else
3303 return (g_strdup("vi"));
3307 set_edit_mode(struct settings *s, char *val)
3309 if (!strcmp(val, "hybrid"))
3310 edit_mode = XT_EM_HYBRID;
3311 else if (!strcmp(val, "vi"))
3312 edit_mode = XT_EM_VI;
3313 else
3314 return (1);
3316 return (0);
3320 check_edit_mode(char **tt)
3322 *tt = g_strdup("Default: hybrid");
3323 return (edit_mode != XT_EM_HYBRID);
3326 char *
3327 get_download_mode(struct settings *s)
3329 switch (download_mode) {
3330 case XT_DM_START:
3331 return (g_strdup("start"));
3332 break;
3333 case XT_DM_ASK:
3334 return (g_strdup("ask"));
3335 break;
3336 case XT_DM_ADD:
3337 return (g_strdup("add"));
3338 break;
3340 return (g_strdup("unknown"));
3344 set_download_mode(struct settings *s, char *val)
3346 if (val == NULL || strlen(val) == 0 || !strcmp(val, "start"))
3347 download_mode = XT_DM_START;
3348 else if (!strcmp(val, "ask"))
3349 download_mode = XT_DM_ASK;
3350 else if (!strcmp(val, "add"))
3351 download_mode = XT_DM_ADD;
3352 else
3353 return (1);
3355 return (0);
3359 set_download_mode_rt(char *val)
3361 return (set_download_mode(NULL, val));
3365 check_download_mode(char **tt)
3367 *tt = g_strdup("Default: start");
3368 return (download_mode != XT_DM_START);
3371 char *
3372 get_work_dir(struct settings *s)
3374 if (work_dir[0] == '\0')
3375 return (0);
3376 return (g_strdup(work_dir));
3380 set_work_dir(struct settings *s, char *val)
3382 expand_tilde(work_dir, sizeof work_dir, val);
3383 return (0);
3386 void
3387 walk_cookie_wl(struct settings *s,
3388 void (*cb)(struct settings *, char *, void *), void *cb_args)
3390 struct domain *d;
3392 if (s == NULL || cb == NULL) {
3393 show_oops(NULL, "walk_cookie_wl invalid parameters");
3394 return;
3397 RB_FOREACH_REVERSE(d, domain_list, &c_wl)
3398 cb(s, d->d, cb_args);
3401 void
3402 walk_js_wl(struct settings *s,
3403 void (*cb)(struct settings *, char *, void *), void *cb_args)
3405 struct domain *d;
3407 if (s == NULL || cb == NULL) {
3408 show_oops(NULL, "walk_js_wl invalid parameters");
3409 return;
3412 RB_FOREACH_REVERSE(d, domain_list, &js_wl)
3413 cb(s, d->d, cb_args);
3416 void
3417 walk_pl_wl(struct settings *s,
3418 void (*cb)(struct settings *, char *, void *), void *cb_args)
3420 struct domain *d;
3422 if (s == NULL || cb == NULL) {
3423 show_oops(NULL, "walk_pl_wl invalid parameters");
3424 return;
3427 RB_FOREACH_REVERSE(d, domain_list, &pl_wl)
3428 cb(s, d->d, cb_args);
3431 void
3432 walk_force_https(struct settings *s,
3433 void (*cb)(struct settings *, char *, void *), void *cb_args)
3435 struct domain *d;
3437 if (s == NULL || cb == NULL) {
3438 show_oops(NULL, "walk_force_https invalid parameters");
3439 return;
3442 RB_FOREACH_REVERSE(d, domain_list, &force_https)
3443 cb(s, d->d, cb_args);
3447 settings_add(char *var, char *val)
3449 int i, rv, *p;
3450 gfloat *f;
3451 char c[PATH_MAX], **s;
3453 /* get settings */
3454 for (i = 0, rv = 0; i < LENGTH(rs); i++) {
3455 if (strcmp(var, rs[i].name))
3456 continue;
3458 if (!strcmp(var, "include_config")) {
3459 expand_tilde(c, sizeof c, val);
3460 config_parse(c, 0);
3461 rv = 1;
3462 break;
3465 if (rs[i].s) {
3466 if (rs[i].s->set(&rs[i], val))
3467 startpage_add("invalid value for %s: %s", var,
3468 val);
3469 rv = 1;
3470 break;
3471 } else
3472 switch (rs[i].type) {
3473 case XT_S_INT: /* FALLTHROUGH */
3474 case XT_S_BOOL:
3475 p = rs[i].ival;
3476 *p = atoi(val);
3477 rv = 1;
3478 break;
3479 case XT_S_STR:
3480 s = rs[i].sval;
3481 if (s == NULL)
3482 errx(1, "invalid sval for %s",
3483 rs[i].name);
3484 if (*s)
3485 g_free(*s);
3486 *s = g_strdup(val);
3487 rv = 1;
3488 break;
3489 case XT_S_FLOAT:
3490 f = rs[i].fval;
3491 *f = atof(val);
3492 rv = 1;
3493 break;
3494 case XT_S_INVALID:
3495 default:
3496 errx(1, "invalid type for %s", var);
3498 break;
3500 return (rv);
3503 #define WS "\n= \t"
3504 void
3505 config_parse(char *filename, int runtime)
3507 FILE *config, *f;
3508 char *line, *cp, *var, *val;
3509 size_t len, lineno = 0;
3510 int handled;
3511 char file[PATH_MAX];
3512 struct stat sb;
3514 DNPRINTF(XT_D_CONFIG, "config_parse: filename %s\n", filename);
3516 if (filename == NULL)
3517 return;
3519 if (runtime && runtime_settings[0] != '\0') {
3520 snprintf(file, sizeof file, "%s" PS "%s",
3521 work_dir, runtime_settings);
3522 if (stat(file, &sb)) {
3523 warnx("runtime file doesn't exist, creating it");
3524 if ((f = fopen(file, "w")) == NULL)
3525 err(1, "runtime");
3526 fprintf(f, "# AUTO GENERATED, DO NOT EDIT\n");
3527 fclose(f);
3529 } else
3530 strlcpy(file, filename, sizeof file);
3532 if ((config = fopen(file, "r")) == NULL) {
3533 warn("config_parse: cannot open %s", filename);
3534 return;
3537 for (;;) {
3538 if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL)
3539 if (feof(config) || ferror(config))
3540 break;
3542 cp = line;
3543 cp += (long)strspn(cp, WS);
3544 if (cp[0] == '\0') {
3545 /* empty line */
3546 free(line);
3547 continue;
3550 if ((var = strsep(&cp, WS)) == NULL || cp == NULL)
3551 startpage_add("invalid configuration file entry: %s",
3552 line);
3553 else {
3554 cp += (long)strspn(cp, WS);
3556 if ((val = strsep(&cp, "\0")) == NULL)
3557 break;
3559 DNPRINTF(XT_D_CONFIG, "config_parse: %s=%s\n",
3560 var, val);
3561 handled = settings_add(var, val);
3563 if (handled == 0)
3564 startpage_add("invalid configuration file entry"
3565 ": %s=%s", var, val);
3568 free(line);
3571 fclose(config);
3574 struct settings_args {
3575 char **body;
3576 int i;
3579 void
3580 print_setting(struct settings *s, char *val, void *cb_args)
3582 char *enc_val, *tmp, *color;
3583 struct settings_args *sa = cb_args;
3585 if (sa == NULL || s->flags & XT_SF_INVISIBLE)
3586 return;
3588 if (s->flags & XT_SF_RUNTIME)
3589 color = "#22cc22";
3590 else
3591 color = "#cccccc";
3593 enc_val = html_escape(val);
3594 tmp = *sa->body;
3595 *sa->body = g_strdup_printf(
3596 "%s\n<tr>"
3597 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
3598 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
3599 *sa->body,
3600 color,
3601 s->name,
3602 color,
3603 enc_val == NULL ? "" : enc_val
3605 g_free(tmp);
3606 if (enc_val)
3607 g_free(enc_val);
3608 sa->i++;
3611 void
3612 print_runtime_setting(struct settings *s, char *val, void *cb_args)
3614 char *tmp, *tt = NULL;
3615 struct settings_args *sa = cb_args;
3616 int modified = 0;
3617 int i;
3619 if (sa == NULL)
3620 return;
3622 if (s == NULL || s->flags & XT_SF_INVISIBLE || s->activate == NULL)
3623 return;
3625 tmp = *sa->body;
3626 if (s->ismodified)
3627 modified = s->ismodified(&tt);
3628 *sa->body = g_strdup_printf(
3629 "%s\n<tr %s>"
3630 "<td title=\"%s\" style='width: 240px;'><div style='width: 100%%;'>%s</div></td>"
3631 "<td title=\"%s\"><div style='width: 100%%; word-break:break-all'>",
3632 *sa->body,
3633 modified ? "id='modified'" : "",
3634 s->tt ? s->tt : "",
3635 s->name,
3636 tt);
3637 g_free(tmp);
3638 g_free(tt);
3640 tmp = *sa->body;
3641 if (s->type == XT_S_STR && s->s && s->s->valid_options[0]) {
3642 *sa->body = g_strdup_printf("%s<select name='%s'>",
3643 *sa->body,
3644 s->name);
3645 for (i = 0; s->s->valid_options[i]; ++i) {
3646 g_free(tmp);
3647 tmp = *sa->body;
3648 *sa->body = g_strdup_printf("%s"
3649 "<option value='%s' %s>%s</option>",
3650 *sa->body,
3651 s->s->valid_options[i],
3652 !strcmp(s->s->valid_options[i], val) ? "selected" : "",
3653 s->s->valid_options[i]);
3655 } else if (s->type == XT_S_STR)
3656 *sa->body = g_strdup_printf(
3657 "%s<input style='width: 98%%' type='text' name='%s' value='%s'>"
3658 "</div></td></tr>",
3659 *sa->body,
3660 s->name,
3661 val ? val : "");
3662 else if (s->type == XT_S_INT)
3663 *sa->body = g_strdup_printf(
3664 "%s<input type='number' name='%s' value='%s'>"
3665 "</div></td></tr>",
3666 *sa->body,
3667 s->name,
3668 val);
3669 else if (s->type == XT_S_FLOAT)
3670 *sa->body = g_strdup_printf(
3671 "%s<input type='number' step='0.000001' name='%s' value='%s'>"
3672 "</div></td></tr>",
3673 *sa->body,
3674 s->name,
3675 val);
3676 else if (s->type == XT_S_BOOL)
3677 *sa->body = g_strdup_printf(
3678 "%s<input type='hidden' name='%s' value='0'>"
3679 "<input type='checkbox' name='%s' value='1''%s>"
3680 "</div></td></tr>",
3681 *sa->body,
3682 s->name,
3683 s->name,
3684 atoi(val) ? " checked='checked'" : "");
3685 else {
3686 *sa->body = g_strdup(*sa->body);
3687 warnx("Did not print setting %s", s->name);
3689 g_free(tmp);
3690 sa->i++;
3693 char *
3694 print_set_rejects(void)
3696 struct set_reject *sr, *st;
3697 char *body = NULL, *tmp;
3699 if (TAILQ_EMPTY(&srl))
3700 return (NULL);
3702 body = g_strdup_printf("The following settings were invalid and could "
3703 "not be set:<br><div align='center'><table id='settings'>"
3704 "<th align='left'>Setting</th>"
3705 "<th align='left'>Value</th>");
3706 TAILQ_FOREACH_SAFE(sr, &srl, entry, st) {
3707 tmp = body;
3708 body = g_strdup_printf("%s\n<tr>"
3709 "<td style='width:240px'><div>%s</div></td>"
3710 "<td><div style='word-break:break-all'>%s</div></td></tr>",
3711 body,
3712 sr->name,
3713 sr->value);
3714 g_free(tmp);
3715 TAILQ_REMOVE(&srl, sr, entry);
3716 g_free(sr->name);
3717 g_free(sr->value);
3718 g_free(sr);
3720 tmp = body;
3721 body = g_strdup_printf("%s</table></div><br>", body);
3722 g_free(tmp);
3723 return (body);
3727 xtp_page_set(struct tab *t, struct karg *args)
3729 char *body, *page, *tmp;
3730 int i = 1;
3731 struct settings_args sa;
3733 bzero(&sa, sizeof sa);
3734 sa.body = &body;
3736 /* body */
3737 body = g_strdup_printf("<div align='center'><table><tr>"
3738 "<th align='left'>Setting</th>"
3739 "<th align='left'>Value</th></tr>\n");
3741 settings_walk(print_setting, &sa);
3742 i = sa.i;
3744 /* small message if there are none */
3745 if (i == 1) {
3746 tmp = body;
3747 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3748 "colspan='2'>No settings</td></tr>\n", body);
3749 g_free(tmp);
3752 tmp = body;
3753 body = g_strdup_printf("%s</table></div>", body);
3754 g_free(tmp);
3756 page = get_html_page("Settings", body, "", 0);
3758 g_free(body);
3760 load_webkit_string(t, page, XT_URI_ABOUT_SET);
3762 g_free(page);
3764 return (XT_CB_PASSTHROUGH);
3768 xtp_page_rt(struct tab *t, struct karg *args)
3770 char *body = NULL, *page, *tmp;
3771 int i = 1;
3772 struct settings_args sa;
3774 generate_xtp_session_key(&t->session_key);
3776 bzero(&sa, sizeof sa);
3777 sa.body = &body;
3779 /* body */
3780 body = print_set_rejects();
3782 tmp = body;
3783 body = g_strdup_printf("%s<div align='center'>"
3784 "<form method='GET' action='%s%d/%s/%d'>"
3785 "<input type='submit' value='Save Settings'>"
3786 "<table id='settings'>"
3787 "<th align='left'>Setting</th>"
3788 "<th align='left'>Value</th>\n",
3789 body ? body : "",
3790 XT_XTP_STR,
3791 XT_XTP_RT,
3792 t->session_key,
3793 XT_XTP_RT_SAVE);
3794 g_free(tmp);
3796 settings_walk(print_runtime_setting, &sa);
3797 i = sa.i;
3799 /* small message if there are none */
3800 if (i == 1) {
3801 tmp = body;
3802 body = g_strdup_printf("%s\n<tr><td style='text-align:center'"
3803 "colspan='2'>No settings</td></tr>\n", body);
3804 g_free(tmp);
3807 tmp = body;
3808 body = g_strdup_printf("%s</table>"
3809 "<input type='submit' value='Save Settings'></form></div>", body);
3810 g_free(tmp);
3812 page = get_html_page("Runtime Settings", body, "", 1);
3814 g_free(body);
3816 load_webkit_string(t, page, XT_URI_ABOUT_RUNTIME);
3818 g_free(page);
3820 return (XT_CB_PASSTHROUGH);
3824 set(struct tab *t, struct karg *args)
3826 char *p, *val;
3827 int i;
3829 if (args == NULL || args->s == NULL)
3830 return (xtp_page_set(t, args));
3832 /* strip spaces */
3833 p = g_strstrip(args->s);
3835 if (strlen(p) == 0)
3836 return (xtp_page_set(t, args));
3838 /* we got some sort of string */
3839 val = g_strstr_len(p, strlen(p), "=");
3840 if (val) {
3841 *val++ = '\0';
3842 val = g_strstrip(val);
3843 p = g_strchomp(p);
3845 for (i = 0; i < get_settings_size(); i++) {
3846 if (strcmp(rs[i].name, p))
3847 continue;
3849 if (rs[i].activate) {
3850 if (rs[i].activate(val))
3851 show_oops(t, "%s invalid value %s",
3852 p, val);
3853 else
3854 show_oops(t, ":set %s = %s", p, val);
3855 goto done;
3856 } else {
3857 show_oops(t, "not a runtime option: %s", p);
3858 goto done;
3861 show_oops(t, "unknown option: %s", p);
3862 } else {
3863 p = g_strchomp(p);
3865 for (i = 0; i < get_settings_size(); i++) {
3866 if (strcmp(rs[i].name, p))
3867 continue;
3869 /* XXX this could use some cleanup */
3870 switch (rs[i].type) {
3871 case XT_S_INT: /* FALLTHROUGH */
3872 case XT_S_BOOL:
3873 if (rs[i].ival)
3874 show_oops(t, "%s = %d",
3875 rs[i].name, *rs[i].ival);
3876 else if (rs[i].s && rs[i].s->get)
3877 show_oops(t, "%s = %s",
3878 rs[i].name,
3879 rs[i].s->get(&rs[i]));
3880 else if (rs[i].s && rs[i].s->get == NULL)
3881 show_oops(t, "%s = ...", rs[i].name);
3882 else
3883 show_oops(t, "%s = ", rs[i].name);
3884 break;
3885 case XT_S_FLOAT:
3886 if (rs[i].fval)
3887 show_oops(t, "%s = %f",
3888 rs[i].name, *rs[i].fval);
3889 else if (rs[i].s && rs[i].s->get)
3890 show_oops(t, "%s = %s",
3891 rs[i].name,
3892 rs[i].s->get(&rs[i]));
3893 else if (rs[i].s && rs[i].s->get == NULL)
3894 show_oops(t, "%s = ...", rs[i].name);
3895 else
3896 show_oops(t, "%s = ", rs[i].name);
3897 break;
3898 case XT_S_STR:
3899 if (rs[i].sval && *rs[i].sval)
3900 show_oops(t, "%s = %s",
3901 rs[i].name, *rs[i].sval);
3902 else if (rs[i].s && rs[i].s->get)
3903 show_oops(t, "%s = %s",
3904 rs[i].name,
3905 rs[i].s->get(&rs[i]));
3906 else if (rs[i].s && rs[i].s->get == NULL)
3907 show_oops(t, "%s = ...", rs[i].name);
3908 else
3909 show_oops(t, "%s = ", rs[i].name);
3910 break;
3911 default:
3912 show_oops(t, "unknown type for %s", rs[i].name);
3913 goto done;
3916 goto done;
3918 show_oops(t, "unknown option: %s", p);
3920 done:
3921 return (XT_CB_PASSTHROUGH);