-
Notifications
You must be signed in to change notification settings - Fork 0
/
xxxterm.c
8441 lines (7131 loc) · 195 KB
/
xxxterm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $xxxterm: xxxterm.c,v 1.363 2011/03/18 13:23:00 marco Exp $ */
/*
* Copyright (c) 2010, 2011 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2011 Stevan Andjelkovic <stevan@student.chalmers.se>
* Copyright (c) 2010 Edd Barrett <vext01@gmail.com>
* Copyright (c) 2011 Todd T. Fries <todd@fries.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* TODO:
* multi letter commands
* pre and post counts for commands
* autocompletion on various inputs
* create privacy browsing
* - encrypted local data
*/
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <pwd.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <dlfcn.h>
#include <errno.h>
#include <signal.h>
#include <libgen.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/wait.h>
#if defined(__linux__)
#include "linux/util.h"
#include "linux/tree.h"
#elif defined(__FreeBSD__)
#include <libutil.h>
#include "freebsd/util.h"
#include <sys/tree.h>
#else /* OpenBSD */
#include <util.h>
#include <sys/tree.h>
#endif
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <webkit/webkit.h>
#include <libsoup/soup.h>
#include <gnutls/gnutls.h>
#include <JavaScriptCore/JavaScript.h>
#include <gnutls/x509.h>
#include "javascript.h"
/*
javascript.h borrowed from vimprobable2 under the following license:
Copyright (c) 2009 Leon Winter
Copyright (c) 2009 Hannes Schueller
Copyright (c) 2009 Matto Fransen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
static char *version = "$xxxterm: xxxterm.c,v 1.363 2011/03/18 13:23:00 marco Exp $";
/* hooked functions */
void (*_soup_cookie_jar_add_cookie)(SoupCookieJar *, SoupCookie *);
void (*_soup_cookie_jar_delete_cookie)(SoupCookieJar *,
SoupCookie *);
/*#define XT_DEBUG*/
#ifdef XT_DEBUG
#define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0)
#define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while (0)
#define XT_D_MOVE 0x0001
#define XT_D_KEY 0x0002
#define XT_D_TAB 0x0004
#define XT_D_URL 0x0008
#define XT_D_CMD 0x0010
#define XT_D_NAV 0x0020
#define XT_D_DOWNLOAD 0x0040
#define XT_D_CONFIG 0x0080
#define XT_D_JS 0x0100
#define XT_D_FAVORITE 0x0200
#define XT_D_PRINTING 0x0400
#define XT_D_COOKIE 0x0800
#define XT_D_KEYBINDING 0x1000
u_int32_t swm_debug = 0
| XT_D_MOVE
| XT_D_KEY
| XT_D_TAB
| XT_D_URL
| XT_D_CMD
| XT_D_NAV
| XT_D_DOWNLOAD
| XT_D_CONFIG
| XT_D_JS
| XT_D_FAVORITE
| XT_D_PRINTING
| XT_D_COOKIE
| XT_D_KEYBINDING
;
#else
#define DPRINTF(x...)
#define DNPRINTF(n,x...)
#endif
#define LENGTH(x) (sizeof x / sizeof x[0])
#define CLEAN(mask) (mask & ~(GDK_MOD2_MASK) & \
~(GDK_BUTTON1_MASK) & \
~(GDK_BUTTON2_MASK) & \
~(GDK_BUTTON3_MASK) & \
~(GDK_BUTTON4_MASK) & \
~(GDK_BUTTON5_MASK))
char *icons[] = {
"xxxtermicon16.png",
"xxxtermicon32.png",
"xxxtermicon48.png",
"xxxtermicon64.png",
"xxxtermicon128.png"
};
struct tab {
TAILQ_ENTRY(tab) entry;
GtkWidget *vbox;
GtkWidget *tab_content;
GtkWidget *label;
GtkWidget *spinner;
GtkWidget *uri_entry;
GtkWidget *search_entry;
GtkWidget *toolbar;
GtkWidget *browser_win;
GtkWidget *statusbar;
GtkWidget *cmd;
GtkWidget *oops;
GtkWidget *backward;
GtkWidget *forward;
GtkWidget *stop;
GtkWidget *gohome;
GtkWidget *js_toggle;
GtkEntryCompletion *completion;
guint tab_id;
WebKitWebView *wv;
WebKitWebHistoryItem *item;
WebKitWebBackForwardList *bfl;
/* favicon */
WebKitNetworkRequest *icon_request;
WebKitDownload *icon_download;
GdkPixbuf *icon_pixbuf;
gchar *icon_dest_uri;
/* adjustments for browser */
GtkScrollbar *sb_h;
GtkScrollbar *sb_v;
GtkAdjustment *adjust_h;
GtkAdjustment *adjust_v;
/* flags */
int focus_wv;
int ctrl_click;
gchar *status;
int xtp_meaning; /* identifies dls/favorites */
/* hints */
int hints_on;
int hint_mode;
#define XT_HINT_NONE (0)
#define XT_HINT_NUMERICAL (1)
#define XT_HINT_ALPHANUM (2)
char hint_buf[128];
char hint_num[128];
/* custom stylesheet */
int styled;
char *stylesheet;
/* search */
char *search_text;
int search_forward;
/* settings */
WebKitWebSettings *settings;
int font_size;
gchar *user_agent;
};
TAILQ_HEAD(tab_list, tab);
struct history {
RB_ENTRY(history) entry;
const gchar *uri;
const gchar *title;
};
RB_HEAD(history_list, history);
struct download {
RB_ENTRY(download) entry;
int id;
WebKitDownload *download;
struct tab *tab;
};
RB_HEAD(download_list, download);
struct domain {
RB_ENTRY(domain) entry;
gchar *d;
int handy; /* app use */
};
RB_HEAD(domain_list, domain);
struct undo {
TAILQ_ENTRY(undo) entry;
gchar *uri;
GList *history;
int back; /* Keeps track of how many back
* history items there are. */
};
TAILQ_HEAD(undo_tailq, undo);
/* starts from 1 to catch atoi() failures when calling xtp_handle_dl() */
int next_download_id = 1;
struct karg {
int i;
char *s;
};
/* defines */
#define XT_NAME ("XXXTerm")
#define XT_DIR (".xxxterm")
#define XT_CACHE_DIR ("cache")
#define XT_CERT_DIR ("certs/")
#define XT_SESSIONS_DIR ("sessions/")
#define XT_CONF_FILE ("xxxterm.conf")
#define XT_FAVS_FILE ("favorites")
#define XT_SAVED_TABS_FILE ("main_session")
#define XT_RESTART_TABS_FILE ("restart_tabs")
#define XT_SOCKET_FILE ("socket")
#define XT_HISTORY_FILE ("history")
#define XT_SAVE_SESSION_ID ("SESSION_NAME=")
#define XT_CB_HANDLED (TRUE)
#define XT_CB_PASSTHROUGH (FALSE)
#define XT_DOCTYPE "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
#define XT_HTML_TAG "<html xmlns='http://www.w3.org/1999/xhtml'>"
#define XT_DLMAN_REFRESH "10"
#define XT_PAGE_STYLE "<style type='text/css'>\n" \
"td {overflow: hidden;" \
" padding: 2px 2px 2px 2px;" \
" border: 1px solid black}\n" \
"tr:hover {background: #ffff99 ;}\n" \
"th {background-color: #cccccc;" \
" border: 1px solid black}" \
"table {border-spacing: 0; " \
" width: 90%%;" \
" border: 1px black solid;}\n" \
".progress-outer{" \
" border: 1px solid black;" \
" height: 8px;" \
" width: 90%%;}" \
".progress-inner{" \
" float: left;" \
" height: 8px;" \
" background: green;}" \
".dlstatus{" \
" font-size: small;" \
" text-align: center;}" \
"</style>\n\n"
#define XT_MAX_URL_LENGTH (4096) /* 1 page is atomic, don't make bigger */
#define XT_MAX_UNDO_CLOSE_TAB (32)
#define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`"
#define XT_PRINT_EXTRA_MARGIN 10
/* colors */
#define XT_COLOR_RED "#cc0000"
#define XT_COLOR_YELLOW "#ffff66"
#define XT_COLOR_BLUE "lightblue"
#define XT_COLOR_GREEN "#99ff66"
#define XT_COLOR_WHITE "white"
#define XT_COLOR_BLACK "black"
/*
* xxxterm "protocol" (xtp)
* We use this for managing stuff like downloads and favorites. They
* make magical HTML pages in memory which have xxxt:// links in order
* to communicate with xxxterm's internals. These links take the format:
* xxxt://class/session_key/action/arg
*
* Don't begin xtp class/actions as 0. atoi returns that on error.
*
* Typically we have not put addition of items in this framework, as
* adding items is either done via an ex-command or via a keybinding instead.
*/
#define XT_XTP_STR "xxxt://"
/* XTP classes (xxxt://<class>) */
#define XT_XTP_DL 1 /* downloads */
#define XT_XTP_HL 2 /* history */
#define XT_XTP_CL 3 /* cookies */
#define XT_XTP_FL 4 /* favorites */
/* XTP download actions */
#define XT_XTP_DL_LIST 1
#define XT_XTP_DL_CANCEL 2
#define XT_XTP_DL_REMOVE 3
/* XTP history actions */
#define XT_XTP_HL_LIST 1
#define XT_XTP_HL_REMOVE 2
/* XTP cookie actions */
#define XT_XTP_CL_LIST 1
#define XT_XTP_CL_REMOVE 2
/* XTP cookie actions */
#define XT_XTP_FL_LIST 1
#define XT_XTP_FL_REMOVE 2
/* xtp tab meanings - identifies which tabs have xtp pages in */
#define XT_XTP_TAB_MEANING_NORMAL 0 /* normal url */
#define XT_XTP_TAB_MEANING_DL 1 /* download manager in this tab */
#define XT_XTP_TAB_MEANING_FL 2 /* favorite manager in this tab */
#define XT_XTP_TAB_MEANING_HL 3 /* history manager in this tab */
#define XT_XTP_TAB_MEANING_CL 4 /* cookie manager in this tab */
/* actions */
#define XT_MOVE_INVALID (0)
#define XT_MOVE_DOWN (1)
#define XT_MOVE_UP (2)
#define XT_MOVE_BOTTOM (3)
#define XT_MOVE_TOP (4)
#define XT_MOVE_PAGEDOWN (5)
#define XT_MOVE_PAGEUP (6)
#define XT_MOVE_HALFDOWN (7)
#define XT_MOVE_HALFUP (8)
#define XT_MOVE_LEFT (9)
#define XT_MOVE_FARLEFT (10)
#define XT_MOVE_RIGHT (11)
#define XT_MOVE_FARRIGHT (12)
#define XT_TAB_LAST (-4)
#define XT_TAB_FIRST (-3)
#define XT_TAB_PREV (-2)
#define XT_TAB_NEXT (-1)
#define XT_TAB_INVALID (0)
#define XT_TAB_NEW (1)
#define XT_TAB_DELETE (2)
#define XT_TAB_DELQUIT (3)
#define XT_TAB_OPEN (4)
#define XT_TAB_UNDO_CLOSE (5)
#define XT_TAB_SHOW (6)
#define XT_TAB_HIDE (7)
#define XT_NAV_INVALID (0)
#define XT_NAV_BACK (1)
#define XT_NAV_FORWARD (2)
#define XT_NAV_RELOAD (3)
#define XT_NAV_RELOAD_CACHE (4)
#define XT_FOCUS_INVALID (0)
#define XT_FOCUS_URI (1)
#define XT_FOCUS_SEARCH (2)
#define XT_SEARCH_INVALID (0)
#define XT_SEARCH_NEXT (1)
#define XT_SEARCH_PREV (2)
#define XT_PASTE_CURRENT_TAB (0)
#define XT_PASTE_NEW_TAB (1)
#define XT_FONT_SET (0)
#define XT_URL_SHOW (1)
#define XT_URL_HIDE (2)
#define XT_STATUSBAR_SHOW (1)
#define XT_STATUSBAR_HIDE (2)
#define XT_WL_TOGGLE (1<<0)
#define XT_WL_ENABLE (1<<1)
#define XT_WL_DISABLE (1<<2)
#define XT_WL_FQDN (1<<3) /* default */
#define XT_WL_TOPLEVEL (1<<4)
#define XT_CMD_OPEN (0)
#define XT_CMD_OPEN_CURRENT (1)
#define XT_CMD_TABNEW (2)
#define XT_CMD_TABNEW_CURRENT (3)
#define XT_STATUS_NOTHING (0)
#define XT_STATUS_LINK (1)
#define XT_STATUS_URI (2)
#define XT_STATUS_LOADING (3)
#define XT_SES_DONOTHING (0)
#define XT_SES_CLOSETABS (1)
#define XT_BM_NORMAL (0)
#define XT_BM_WHITELIST (1)
#define XT_BM_KIOSK (2)
/* mime types */
struct mime_type {
char *mt_type;
char *mt_action;
int mt_default;
int mt_download;
TAILQ_ENTRY(mime_type) entry;
};
TAILQ_HEAD(mime_type_list, mime_type);
/* uri aliases */
struct alias {
char *a_name;
char *a_uri;
TAILQ_ENTRY(alias) entry;
};
TAILQ_HEAD(alias_list, alias);
/* settings that require restart */
int tabless = 0; /* allow only 1 tab */
int enable_socket = 0;
int single_instance = 0; /* only allow one xxxterm to run */
int fancy_bar = 1; /* fancy toolbar */
int browser_mode = XT_BM_NORMAL;
/* runtime settings */
int show_tabs = 1; /* show tabs on notebook */
int show_url = 1; /* show url toolbar on notebook */
int show_statusbar = 0; /* vimperator style status bar */
int ctrl_click_focus = 0; /* ctrl click gets focus */
int cookies_enabled = 1; /* enable cookies */
int read_only_cookies = 0; /* enable to not write cookies */
int enable_scripts = 1;
int enable_plugins = 0;
int default_font_size = 12;
char *default_font_family = NULL;
char *serif_font_family = NULL;
char *sans_serif_font_family = NULL;
char *monospace_font_family = NULL;
char *default_encoding = NULL;
char *user_stylesheet = NULL;
gfloat default_zoom_level = 1.0;
int window_height = 768;
int window_width = 1024;
int icon_size = 2; /* 1 = smallest, 2+ = bigger */
unsigned refresh_interval = 10; /* download refresh interval */
int enable_cookie_whitelist = 0;
int enable_js_whitelist = 0;
time_t session_timeout = 3600; /* cookie session timeout */
int cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
char *ssl_ca_file = NULL;
char *resource_dir = NULL;
gboolean ssl_strict_certs = FALSE;
int append_next = 1; /* append tab after current tab */
char *home = NULL;
char *search_string = NULL;
char *http_proxy = NULL;
char download_dir[PATH_MAX];
char runtime_settings[PATH_MAX]; /* override of settings */
int allow_volatile_cookies = 0;
int save_global_history = 0; /* save global history to disk */
char *user_agent = NULL;
int save_rejected_cookies = 0;
time_t session_autosave = 0;
int guess_search = 0;
int dns_prefetch = FALSE;
gint max_connections = 25;
gint max_host_connections = 5;
struct settings;
struct key_binding;
int set_download_dir(struct settings *, char *);
int set_work_dir(struct settings *, char *);
int set_runtime_dir(struct settings *, char *);
int set_browser_mode(struct settings *, char *);
int set_cookie_policy(struct settings *, char *);
int add_alias(struct settings *, char *);
int add_mime_type(struct settings *, char *);
int add_cookie_wl(struct settings *, char *);
int add_js_wl(struct settings *, char *);
int add_kb(struct settings *, char *);
void button_set_stockid(GtkWidget *, char *);
GtkWidget * create_button(char *, char *, int);
char *get_browser_mode(struct settings *);
char *get_cookie_policy(struct settings *);
char *get_download_dir(struct settings *);
char *get_work_dir(struct settings *);
char *get_runtime_dir(struct settings *);
void walk_alias(struct settings *, void (*)(struct settings *, char *, void *), void *);
void walk_cookie_wl(struct settings *, void (*)(struct settings *, char *, void *), void *);
void walk_js_wl(struct settings *, void (*)(struct settings *, char *, void *), void *);
void walk_kb(struct settings *, void (*)(struct settings *, char *, void *), void *);
void walk_mime_type(struct settings *, void (*)(struct settings *, char *, void *), void *);
struct special {
int (*set)(struct settings *, char *);
char *(*get)(struct settings *);
void (*walk)(struct settings *, void (*cb)(struct settings *, char *, void *), void *);
};
struct special s_browser_mode = {
set_browser_mode,
get_browser_mode,
NULL
};
struct special s_cookie = {
set_cookie_policy,
get_cookie_policy,
NULL
};
struct special s_alias = {
add_alias,
NULL,
walk_alias
};
struct special s_mime = {
add_mime_type,
NULL,
walk_mime_type
};
struct special s_js = {
add_js_wl,
NULL,
walk_js_wl
};
struct special s_kb = {
add_kb,
NULL,
walk_kb
};
struct special s_cookie_wl = {
add_cookie_wl,
NULL,
walk_cookie_wl
};
struct special s_download_dir = {
set_download_dir,
get_download_dir,
NULL
};
struct special s_work_dir = {
set_work_dir,
get_work_dir,
NULL
};
struct settings {
char *name;
int type;
#define XT_S_INVALID (0)
#define XT_S_INT (1)
#define XT_S_STR (2)
#define XT_S_FLOAT (3)
uint32_t flags;
#define XT_SF_RESTART (1<<0)
#define XT_SF_RUNTIME (1<<1)
int *ival;
char **sval;
struct special *s;
gfloat *fval;
} rs[] = {
{ "append_next", XT_S_INT, 0, &append_next, NULL, NULL },
{ "allow_volatile_cookies", XT_S_INT, 0, &allow_volatile_cookies, NULL, NULL },
{ "browser_mode", XT_S_INT, 0, NULL, NULL,&s_browser_mode },
{ "cookie_policy", XT_S_INT, 0, NULL, NULL,&s_cookie },
{ "cookies_enabled", XT_S_INT, 0, &cookies_enabled, NULL, NULL },
{ "ctrl_click_focus", XT_S_INT, 0, &ctrl_click_focus, NULL, NULL },
{ "default_encoding", XT_S_STR, 0, NULL, &default_encoding, NULL },
{ "default_font_size", XT_S_INT, 0, &default_font_size, NULL, NULL },
{ "default_font_family", XT_S_STR, 0, NULL, &default_font_family, NULL },
{ "default_zoom_level", XT_S_FLOAT, 0, NULL, NULL, NULL, &default_zoom_level },
{ "download_dir", XT_S_STR, 0, NULL, NULL,&s_download_dir },
{ "enable_cookie_whitelist", XT_S_INT, 0, &enable_cookie_whitelist, NULL, NULL },
{ "enable_js_whitelist", XT_S_INT, 0, &enable_js_whitelist, NULL, NULL },
{ "enable_plugins", XT_S_INT, 0, &enable_plugins, NULL, NULL },
{ "enable_scripts", XT_S_INT, 0, &enable_scripts, NULL, NULL },
{ "enable_socket", XT_S_INT, XT_SF_RESTART,&enable_socket, NULL, NULL },
{ "fancy_bar", XT_S_INT, XT_SF_RESTART,&fancy_bar, NULL, NULL },
{ "home", XT_S_STR, 0, NULL, &home, NULL },
{ "http_proxy", XT_S_STR, 0, NULL, &http_proxy, NULL },
{ "icon_size", XT_S_INT, 0, &icon_size, NULL, NULL },
{ "monospace_font_family", XT_S_STR, 0, NULL, &monospace_font_family, NULL },
{ "max_connections", XT_S_INT, XT_SF_RESTART,&max_connections, NULL, NULL },
{ "max_host_connections", XT_S_INT, XT_SF_RESTART,&max_host_connections, NULL, NULL },
{ "read_only_cookies", XT_S_INT, 0, &read_only_cookies, NULL, NULL },
{ "refresh_interval", XT_S_INT, 0, &refresh_interval, NULL, NULL },
{ "resource_dir", XT_S_STR, 0, NULL, &resource_dir, NULL },
{ "sans_serif_font_family", XT_S_STR, 0, NULL, &sans_serif_font_family, NULL },
{ "search_string", XT_S_STR, 0, NULL, &search_string, NULL },
{ "serif_font_family", XT_S_STR, 0, NULL, &serif_font_family, NULL },
{ "save_global_history", XT_S_INT, XT_SF_RESTART,&save_global_history, NULL, NULL },
{ "save_rejected_cookies", XT_S_INT, XT_SF_RESTART,&save_rejected_cookies, NULL, NULL },
{ "session_timeout", XT_S_INT, 0, &session_timeout, NULL, NULL },
{ "session_autosave", XT_S_INT, 0, &session_autosave, NULL, NULL },
{ "single_instance", XT_S_INT, XT_SF_RESTART,&single_instance, NULL, NULL },
{ "show_tabs", XT_S_INT, 0, &show_tabs, NULL, NULL },
{ "show_url", XT_S_INT, 0, &show_url, NULL, NULL },
{ "show_statusbar", XT_S_INT, 0, &show_statusbar, NULL, NULL },
{ "ssl_ca_file", XT_S_STR, 0, NULL, &ssl_ca_file, NULL },
{ "ssl_strict_certs", XT_S_INT, 0, &ssl_strict_certs, NULL, NULL },
{ "user_agent", XT_S_STR, 0, NULL, &user_agent, NULL },
{ "user_stylesheet", XT_S_STR, 0, NULL, &user_stylesheet, NULL },
{ "window_height", XT_S_INT, 0, &window_height, NULL, NULL },
{ "window_width", XT_S_INT, 0, &window_width, NULL, NULL },
{ "work_dir", XT_S_STR, 0, NULL, NULL,&s_work_dir },
/* runtime settings */
{ "alias", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_alias },
{ "cookie_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_cookie_wl },
{ "js_wl", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_js },
{ "keybinding", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_kb },
{ "mime_type", XT_S_STR, XT_SF_RUNTIME, NULL, NULL, &s_mime },
};
int about(struct tab *, struct karg *);
int blank(struct tab *, struct karg *);
int cookie_show_wl(struct tab *, struct karg *);
int js_show_wl(struct tab *, struct karg *);
int help(struct tab *, struct karg *);
int set(struct tab *, struct karg *);
int stats(struct tab *, struct karg *);
int xtp_page_cl(struct tab *, struct karg *);
int xtp_page_dl(struct tab *, struct karg *);
int xtp_page_fl(struct tab *, struct karg *);
int xtp_page_hl(struct tab *, struct karg *);
#define XT_URI_ABOUT ("about:")
#define XT_URI_ABOUT_LEN (strlen(XT_URI_ABOUT))
#define XT_URI_ABOUT_ABOUT ("about")
#define XT_URI_ABOUT_BLANK ("blank")
#define XT_URI_ABOUT_CERTS ("certs") /* XXX NOT YET */
#define XT_URI_ABOUT_COOKIEWL ("cookiewl")
#define XT_URI_ABOUT_COOKIEJAR ("cookiejar")
#define XT_URI_ABOUT_DOWNLOADS ("downloads")
#define XT_URI_ABOUT_FAVORITES ("favorites")
#define XT_URI_ABOUT_HELP ("help")
#define XT_URI_ABOUT_HISTORY ("history")
#define XT_URI_ABOUT_JSWL ("jswl")
#define XT_URI_ABOUT_SET ("set")
#define XT_URI_ABOUT_STATS ("stats")
struct about_type {
char *name;
int (*func)(struct tab *, struct karg *);
} about_list[] = {
{ XT_URI_ABOUT_ABOUT, about },
{ XT_URI_ABOUT_BLANK, blank },
{ XT_URI_ABOUT_COOKIEWL, cookie_show_wl },
{ XT_URI_ABOUT_COOKIEJAR, xtp_page_cl },
{ XT_URI_ABOUT_DOWNLOADS, xtp_page_dl },
{ XT_URI_ABOUT_FAVORITES, xtp_page_fl },
{ XT_URI_ABOUT_HELP, help },
{ XT_URI_ABOUT_HISTORY, xtp_page_hl },
{ XT_URI_ABOUT_JSWL, js_show_wl },
{ XT_URI_ABOUT_SET, set },
{ XT_URI_ABOUT_STATS, stats },
};
/* globals */
extern char *__progname;
char **start_argv;
struct passwd *pwd;
GtkWidget *main_window;
GtkNotebook *notebook;
GtkWidget *arrow, *abtn;
struct tab_list tabs;
struct history_list hl;
struct download_list downloads;
struct domain_list c_wl;
struct domain_list js_wl;
struct undo_tailq undos;
struct keybinding_list kbl;
int undo_count;
int updating_dl_tabs = 0;
int updating_hl_tabs = 0;
int updating_cl_tabs = 0;
int updating_fl_tabs = 0;
char *global_search;
uint64_t blocked_cookies = 0;
char named_session[PATH_MAX];
void update_favicon(struct tab *);
int icon_size_map(int);
GtkListStore *completion_model;
void completion_add(struct tab *);
void completion_add_uri(const gchar *);
void
sigchild(int sig)
{
int saved_errno, status;
pid_t pid;
saved_errno = errno;
while ((pid = waitpid(WAIT_ANY, &status, WNOHANG)) != 0) {
if (pid == -1) {
if (errno == EINTR)
continue;
if (errno != ECHILD) {
/*
clog_warn("sigchild: waitpid:");
*/
}
break;
}
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
/*
clog_warnx("sigchild: child exit status: %d",
WEXITSTATUS(status));
*/
}
} else {
/*
clog_warnx("sigchild: child is terminated abnormally");
*/
}
}
errno = saved_errno;
}
int
is_g_object_setting(GObject *o, char *str)
{
guint n_props = 0, i;
GParamSpec **proplist;
if (! G_IS_OBJECT(o))
return (0);
proplist = g_object_class_list_properties(G_OBJECT_GET_CLASS(o),
&n_props);
for (i=0; i < n_props; i++) {
if (! strcmp(proplist[i]->name, str))
return (1);
}
return (0);
}
void
load_webkit_string(struct tab *t, const char *str, gchar *title)
{
gchar *uri;
char file[PATH_MAX];
GdkPixbuf *pb;
/* we set this to indicate we want to manually do navaction */
if (t->bfl)
t->item = webkit_web_back_forward_list_get_current_item(t->bfl);
webkit_web_view_load_string(t->wv, str, NULL, NULL, NULL);
if (title) {
uri = g_strdup_printf("%s%s", XT_URI_ABOUT, title);
gtk_entry_set_text(GTK_ENTRY(t->uri_entry), uri);
g_free(uri);
snprintf(file, sizeof file, "%s/%s", resource_dir, icons[0]);
pb = gdk_pixbuf_new_from_file(file, NULL);
gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t->uri_entry),
GTK_ENTRY_ICON_PRIMARY, pb);
gdk_pixbuf_unref(pb);
}
}
void
set_status(struct tab *t, gchar *s, int status)
{
gchar *type = NULL;
if (s == NULL)
return;
switch (status) {
case XT_STATUS_LOADING:
type = g_strdup_printf("Loading: %s", s);
s = type;
break;
case XT_STATUS_LINK:
type = g_strdup_printf("Link: %s", s);
if (!t->status)
t->status = g_strdup(gtk_entry_get_text(GTK_ENTRY(t->statusbar)));
s = type;
break;
case XT_STATUS_URI:
type = g_strdup_printf("%s", s);
if (!t->status) {
t->status = g_strdup(type);
}
s = type;
if (!t->status)
t->status = g_strdup(s);
break;
case XT_STATUS_NOTHING:
/* FALL THROUGH */
default:
break;
}
gtk_entry_set_text(GTK_ENTRY(t->statusbar), s);
if (type)
g_free(type);
}
void
hide_oops(struct tab *t)
{
gtk_widget_hide(t->oops);
}
void
hide_cmd(struct tab *t)
{
gtk_widget_hide(t->cmd);
}
void
show_cmd(struct tab *t)
{
gtk_widget_hide(t->oops);
gtk_widget_show(t->cmd);
}
void
show_oops(struct tab *t, const char *fmt, ...)
{
va_list ap;
char *msg;
if (fmt == NULL)
return;
va_start(ap, fmt);
if (vasprintf(&msg, fmt, ap) == -1)
errx(1, "show_oops failed");
va_end(ap);
gtk_entry_set_text(GTK_ENTRY(t->oops), msg);
gtk_widget_hide(t->cmd);
gtk_widget_show(t->oops);
}
/* XXX collapse with show_oops */
void
show_oops_s(const char *fmt, ...)
{
va_list ap;
char *msg;
struct tab *ti, *t = NULL;
if (fmt == NULL)
return;
TAILQ_FOREACH(ti, &tabs, entry)
if (ti->tab_id == gtk_notebook_current_page(notebook)) {
t = ti;
break;
}
if (t == NULL)
return;
va_start(ap, fmt);
if (vasprintf(&msg, fmt, ap) == -1)
errx(1, "show_oops_s failed");
va_end(ap);
gtk_entry_set_text(GTK_ENTRY(t->oops), msg);
gtk_widget_hide(t->cmd);
gtk_widget_show(t->oops);
}
char *
get_as_string(struct settings *s)
{
char *r = NULL;
if (s == NULL)
return (NULL);
if (s->s) {
if (s->s->get)
r = s->s->get(s);
else
warnx("get_as_string skip %s\n", s->name);
} else if (s->type == XT_S_INT)
r = g_strdup_printf("%d", *s->ival);
else if (s->type == XT_S_STR)
r = g_strdup(*s->sval);
else if (s->type == XT_S_FLOAT)
r = g_strdup_printf("%f", *s->fval);
else
r = g_strdup_printf("INVALID TYPE");
return (r);
}
void
settings_walk(void (*cb)(struct settings *, char *, void *), void *cb_args)
{
int i;
char *s;
for (i = 0; i < LENGTH(rs); i++) {
if (rs[i].s && rs[i].s->walk)
rs[i].s->walk(&rs[i], cb, cb_args);
else {
s = get_as_string(&rs[i]);
cb(&rs[i], s, cb_args);
g_free(s);
}
}
}
int
set_browser_mode(struct settings *s, char *val)
{
if (!strcmp(val, "whitelist")) {
browser_mode = XT_BM_WHITELIST;
allow_volatile_cookies = 0;
cookie_policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
cookies_enabled = 1;
enable_cookie_whitelist = 1;
read_only_cookies = 0;
save_rejected_cookies = 0;
session_timeout = 3600;
enable_scripts = 0;
enable_js_whitelist = 1;
} else if (!strcmp(val, "normal")) {
browser_mode = XT_BM_NORMAL;
allow_volatile_cookies = 0;
cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
cookies_enabled = 1;
enable_cookie_whitelist = 0;
read_only_cookies = 0;
save_rejected_cookies = 0;
session_timeout = 3600;
enable_scripts = 1;
enable_js_whitelist = 0;
} else if (!strcmp(val, "kiosk")) {
browser_mode = XT_BM_KIOSK;
allow_volatile_cookies = 0;
cookie_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
cookies_enabled = 1;
enable_cookie_whitelist = 0;
read_only_cookies = 0;
save_rejected_cookies = 0;
session_timeout = 3600;
enable_scripts = 1;
enable_js_whitelist = 0;
show_tabs = 0;
} else