[go: up one dir, main page]

File: regexp.c

package info (click to toggle)
dnshistory 1.3-3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 744 kB
  • sloc: ansic: 2,077; sh: 818; makefile: 72
file content (132 lines) | stat: -rw-r--r-- 6,342 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *   Copyright (C) 2004, 2005, 2006 by Stephen McInerney                   *
 *   spm@stedee.id.au                                                      *
 *                                                                         *
 *   $Id: regexp.c 58 2006-01-02 10:40:49Z steve $
 *                                                                         *
 *   This program 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 to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/***************************************************************************
 ***************************************************************************
 * regexp.c
 *
 * All the various regular expression handling
 *
 ***************************************************************************
 ***************************************************************************/

/***************************************************************************
 ***************************************************************************
 * ModificationHistory:
 **********************
 * 17-Mar-2005 steve     Initial Creation - taken from visitors
 *
 ***************************************************************************
 ***************************************************************************/


#include "dnshistory.h"

/************************************************************************
 *                              GLOBALS                                 *
 ************************************************************************/
// pcre *re_pattern_main = NULL;                   /* Main RE */
// pcre *re_pattern_filter = NULL;                 /* ignore these file types */

bool is_shown_filter = false;                   /* We have already displayed the filter; For errors */


/************************************************************************
 * re_check_errors                                                      *
 *                                                                      *
 * After an RE check, deal with any errors                              *
 ************************************************************************/
void
re_check_errors(int err, unsigned long int line_nbr, char *str_ptr)
{
    /* err: value returned from pcre_exec       */
    /* str_ptr: String that failed to match     */

    int out_vector_size;

    /* Matching failed: handle error cases */
    switch (err) {
    case PCRE_ERROR_NOMATCH:
        ERRVPRINT(VERBOSE1, msg_W_re_match_failed, line_nbr, str_ptr);
        break;
    case 0:
        /* The output vector wasn't big enough */
        out_vector_size = OVECCOUNT / 3;
        ERRVPRINT(VERBOSE1, msg_E_re_too_many_substrings, line_nbr, out_vector_size - 1);
        break;
    default:
        ERRVPRINT(VERBOSE1, msg_W_re_match_error, err, line_nbr, str_ptr);
        break;
    }
}


/************************************************************************
 * re_compile_failed                                                    *
 *                                                                      *
 * Display a failed RE Compile & where                                  *
 * FATAL failure. Will exit the run.                                    *
 ************************************************************************/
void
re_compile_failed(int err, const char *err_offset, char *re_str)
{
    ERRVPRINT(VERBOSE0, "%s %d: %s\n%s\n", msg_F_pcre_failed_compilation, err, err_offset, re_str);
    exit(V_EXIT_PCRE_COMPILE);
}


/************************************************************************
 * error_substring_extract                                              *
 *                                                                      *
 * Display a failed substring extraction                                *
 * Error Only, as this should have failed the RE                        *
 *                                                                      *
 * Typically these are seen with invalid cookie fields,                 *
 *  or super long User Agent fields.                                    *
 ************************************************************************/
void
error_substring_extract(char *failed_pattern, char *text, int substr_idx, int err, unsigned long int line_nbr)
{
    if (is_shown_filter == false) {
        VPRINT(VERBOSE1, "RegExp Pattern: %s\n", failed_pattern);
        is_shown_filter = true;
    }
    ERRVPRINT(VERBOSE1, msg_E_substring_extraction, substr_idx, line_nbr);
    switch (err) {
    case PCRE_ERROR_NOMEMORY:
        ERRVPRINT(VERBOSE1, msg_E_pcre_no_memory, "");
        break;
    case PCRE_ERROR_NOSUBSTRING:
        ERRVPRINT(VERBOSE1, msg_E_pcre_nonexist_substring, "");
        break;
    default:
        ERRVPRINT(VERBOSE1, msg_E_pcre_unknown, err);
    }
    ERRVPRINT(VERBOSE1, "  %s\n", text);
}


/************************************************************************
 ************************************************************************
 *                      END OF FILE                                     *
 ************************************************************************
 ************************************************************************/