int check_restriction(long idx_article) { int fd; int len; char restriction_pass2[20]; SHA1Context sha; char title[MAX_TITLE_ACTUAL]; init_filtering = 0; if (restriction_filter_off == -1) { fd = wl_open("wiki.pas", WL_O_RDONLY); if (fd >= 0) { len = wl_read(fd, restriction_pass1, 20); if (len < 20) memset(restriction_pass1, 0, 20); memset(restriction_pass2, 0, 20); if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved { len = wl_read(fd, restriction_pass2, 20); if (len < 20) memset(restriction_pass2, 0, 20); SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20); SHA1Result(&sha); if (!memcmp(sha.Message_Digest, restriction_pass2, 20)) restriction_filter_off = 1; else restriction_filter_off = 0; } wl_close(fd); } } if (restriction_filter_off == -1) { get_article_title_from_idx(saved_idx_article, title); memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8); render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0); first_time_password(0); return -1; } else if (restriction_filter_off) return 0; // ok else { get_article_title_from_idx(saved_idx_article, title); memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8); render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0); password_str_len = 0; check_password(); return -1; } }
int init_article_filter(void) { int fd; int len; char restriction_pass2[20]; SHA1Context sha; unsigned char *pText; if (restriction_filter_off == -1) { fd = wl_open("wiki.pas", WL_O_RDONLY); if (fd >= 0) { len = wl_read(fd, restriction_pass1, 20); if (len < 20) memset(restriction_pass1, 0, 20); memset(restriction_pass2, 0, 20); if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved { len = wl_read(fd, restriction_pass2, 20); if (len < 20) memset(restriction_pass2, 0, 20); SHA1Reset(&sha); SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20); SHA1Result(&sha); if (!memcmp(sha.Message_Digest, restriction_pass2, 20)) restriction_filter_off = 1; else restriction_filter_off = 0; } wl_close(fd); } } if (restriction_filter_off == -1) { init_filtering = 1; memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8); pText = get_nls_text("parental_controls"); render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, pText, strlen(pText), 0); first_time_password(1); return -1; } else return 0; }
void init_bigram(int fd) { if (!aBigram) { aBigram = (PBIGRAM)malloc_simple(sizeof(BIGRAM) * get_wiki_count(), MEM_TAG_INDEX_M1); } init_char_idx(); wl_read(fd, &aBigram[nCurrentWiki], sizeof(BIGRAM)); }
void history_list_init(void) { unsigned int len; int fd_hst; memset((void *)history_list, 0, sizeof(history_list)); history_count = 0; fd_hst = wl_open("wiki.hst", WL_O_RDONLY); if (fd_hst >= 0) { while ((len = wl_read(fd_hst, (void *)&history_list[history_count], sizeof(HISTORY))) >= sizeof(HISTORY) && history_count < MAX_HISTORY) { if (history_list[history_count].idx_article) history_count++; else break; } wl_close(fd_hst); } }
void init_bigram(int fd) { init_char_idx(); wl_read(fd, aBigram, sizeof(aBigram)); }
void perf_test(void) { char *mem_src = NULL, *mem_dst = NULL, *file = NULL; int fd = -1, read; unsigned int file_size; mem_src = malloc_simple(MB, MEM_TAG_PERF_M1); if (!mem_src) { msg(MSG_INFO, "no mem_src: out of mem ?\n"); malloc_status_simple(); goto out; } mem_dst = malloc_simple(MB, MEM_TAG_PERF_M2); if (!mem_dst) { msg(MSG_INFO, "no mem_dst: out of mem ?\n"); malloc_status_simple(); goto out; } file = malloc_simple(MB, MEM_TAG_PERF_M3); if (!file) { msg(MSG_INFO, "no file: out of mem ?\n"); malloc_status_simple(); goto out; } prof_start(PROF_memset); memset(mem_src, 1, MB); prof_stop(PROF_memset); prof_start(PROF_memcpy); memcpy(mem_dst, mem_src, MB); prof_stop(PROF_memcpy); prof_start(PROF_memcmp); memcmp(mem_src, mem_dst, MB); prof_stop(PROF_memcmp); prof_start(PROF_sd_read); for (fd = 0; fd < 8; fd++) { read = disk_read(0, file + (fd * 512 * 256), fd * 255, 255); if (read != RES_OK) { prof_stop(PROF_sd_read); msg(MSG_INFO, "Could not read sd card: %i\n", read); goto out; } } prof_stop(PROF_sd_read); fd = wl_open("8dcec2", WL_O_RDONLY); if (fd < 0) { msg(MSG_INFO, "Could not read file '8dcec2': file not found\n"); goto out; } wl_fsize(fd, &file_size); if (file_size > MB) { msg(MSG_INFO, "Could not read file '8dcec2': file size bigger than %i bytes\n", MB); goto out; } prof_start(PROF_fread); read = wl_read(fd, file, file_size); prof_stop(PROF_fread); if (read != file_size) { msg(MSG_INFO, "Could not read file '8dcec2': read process aborted after %i bytes\n", read); goto out; } msg(MSG_INFO, "memcpy speed: 1MB/%dms, SD card: 1MB/%dms, fatfs: 1MB/%dms\n", (prof_container[PROF_memcpy].calls == 0 ? 0 : ((prof_container[PROF_memcpy].total_time / MCLK_MHz) / prof_container[PROF_memcpy].calls / 1000)), (prof_container[PROF_sd_read].calls == 0 ? 0 : ((prof_container[PROF_sd_read].total_time / MCLK_MHz) / prof_container[PROF_sd_read].calls / 1000)), (prof_container[PROF_fread].calls == 0 ? 0 : ((prof_container[PROF_fread].total_time / MCLK_MHz) / prof_container[PROF_fread].calls / (file_size / 100 / KB) / 100))); out: if (fd) wl_close(fd); if (file) free_simple(file, MEM_TAG_PERF_F3); if (mem_dst) free_simple(mem_dst, MEM_TAG_PERF_F4); if (mem_src) free_simple(mem_src, MEM_TAG_PERF_F5); return; }