sort whitelist stuff into whitelist.c
[xombrero.git] / xxxterm.h
blob3ad3fb2a84097b7d6d92392cd2d8fc4cbd0fbc14
1 /*
2 * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
3 * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <ctype.h>
19 #include <dlfcn.h>
20 #include <err.h>
21 #include <errno.h>
22 #include <libgen.h>
23 #include <pwd.h>
24 #include <regex.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <dirent.h>
32 #include <sys/types.h>
33 #include <sys/wait.h>
34 #if defined(__linux__)
35 #include "linux/util.h"
36 #include "linux/tree.h"
37 #include <bsd/stdlib.h>
38 # if !defined(sane_libbsd_headers)
39 void arc4random_buf(void *, size_t);
40 # endif
41 #elif defined(__FreeBSD__)
42 #include <libutil.h>
43 #include "freebsd/util.h"
44 #include <sys/tree.h>
45 #else /* OpenBSD */
46 #include <util.h>
47 #include <sys/tree.h>
48 #endif
49 #include <sys/queue.h>
50 #include <sys/resource.h>
51 #include <sys/socket.h>
52 #include <sys/stat.h>
53 #include <sys/time.h>
54 #include <sys/un.h>
56 #include <gtk/gtk.h>
57 #include <gdk/gdkkeysyms.h>
59 #if GTK_CHECK_VERSION(3,0,0)
60 /* we still use GDK_* instead of GDK_KEY_* */
61 #include <gdk/gdkkeysyms-compat.h>
62 #endif
64 #include <webkit/webkit.h>
65 #include <libsoup/soup.h>
66 #include <JavaScriptCore/JavaScript.h>
67 #include <gnutls/gnutls.h>
68 #include <gnutls/x509.h>
70 /* comment if you don't want to use threads */
71 #define USE_THREADS
73 #ifdef USE_THREADS
74 #include <gcrypt.h>
75 #include <pthread.h>
76 #endif
78 #include "version.h"
79 #include "javascript.h"
81 javascript.h borrowed from vimprobable2 under the following license:
83 Copyright (c) 2009 Leon Winter
84 Copyright (c) 2009-2011 Hannes Schueller
85 Copyright (c) 2009-2010 Matto Fransen
86 Copyright (c) 2010-2011 Hans-Peter Deifel
87 Copyright (c) 2010-2011 Thomas Adam
88 Copyright (c) 2011 Albert Kim
89 Copyright (c) 2011 Daniel Carl
91 Permission is hereby granted, free of charge, to any person obtaining a copy
92 of this software and associated documentation files (the "Software"), to deal
93 in the Software without restriction, including without limitation the rights
94 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95 copies of the Software, and to permit persons to whom the Software is
96 furnished to do so, subject to the following conditions:
98 The above copyright notice and this permission notice shall be included in
99 all copies or substantial portions of the Software.
101 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
107 THE SOFTWARE.
110 /*#define XT_DEBUG*/
111 #ifdef XT_DEBUG
112 #define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0)
113 #define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while (0)
114 #define XT_D_MOVE 0x0001
115 #define XT_D_KEY 0x0002
116 #define XT_D_TAB 0x0004
117 #define XT_D_URL 0x0008
118 #define XT_D_CMD 0x0010
119 #define XT_D_NAV 0x0020
120 #define XT_D_DOWNLOAD 0x0040
121 #define XT_D_CONFIG 0x0080
122 #define XT_D_JS 0x0100
123 #define XT_D_FAVORITE 0x0200
124 #define XT_D_PRINTING 0x0400
125 #define XT_D_COOKIE 0x0800
126 #define XT_D_KEYBINDING 0x1000
127 #define XT_D_CLIP 0x2000
128 #define XT_D_BUFFERCMD 0x4000
129 extern u_int32_t swm_debug;
130 #else
131 #define DPRINTF(x...)
132 #define DNPRINTF(n,x...)
133 #endif
135 #define LENGTH(x) (sizeof x / sizeof x[0])
136 #define CLEAN(mask) (mask & ~(GDK_MOD2_MASK) & \
137 ~(GDK_BUTTON1_MASK) & \
138 ~(GDK_BUTTON2_MASK) & \
139 ~(GDK_BUTTON3_MASK) & \
140 ~(GDK_BUTTON4_MASK) & \
141 ~(GDK_BUTTON5_MASK))
143 #define XT_NOMARKS (('z' - 'a' + 1) * 2 + 10)
145 #define XT_BM_NORMAL (0)
146 #define XT_BM_WHITELIST (1)
147 #define XT_BM_KIOSK (2)
149 #define XT_SHOW (1<<7)
150 #define XT_DELETE (1<<8)
151 #define XT_SAVE (1<<9)
152 #define XT_OPEN (1<<10)
154 #define XT_WL_TOGGLE (1<<0)
155 #define XT_WL_ENABLE (1<<1)
156 #define XT_WL_DISABLE (1<<2)
157 #define XT_WL_FQDN (1<<3) /* default */
158 #define XT_WL_TOPLEVEL (1<<4)
159 #define XT_WL_PERSISTENT (1<<5)
160 #define XT_WL_SESSION (1<<6)
161 #define XT_WL_RELOAD (1<<7)
163 #define XT_URI_ABOUT ("about:")
164 #define XT_URI_ABOUT_LEN (strlen(XT_URI_ABOUT))
165 #define XT_URI_ABOUT_ABOUT ("about")
166 #define XT_URI_ABOUT_BLANK ("blank")
167 #define XT_URI_ABOUT_CERTS ("certs")
168 #define XT_URI_ABOUT_COOKIEWL ("cookiewl")
169 #define XT_URI_ABOUT_COOKIEJAR ("cookiejar")
170 #define XT_URI_ABOUT_DOWNLOADS ("downloads")
171 #define XT_URI_ABOUT_FAVORITES ("favorites")
172 #define XT_URI_ABOUT_HELP ("help")
173 #define XT_URI_ABOUT_HISTORY ("history")
174 #define XT_URI_ABOUT_JSWL ("jswl")
175 #define XT_URI_ABOUT_PLUGINWL ("plwl")
176 #define XT_URI_ABOUT_SET ("set")
177 #define XT_URI_ABOUT_STATS ("stats")
178 #define XT_URI_ABOUT_MARCO ("marco")
179 #define XT_URI_ABOUT_STARTPAGE ("startpage")
182 extern int enable_plugin_whitelist;
183 extern int enable_cookie_whitelist;
184 extern int enable_js_whitelist;
185 extern int browser_mode;
186 extern int allow_volatile_cookies;
187 extern int cookie_policy;
188 extern int cookies_enabled;
189 extern int enable_plugins;
190 extern int read_only_cookies;
191 extern int save_rejected_cookies;
192 extern int session_timeout;
193 extern int enable_scripts;
194 extern int enable_localstorage;
195 extern int show_tabs;
196 extern int tabless;
197 extern char default_script[PATH_MAX];
198 extern struct passwd *pwd;
199 extern char runtime_settings[PATH_MAX];
200 extern char work_dir[PATH_MAX];
201 extern SoupCookieJar *s_cookiejar;
202 extern SoupCookieJar *p_cookiejar;
204 struct domain_list;
205 extern struct domain_list c_wl;
206 extern struct domain_list js_wl;
207 extern struct domain_list pl_wl;
209 struct tab {
210 TAILQ_ENTRY(tab) entry;
211 GtkWidget *vbox;
212 GtkWidget *tab_content;
213 struct {
214 GtkWidget *label;
215 GtkWidget *eventbox;
216 GtkWidget *box;
217 GtkWidget *sep;
218 } tab_elems;
219 GtkWidget *label;
220 GtkWidget *spinner;
221 GtkWidget *uri_entry;
222 GtkWidget *search_entry;
223 GtkWidget *toolbar;
224 GtkWidget *browser_win;
225 GtkWidget *statusbar_box;
226 struct {
227 GtkWidget *statusbar;
228 GtkWidget *buffercmd;
229 GtkWidget *zoom;
230 GtkWidget *position;
231 } sbe;
232 GtkWidget *cmd;
233 GtkWidget *buffers;
234 GtkWidget *oops;
235 GtkWidget *backward;
236 GtkWidget *forward;
237 GtkWidget *stop;
238 GtkWidget *gohome;
239 GtkWidget *js_toggle;
240 GtkEntryCompletion *completion;
241 guint tab_id;
242 WebKitWebView *wv;
244 WebKitWebHistoryItem *item;
245 WebKitWebBackForwardList *bfl;
247 /* favicon */
248 WebKitNetworkRequest *icon_request;
249 WebKitDownload *icon_download;
250 gchar *icon_dest_uri;
252 /* adjustments for browser */
253 GtkScrollbar *sb_h;
254 GtkScrollbar *sb_v;
255 GtkAdjustment *adjust_h;
256 GtkAdjustment *adjust_v;
258 /* flags */
259 int focus_wv;
260 int ctrl_click;
261 gchar *status;
262 int xtp_meaning; /* identifies dls/favorites */
263 gchar *tmp_uri;
264 int popup; /* 1 if cmd_entry has popup visible */
265 #ifdef USE_THREADS
266 /* https thread stuff */
267 GThread *thread;
268 #endif
269 /* hints */
270 int script_init;
271 int hints_on;
272 int new_tab;
274 /* custom stylesheet */
275 int styled;
276 char *stylesheet;
278 /* search */
279 char *search_text;
280 int search_forward;
281 guint search_id;
283 /* settings */
284 WebKitWebSettings *settings;
285 gchar *user_agent;
287 /* marks */
288 double mark[XT_NOMARKS];
290 TAILQ_HEAD(tab_list, tab);
292 struct domain {
293 RB_ENTRY(domain) entry;
294 gchar *d;
295 int handy; /* app use */
298 struct karg {
299 int i;
300 char *s;
301 int precount;
305 GtkWidget *create_window(const gchar *);
307 WebKitWebView* inspector_inspect_web_view_cb(WebKitWebInspector *,
308 WebKitWebView*, struct tab *);
309 struct settings;
310 struct key_binding;
311 int set_browser_mode(struct settings *, char *);
312 int set_cookie_policy(struct settings *, char *);
313 int set_download_dir(struct settings *, char *);
314 int set_default_script(struct settings *, char *);
315 int set_runtime_dir(struct settings *, char *);
316 int set_tab_style(struct settings *, char *);
317 int set_work_dir(struct settings *, char *);
318 int add_alias(struct settings *, char *);
319 int add_mime_type(struct settings *, char *);
320 int add_cookie_wl(struct settings *, char *);
321 int add_js_wl(struct settings *, char *);
322 int add_pl_wl(struct settings *, char *);
323 int add_kb(struct settings *, char *);
324 void button_set_stockid(GtkWidget *, char *);
325 GtkWidget * create_button(char *, char *, int);
327 char *get_browser_mode(struct settings *);
328 char *get_cookie_policy(struct settings *);
329 char *get_download_dir(struct settings *);
330 char *get_default_script(struct settings *);
331 char *get_runtime_dir(struct settings *);
332 char *get_tab_style(struct settings *);
333 char *get_work_dir(struct settings *);
334 void startpage_add(const char *, ...);
336 struct domain *wl_find(const gchar *, struct domain_list *);
337 void wl_add(char *, struct domain_list *, int);
338 int toggle_pl(struct tab *, struct karg *);
339 int js_cmd(struct tab *, struct karg *);
340 int cookie_cmd(struct tab *, struct karg *);
341 int pl_cmd(struct tab *, struct karg *);
342 int toplevel_cmd(struct tab *, struct karg *);
343 struct domain *wl_find_uri(const gchar *, struct domain_list *);
344 void js_toggle_cb(GtkWidget *, struct tab *);
345 void show_oops(struct tab *, const char *, ...);
346 const gchar *get_uri(struct tab *);
347 gchar *find_domain(const gchar *, int);
348 gchar *get_html_page(gchar *title, gchar *, gchar *, bool);
349 void load_webkit_string(struct tab *, const char *, gchar *);
350 int settings_add(char *, char *);
351 void wl_init(void);
353 /* hooked functions */
354 void (*_soup_cookie_jar_add_cookie)(SoupCookieJar *, SoupCookie *);
355 void (*_soup_cookie_jar_delete_cookie)(SoupCookieJar *,
356 SoupCookie *);