1 /* $Id$ */ 2 /* Copyright (C) 2005 Nicholas Harbour 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; either version 2, or (at your option) 6 any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software Foundation, 15 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 */ 17 18 /* This file is part of 19 Tcpxtract, a sniffer that extracts files based on headers 20 by Nick Harbour 21 */ 22 23 #ifndef SEARCH_H 24 #define SEARCH_H 25 26 #include <sys/types.h> 27 #include <inttypes.h> 28 29 typedef enum { 30 TABLE, 31 COMPLETE 32 } srch_nodetype_t; 33 34 typedef enum { 35 HEADER, 36 FOOTER 37 } spectype_t; 38 39 typedef struct { 40 int id; 41 char *ext; 42 unsigned long maxlen; 43 size_t len; /* the length of the header or footer */ 44 } fileid_t; 45 46 /* srch_node_t objects represent the compiled form of a set of search keywords */ 47 typedef struct srch_node { 48 srch_nodetype_t nodetype; 49 spectype_t spectype; 50 union { 51 struct srch_node *table[256]; 52 fileid_t fileid; 53 } data; 54 } srch_node_t; 55 56 /* srchptr_list_t is for maintaining a list of concurrent search threads */ 57 typedef struct srchptr_list { 58 struct srchptr_list *next; 59 struct srchptr_list *prev; 60 srch_node_t *node; 61 } srchptr_list_t; 62 63 typedef struct srch_results { 64 struct srch_results *next; 65 struct srch_results *prev; 66 fileid_t *fileid; 67 spectype_t spectype; 68 struct { 69 int start; /* for HEADERs */ 70 int end; /* for FOOTERs */ 71 } offset; 72 } srch_results_t; 73 74 extern srch_node_t *srch_machine; 75 76 extern void compile_srch(srch_node_t **, int, char *, unsigned long, char *, spectype_t); 77 extern srch_results_t *search(srch_node_t *, srchptr_list_t **, uint8_t *, size_t); 78 extern void free_results_list(srch_results_t **); 79 80 #endif /* SEARCH_H */ 81