annotate src/prefsparser.cc @ 1644:2650456b8199

filter automatic requests same_domain option in preference so that spying on users isn't so easy.
author corvid <corvid@lavabit.com>
date Tue, 06 Apr 2010 02:27:54 +0000
parents c47ab3201464
children 44b04d308585
rev   line source
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
1 /*
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
2 * Preferences parser
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
3 *
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
4 * Copyright (C) 2006-2009 Jorge Arellano Cid <jcid@dillo.org>
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
5 *
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
9 * (at your option) any later version.
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
10 */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
11
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
12 #include <sys/types.h>
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
13 #include <stdlib.h>
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
14 #include <locale.h> /* for setlocale */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
15
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
16 #include "prefs.h"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
17 #include "misc.h"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
18 #include "msg.h"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
19
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
20 #include "prefsparser.hh"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
21
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
22 typedef enum {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
23 PREFS_BOOL,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
24 PREFS_STRING,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
25 PREFS_URL,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
26 PREFS_INT32,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
27 PREFS_DOUBLE,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
28 PREFS_GEOMETRY,
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
29 PREFS_FILTER,
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
30 PREFS_PANEL_SIZE
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
31 } PrefType_t;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
32
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
33 typedef struct SymNode_ {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
34 const char *name;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
35 void *pref;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
36 PrefType_t type;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
37 } SymNode_t;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
38
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
39 /*
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
40 * Parse a name/value pair and set preferences accordingly.
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
41 */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
42 int PrefsParser::parseOption(char *name, char *value)
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
43 {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
44 const SymNode_t *node;
1059
7bec6cfe6b6b Switched a few remaining "unsigned int" to "uint_t"
Jorge Arellano Cid <jcid@dillo.org>
parents: 1053
diff changeset
45 uint_t i;
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
46
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
47 /* Symbol array, sorted alphabetically */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
48 const SymNode_t symbols[] = {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
49 { "allow_white_bg", &prefs.allow_white_bg, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
50 { "buffered_drawing", &prefs.buffered_drawing, PREFS_INT32 },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
51 { "contrast_visited_color", &prefs.contrast_visited_color, PREFS_BOOL },
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1186
diff changeset
52 { "enterpress_forces_submit", &prefs.enterpress_forces_submit,
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
53 PREFS_BOOL },
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
54 { "filter_auto_requests", &prefs.filter_auto_requests, PREFS_FILTER },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
55 { "focus_new_tab", &prefs.focus_new_tab, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
56 { "font_cursive", &prefs.font_cursive, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
57 { "font_factor", &prefs.font_factor, PREFS_DOUBLE },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
58 { "font_fantasy", &prefs.font_fantasy, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
59 { "font_max_size", &prefs.font_max_size, PREFS_INT32 },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
60 { "font_min_size", &prefs.font_min_size, PREFS_INT32 },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
61 { "font_monospace", &prefs.font_monospace, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
62 { "font_sans_serif", &prefs.font_sans_serif, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
63 { "font_serif", &prefs.font_serif, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
64 { "fullwindow_start", &prefs.fullwindow_start, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
65 { "geometry", NULL, PREFS_GEOMETRY },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
66 { "home", &prefs.home, PREFS_URL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
67 { "http_language", &prefs.http_language, PREFS_STRING },
1530
356c339d0761 limit the number of simultaneous connections
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1525
diff changeset
68 { "http_max_conns", &prefs.http_max_conns, PREFS_INT32 },
1514
239f9fc6c313 backout: That way would make no_proxy complicated.
corvid <corvid@lavabit.com>
parents: 1513
diff changeset
69 { "http_proxy", &prefs.http_proxy, PREFS_URL },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
70 { "http_proxyuser", &prefs.http_proxyuser, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
71 { "http_referer", &prefs.http_referer, PREFS_STRING },
1560
c47ab3201464 add http_user_agent preference
Alexander Voigt, corvid
parents: 1530
diff changeset
72 { "http_user_agent", &prefs.http_user_agent, PREFS_STRING },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
73 { "limit_text_width", &prefs.limit_text_width, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
74 { "load_images", &prefs.load_images, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
75 { "load_stylesheets", &prefs.load_stylesheets, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
76 { "middle_click_drags_page", &prefs.middle_click_drags_page,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
77 PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
78 { "middle_click_opens_new_tab", &prefs.middle_click_opens_new_tab,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
79 PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
80 { "no_proxy", &prefs.no_proxy, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
81 { "panel_size", &prefs.panel_size, PREFS_PANEL_SIZE },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
82 { "parse_embedded_css", &prefs.parse_embedded_css, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
83 { "save_dir", &prefs.save_dir, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
84 { "search_url", &prefs.search_url, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
85 { "show_back", &prefs.show_back, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
86 { "show_bookmarks", &prefs.show_bookmarks, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
87 { "show_clear_url", &prefs.show_clear_url, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
88 { "show_extra_warnings", &prefs.show_extra_warnings, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
89 { "show_filemenu", &prefs.show_filemenu, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
90 { "show_forw", &prefs.show_forw, PREFS_BOOL },
1525
3c683905dbe3 Added a help button. It tries a local help file then dillo.org's one.
corvid, jcid
parents: 1514
diff changeset
91 { "show_help", &prefs.show_help, PREFS_BOOL },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
92 { "show_home", &prefs.show_home, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
93 { "show_msg", &prefs.show_msg, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
94 { "show_progress_box", &prefs.show_progress_box, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
95 { "show_reload", &prefs.show_reload, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
96 { "show_save", &prefs.show_save, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
97 { "show_search", &prefs.show_search, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
98 { "show_stop", &prefs.show_stop, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
99 { "show_tools", &prefs.show_tools, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
100 { "show_tooltip", &prefs.show_tooltip, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
101 { "show_url", &prefs.show_url, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
102 { "small_icons", &prefs.small_icons, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
103 { "start_page", &prefs.start_page, PREFS_URL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
104 { "w3c_plus_heuristics", &prefs.w3c_plus_heuristics, PREFS_BOOL }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
105 };
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
106
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
107 node = NULL;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
108 for (i = 0; i < sizeof(symbols) / sizeof(SymNode_t); i++) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
109 if (!strcmp(symbols[i].name, name)) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
110 node = & (symbols[i]);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
111 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
112 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
113 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
114
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
115 if (!node) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
116 MSG("prefs: {%s} is not a recognized token.\n", name);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
117 return -1;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
118 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
119
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
120 switch (node->type) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
121 case PREFS_BOOL:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
122 *(bool_t *)node->pref = (!dStrcasecmp(value, "yes") ||
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
123 !dStrcasecmp(value, "true"));
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
124 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
125 case PREFS_STRING:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
126 dFree(*(char **)node->pref);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
127 *(char **)node->pref = dStrdup(value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
128 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
129 case PREFS_URL:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
130 a_Url_free(*(DilloUrl **)node->pref);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
131 *(DilloUrl **)node->pref = a_Url_new(value, NULL);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
132 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
133 case PREFS_INT32:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
134 *(int32_t *)node->pref = strtol(value, NULL, 10);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
135 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
136 case PREFS_DOUBLE:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
137 *(double *)node->pref = strtod(value, NULL);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
138 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
139 case PREFS_GEOMETRY:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
140 a_Misc_parse_geometry(value, &prefs.xpos, &prefs.ypos,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
141 &prefs.width, &prefs.height);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
142 break;
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
143 case PREFS_FILTER:
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
144 if (!dStrcasecmp(value, "same_domain"))
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
145 prefs.filter_auto_requests = PREFS_FILTER_SAME_DOMAIN;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
146 else {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
147 if (dStrcasecmp(value, "allow_all"))
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
148 MSG_WARN("prefs: unrecognized value for filter_auto_requests\n");
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
149 prefs.filter_auto_requests = PREFS_FILTER_ALLOW_ALL;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
150 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
151 break;
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
152 case PREFS_PANEL_SIZE:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
153 if (!dStrcasecmp(value, "tiny"))
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
154 prefs.panel_size = P_tiny;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
155 else if (!dStrcasecmp(value, "small"))
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
156 prefs.panel_size = P_small;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
157 else if (!dStrcasecmp(value, "large"))
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
158 prefs.panel_size = P_large;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
159 else /* default to "medium" */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
160 prefs.panel_size = P_medium;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
161 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
162 default:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
163 MSG_WARN("prefs: {%s} IS recognized but not handled!\n", name);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
164 break; /* Not reached */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
165 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
166
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
167 if (prefs.limit_text_width) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
168 /* BUG: causes 100% CPU usage with <button> or <input type="image"> */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
169 MSG_WARN("Disabling limit_text_width preference (currently broken).\n");
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
170 prefs.limit_text_width = FALSE;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
171 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
172
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
173 return 0;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
174 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
175
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
176 /*
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
177 * Parses the dillorc and sets the values in the prefs structure.
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
178 */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
179 void PrefsParser::parse(FILE *fp)
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
180 {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
181 char *line, *name, *value, *oldLocale;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
182 int st;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
183
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
184 // changing the LC_NUMERIC locale (temporarily) to C
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
185 // avoids parsing problems with float numbers
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
186 oldLocale = dStrdup(setlocale(LC_NUMERIC, NULL));
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
187 setlocale(LC_NUMERIC, "C");
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
188
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
189 // scan the file line by line
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
190 while ((line = dGetline(fp)) != NULL) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
191 st = dParser_parse_rc_line(&line, &name, &value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
192
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
193 if (st == 0) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
194 _MSG("prefsparser: name=%s, value=%s\n", name, value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
195 parseOption(name, value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
196 } else if (st < 0) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
197 MSG_ERR("prefsparser: Syntax error in dillorc:"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
198 " name=\"%s\" value=\"%s\"\n", name, value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
199 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
200
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
201 dFree(line);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
202 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
203 fclose(fp);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
204
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
205 // restore the old numeric locale
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
206 setlocale(LC_NUMERIC, oldLocale);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
207 dFree(oldLocale);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
208 }