Move more stuff into about
[xxxterm.git] / xxxterm.h
blob7dd3b905b8828f04c654dee122e2ab1fa30915c8
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 #define XT_D_INSPECTOR 0x8000
130 extern u_int32_t swm_debug;
131 #else
132 #define DPRINTF(x...)
133 #define DNPRINTF(n,x...)
134 #endif
136 #define LENGTH(x) (sizeof x / sizeof x[0])
137 #define CLEAN(mask) (mask & ~(GDK_MOD2_MASK) & \
138 ~(GDK_BUTTON1_MASK) & \
139 ~(GDK_BUTTON2_MASK) & \
140 ~(GDK_BUTTON3_MASK) & \
141 ~(GDK_BUTTON4_MASK) & \
142 ~(GDK_BUTTON5_MASK))
144 #define XT_NOMARKS (('z' - 'a' + 1) * 2 + 10)
146 struct tab {
147 TAILQ_ENTRY(tab) entry;
148 GtkWidget *vbox;
149 GtkWidget *tab_content;
150 struct {
151 GtkWidget *label;
152 GtkWidget *eventbox;
153 GtkWidget *box;
154 GtkWidget *sep;
155 } tab_elems;
156 GtkWidget *label;
157 GtkWidget *spinner;
158 GtkWidget *uri_entry;
159 GtkWidget *search_entry;
160 GtkWidget *toolbar;
161 GtkWidget *browser_win;
162 GtkWidget *statusbar_box;
163 struct {
164 GtkWidget *statusbar;
165 GtkWidget *buffercmd;
166 GtkWidget *zoom;
167 GtkWidget *position;
168 } sbe;
169 GtkWidget *cmd;
170 GtkWidget *buffers;
171 GtkWidget *oops;
172 GtkWidget *backward;
173 GtkWidget *forward;
174 GtkWidget *stop;
175 GtkWidget *gohome;
176 GtkWidget *js_toggle;
177 GtkEntryCompletion *completion;
178 guint tab_id;
179 WebKitWebView *wv;
181 WebKitWebHistoryItem *item;
182 WebKitWebBackForwardList *bfl;
184 /* favicon */
185 WebKitNetworkRequest *icon_request;
186 WebKitDownload *icon_download;
187 gchar *icon_dest_uri;
189 /* adjustments for browser */
190 GtkScrollbar *sb_h;
191 GtkScrollbar *sb_v;
192 GtkAdjustment *adjust_h;
193 GtkAdjustment *adjust_v;
195 /* flags */
196 int focus_wv;
197 int ctrl_click;
198 gchar *status;
199 int xtp_meaning; /* identifies dls/favorites */
200 gchar *tmp_uri;
201 int popup; /* 1 if cmd_entry has popup visible */
202 #ifdef USE_THREADS
203 /* https thread stuff */
204 GThread *thread;
205 #endif
206 /* hints */
207 int script_init;
208 int hints_on;
209 int new_tab;
211 /* custom stylesheet */
212 int styled;
213 char *stylesheet;
215 /* search */
216 char *search_text;
217 int search_forward;
218 guint search_id;
220 /* settings */
221 WebKitWebSettings *settings;
222 gchar *user_agent;
224 /* marks */
225 double mark[XT_NOMARKS];
227 /* inspector */
228 WebKitWebInspector *inspector;
229 GtkWidget *inspector_window;
230 GtkWidget *inspector_view;
232 TAILQ_HEAD(tab_list, tab);
234 struct karg {
235 int i;
236 char *s;
237 int precount;
240 struct download {
241 RB_ENTRY(download) entry;
242 int id;
243 WebKitDownload *download;
244 struct tab *tab;
246 RB_HEAD(download_list, download);
247 RB_PROTOTYPE(download_list, download, entry, download_rb_cmp);
249 struct history {
250 RB_ENTRY(history) entry;
251 const gchar *uri;
252 const gchar *title;
254 RB_HEAD(history_list, history);
255 RB_PROTOTYPE(history_list, history, entry, history_rb_cmp);
257 /* utility */
258 #define XT_NAME ("XXXTerm")
259 #define XT_CB_HANDLED (TRUE)
260 #define XT_CB_PASSTHROUGH (FALSE)
261 #define XT_FAVS_FILE ("favorites")
263 void xt_icon_from_file(struct tab *, char *);
264 GtkWidget *create_window(const gchar *);
265 void show_oops(struct tab *, const char *, ...);
266 gchar *get_html_page(gchar *, gchar *, gchar *, bool);
267 const gchar *get_uri(struct tab *);
268 const gchar *get_title(struct tab *, bool);
270 void load_webkit_string(struct tab *, const char *, gchar *);
272 /* cookies */
273 int remove_cookie(int);
275 /* inspector */
276 #define XT_INS_SHOW (1<<0)
277 #define XT_INS_HIDE (1<<1)
278 #define XT_INS_CLOSE (1<<2)
280 WebKitWebView* inspector_inspect_web_view_cb(WebKitWebInspector *,
281 WebKitWebView*, struct tab *);
282 void setup_inspector(struct tab *);
283 int inspector_cmd(struct tab *, struct karg *);
285 /* about */
286 #define XT_XTP_STR "xxxt://"
287 #define XT_URI_ABOUT ("about:")
288 #define XT_URI_ABOUT_LEN (strlen(XT_URI_ABOUT))
289 #define XT_URI_ABOUT_ABOUT ("about")
290 #define XT_URI_ABOUT_BLANK ("blank")
291 #define XT_URI_ABOUT_CERTS ("certs")
292 #define XT_URI_ABOUT_COOKIEWL ("cookiewl")
293 #define XT_URI_ABOUT_COOKIEJAR ("cookiejar")
294 #define XT_URI_ABOUT_DOWNLOADS ("downloads")
295 #define XT_URI_ABOUT_FAVORITES ("favorites")
296 #define XT_URI_ABOUT_HELP ("help")
297 #define XT_URI_ABOUT_HISTORY ("history")
298 #define XT_URI_ABOUT_JSWL ("jswl")
299 #define XT_URI_ABOUT_PLUGINWL ("plwl")
300 #define XT_URI_ABOUT_SET ("set")
301 #define XT_URI_ABOUT_STATS ("stats")
302 #define XT_URI_ABOUT_MARCO ("marco")
303 #define XT_URI_ABOUT_STARTPAGE ("startpage")
305 struct about_type {
306 char *name;
307 int (*func)(struct tab *, struct karg *);
310 int blank(struct tab *, struct karg *);
311 int help(struct tab *, struct karg *);
312 int about(struct tab *, struct karg *);
313 int stats(struct tab *, struct karg *);
314 void show_certs(struct tab *, gnutls_x509_crt_t *,
315 size_t, char *);
316 int ca_cmd(struct tab *, struct karg *);
317 int cookie_show_wl(struct tab *, struct karg *);
318 int xtp_page_cl(struct tab *, struct karg *);
319 int xtp_page_dl(struct tab *, struct karg *);
320 int xtp_page_fl(struct tab *, struct karg *);
321 int xtp_page_hl(struct tab *, struct karg *);
322 int parse_xtp_url(struct tab *, const char *);
323 int add_favorite(struct tab *, struct karg *);
324 void update_favorite_tabs(struct tab *);
325 void update_history_tabs(struct tab *);
326 void update_download_tabs(struct tab *);
327 void xtp_generate_keys(void);
328 size_t about_list_size(void);
331 * xtp tab meanings
332 * identifies which tabs have xtp pages in (corresponding to about_list indices)
334 #define XT_XTP_TAB_MEANING_NORMAL (-1) /* normal url */
335 #define XT_XTP_TAB_MEANING_BL (1) /* about:blank in this tab */
336 #define XT_XTP_TAB_MEANING_CL (4) /* cookie manager in this tab */
337 #define XT_XTP_TAB_MEANING_DL (5) /* download manager in this tab */
338 #define XT_XTP_TAB_MEANING_FL (6) /* favorite manager in this tab */
339 #define XT_XTP_TAB_MEANING_HL (8) /* history manager in this tab */
341 /* whitelists */
342 #define XT_WL_TOGGLE (1<<0)
343 #define XT_WL_ENABLE (1<<1)
344 #define XT_WL_DISABLE (1<<2)
345 #define XT_WL_FQDN (1<<3) /* default */
346 #define XT_WL_TOPLEVEL (1<<4)
347 #define XT_WL_PERSISTENT (1<<5)
348 #define XT_WL_SESSION (1<<6)
349 #define XT_WL_RELOAD (1<<7)
350 #define XT_SHOW (1<<8)
351 #define XT_DELETE (1<<9)
352 #define XT_SAVE (1<<10)
353 #define XT_OPEN (1<<11)
355 struct domain {
356 RB_ENTRY(domain) entry;
357 gchar *d;
358 int handy; /* app use */
360 RB_HEAD(domain_list, domain);
361 RB_PROTOTYPE(domain_list, domain, entry, domain_rb_cmp);
363 int wl_show(struct tab *, struct karg *, char *,
364 struct domain_list *);
366 /* settings */
367 extern char *encoding;
368 extern char *resource_dir;
369 extern int save_rejected_cookies;
370 extern int refresh_interval;
371 extern char *ssl_ca_file;
373 /* globals */
374 extern char *version;
375 extern char *icons[];
376 extern char rc_fname[PATH_MAX];
377 extern char work_dir[PATH_MAX];
378 long long unsigned int blocked_cookies;
379 extern SoupCookieJar *s_cookiejar;
380 extern SoupCookieJar *p_cookiejar;
382 extern struct history_list hl;
383 extern struct download_list downloads;
384 extern struct tab_list tabs;
385 extern struct about_type about_list[];
386 extern struct domain_list c_wl;
387 extern struct domain_list js_wl;
388 extern struct domain_list pl_wl;