Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 668 lines (611 sloc) 21.625 kb
07921e8 @hxw [grifo] updates from Symbio
hxw authored
1 /*
2 * Copyright (c) 2009 Openmoko Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdio.h>
19 #include <stddef.h>
20 #include <stdlib.h>
21 #include <ctype.h>
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
22
23 #include <grifo.h>
24
25 #include "ustring.h"
07921e8 @hxw [grifo] updates from Symbio
hxw authored
26 #include "guilib.h"
27 #include "glyph.h"
28 #include "sha1.h"
29 #include "search.h"
30 #include "wikilib.h"
31 #include "lcd_buf_draw.h"
32 #include "keyboard.h"
33 #include "restricted.h"
34 #include "bigram.h"
35 #include "history.h"
36 #include "wiki_info.h"
37
38 #define BLACK_SPACE_START RESULT_START
39
40 enum restricted_screen_e {
41
42 RESTRICTED_SCREEN_FIRST_TIME_PASSWORD,
43 RESTRICTED_SCREEN_SET_PASSWORD,
44 RESTRICTED_SCREEN_CONFIRM_PASSWORD,
45 RESTRICTED_SCREEN_CHECK_PASSWORD,
46 RESTRICTED_SCREEN_FILTER_ON_OFF,
47 RESTRICTED_SCREEN_FILTER_OPTION,
48 RESTRICTED_SCREEN_CHANGE_PASSWORD,
49 };
50
51 enum filter_option_e {
52
53 FILTER_OPTION_TO_SET_NONE,
54 FILTER_OPTION_TO_SET_ON,
55 FILTER_OPTION_TO_SET_OFF,
56 };
57
58 extern int restricted_article;
59 extern int display_mode;
60 extern int last_display_mode;
61 extern int article_offset;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
62 static unsigned char password_string[MAX_PASSWORD_LEN];
63 static unsigned char password1[MAX_PASSWORD_LEN];
07921e8 @hxw [grifo] updates from Symbio
hxw authored
64 static int password_str_len = 0;
65 static int restricted_screen_mode;
66 static int filter_option_to_set = FILTER_OPTION_TO_SET_NONE;
67 int restriction_filter_off = -1;
68 char restriction_pass1[20];
69 extern long saved_idx_article;
70 int init_filtering = 0;
71 void first_time_password(int flag)
72 {
73 int i;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
74 const unsigned char *pText;
75 unsigned char str[256];
07921e8 @hxw [grifo] updates from Symbio
hxw authored
76 uint8_t *framebuffer = lcd_get_framebuffer();
77
78 guilib_fb_lock();
79 memset(&framebuffer[(BLACK_SPACE_START - 6)* LCD_BUFFER_WIDTH / 8], 0, 6 * LCD_BUFFER_WIDTH / 8);
80 memset(&framebuffer[BLACK_SPACE_START * LCD_BUFFER_WIDTH / 8], 0xFF, (LCD_HEIGHT - BLACK_SPACE_START)* LCD_BUFFER_WIDTH / 8);
81
82 framebuffer[149 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
83 memset(&framebuffer[149 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
84 framebuffer[149 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
85 for (i = 150; i <= 168; i++)
86 {
87 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 1] = 0xF8;
88 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
89 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
90 }
91 framebuffer[169 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
92 memset(&framebuffer[169 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
93 framebuffer[169 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
94
95 if (flag)
96 {
97 pText = get_nls_text("protection");
549d219 @hxw [compiler warnings] fixes for updated compiler in Ubuntu 11.10
hxw authored
98 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
99 if (ustrlen(str))
100 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 10, str, ustrlen(str), 1);
549d219 @hxw [compiler warnings] fixes for updated compiler in Ubuntu 11.10
hxw authored
101 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
102 if (ustrlen(str))
103 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 30, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
104 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
105 if (ustrlen(str))
106 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 50, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
107 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
108 if (ustrlen(str))
109 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 70, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
110 }
111 else
112 {
113 pText = get_nls_text("restricted");
114 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
115 if (ustrlen(str))
116 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 10, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
117 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
118 if (ustrlen(str))
119 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 30, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
120 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
121 if (ustrlen(str))
122 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 50, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
123 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
124 if (ustrlen(str))
125 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 70, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
126 }
127 pText = get_nls_text("set_password");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
128 render_string(SUBTITLE_FONT_IDX, -1, 151, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
129 guilib_fb_unlock();
130 display_mode = DISPLAY_MODE_RESTRICTED;
131 keyboard_set_mode(KEYBOARD_RESTRICTED);
132 restricted_screen_mode = RESTRICTED_SCREEN_FIRST_TIME_PASSWORD;
133 }
134
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
135 void enter_password_screen(const unsigned char *msg)
07921e8 @hxw [grifo] updates from Symbio
hxw authored
136 {
137 int i;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
138 const unsigned char *pText;
07921e8 @hxw [grifo] updates from Symbio
hxw authored
139 uint8_t *framebuffer = lcd_get_framebuffer();
140
141 display_mode = DISPLAY_MODE_RESTRICTED;
142 keyboard_set_mode(KEYBOARD_PASSWORD_CHAR);
143 guilib_fb_lock();
144 keyboard_paint();
145 memset(&framebuffer[(BLACK_SPACE_START - 6)* LCD_BUFFER_WIDTH / 8], 0, 6 * LCD_BUFFER_WIDTH / 8);
146 memset(&framebuffer[BLACK_SPACE_START * LCD_BUFFER_WIDTH / 8], 0xFF,
147 (LCD_HEIGHT - BLACK_SPACE_START - keyboard_height())* LCD_BUFFER_WIDTH / 8);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
148 render_string(SUBTITLE_FONT_IDX, -1, 50, msg, ustrlen(msg), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
149
150 framebuffer[82 * LCD_BUFFER_WIDTH / 8 + 4] = 0xFC;
151 memset(&framebuffer[82 * LCD_BUFFER_WIDTH / 8 + 5], 0, 16);
152 framebuffer[82 * LCD_BUFFER_WIDTH / 8 + 21] = 0x07;
153
154 framebuffer[82 * LCD_BUFFER_WIDTH / 8 + 22] = 0x80;
0252051 @hxw [wiki] Update from Symbio: ok button size increase
hxw authored
155 memset(&framebuffer[82 * LCD_BUFFER_WIDTH / 8 + 23], 0, 5);
156 framebuffer[82 * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
07921e8 @hxw [grifo] updates from Symbio
hxw authored
157
158 for (i = 83; i <= 103; i++)
159 {
160 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 4] = 0xF8;
161 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 5], 0, 16);
162 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 21] = 0x03;
163
164 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 22] = 0x00;
0252051 @hxw [wiki] Update from Symbio: ok button size increase
hxw authored
165 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 23], 0, 5);
166 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x0F;
07921e8 @hxw [grifo] updates from Symbio
hxw authored
167 }
168
169 framebuffer[104 * LCD_BUFFER_WIDTH / 8 + 4] = 0xFC;
170 memset(&framebuffer[104 * LCD_BUFFER_WIDTH / 8 + 5], 0, 16);
171 framebuffer[104 * LCD_BUFFER_WIDTH / 8 + 21] = 0x07;
172
173 framebuffer[104 * LCD_BUFFER_WIDTH / 8 + 22] = 0x80;
0252051 @hxw [wiki] Update from Symbio: ok button size increase
hxw authored
174 memset(&framebuffer[104 * LCD_BUFFER_WIDTH / 8 + 23], 0, 5);
175 framebuffer[104 * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
07921e8 @hxw [grifo] updates from Symbio
hxw authored
176
177 pText = get_nls_text("ok");
0252051 @hxw [wiki] Update from Symbio: ok button size increase
hxw authored
178 render_string_centered(SUBTITLE_FONT_IDX, 177, 85, 50, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
179 guilib_fb_unlock();
180 }
181
182 void filter_on_off(void)
183 {
184 int i;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
185 const unsigned char *pText;
186 unsigned char str[256];
07921e8 @hxw [grifo] updates from Symbio
hxw authored
187 uint8_t *framebuffer = lcd_get_framebuffer();
188
189 guilib_fb_lock();
190 memset(&framebuffer[(BLACK_SPACE_START - 6)* LCD_BUFFER_WIDTH / 8], 0, 6 * LCD_BUFFER_WIDTH / 8);
191 memset(&framebuffer[BLACK_SPACE_START * LCD_BUFFER_WIDTH / 8], 0xFF, (LCD_HEIGHT - BLACK_SPACE_START)* LCD_BUFFER_WIDTH / 8);
192
193 framebuffer[135 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
194 memset(&framebuffer[135 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
195 framebuffer[135 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
196 for (i = 136; i <= 155; i++)
197 {
198 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 1] = 0xF8;
199 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
200 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
201 }
202 framebuffer[156 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
203 memset(&framebuffer[156 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
204 framebuffer[156 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
205
206 framebuffer[164 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
207 memset(&framebuffer[164 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
208 framebuffer[164 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
209 for (i = 165; i <= 184; i++)
210 {
211 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 1] = 0xF8;
212 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
213 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
214 }
215 framebuffer[185 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
216 memset(&framebuffer[185 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
217 framebuffer[185 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
218
219 pText = get_nls_text("set_filter");
220 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
221 if (ustrlen(str))
222 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 10, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
223 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
224 if (ustrlen(str))
225 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 30, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
226 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
227 if (ustrlen(str))
228 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 50, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
229 extract_str_fitting_width(&pText, str, LCD_BUF_WIDTH_PIXELS - LCD_LEFT_MARGIN, SUBTITLE_FONT_IDX);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
230 if (ustrlen(str))
231 render_string(SUBTITLE_FONT_IDX, LCD_LEFT_MARGIN, BLACK_SPACE_START + 70, str, ustrlen(str), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
232 pText = get_nls_text("keep_filter_on");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
233 render_string(SUBTITLE_FONT_IDX, -1, 137, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
234 pText = get_nls_text("keep_filter_off");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
235 render_string(SUBTITLE_FONT_IDX, -1, 166, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
236 guilib_fb_unlock();
237 keyboard_set_mode(KEYBOARD_FILTER_ON_OFF);
238 }
239
240 void filter_option(void)
241 {
242 int i;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
243 const unsigned char *pText;
07921e8 @hxw [grifo] updates from Symbio
hxw authored
244 uint8_t *framebuffer = lcd_get_framebuffer();
245
246 display_mode = DISPLAY_MODE_RESTRICTED;
247 keyboard_set_mode(KEYBOARD_FILTER_OPTION);
248 restricted_screen_mode = RESTRICTED_SCREEN_FILTER_OPTION;
249 guilib_fb_lock();
250 memset(&framebuffer[(BLACK_SPACE_START - 6)* LCD_BUFFER_WIDTH / 8], 0, 6 * LCD_BUFFER_WIDTH / 8);
251 memset(&framebuffer[BLACK_SPACE_START * LCD_BUFFER_WIDTH / 8], 0xFF, (LCD_HEIGHT - BLACK_SPACE_START)* LCD_BUFFER_WIDTH / 8);
252
253 pText = get_nls_text("filter_options");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
254 render_string(TITLE_FONT_IDX, -1, 60, pText, ustrlen(pText), 1);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
255
256 framebuffer[106 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
257 memset(&framebuffer[106 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
258 framebuffer[106 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
259 for (i = 107; i <= 126; i++)
260 {
261 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 1] = 0xF8;
262 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
263 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
264 }
265 framebuffer[127 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
266 memset(&framebuffer[127 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
267 framebuffer[127 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
268
269 framebuffer[135 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
270 memset(&framebuffer[135 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
271 framebuffer[135 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
272 for (i = 136; i <= 155; i++)
273 {
274 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 1] = 0xF8;
275 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
276 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
277 }
278 framebuffer[156 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
279 memset(&framebuffer[156 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
280 framebuffer[156 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
281
282 framebuffer[164 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
283 memset(&framebuffer[164 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
284 framebuffer[164 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
285 for (i = 165; i <= 185; i++)
286 {
287 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 1] = 0xF8;
288 memset(&framebuffer[i * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
289 framebuffer[i * LCD_BUFFER_WIDTH / 8 + 28] = 0x1F;
290 }
291 framebuffer[186 * LCD_BUFFER_WIDTH / 8 + 1] = 0xFC;
292 memset(&framebuffer[186 * LCD_BUFFER_WIDTH / 8 + 2], 0, 26);
293 framebuffer[186 * LCD_BUFFER_WIDTH / 8 + 28] = 0x3F;
294
295 pText = get_nls_text("turn_filter_on");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
296 render_string(SUBTITLE_FONT_IDX, -1, 108, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
297 pText = get_nls_text("turn_filter_off");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
298 render_string(SUBTITLE_FONT_IDX, -1, 137, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
299 pText = get_nls_text("change_password");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
300 render_string(SUBTITLE_FONT_IDX, -1, 166, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
301 guilib_fb_unlock();
302 keyboard_set_mode(KEYBOARD_FILTER_OPTION);
303 }
304
305 void save_password(int flag)
306 {
307 int fd;
308 SHA1Context sha;
309
310 fd = file_open("wiki.pas", FILE_OPEN_WRITE);
311 if (fd < 0)
312 fd = file_create("wiki.pas", FILE_OPEN_WRITE);
313 if (fd >= 0)
314 {
315 if (password_str_len > 0)
316 {
317 SHA1Reset(&sha);
318 SHA1Input(&sha, (const unsigned char *) password_string, password_str_len);
319 SHA1Result(&sha);
320 memcpy(restriction_pass1, sha.Message_Digest, 20);
321 }
322 else
1f1b68f @hxw [grifo] tidy up spacing and remove CR characters
hxw authored
323 memset(restriction_pass1, 0, 20);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
324 file_write(fd, restriction_pass1, 20);
325 if (password_str_len > 0 && flag > 1)
326 {
327 SHA1Reset(&sha);
328 SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20);
329 SHA1Result(&sha);
330 file_write(fd, sha.Message_Digest, 20);
331 }
1f1b68f @hxw [grifo] tidy up spacing and remove CR characters
hxw authored
332 else
333 {
334 char buf[20];
335 memset(buf, 0, 20);
336 file_write(fd, buf, 20);
337 }
07921e8 @hxw [grifo] updates from Symbio
hxw authored
338
339 file_close(fd);
340 delay_us(200000); // for some reason, save may not work if no delay
341 }
342 }
343
344 void handle_password_key(char keycode)
345 {
346 switch (restricted_screen_mode)
347 {
348 case RESTRICTED_SCREEN_FIRST_TIME_PASSWORD:
349 case RESTRICTED_SCREEN_SET_PASSWORD:
350 case RESTRICTED_SCREEN_CONFIRM_PASSWORD:
351 case RESTRICTED_SCREEN_CHECK_PASSWORD:
352 case RESTRICTED_SCREEN_CHANGE_PASSWORD:
353 if (keycode == 'Y') {
354 if (restricted_screen_mode == RESTRICTED_SCREEN_FIRST_TIME_PASSWORD)
355 {
356 password_str_len = 0;
357 keyboard_set_mode(KEYBOARD_PASSWORD_CHAR);
358 enter_password_screen(get_nls_text("set_password"));
359 restricted_screen_mode = RESTRICTED_SCREEN_SET_PASSWORD;
360 }
361 else if (restricted_screen_mode == RESTRICTED_SCREEN_SET_PASSWORD && password_str_len > 0)
362 {
363 restricted_screen_mode = RESTRICTED_SCREEN_CONFIRM_PASSWORD;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
364 ustrcpy(password1, password_string);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
365 password_str_len = 0;
366 if (restriction_filter_off == -1)
367 enter_password_screen(get_nls_text("re_enter_password"));
368 else
369 enter_password_screen(get_nls_text("re_enter_new_password"));
370 }
371 else if (restricted_screen_mode == RESTRICTED_SCREEN_CONFIRM_PASSWORD && password_str_len > 0)
372 {
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
373 if (ustrcmp(password1, password_string))
07921e8 @hxw [grifo] updates from Symbio
hxw authored
374 {
375 password_str_len = 0;
376 restricted_screen_mode = RESTRICTED_SCREEN_SET_PASSWORD;
377 enter_password_screen(get_nls_text("passwords_not_match"));
378 }
379 else
380 {
381 restriction_filter_off = 0;
382 save_password(1);
383 restricted_screen_mode = RESTRICTED_SCREEN_FILTER_ON_OFF;
384 filter_on_off();
385 }
386 }
387 else if (password_str_len > 0)
388 {
389 check_password();
390 }
391 } else if (keycode == WL_KEY_BACKSPACE) {
392 password_remove_char();
393 } else if (is_supported_search_char(keycode)) {
394 password_add_char(tolower(keycode));
395 }
396 break;
397 case RESTRICTED_SCREEN_FILTER_ON_OFF:
398 if (keycode == 'Y') {
399 restriction_filter_off = 0;
400 if (init_filtering)
401 {
402 init_filtering = 0;
403 search_set_selection(-1);
404 display_mode = DISPLAY_MODE_INDEX;
405 keyboard_set_mode(wiki_default_keyboard());
406 repaint_search();
407 }
408 else
409 {
410 display_mode = DISPLAY_MODE_ARTICLE;
411 display_retrieved_article(saved_idx_article);
412 }
413 } else if (keycode == 'N') {
414 restriction_filter_off = 1;
415 save_password(2);
416 if (init_filtering)
417 {
418 init_filtering = 0;
419 search_set_selection(-1);
420 display_mode = DISPLAY_MODE_INDEX;
421 keyboard_set_mode(wiki_default_keyboard());
422 repaint_search();
423 }
424 else
425 {
426 display_mode = DISPLAY_MODE_ARTICLE;
427 display_retrieved_article(saved_idx_article);
428 }
429 }
430 break;
431 case RESTRICTED_SCREEN_FILTER_OPTION:
432 if (keycode == 'Y') {
433 filter_option_to_set = FILTER_OPTION_TO_SET_ON;
434 password_str_len = 0;
435 check_password();
436 }
437 else if (keycode == 'N') {
438 filter_option_to_set = FILTER_OPTION_TO_SET_OFF;
439 password_str_len = 0;
440 check_password();
441 }
442 if (keycode == 'P') {
443 password_str_len = 0;
444 keyboard_set_mode(KEYBOARD_PASSWORD_CHAR);
445 enter_password_screen(get_nls_text("enter_old_password"));
446 restricted_screen_mode = RESTRICTED_SCREEN_CHANGE_PASSWORD;
447 }
448 break;
449 default:
450 break;
451 }
452 }
453
454 void check_password()
455 {
456 SHA1Context sha;
457 char pass_sha1[20];
458
459
460 if (password_str_len <= 0)
461 {
462 if (restricted_screen_mode != RESTRICTED_SCREEN_FILTER_OPTION)
463 filter_option_to_set = FILTER_OPTION_TO_SET_NONE;
464 restricted_screen_mode = RESTRICTED_SCREEN_CHECK_PASSWORD;
465 enter_password_screen(get_nls_text("enter_password"));
466 }
467 else
468 {
469 SHA1Reset(&sha);
470 SHA1Input(&sha, (const unsigned char *) password_string, password_str_len);
471 SHA1Result(&sha);
472 memcpy(pass_sha1, sha.Message_Digest, 20);
473 if (memcmp(pass_sha1, restriction_pass1, 20))
474 {
475 password_str_len = 0;
476 if (restricted_screen_mode != RESTRICTED_SCREEN_CHANGE_PASSWORD)
477 restricted_screen_mode = RESTRICTED_SCREEN_CHECK_PASSWORD;
478 enter_password_screen(get_nls_text("try_again"));
479 }
480 else
481 {
482 if (restricted_screen_mode == RESTRICTED_SCREEN_CHANGE_PASSWORD)
483 {
484 password_str_len = 0;
485 keyboard_set_mode(KEYBOARD_PASSWORD_CHAR);
486 enter_password_screen(get_nls_text("enter_new_password"));
487 restricted_screen_mode = RESTRICTED_SCREEN_SET_PASSWORD;
488 }
489 else if (filter_option_to_set == FILTER_OPTION_TO_SET_ON)
490 {
491 restriction_filter_off = 0;
492 save_password(1);
493 last_display_mode = DISPLAY_MODE_ARTICLE;
494 display_mode = DISPLAY_MODE_ARTICLE;
495 display_retrieved_article(saved_idx_article);
496 }
497 else if (filter_option_to_set == FILTER_OPTION_TO_SET_OFF)
498 {
499 restriction_filter_off = 1;
500 save_password(2);
501 last_display_mode = DISPLAY_MODE_ARTICLE;
502 display_mode = DISPLAY_MODE_ARTICLE;
503 display_retrieved_article(saved_idx_article);
504 }
505 else
506 {
507 display_mode = DISPLAY_MODE_ARTICLE;
508 display_retrieved_article(saved_idx_article);
509 }
510 }
511 }
512 }
513
514 int init_article_filter(void)
515 {
516 int fd;
517 int len;
518 char restriction_pass2[20];
519 SHA1Context sha;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
520 const unsigned char *pText;
07921e8 @hxw [grifo] updates from Symbio
hxw authored
521 uint8_t *framebuffer = lcd_get_framebuffer();
522
523 if (restriction_filter_off == -1)
524 {
525 fd = file_open("wiki.pas", FILE_OPEN_READ);
526 if (fd >= 0)
527 {
528 len = file_read(fd, restriction_pass1, 20);
529 if (len < 20)
530 memset(restriction_pass1, 0, 20);
1f1b68f @hxw [grifo] tidy up spacing and remove CR characters
hxw authored
531 memset(restriction_pass2, 0, 20);
532 if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved
07921e8 @hxw [grifo] updates from Symbio
hxw authored
533 {
534 len = file_read(fd, restriction_pass2, 20);
535 if (len < 20)
536 memset(restriction_pass2, 0, 20);
537
538 SHA1Reset(&sha);
539 SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20);
540 SHA1Result(&sha);
541 if (!memcmp(sha.Message_Digest, restriction_pass2, 20))
542 restriction_filter_off = 1;
543 else
544 restriction_filter_off = 0;
545 }
546 file_close(fd);
547 }
548 }
549
550 if (restriction_filter_off == -1)
551 {
552 init_filtering = 1;
553 memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_BUFFER_WIDTH / 8);
554 pText = get_nls_text("parental_controls");
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
555 render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, pText, ustrlen(pText), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
556 first_time_password(1);
557 return -1;
558 }
559 else
560 return 0;
561 }
562
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
563 int check_restriction(void)
07921e8 @hxw [grifo] updates from Symbio
hxw authored
564 {
565 int fd;
566 int len;
567 char restriction_pass2[20];
568 SHA1Context sha;
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
569 unsigned char title[MAX_TITLE_ACTUAL];
07921e8 @hxw [grifo] updates from Symbio
hxw authored
570 uint8_t *framebuffer = lcd_get_framebuffer();
571
572 init_filtering = 0;
573 if (restriction_filter_off == -1)
574 {
575 fd = file_open("wiki.pas", FILE_OPEN_READ);
576 if (fd >= 0)
577 {
578 len = file_read(fd, restriction_pass1, 20);
579 if (len < 20)
580 memset(restriction_pass1, 0, 20);
1f1b68f @hxw [grifo] tidy up spacing and remove CR characters
hxw authored
581 memset(restriction_pass2, 0, 20);
582 if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved
07921e8 @hxw [grifo] updates from Symbio
hxw authored
583 {
584 len = file_read(fd, restriction_pass2, 20);
585 if (len < 20)
586 memset(restriction_pass2, 0, 20);
587
588 SHA1Reset(&sha);
589 SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20);
590 SHA1Result(&sha);
591 if (!memcmp(sha.Message_Digest, restriction_pass2, 20))
592 restriction_filter_off = 1;
593 else
594 restriction_filter_off = 0;
595 }
596 file_close(fd);
597 }
598 }
599
600 if (restriction_filter_off == -1)
601 {
602 get_article_title_from_idx(saved_idx_article, title);
603 memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_BUFFER_WIDTH / 8);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
604 render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, ustrlen(title), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
605 first_time_password(0);
606 return -1;
607 } else if (restriction_filter_off)
608 return 0; // ok
609 else
610 {
611 get_article_title_from_idx(saved_idx_article, title);
612 memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_BUFFER_WIDTH / 8);
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
613 render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, ustrlen(title), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
614 password_str_len = 0;
615 check_password();
616 return -1;
617 }
618 }
619
620 int password_add_char(char c)
621 {
622 if(c == 0x20 && password_str_len > 0 && password_string[password_str_len-1] == 0x20)
623 return -1;
624 if (password_str_len >= MAX_PASSWORD_LEN - 1) // reserve one byte for '\0'
625 return -1;
626
627 if (!password_str_len && c == 0x20)
628 return -1;
629
630 keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW, 0);
631 if ('A' <= c && c <= 'Z')
632 c += 32;
633 password_string[password_str_len++] = c;
634 password_string[password_str_len] = '\0';
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
635 render_string(SUBTITLE_FONT_IDX, 38, 85, password_string, ustrlen(password_string), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
636 return 0;
637 }
638
639 /*
640 * return value - 0: remove ok, -1: no key to remove
641 */
642 int password_remove_char(void)
643 {
644 int x;
645
646 if (password_str_len == 0)
647 return -1;
648
649 password_string[--password_str_len] = '\0';
65f4d63 @hxw [grifo] make the wiki.app work on the grifo simulator
hxw authored
650 x = render_string(SUBTITLE_FONT_IDX, 38, 85, password_string, ustrlen(password_string), 0);
07921e8 @hxw [grifo] updates from Symbio
hxw authored
651 guilib_clear_area(x, 85, 172, 103);
652 return 0;
653 }
654
655 int clear_password_string(void)
656 {
657 if (password_str_len == 0)
658 return -1;
659 password_str_len = 0;
660 password_string[0] = '\0';
661 return 0;
662 }
663
664 int get_password_string_len(void)
665 {
666 return password_str_len;
667 }
Something went wrong with that request. Please try again.