/* File: file_txt.c Copyright (C) 2005-2008 Christophe GRENIER This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_TIME_H #include #endif #include /* tolower */ #include #include "types.h" #include "common.h" #include "filegen.h" #include "log.h" #include "memmem.h" extern const file_hint_t file_hint_doc; extern const file_hint_t file_hint_jpg; extern const file_hint_t file_hint_pdf; extern const file_hint_t file_hint_zip; static inline int filtre(unsigned char car); static inline int UTF2Lat(unsigned char *buffer_lower, const unsigned char *buffer, const int buf_len); static void register_header_check_txt(file_stat_t *file_stat); static int header_check_txt(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); static void register_header_check_fasttxt(file_stat_t *file_stat); static int header_check_fasttxt(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new); static int data_check_txt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery); static void file_check_emlx(file_recovery_t *file_recovery); static void file_check_ers(file_recovery_t *file_recovery); static void file_check_html(file_recovery_t *file_recovery); static void file_check_xml(file_recovery_t *file_recovery); const file_hint_t file_hint_fasttxt= { .extension="tx?", .description="Text files with header: rtf,xml,xhtml,imm,pm,ram,reg,sh,slk,stp", .min_header_distance=0, .max_filesize=PHOTOREC_MAX_FILE_SIZE, .recover=1, .enable_by_default=1, .register_header_check=®ister_header_check_fasttxt }; const file_hint_t file_hint_txt= { .extension="txt", .description="Other text files: txt,html,asp,bat,C,jsp,perl,php,py/emlx... scripts", .min_header_distance=0, .max_filesize=PHOTOREC_MAX_FILE_SIZE, .recover=1, .enable_by_default=1, .register_header_check=®ister_header_check_txt }; static const unsigned char header_adr[25] = "Opera Hotlist version 2.0"; static const unsigned char header_bash[11] = "#!/bin/bash"; static const unsigned char header_cls[24] = {'V','E','R','S','I','O','N',' ','1','.','0',' ','C','L','A','S','S','\r','\n','B','E','G','I','N'}; static const unsigned char header_cue[10] = "REM GENRE "; static const unsigned char header_dc[6] = "SC V10"; static const unsigned char header_dif[12] = { 'T', 'A', 'B', 'L', 'E', '\r', '\n', '0', ',', '1', '\r', '\n'}; static const unsigned char header_ers[19] = "DatasetHeader Begin"; static const unsigned char header_ics[15] = "BEGIN:VCALENDAR"; static const unsigned char header_imm[13] = {'M','I','M','E','-','V','e','r','s','i','o','n',':'}; static const unsigned char header_lyx[7] = {'#', 'L', 'y', 'X', ' ', '1', '.'}; static const unsigned char header_m3u[7] = {'#','E','X','T','M','3','U'}; static const unsigned char header_mail[5] = {'F','r','o','m',' '}; static const unsigned char header_msf[19] = "//