2 * Copyright (c) 2010, 2011 Marco Peereboom <marco@peereboom.us>
3 * Copyright (c) 2011 Stevan Andjelkovic <stevan@student.chalmers.se>
4 * Copyright (c) 2010, 2011 Edd Barrett <vext01@gmail.com>
5 * Copyright (c) 2011 Todd T. Fries <todd@fries.net>
6 * Copyright (c) 2011 Raphael Graf <r@undefined.ch>
7 * Copyright (c) 2011 Michal Mazurek <akfaew@jasminek.net>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 SoupURI
*proxy_uri
= NULL
;
26 PangoFontDescription
*cmd_font
;
27 PangoFontDescription
*oops_font
;
28 PangoFontDescription
*statusbar_font
;
29 PangoFontDescription
*tabbar_font
;
30 extern regex_t url_re
;
32 /* settings that require restart */
33 int tabless
= 0; /* allow only 1 tab */
34 int enable_socket
= 0;
35 int single_instance
= 0; /* only allow one xxxterm to run */
36 int fancy_bar
= 1; /* fancy toolbar */
37 int browser_mode
= XT_BM_NORMAL
;
38 int gui_mode
= XT_GM_CLASSIC
;
39 int enable_localstorage
= 1;
40 char *statusbar_elems
= NULL
;
42 /* runtime settings */
43 int show_tabs
= 1; /* show tabs on notebook */
44 int tab_style
= XT_TABS_NORMAL
; /* tab bar style */
45 int show_url
= 1; /* show url toolbar on notebook */
46 int show_statusbar
= 0; /* vimperator style status bar */
47 int ctrl_click_focus
= 0; /* ctrl click gets focus */
48 int cookies_enabled
= 1; /* enable cookies */
49 int read_only_cookies
= 0; /* enable to not write cookies */
50 int enable_scripts
= 1;
51 int enable_plugins
= 1;
52 gfloat default_zoom_level
= 1.0;
53 char default_script
[PATH_MAX
];
54 int window_height
= 768;
55 int window_width
= 1024;
56 int window_maximize
= 0;
57 int icon_size
= 2; /* 1 = smallest, 2+ = bigger */
58 int refresh_interval
= 10; /* download refresh interval */
59 int enable_plugin_whitelist
= 0;
60 int enable_cookie_whitelist
= 0;
61 int enable_js_whitelist
= 0;
62 int session_timeout
= 3600; /* cookie session timeout */
63 int cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
64 char *ssl_ca_file
= NULL
;
65 char *resource_dir
= NULL
;
66 gboolean ssl_strict_certs
= FALSE
;
67 gboolean enable_strict_transport
= TRUE
;
68 int append_next
= 1; /* append tab after current tab */
70 char *search_string
= NULL
;
71 char *http_proxy
= NULL
;
72 char download_dir
[PATH_MAX
];
73 int download_mode
= XT_DM_START
;
74 char runtime_settings
[PATH_MAX
]; /* override of settings */
75 int allow_volatile_cookies
= 0;
76 int color_visited_uris
= 1;
77 int save_global_history
= 0; /* save global history to disk */
78 struct user_agent
*user_agent
= NULL
;
79 int save_rejected_cookies
= 0;
80 int session_autosave
= 0;
82 int dns_prefetch
= FALSE
;
83 gint max_connections
= 25;
84 gint max_host_connections
= 5;
85 gint enable_spell_checking
= 0;
86 char *spell_check_languages
= NULL
;
87 int xterm_workaround
= 0;
88 char *url_regex
= NULL
;
89 int history_autosave
= 0;
90 char search_file
[PATH_MAX
];
91 char command_file
[PATH_MAX
];
92 char *encoding
= NULL
;
93 int autofocus_onload
= 0;
94 int enable_js_autorun
= 1;
95 int edit_mode
= XT_EM_HYBRID
;
96 int userstyle_global
= 0;
97 int auto_load_images
= 1;
98 int enable_autoscroll
= 0;
99 int enable_favicon_entry
= 1;
100 int enable_favicon_tabs
= 0;
101 char *external_editor
= NULL
;
102 int referer_mode
= XT_REFERER_ALWAYS
;
103 char *referer_custom
= NULL
;
104 int download_notifications
= 0;
105 char *include_config
= NULL
;
107 char *cmd_font_name
= NULL
;
108 char *oops_font_name
= NULL
;
109 char *statusbar_font_name
= NULL
;
110 char *tabbar_font_name
= NULL
;
112 char *get_download_dir(struct settings
*);
113 char *get_default_script(struct settings
*);
114 char *get_runtime_dir(struct settings
*);
115 char *get_tab_style(struct settings
*);
116 char *get_edit_mode(struct settings
*);
117 char *get_download_mode(struct settings
*);
118 char *get_work_dir(struct settings
*);
119 char *get_referer(struct settings
*);
121 int add_cookie_wl(struct settings
*, char *);
122 int add_js_wl(struct settings
*, char *);
123 int add_pl_wl(struct settings
*, char *);
124 int add_mime_type(struct settings
*, char *);
125 int add_alias(struct settings
*, char *);
126 int add_kb(struct settings
*, char *);
127 int add_ua(struct settings
*, char *);
129 int set_append_next(char *);
130 int set_cmd_font(char *);
131 int set_color_visited_uris(char *);
132 int set_cookie_policy_rt(char *);
133 int set_cookies_enabled(char *);
134 int set_ctrl_click_focus(char *);
135 int set_home(char *);
136 int set_download_dir(struct settings
*, char *);
137 int set_download_notifications(char *);
138 int set_default_script(struct settings
*, char *);
139 int set_default_script_rt(char *);
140 int set_default_zoom_level(char *);
141 int set_enable_cookie_whitelist(char *);
142 int set_enable_js_autorun(char *);
143 int set_enable_js_whitelist(char *);
144 int set_enable_localstorage(char *);
145 int set_enable_plugins(char *);
146 int set_enable_plugin_whitelist(char *);
147 int set_enable_scripts(char *);
148 int set_enable_spell_checking(char *);
149 int set_enable_strict_transport(char *);
150 int set_encoding_rt(char *);
151 int set_runtime_dir(struct settings
*, char *);
152 int set_tabbar_font(char *value
);
153 int set_tab_style(struct settings
*, char *);
154 int set_tab_style_rt(char *);
155 int set_edit_mode(struct settings
*, char *);
156 int set_work_dir(struct settings
*, char *);
157 int set_auto_load_images(char *);
158 int set_enable_autoscroll(char *);
159 int set_enable_favicon_entry(char *);
160 int set_enable_favicon_tabs(char *);
161 int set_guess_search(char *);
162 int set_download_mode(struct settings
*, char *);
163 int set_download_mode_rt(char *);
164 int set_oops_font(char *);
165 int set_read_only_cookies(char *);
166 int set_referer(struct settings
*, char *);
167 int set_referer_rt(char *);
168 int set_refresh_interval(char *);
169 int set_search_string(char *s
);
170 int set_session_autosave(char *);
171 int set_session_timeout(char *);
172 int set_show_statusbar(char *);
173 int set_show_tabs(char *);
174 int set_show_url(char *);
175 int set_spell_check_languages(char *);
176 int set_ssl_ca_file_rt(char *);
177 int set_ssl_strict_certs(char *);
178 int set_statusbar_font(char *);
179 int set_url_regex(char *);
180 int set_userstyle_global(char *);
181 int set_external_editor(char *);
182 int set_xterm_workaround(char *);
184 void walk_mime_type(struct settings
*, void (*)(struct settings
*,
185 char *, void *), void *);
186 void walk_alias(struct settings
*, void (*)(struct settings
*,
187 char *, void *), void *);
188 void walk_cookie_wl(struct settings
*, void (*)(struct settings
*,
189 char *, void *), void *);
190 void walk_js_wl(struct settings
*, void (*)(struct settings
*,
191 char *, void *), void *);
192 void walk_pl_wl(struct settings
*, void (*)(struct settings
*,
193 char *, void *), void *);
194 void walk_kb(struct settings
*, void (*)(struct settings
*, char *,
196 void walk_ua(struct settings
*, void (*)(struct settings
*, char *,
200 set_http_proxy(char *proxy
)
207 /* see if we need to clear it instead */
208 if (strlen(proxy
) == 0) {
213 uri
= soup_uri_new(proxy
);
214 if (uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(uri
))
225 int (*set
)(struct settings
*, char *);
226 char *(*get
)(struct settings
*);
227 void (*walk
)(struct settings
*,
228 void (*cb
)(struct settings
*, char *, void *),
232 struct special s_browser_mode
= {
238 struct special s_gui_mode
= {
244 struct special s_cookie
= {
250 struct special s_alias
= {
256 struct special s_mime
= {
262 struct special s_js
= {
268 struct special s_pl
= {
274 struct special s_kb
= {
280 struct special s_cookie_wl
= {
286 struct special s_default_script
= {
292 struct special s_download_dir
= {
298 struct special s_work_dir
= {
304 struct special s_tab_style
= {
310 struct special s_edit_mode
= {
316 struct special s_download_mode
= {
322 struct special s_ua
= {
328 struct special s_referer
= {
334 struct settings rs
[] = {
335 { "allow_volatile_cookies", XT_S_INT
, 0, &allow_volatile_cookies
, NULL
, NULL
, NULL
, NULL
},
336 { "autofocus_onload", XT_S_INT
, 0, &autofocus_onload
, NULL
, NULL
, NULL
, NULL
},
337 { "browser_mode", XT_S_INT
, 0, NULL
, NULL
,&s_browser_mode
, NULL
, NULL
},
338 { "gui_mode", XT_S_INT
, 0, NULL
, NULL
,&s_gui_mode
, NULL
, NULL
},
339 { "color_visited_uris", XT_S_INT
, 0, &color_visited_uris
, NULL
, NULL
, NULL
, set_color_visited_uris
},
340 { "cookie_policy", XT_S_INT
, 0, NULL
, NULL
,&s_cookie
, NULL
, set_cookie_policy_rt
},
341 { "cookies_enabled", XT_S_INT
, 0, &cookies_enabled
, NULL
, NULL
, NULL
, set_cookies_enabled
},
342 { "ctrl_click_focus", XT_S_INT
, 0, &ctrl_click_focus
, NULL
, NULL
, NULL
, set_ctrl_click_focus
},
343 { "default_zoom_level", XT_S_FLOAT
, 0, NULL
, NULL
, NULL
, &default_zoom_level
, set_default_zoom_level
},
344 { "default_script", XT_S_STR
, 0, NULL
, NULL
,&s_default_script
, NULL
, set_default_script_rt
},
345 { "download_dir", XT_S_STR
, 0, NULL
, NULL
,&s_download_dir
, NULL
, NULL
},
346 { "download_mode", XT_S_STR
, 0, NULL
, NULL
,&s_download_mode
, NULL
, set_download_mode_rt
},
347 { "edit_mode", XT_S_STR
, 0, NULL
, NULL
,&s_edit_mode
, NULL
, NULL
},
348 { "enable_cookie_whitelist", XT_S_INT
, 0, &enable_cookie_whitelist
, NULL
, NULL
, NULL
, set_enable_cookie_whitelist
},
349 { "enable_js_whitelist", XT_S_INT
, 0, &enable_js_whitelist
, NULL
, NULL
, NULL
, set_enable_js_whitelist
},
350 { "enable_plugin_whitelist", XT_S_INT
, 0, &enable_plugin_whitelist
, NULL
, NULL
, NULL
, set_enable_plugin_whitelist
},
351 { "enable_localstorage", XT_S_INT
, 0, &enable_localstorage
, NULL
, NULL
, NULL
, set_enable_localstorage
},
352 { "enable_plugins", XT_S_INT
, 0, &enable_plugins
, NULL
, NULL
, NULL
, set_enable_plugins
},
353 { "enable_scripts", XT_S_INT
, 0, &enable_scripts
, NULL
, NULL
, NULL
, set_enable_scripts
},
354 { "enable_socket", XT_S_INT
, XT_SF_RESTART
,&enable_socket
, NULL
, NULL
, NULL
, NULL
},
355 { "enable_spell_checking", XT_S_INT
, 0, &enable_spell_checking
, NULL
, NULL
, NULL
, set_enable_spell_checking
},
356 { "encoding", XT_S_STR
, 0, NULL
, &encoding
, NULL
, NULL
, NULL
},
357 { "external_editor", XT_S_STR
,0, NULL
, &external_editor
, NULL
, NULL
, set_external_editor
},
358 { "fancy_bar", XT_S_INT
, XT_SF_RESTART
,&fancy_bar
, NULL
, NULL
, NULL
, NULL
},
359 { "guess_search", XT_S_INT
, 0, &guess_search
, NULL
, NULL
, NULL
, set_guess_search
},
360 { "history_autosave", XT_S_INT
, 0, &history_autosave
, NULL
, NULL
, NULL
, NULL
},
361 { "http_proxy", XT_S_STR
, 0, NULL
, &http_proxy
, NULL
, NULL
, set_http_proxy
},
362 { "icon_size", XT_S_INT
, 0, &icon_size
, NULL
, NULL
, NULL
, NULL
},
363 { "enable_js_autorun", XT_S_INT
, 0, &enable_js_autorun
, NULL
, NULL
, NULL
, set_enable_js_autorun
},
364 { "max_connections", XT_S_INT
, XT_SF_RESTART
,&max_connections
, NULL
, NULL
, NULL
, NULL
},
365 { "max_host_connections", XT_S_INT
, XT_SF_RESTART
,&max_host_connections
, NULL
, NULL
, NULL
, NULL
},
366 { "read_only_cookies", XT_S_INT
, 0, &read_only_cookies
, NULL
, NULL
, NULL
, set_read_only_cookies
},
367 { "refresh_interval", XT_S_INT
, 0, &refresh_interval
, NULL
, NULL
, NULL
, set_refresh_interval
},
368 { "resource_dir", XT_S_STR
, 0, NULL
, &resource_dir
, NULL
, NULL
, NULL
},
369 { "search_string", XT_S_STR
, 0, NULL
, &search_string
, NULL
, NULL
, set_search_string
},
370 { "save_global_history", XT_S_INT
, XT_SF_RESTART
,&save_global_history
, NULL
, NULL
, NULL
, NULL
},
371 { "save_rejected_cookies", XT_S_INT
, XT_SF_RESTART
,&save_rejected_cookies
, NULL
, NULL
, NULL
, NULL
},
372 { "session_timeout", XT_S_INT
, 0, &session_timeout
, NULL
, NULL
, NULL
, set_session_timeout
},
373 { "session_autosave", XT_S_INT
, 0, &session_autosave
, NULL
, NULL
, NULL
, set_session_autosave
},
374 { "single_instance", XT_S_INT
, XT_SF_RESTART
,&single_instance
, NULL
, NULL
, NULL
, NULL
},
375 { "show_tabs", XT_S_INT
, 0, &show_tabs
, NULL
, NULL
, NULL
, set_show_tabs
},
376 { "show_url", XT_S_INT
, 0, &show_url
, NULL
, NULL
, NULL
, set_show_url
},
377 { "show_statusbar", XT_S_INT
, 0, &show_statusbar
, NULL
, NULL
, NULL
, set_show_statusbar
},
378 { "spell_check_languages", XT_S_STR
, 0, NULL
, &spell_check_languages
, NULL
, NULL
, set_spell_check_languages
},
379 { "ssl_ca_file", XT_S_STR
, 0, NULL
, &ssl_ca_file
, NULL
, NULL
, set_ssl_ca_file_rt
},
380 { "ssl_strict_certs", XT_S_INT
, 0, &ssl_strict_certs
, NULL
, NULL
, NULL
, set_ssl_strict_certs
},
381 { "enable_strict_transport", XT_S_INT
, 0, &enable_strict_transport
, NULL
, NULL
, NULL
, set_enable_strict_transport
},
382 { "statusbar_elems", XT_S_STR
, 0, NULL
, &statusbar_elems
, NULL
, NULL
, NULL
},
383 { "tab_style", XT_S_STR
, 0, NULL
, NULL
,&s_tab_style
, NULL
, set_tab_style_rt
},
384 { "userstyle_global", XT_S_INT
, 0, &userstyle_global
, NULL
, NULL
, NULL
, set_userstyle_global
},
385 { "url_regex", XT_S_STR
, 0, NULL
, &url_regex
, NULL
, NULL
, set_url_regex
},
386 { "window_height", XT_S_INT
, 0, &window_height
, NULL
, NULL
, NULL
, NULL
},
387 { "window_width", XT_S_INT
, 0, &window_width
, NULL
, NULL
, NULL
, NULL
},
388 { "window_maximize", XT_S_INT
, 0, &window_maximize
, NULL
, NULL
, NULL
, NULL
},
389 { "work_dir", XT_S_STR
, 0, NULL
, NULL
,&s_work_dir
, NULL
, NULL
},
390 { "xterm_workaround", XT_S_INT
, 0, &xterm_workaround
, NULL
, NULL
, NULL
, set_xterm_workaround
},
391 { "auto_load_images", XT_S_INT
, 0, &auto_load_images
, NULL
, NULL
, NULL
, set_auto_load_images
},
392 { "enable_favicon_entry", XT_S_INT
, 0, &enable_favicon_entry
, NULL
, NULL
, NULL
, set_enable_favicon_entry
},
393 { "enable_favicon_tabs", XT_S_INT
, 0, &enable_favicon_tabs
, NULL
, NULL
, NULL
, set_enable_favicon_tabs
},
394 { "referer", XT_S_STR
, 0, NULL
, NULL
,&s_referer
, NULL
, set_referer_rt
},
395 { "download_notifications", XT_S_INT
, 0, &download_notifications
, NULL
, NULL
, NULL
, set_download_notifications
},
396 { "include_config", XT_S_STR
, 0, NULL
, &include_config
, NULL
, NULL
, NULL
},
399 { "cmd_font", XT_S_STR
, 0, NULL
, &cmd_font_name
, NULL
, NULL
, set_cmd_font
},
400 { "oops_font", XT_S_STR
, 0, NULL
, &oops_font_name
, NULL
, NULL
, set_oops_font
},
401 { "statusbar_font", XT_S_STR
, 0, NULL
, &statusbar_font_name
, NULL
, NULL
, set_statusbar_font
},
402 { "tabbar_font", XT_S_STR
, 0, NULL
, &tabbar_font_name
, NULL
, NULL
, set_tabbar_font
},
404 /* runtime settings */
405 { "append_next", XT_S_INT
, 0, &append_next
, NULL
, NULL
, NULL
, set_append_next
},
406 { "enable_autoscroll", XT_S_INT
, 0, &enable_autoscroll
, NULL
, NULL
, NULL
, set_enable_autoscroll
},
407 { "home", XT_S_STR
, 0, NULL
, &home
, NULL
, NULL
, set_home
},
409 /* special settings */
410 { "alias", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_alias
, NULL
, NULL
},
411 { "cookie_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_cookie_wl
, NULL
, NULL
},
412 { "js_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_js
, NULL
, NULL
},
413 { "keybinding", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_kb
, NULL
, NULL
},
414 { "mime_type", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_mime
, NULL
, NULL
},
415 { "pl_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_pl
, NULL
, NULL
},
416 { "user_agent", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_ua
, NULL
, NULL
},
420 set_default_zoom_level(char *value
)
422 struct karg args
= {0};
425 if (value
== NULL
|| strlen(value
) == 0)
427 default_zoom_level
= g_strtod(value
, NULL
);
428 args
.i
= 100; /* adjust = 100 percent for no additional adjustment */
429 TAILQ_FOREACH(t
, &tabs
, entry
)
435 set_cookies_enabled(char *value
)
440 tmp
= strtonum(value
, 0, 1, &errstr
);
443 cookies_enabled
= tmp
;
448 set_append_next(char *value
)
453 tmp
= strtonum(value
, 0, 1, &errstr
);
461 set_cmd_font(char *value
)
465 if (value
== NULL
|| strlen(value
))
468 g_free(cmd_font_name
);
470 pango_font_description_free(cmd_font
);
471 cmd_font_name
= g_strdup(value
);
472 cmd_font
= pango_font_description_from_string(cmd_font_name
);
473 TAILQ_FOREACH(t
, &tabs
, entry
)
474 gtk_widget_modify_font(GTK_WIDGET(t
->cmd
), cmd_font
);
479 set_oops_font(char *value
)
483 if (value
== NULL
|| strlen(value
) == 0)
486 g_free(oops_font_name
);
488 pango_font_description_free(oops_font
);
489 oops_font_name
= g_strdup(value
);
490 oops_font
= pango_font_description_from_string(oops_font_name
);
491 TAILQ_FOREACH(t
, &tabs
, entry
)
492 gtk_widget_modify_font(GTK_WIDGET(t
->oops
), oops_font
);
497 set_statusbar_font(char *value
)
501 if (value
== NULL
|| strlen(value
) == 0)
503 if (statusbar_font_name
)
504 g_free(statusbar_font_name
);
506 pango_font_description_free(statusbar_font
);
507 statusbar_font_name
= g_strdup(value
);
508 statusbar_font
= pango_font_description_from_string(
509 statusbar_font_name
);
510 TAILQ_FOREACH(t
, &tabs
, entry
) {
511 gtk_widget_modify_font(GTK_WIDGET(t
->sbe
.statusbar
),
513 gtk_widget_modify_font(GTK_WIDGET(t
->sbe
.buffercmd
),
515 gtk_widget_modify_font(GTK_WIDGET(t
->sbe
.zoom
),
517 gtk_widget_modify_font(GTK_WIDGET(t
->sbe
.position
),
524 set_tabbar_font(char *value
)
528 if (value
== NULL
|| strlen(value
) == 0)
530 if (tabbar_font_name
)
531 g_free(tabbar_font_name
);
533 pango_font_description_free(tabbar_font
);
534 tabbar_font_name
= g_strdup(value
);
535 tabbar_font
= pango_font_description_from_string(tabbar_font_name
);
536 TAILQ_FOREACH(t
, &tabs
, entry
)
537 gtk_widget_modify_font(GTK_WIDGET(t
->tab_elems
.label
),
543 set_color_visited_uris(char *value
)
548 tmp
= strtonum(value
, 0, 1, &errstr
);
551 color_visited_uris
= tmp
;
556 set_home(char *value
)
558 if (value
== NULL
|| strlen(value
) == 0)
562 home
= g_strdup(value
);
567 set_search_string(char *value
)
569 if (value
== NULL
|| strlen(value
) == 0)
572 g_free(search_string
);
573 search_string
= g_strdup(value
);
578 get_settings_size(void)
584 get_setting_name(int i
)
592 get_as_string(struct settings
*s
)
603 warnx("get_as_string skip %s\n", s
->name
);
604 } else if (s
->type
== XT_S_INT
)
605 r
= g_strdup_printf("%d", *s
->ival
);
606 else if (s
->type
== XT_S_STR
)
607 r
= g_strdup(*s
->sval
);
608 else if (s
->type
== XT_S_FLOAT
)
609 r
= g_strdup_printf("%f", *s
->fval
);
611 r
= g_strdup_printf("INVALID TYPE");
617 settings_walk(void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
622 for (i
= 0; i
< LENGTH(rs
); i
++) {
623 if (rs
[i
].s
&& rs
[i
].s
->walk
)
624 rs
[i
].s
->walk(&rs
[i
], cb
, cb_args
);
626 s
= get_as_string(&rs
[i
]);
627 cb(&rs
[i
], s
, cb_args
);
634 set_browser_mode(struct settings
*s
, char *val
)
636 if (!strcmp(val
, "whitelist")) {
637 browser_mode
= XT_BM_WHITELIST
;
638 allow_volatile_cookies
= 0;
639 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
;
641 enable_cookie_whitelist
= 1;
642 enable_plugin_whitelist
= 1;
644 read_only_cookies
= 0;
645 save_rejected_cookies
= 0;
646 session_timeout
= 3600;
648 enable_js_whitelist
= 1;
649 enable_localstorage
= 0;
650 referer_mode
= XT_REFERER_SAME_DOMAIN
;
651 } else if (!strcmp(val
, "normal")) {
652 browser_mode
= XT_BM_NORMAL
;
653 allow_volatile_cookies
= 0;
654 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
656 enable_cookie_whitelist
= 0;
657 enable_plugin_whitelist
= 0;
659 read_only_cookies
= 0;
660 save_rejected_cookies
= 0;
661 session_timeout
= 3600;
663 enable_js_whitelist
= 0;
664 enable_localstorage
= 1;
665 referer_mode
= XT_REFERER_ALWAYS
;
666 } else if (!strcmp(val
, "kiosk")) {
667 browser_mode
= XT_BM_KIOSK
;
668 allow_volatile_cookies
= 0;
669 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
671 enable_cookie_whitelist
= 0;
672 enable_plugin_whitelist
= 0;
674 read_only_cookies
= 0;
675 save_rejected_cookies
= 0;
676 session_timeout
= 3600;
678 enable_js_whitelist
= 0;
679 enable_localstorage
= 1;
680 referer_mode
= XT_REFERER_ALWAYS
;
690 get_browser_mode(struct settings
*s
)
694 if (browser_mode
== XT_BM_WHITELIST
)
695 r
= g_strdup("whitelist");
696 else if (browser_mode
== XT_BM_NORMAL
)
697 r
= g_strdup("normal");
698 else if (browser_mode
== XT_BM_KIOSK
)
699 r
= g_strdup("kiosk");
707 set_gui_mode(struct settings
*s
, char *val
)
709 if (!strcmp(val
, "classic")) {
712 tab_style
= XT_TABS_NORMAL
;
715 } else if (!strcmp(val
, "minimal")) {
718 tab_style
= XT_TABS_COMPACT
;
728 get_gui_mode(struct settings
*s
)
732 if (gui_mode
== XT_GM_CLASSIC
)
733 r
= g_strdup("classic");
734 else if (browser_mode
== XT_GM_MINIMAL
)
735 r
= g_strdup("minimal");
743 set_cookie_policy(struct settings
*s
, char *val
)
745 if (!strcmp(val
, "no3rdparty"))
746 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
;
747 else if (!strcmp(val
, "accept"))
748 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
749 else if (!strcmp(val
, "reject"))
750 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NEVER
;
758 set_cookie_policy_rt(char *value
)
760 if (set_cookie_policy(NULL
, value
))
762 g_object_set(G_OBJECT(s_cookiejar
), SOUP_COOKIE_JAR_ACCEPT_POLICY
,
763 cookie_policy
, (void *)NULL
);
768 get_cookie_policy(struct settings
*s
)
772 if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
)
773 r
= g_strdup("no3rdparty");
774 else if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_ALWAYS
)
775 r
= g_strdup("accept");
776 else if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_NEVER
)
777 r
= g_strdup("reject");
785 get_default_script(struct settings
*s
)
787 if (default_script
[0] == '\0')
789 return (g_strdup(default_script
));
793 set_default_script(struct settings
*s
, char *val
)
796 snprintf(default_script
, sizeof default_script
, "%s" PS
"%s",
797 pwd
->pw_dir
, &val
[1]);
799 strlcpy(default_script
, val
, sizeof default_script
);
805 set_default_script_rt(char *value
)
807 if (value
== NULL
|| strlen(value
) == 0)
809 return (set_default_script(NULL
, value
));
813 get_download_dir(struct settings
*s
)
815 if (download_dir
[0] == '\0')
817 return (g_strdup(download_dir
));
821 set_download_dir(struct settings
*s
, char *val
)
824 snprintf(download_dir
, sizeof download_dir
, "%s" PS
"%s",
825 pwd
->pw_dir
, &val
[1]);
827 strlcpy(download_dir
, val
, sizeof download_dir
);
833 add_alias(struct settings
*s
, char *line
)
836 struct alias
*a
= NULL
;
838 if (s
== NULL
|| line
== NULL
) {
839 show_oops(NULL
, "add_alias invalid parameters");
844 a
= g_malloc(sizeof(*a
));
846 if ((alias
= strsep(&l
, " \t,")) == NULL
|| l
== NULL
) {
847 show_oops(NULL
, "add_alias: incomplete alias definition");
850 if (strlen(alias
) == 0 || strlen(l
) == 0) {
851 show_oops(NULL
, "add_alias: invalid alias definition");
855 a
->a_name
= g_strdup(alias
);
856 a
->a_uri
= g_strdup(l
);
858 DNPRINTF(XT_D_CONFIG
, "add_alias: %s for %s\n", a
->a_name
, a
->a_uri
);
860 TAILQ_INSERT_TAIL(&aliases
, a
, entry
);
870 walk_alias(struct settings
*s
,
871 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
876 if (s
== NULL
|| cb
== NULL
) {
877 show_oops(NULL
, "walk_alias invalid parameters");
881 TAILQ_FOREACH(a
, &aliases
, entry
) {
882 str
= g_strdup_printf("%s --> %s", a
->a_name
, a
->a_uri
);
889 add_mime_type(struct settings
*s
, char *line
)
893 struct mime_type
*m
= NULL
;
894 int downloadfirst
= 0;
896 /* XXX this could be smarter */
898 if (line
== NULL
|| strlen(line
) == 0) {
899 show_oops(NULL
, "add_mime_type invalid parameters");
908 m
= g_malloc(sizeof(*m
));
910 if ((mime_type
= strsep(&l
, " \t,")) == NULL
|| l
== NULL
) {
911 show_oops(NULL
, "add_mime_type: invalid mime_type");
914 if (mime_type
[strlen(mime_type
) - 1] == '*') {
915 mime_type
[strlen(mime_type
) - 1] = '\0';
920 if (strlen(mime_type
) == 0 || strlen(l
) == 0) {
921 show_oops(NULL
, "add_mime_type: invalid mime_type");
925 m
->mt_type
= g_strdup(mime_type
);
926 m
->mt_action
= g_strdup(l
);
927 m
->mt_download
= downloadfirst
;
929 DNPRINTF(XT_D_CONFIG
, "add_mime_type: type %s action %s default %d\n",
930 m
->mt_type
, m
->mt_action
, m
->mt_default
);
932 TAILQ_INSERT_TAIL(&mtl
, m
, entry
);
942 walk_mime_type(struct settings
*s
,
943 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
948 if (s
== NULL
|| cb
== NULL
) {
949 show_oops(NULL
, "walk_mime_type invalid parameters");
953 TAILQ_FOREACH(m
, &mtl
, entry
) {
954 str
= g_strdup_printf("%s%s --> %s",
956 m
->mt_default
? "*" : "",
963 /* inherent to GTK not all keys will be caught at all times */
964 /* XXX sort key bindings */
965 struct key_binding keys
[] = {
966 { "command_mode", 0, 1, GDK_Escape
},
967 { "insert_mode", 0, 0, GDK_i
},
968 { "cookiejar", MOD1
, 1, GDK_j
},
969 { "downloadmgr", MOD1
, 1, GDK_d
},
970 { "history", MOD1
, 1, GDK_h
},
971 { "print", CTRL
, 1, GDK_p
},
972 { "search", 0, 0, GDK_slash
},
973 { "searchb", 0, 0, GDK_question
},
974 { "statustoggle", CTRL
, 1, GDK_n
},
975 { "command", 0, 0, GDK_colon
},
976 { "qa", CTRL
, 1, GDK_q
},
977 { "restart", MOD1
, 1, GDK_q
},
978 { "js toggle", CTRL
, 1, GDK_j
},
979 { "plugin toggle", MOD1
, 1, GDK_p
},
980 { "cookie toggle", MOD1
, 1, GDK_c
},
981 { "togglesrc", CTRL
, 1, GDK_s
},
982 { "yankuri", 0, 0, GDK_y
},
983 { "pasteuricur", 0, 0, GDK_p
},
984 { "pasteurinew", 0, 0, GDK_P
},
985 { "toplevel toggle", 0, 1, GDK_F4
},
986 { "help", 0, 1, GDK_F1
},
987 { "run_script", MOD1
, 1, GDK_r
},
988 { "proxy toggle", 0, 1, GDK_F2
},
989 { "editelement", CTRL
, 1, GDK_i
},
990 { "passthrough", CTRL
, 1, GDK_z
},
991 { "modurl", CTRL
, 1, GDK_Return
},
994 { "searchnext", 0, 0, GDK_n
},
995 { "searchprevious", 0, 0, GDK_N
},
998 { "focusaddress", 0, 1, GDK_F6
},
999 { "focussearch", 0, 1, GDK_F7
},
1002 { "hinting", 0, 0, GDK_f
},
1003 { "hinting", 0, 0, GDK_period
},
1004 { "hinting_newtab", SHFT
, 0, GDK_F
},
1005 { "hinting_newtab", 0, 0, GDK_comma
},
1007 /* custom stylesheet */
1008 { "userstyle", 0, 0, GDK_s
},
1009 { "userstyle_global", SHFT
, 0, GDK_S
},
1012 { "goback", 0, 0, GDK_BackSpace
},
1013 { "goback", MOD1
, 1, GDK_Left
},
1014 { "goforward", SHFT
, 1, GDK_BackSpace
},
1015 { "goforward", MOD1
, 1, GDK_Right
},
1016 { "reload", 0, 1, GDK_F5
},
1017 { "reload", CTRL
, 1, GDK_r
},
1018 { "reload", CTRL
, 1, GDK_l
},
1019 { "favorites", MOD1
, 1, GDK_f
},
1021 /* vertical movement */
1022 { "scrolldown", 0, 0, GDK_j
},
1023 { "scrolldown", 0, 0, GDK_Down
},
1024 { "scrollup", 0, 0, GDK_Up
},
1025 { "scrollup", 0, 0, GDK_k
},
1026 { "scrollbottom", 0, 0, GDK_G
},
1027 { "scrollbottom", 0, 0, GDK_End
},
1028 { "scrolltop", 0, 0, GDK_Home
},
1029 { "scrollpagedown", 0, 0, GDK_space
},
1030 { "scrollpagedown", CTRL
, 1, GDK_f
},
1031 { "scrollhalfdown", CTRL
, 1, GDK_d
},
1032 { "scrollpagedown", 0, 0, GDK_Page_Down
},
1033 { "scrollpageup", 0, 0, GDK_Page_Up
},
1034 { "scrollpageup", CTRL
, 1, GDK_b
},
1035 { "scrollhalfup", CTRL
, 1, GDK_u
},
1036 /* horizontal movement */
1037 { "scrollright", 0, 0, GDK_l
},
1038 { "scrollright", 0, 0, GDK_Right
},
1039 { "scrollleft", 0, 0, GDK_Left
},
1040 { "scrollleft", 0, 0, GDK_h
},
1041 { "scrollfarright", 0, 0, GDK_dollar
},
1042 { "scrollfarleft", 0, 0, GDK_0
},
1045 { "tabnew", CTRL
, 1, GDK_t
},
1046 { "999tabnew", CTRL
, 1, GDK_T
},
1047 { "tabclose", CTRL
, 1, GDK_w
},
1048 { "tabundoclose", 0, 0, GDK_U
},
1049 { "tabnext 1", CTRL
, 1, GDK_1
},
1050 { "tabnext 2", CTRL
, 1, GDK_2
},
1051 { "tabnext 3", CTRL
, 1, GDK_3
},
1052 { "tabnext 4", CTRL
, 1, GDK_4
},
1053 { "tabnext 5", CTRL
, 1, GDK_5
},
1054 { "tabnext 6", CTRL
, 1, GDK_6
},
1055 { "tabnext 7", CTRL
, 1, GDK_7
},
1056 { "tabnext 8", CTRL
, 1, GDK_8
},
1057 { "tabnext 9", CTRL
, 1, GDK_9
},
1058 { "tabfirst", CTRL
, 1, GDK_less
},
1059 { "tablast", CTRL
, 1, GDK_greater
},
1060 { "tabprevious", CTRL
, 1, GDK_Left
},
1061 { "tabnext", CTRL
, 1, GDK_Right
},
1062 { "focusout", CTRL
, 1, GDK_minus
},
1063 { "focusin", CTRL
, 1, GDK_plus
},
1064 { "focusin", CTRL
, 1, GDK_equal
},
1065 { "focusreset", CTRL
, 1, GDK_0
},
1067 /* command aliases (handy when -S flag is used) */
1068 { "promptopen", 0, 1, GDK_F9
},
1069 { "promptopencurrent", 0, 1, GDK_F10
},
1070 { "prompttabnew", 0, 1, GDK_F11
},
1071 { "prompttabnewcurrent",0, 1, GDK_F12
},
1075 walk_kb(struct settings
*s
,
1076 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1078 struct key_binding
*k
;
1081 if (s
== NULL
|| cb
== NULL
) {
1082 show_oops(NULL
, "walk_kb invalid parameters");
1086 TAILQ_FOREACH(k
, &kbl
, entry
) {
1092 if (gdk_keyval_name(k
->key
) == NULL
)
1095 strlcat(str
, k
->cmd
, sizeof str
);
1096 strlcat(str
, ",", sizeof str
);
1098 if (k
->mask
& GDK_SHIFT_MASK
)
1099 strlcat(str
, "S-", sizeof str
);
1100 if (k
->mask
& GDK_CONTROL_MASK
)
1101 strlcat(str
, "C-", sizeof str
);
1102 if (k
->mask
& GDK_MOD1_MASK
)
1103 strlcat(str
, "M1-", sizeof str
);
1104 if (k
->mask
& GDK_MOD2_MASK
)
1105 strlcat(str
, "M2-", sizeof str
);
1106 if (k
->mask
& GDK_MOD3_MASK
)
1107 strlcat(str
, "M3-", sizeof str
);
1108 if (k
->mask
& GDK_MOD4_MASK
)
1109 strlcat(str
, "M4-", sizeof str
);
1110 if (k
->mask
& GDK_MOD5_MASK
)
1111 strlcat(str
, "M5-", sizeof str
);
1113 strlcat(str
, gdk_keyval_name(k
->key
), sizeof str
);
1114 cb(s
, str
, cb_args
);
1119 init_keybindings(void)
1122 struct key_binding
*k
;
1124 for (i
= 0; i
< LENGTH(keys
); i
++) {
1125 k
= g_malloc0(sizeof *k
);
1126 k
->cmd
= keys
[i
].cmd
;
1127 k
->mask
= keys
[i
].mask
;
1128 k
->use_in_entry
= keys
[i
].use_in_entry
;
1129 k
->key
= keys
[i
].key
;
1130 TAILQ_INSERT_HEAD(&kbl
, k
, entry
);
1132 DNPRINTF(XT_D_KEYBINDING
, "init_keybindings: added: %s\n",
1133 k
->cmd
? k
->cmd
: "unnamed key");
1138 keybinding_clearall(void)
1140 struct key_binding
*k
, *next
;
1142 for (k
= TAILQ_FIRST(&kbl
); k
; k
= next
) {
1143 next
= TAILQ_NEXT(k
, entry
);
1147 DNPRINTF(XT_D_KEYBINDING
, "keybinding_clearall: %s\n",
1148 k
->cmd
? k
->cmd
: "unnamed key");
1149 TAILQ_REMOVE(&kbl
, k
, entry
);
1155 keybinding_add(char *cmd
, char *key
, int use_in_entry
)
1157 struct key_binding
*k
;
1158 guint keyval
, mask
= 0;
1161 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: %s %s\n", cmd
, key
);
1163 /* Keys which are to be used in entry have been prefixed with an
1164 * exclamation mark. */
1168 /* find modifier keys */
1169 if (strstr(key
, "S-"))
1170 mask
|= GDK_SHIFT_MASK
;
1171 if (strstr(key
, "C-"))
1172 mask
|= GDK_CONTROL_MASK
;
1173 if (strstr(key
, "M1-"))
1174 mask
|= GDK_MOD1_MASK
;
1175 if (strstr(key
, "M2-"))
1176 mask
|= GDK_MOD2_MASK
;
1177 if (strstr(key
, "M3-"))
1178 mask
|= GDK_MOD3_MASK
;
1179 if (strstr(key
, "M4-"))
1180 mask
|= GDK_MOD4_MASK
;
1181 if (strstr(key
, "M5-"))
1182 mask
|= GDK_MOD5_MASK
;
1185 for (i
= strlen(key
) - 1; i
> 0; i
--)
1189 /* validate keyname */
1190 keyval
= gdk_keyval_from_name(key
);
1191 if (keyval
== GDK_VoidSymbol
) {
1192 warnx("invalid keybinding name %s", key
);
1195 /* must run this test too, gtk+ doesn't handle 10 for example */
1196 if (gdk_keyval_name(keyval
) == NULL
) {
1197 warnx("invalid keybinding name %s", key
);
1201 /* Remove eventual dupes. */
1202 TAILQ_FOREACH(k
, &kbl
, entry
)
1203 if (k
->key
== keyval
&& k
->mask
== mask
) {
1204 TAILQ_REMOVE(&kbl
, k
, entry
);
1210 k
= g_malloc0(sizeof *k
);
1211 k
->cmd
= g_strdup(cmd
);
1213 k
->use_in_entry
= use_in_entry
;
1216 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: %s 0x%x %d 0x%x\n",
1221 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: adding: %s %s\n",
1222 k
->cmd
, gdk_keyval_name(keyval
));
1224 TAILQ_INSERT_HEAD(&kbl
, k
, entry
);
1230 add_kb(struct settings
*s
, char *entry
)
1234 DNPRINTF(XT_D_KEYBINDING
, "add_kb: %s\n", entry
);
1236 /* clearall is special */
1237 if (!strcmp(entry
, "clearall")) {
1238 keybinding_clearall();
1242 kb
= strstr(entry
, ",");
1248 return (keybinding_add(entry
, key
, key
[0] == '!'));
1252 add_ua(struct settings
*s
, char *value
)
1254 struct user_agent
*ua
;
1256 ua
= g_malloc0(sizeof *ua
);
1257 ua
->value
= g_strdup(value
);
1259 TAILQ_INSERT_HEAD(&ua_list
, ua
, entry
);
1261 /* use the last added user agent */
1262 user_agent
= TAILQ_FIRST(&ua_list
);
1270 walk_ua(struct settings
*s
,
1271 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1273 struct user_agent
*ua
;
1275 if (s
== NULL
|| cb
== NULL
) {
1276 show_oops(NULL
, "walk_ua invalid parameters");
1280 TAILQ_FOREACH(ua
, &ua_list
, entry
)
1281 cb(s
, ua
->value
, cb_args
);
1285 set_auto_load_images(char *value
)
1291 tmp
= strtonum(value
, 0, 1, &errstr
);
1294 auto_load_images
= tmp
;
1295 TAILQ_FOREACH(t
, &tabs
, entry
) {
1296 g_object_set(G_OBJECT(t
->settings
),
1297 "auto-load-images", auto_load_images
, (char *)NULL
);
1298 webkit_web_view_set_settings(t
->wv
, t
->settings
);
1304 set_ctrl_click_focus(char *value
)
1309 tmp
= strtonum(value
, 0, 1, &errstr
);
1312 ctrl_click_focus
= tmp
;
1317 set_download_notifications(char *value
)
1322 tmp
= strtonum(value
, 0, 1, &errstr
);
1325 download_notifications
= tmp
;
1330 set_enable_autoscroll(char *value
)
1335 tmp
= strtonum(value
, 0, 1, &errstr
);
1338 enable_autoscroll
= tmp
;
1343 set_enable_cookie_whitelist(char *value
)
1348 tmp
= strtonum(value
, 0, 1, &errstr
);
1351 enable_cookie_whitelist
= tmp
;
1356 set_enable_js_autorun(char *value
)
1361 tmp
= strtonum(value
, 0, 1, &errstr
);
1364 enable_js_autorun
= tmp
;
1369 set_enable_js_whitelist(char *value
)
1374 tmp
= strtonum(value
, 0, 1, &errstr
);
1377 enable_js_whitelist
= tmp
;
1382 set_enable_favicon_entry(char *value
)
1387 tmp
= strtonum(value
, 0, 1, &errstr
);
1390 enable_favicon_entry
= tmp
;
1395 set_enable_favicon_tabs(char *value
)
1400 tmp
= strtonum(value
, 0, 1, &errstr
);
1403 enable_favicon_tabs
= tmp
;
1408 set_enable_localstorage(char *value
)
1414 tmp
= strtonum(value
, 0, 1, &errstr
);
1417 enable_localstorage
= tmp
;
1418 TAILQ_FOREACH(t
, &tabs
, entry
) {
1419 g_object_set(G_OBJECT(t
->settings
),
1420 "enable-html5-local-storage", enable_localstorage
,
1427 set_enable_plugins(char *value
)
1433 tmp
= strtonum(value
, 0, 1, &errstr
);
1436 enable_plugins
= tmp
;
1437 TAILQ_FOREACH(t
, &tabs
, entry
)
1438 g_object_set(G_OBJECT(t
->settings
), "enable-plugins",
1439 enable_plugins
, (char *)NULL
);
1444 set_enable_plugin_whitelist(char *value
)
1449 tmp
= strtonum(value
, 0, 1, &errstr
);
1452 enable_plugin_whitelist
= tmp
;
1457 set_enable_scripts(char *value
)
1463 tmp
= strtonum(value
, 0, 1, &errstr
);
1466 enable_scripts
= tmp
;
1467 TAILQ_FOREACH(t
, &tabs
, entry
)
1468 g_object_set(G_OBJECT(t
->settings
), "enable-scripts",
1469 enable_scripts
, (char *)NULL
);
1474 set_enable_spell_checking(char *value
)
1480 tmp
= strtonum(value
, 0, 1, &errstr
);
1483 enable_spell_checking
= tmp
;
1484 TAILQ_FOREACH(t
, &tabs
, entry
)
1485 g_object_set(G_OBJECT(t
->settings
), "enable_spell_checking",
1486 enable_spell_checking
, (char *)NULL
);
1491 set_enable_strict_transport(char *value
)
1496 tmp
= strtonum(value
, 0, 1, &errstr
);
1499 enable_strict_transport
= tmp
;
1505 * XXX: this is currently broken. Need to figure out what to do with
1506 * this. Problemm is set_encoding will refresh the tab it's run on, so
1507 * we can either put a big fat warning in the manpage and refresh every
1508 * single open tab with the new encoding or scrap it as a runtime
1512 set_encoding_rt(char *value
)
1514 struct karg args
= {0};
1516 if (value
== NULL
|| strlen(value
) == 0)
1520 encoding
= g_strdup(value
);
1522 set_encoding(get_current_tab(), &args
);
1528 set_guess_search(char *value
)
1533 tmp
= strtonum(value
, 0, 1, &errstr
);
1541 set_read_only_cookies(char *value
)
1546 tmp
= strtonum(value
, 0, 1, &errstr
);
1549 read_only_cookies
= tmp
;
1550 g_object_set(G_OBJECT(p_cookiejar
), SOUP_COOKIE_JAR_READ_ONLY
,
1551 read_only_cookies
, (void *)NULL
);
1556 get_referer(struct settings
*s
)
1558 if (referer_mode
== XT_REFERER_ALWAYS
)
1559 return (g_strdup("always"));
1560 if (referer_mode
== XT_REFERER_NEVER
)
1561 return (g_strdup("never"));
1562 if (referer_mode
== XT_REFERER_SAME_DOMAIN
)
1563 return (g_strdup("same-domain"));
1564 if (referer_mode
== XT_REFERER_SAME_FQDN
)
1565 return (g_strdup("same-fqdn"));
1566 if (referer_mode
== XT_REFERER_CUSTOM
)
1567 return (g_strdup(referer_custom
));
1572 set_referer(struct settings
*s
, char *value
)
1575 g_free(referer_custom
);
1577 if (!strcmp(value
, "always"))
1578 referer_mode
= XT_REFERER_ALWAYS
;
1579 else if (!strcmp(value
, "never"))
1580 referer_mode
= XT_REFERER_NEVER
;
1581 else if (!strcmp(value
, "same-domain"))
1582 referer_mode
= XT_REFERER_SAME_DOMAIN
;
1583 else if (!strcmp(value
, "same-fqdn"))
1584 referer_mode
= XT_REFERER_SAME_FQDN
;
1585 else if (!valid_url_type(value
)) {
1586 referer_mode
= XT_REFERER_CUSTOM
;
1587 referer_custom
= g_strdup(value
);
1589 /* we've already free'd the custom referer */
1590 if (referer_mode
== XT_REFERER_CUSTOM
)
1591 referer_mode
= XT_REFERER_NEVER
;
1599 set_referer_rt(char *value
)
1601 if (value
== NULL
|| strlen(value
) == 0)
1603 return (set_referer(NULL
, value
));
1607 set_refresh_interval(char *value
)
1612 tmp
= strtonum(value
, 0, INT_MAX
, &errstr
);
1615 refresh_interval
= tmp
;
1620 set_session_autosave(char *value
)
1625 tmp
= strtonum(value
, 0, 1, &errstr
);
1628 session_autosave
= tmp
;
1633 set_session_timeout(char *value
)
1638 tmp
= strtonum(value
, 0, INT_MAX
, &errstr
);
1641 session_timeout
= tmp
;
1646 set_show_statusbar(char *value
)
1651 tmp
= strtonum(value
, 0, 1, &errstr
);
1654 show_statusbar
= tmp
;
1655 statusbar_set_visibility();
1660 set_show_tabs(char *value
)
1662 struct karg args
= {0};
1666 val
= strtonum(value
, 0, 1, &errstr
);
1669 args
.i
= val
? XT_TAB_SHOW
: XT_TAB_HIDE
;
1670 tabaction(get_current_tab(), &args
);
1675 set_show_url(char *value
)
1677 struct karg args
= {0};
1681 val
= strtonum(value
, 0, 1, &errstr
);
1684 args
.i
= val
? XT_URL_SHOW
: XT_URL_HIDE
;
1685 urlaction(get_current_tab(), &args
);
1690 set_spell_check_languages(char *value
)
1694 if (value
== NULL
|| strlen(value
) == 0)
1696 if (spell_check_languages
)
1697 g_free(spell_check_languages
);
1698 spell_check_languages
= g_strdup(value
);
1699 TAILQ_FOREACH(t
, &tabs
, entry
)
1700 g_object_set(G_OBJECT(t
->settings
), "spell_checking_languages",
1701 spell_check_languages
, (char *)NULL
);
1706 check_valid_file(char *name
)
1710 if (name
== NULL
|| stat(name
, &sb
))
1716 set_ssl_ca_file_rt(char *value
)
1718 if (value
== NULL
|| strlen(value
) == 0)
1720 if (set_ssl_ca_file(value
))
1726 set_ssl_strict_certs(char *value
)
1731 tmp
= strtonum(value
, 0, 1, &errstr
);
1734 ssl_strict_certs
= tmp
;
1735 set_ssl_ca_file(ssl_ca_file
);
1740 set_external_editor(char *editor
)
1742 if (external_editor
)
1743 g_free(external_editor
);
1745 external_editor
= g_strdup(editor
);
1751 setup_proxy(char *uri
)
1754 g_object_set(session
, "proxy_uri", NULL
, (char *)NULL
);
1755 soup_uri_free(proxy_uri
);
1759 if (http_proxy
!= uri
) {
1766 http_proxy
= g_strdup(uri
);
1767 DNPRINTF(XT_D_CONFIG
, "setup_proxy: %s\n", uri
);
1768 proxy_uri
= soup_uri_new(http_proxy
);
1769 if (!(proxy_uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(proxy_uri
)))
1770 g_object_set(session
, "proxy-uri", proxy_uri
,
1776 get_tab_style(struct settings
*s
)
1778 if (tab_style
== XT_TABS_NORMAL
)
1779 return (g_strdup("normal"));
1781 return (g_strdup("compact"));
1785 set_tab_style(struct settings
*s
, char *val
)
1787 if (!strcmp(val
, "normal"))
1788 tab_style
= XT_TABS_NORMAL
;
1789 else if (!strcmp(val
, "compact"))
1790 tab_style
= XT_TABS_COMPACT
;
1798 set_tab_style_rt(char *value
)
1800 struct karg args
= {0};
1803 old_tab_style
= tab_style
;
1804 if (set_tab_style(NULL
, value
))
1806 if (old_tab_style
!= tab_style
) {
1807 tab_style
= old_tab_style
;
1808 args
.i
= XT_TAB_NEXTSTYLE
;
1809 tabaction(get_current_tab(), &args
);
1815 set_url_regex(char *value
)
1817 if (regcomp(&url_re
, value
, REG_EXTENDED
| REG_NOSUB
))
1821 url_regex
= g_strdup(value
);
1826 set_userstyle_global(char *value
)
1828 struct karg args
= {0};
1832 old_style
= userstyle_global
;
1833 tmp
= strtonum(value
, 0, 1, &errstr
);
1836 if (tmp
!= old_style
) {
1837 args
.i
= XT_STYLE_GLOBAL
;
1838 userstyle(get_current_tab(), &args
);
1844 get_edit_mode(struct settings
*s
)
1846 if (edit_mode
== XT_EM_HYBRID
)
1847 return (g_strdup("hybrid"));
1849 return (g_strdup("vi"));
1853 set_edit_mode(struct settings
*s
, char *val
)
1855 if (!strcmp(val
, "hybrid"))
1856 edit_mode
= XT_EM_HYBRID
;
1857 else if (!strcmp(val
, "vi"))
1858 edit_mode
= XT_EM_VI
;
1866 get_download_mode(struct settings
*s
)
1868 switch (download_mode
) {
1870 return (g_strdup("start"));
1873 return (g_strdup("ask"));
1876 return (g_strdup("add"));
1879 return (g_strdup("unknown"));
1883 set_download_mode(struct settings
*s
, char *val
)
1885 if (!strcmp(val
, "start"))
1886 download_mode
= XT_DM_START
;
1887 else if (!strcmp(val
, "ask"))
1888 download_mode
= XT_DM_ASK
;
1889 else if (!strcmp(val
, "add"))
1890 download_mode
= XT_DM_ADD
;
1898 set_download_mode_rt(char *val
)
1900 if (val
== NULL
|| strlen(val
) == 0)
1902 return (set_download_mode(NULL
, val
));
1906 get_work_dir(struct settings
*s
)
1908 if (work_dir
[0] == '\0')
1910 return (g_strdup(work_dir
));
1914 set_work_dir(struct settings
*s
, char *val
)
1917 snprintf(work_dir
, sizeof work_dir
, "%s" PS
"%s",
1918 pwd
->pw_dir
, &val
[1]);
1920 strlcpy(work_dir
, val
, sizeof work_dir
);
1926 set_xterm_workaround(char *value
)
1931 tmp
= strtonum(value
, 0, 1, &errstr
);
1934 xterm_workaround
= tmp
;
1939 walk_cookie_wl(struct settings
*s
,
1940 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1944 if (s
== NULL
|| cb
== NULL
) {
1945 show_oops(NULL
, "walk_cookie_wl invalid parameters");
1949 RB_FOREACH_REVERSE(d
, domain_list
, &c_wl
)
1950 cb(s
, d
->d
, cb_args
);
1954 walk_js_wl(struct settings
*s
,
1955 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1959 if (s
== NULL
|| cb
== NULL
) {
1960 show_oops(NULL
, "walk_js_wl invalid parameters");
1964 RB_FOREACH_REVERSE(d
, domain_list
, &js_wl
)
1965 cb(s
, d
->d
, cb_args
);
1969 walk_pl_wl(struct settings
*s
,
1970 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1974 if (s
== NULL
|| cb
== NULL
) {
1975 show_oops(NULL
, "walk_pl_wl invalid parameters");
1979 RB_FOREACH_REVERSE(d
, domain_list
, &pl_wl
)
1980 cb(s
, d
->d
, cb_args
);
1984 settings_add(char *var
, char *val
)
1988 char c
[PATH_MAX
], **s
;
1991 for (i
= 0, rv
= 0; i
< LENGTH(rs
); i
++) {
1992 if (strcmp(var
, rs
[i
].name
))
1995 if (!strcmp(var
, "include_config")) {
1997 snprintf(c
, PATH_MAX
, "%s" PS
"%s", pwd
->pw_dir
,
2000 strlcpy(c
, val
, PATH_MAX
);
2007 if (rs
[i
].s
->set(&rs
[i
], val
))
2008 errx(1, "invalid value for %s: %s", var
, val
);
2012 switch (rs
[i
].type
) {
2021 errx(1, "invalid sval for %s",
2035 errx(1, "invalid type for %s", var
);
2044 config_parse(char *filename
, int runtime
)
2047 char *line
, *cp
, *var
, *val
;
2048 size_t len
, lineno
= 0;
2050 char file
[PATH_MAX
];
2053 DNPRINTF(XT_D_CONFIG
, "config_parse: filename %s\n", filename
);
2055 if (filename
== NULL
)
2058 if (runtime
&& runtime_settings
[0] != '\0') {
2059 snprintf(file
, sizeof file
, "%s" PS
"%s",
2060 work_dir
, runtime_settings
);
2061 if (stat(file
, &sb
)) {
2062 warnx("runtime file doesn't exist, creating it");
2063 if ((f
= fopen(file
, "w")) == NULL
)
2065 fprintf(f
, "# AUTO GENERATED, DO NOT EDIT\n");
2069 strlcpy(file
, filename
, sizeof file
);
2071 if ((config
= fopen(file
, "r")) == NULL
) {
2072 warn("config_parse: cannot open %s", filename
);
2077 if ((line
= fparseln(config
, &len
, &lineno
, NULL
, 0)) == NULL
)
2078 if (feof(config
) || ferror(config
))
2082 cp
+= (long)strspn(cp
, WS
);
2083 if (cp
[0] == '\0') {
2089 if ((var
= strsep(&cp
, WS
)) == NULL
|| cp
== NULL
)
2090 startpage_add("invalid configuration file entry: %s",
2093 cp
+= (long)strspn(cp
, WS
);
2095 if ((val
= strsep(&cp
, "\0")) == NULL
)
2098 DNPRINTF(XT_D_CONFIG
, "config_parse: %s=%s\n",
2100 handled
= settings_add(var
, val
);
2103 startpage_add("invalid configuration file entry"
2104 ": %s=%s", var
, val
);
2113 struct settings_args
{
2119 print_setting(struct settings
*s
, char *val
, void *cb_args
)
2122 struct settings_args
*sa
= cb_args
;
2127 if (s
->flags
& XT_SF_RUNTIME
)
2133 *sa
->body
= g_strdup_printf(
2135 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
2136 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
2148 set_show(struct tab
*t
, struct karg
*args
)
2150 char *body
, *page
, *tmp
;
2152 struct settings_args sa
;
2154 bzero(&sa
, sizeof sa
);
2158 body
= g_strdup_printf("<div align='center'><table><tr>"
2159 "<th align='left'>Setting</th>"
2160 "<th align='left'>Value</th></tr>\n");
2162 settings_walk(print_setting
, &sa
);
2165 /* small message if there are none */
2168 body
= g_strdup_printf("%s\n<tr><td style='text-align:center'"
2169 "colspan='2'>No settings</td></tr>\n", body
);
2174 body
= g_strdup_printf("%s</table></div>", body
);
2177 page
= get_html_page("Settings", body
, "", 0);
2181 load_webkit_string(t
, page
, XT_URI_ABOUT_SET
);
2185 return (XT_CB_PASSTHROUGH
);
2189 set(struct tab
*t
, struct karg
*args
)
2194 if (args
== NULL
|| args
->s
== NULL
)
2195 return (set_show(t
, args
));
2198 p
= g_strstrip(args
->s
);
2201 return (set_show(t
, args
));
2203 /* we got some sort of string */
2204 val
= g_strstr_len(p
, strlen(p
), "=");
2207 val
= g_strstrip(val
);
2210 for (i
= 0; i
< get_settings_size(); i
++) {
2211 if (strcmp(rs
[i
].name
, p
))
2214 if (rs
[i
].activate
) {
2215 if (rs
[i
].activate(val
))
2216 show_oops(t
, "%s invalid value %s",
2219 show_oops(t
, ":set %s = %s", p
, val
);
2222 show_oops(t
, "not a runtime option: %s", p
);
2226 show_oops(t
, "unknown option: %s", p
);
2230 for (i
= 0; i
< get_settings_size(); i
++) {
2231 if (strcmp(rs
[i
].name
, p
))
2234 /* XXX this could use some cleanup */
2235 switch (rs
[i
].type
) {
2238 show_oops(t
, "%s = %d",
2239 rs
[i
].name
, *rs
[i
].ival
);
2240 else if (rs
[i
].s
&& rs
[i
].s
->get
)
2241 show_oops(t
, "%s = %s",
2243 rs
[i
].s
->get(&rs
[i
]));
2244 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
2245 show_oops(t
, "%s = ...", rs
[i
].name
);
2247 show_oops(t
, "%s = ", rs
[i
].name
);
2251 show_oops(t
, "%s = %f",
2252 rs
[i
].name
, *rs
[i
].fval
);
2253 else if (rs
[i
].s
&& rs
[i
].s
->get
)
2254 show_oops(t
, "%s = %s",
2256 rs
[i
].s
->get(&rs
[i
]));
2257 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
2258 show_oops(t
, "%s = ...", rs
[i
].name
);
2260 show_oops(t
, "%s = ", rs
[i
].name
);
2263 if (rs
[i
].sval
&& *rs
[i
].sval
)
2264 show_oops(t
, "%s = %s",
2265 rs
[i
].name
, *rs
[i
].sval
);
2266 else if (rs
[i
].s
&& rs
[i
].s
->get
)
2267 show_oops(t
, "%s = %s",
2269 rs
[i
].s
->get(&rs
[i
]));
2270 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
2271 show_oops(t
, "%s = ...", rs
[i
].name
);
2273 show_oops(t
, "%s = ", rs
[i
].name
);
2276 show_oops(t
, "unknown type for %s", rs
[i
].name
);
2282 show_oops(t
, "unknown option: %s", p
);
2285 return (XT_CB_PASSTHROUGH
);