-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_parser.sh
executable file
·117 lines (103 loc) · 2.44 KB
/
run_parser.sh
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
#!/bin/bash
#
# Author: Pedro Valero
#
# Description: Script use to compile the parser used to
# validate HTTP messages and run it.
#
# Date: 02/09/16
# HTTP Validator. Copyright (C) 2016 Pedro Valero
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
SUB_PARSERS_FOLDER="sub_parsers"
REPEATED_FIELDS=$SUB_PARSERS_FOLDER/"duplicate_fields"
CHUNKED=$SUB_PARSERS_FOLDER/"chunked"
OTHERS=$SUB_PARSERS_FOLDER/"others"
MUST=$SUB_PARSERS_FOLDER/"must"
COMPARISON=$SUB_PARSERS_FOLDER/"comparison"
PARSER="parser"
PARSER_CHUNK="parserChunk"
PARSER_RESP_CHUNK="parserRespChunk"
PARSER_REQ_CHUNK="parserReqChunk"
if [ $# -eq 0 ]
then
echo "Usage: ./run_parser.sh <input_file>"
echo "Informs about the correctness of a HTTP message given as argument"
exit
fi
if [ ! -f $1 ]; then
echo "File not found!"
exit
fi
echo "Checking for invalid duplicate fields..."
./$REPEATED_FIELDS $1
if [ $? -ne 0 ]
then
echo "Wrong message. Duplicate fields"
exit
fi
echo "Checking for a variety of possible many errors..."
./$OTHERS $1
if [ $? -ne 0 ]
then
echo "Wrong message."
exit
fi
echo "Checking for more constraints..."
PARSERS=$(ls --ignore='*.*' $MUST)
for p in $PARSERS; do
./$MUST/$p $1
if [ $? -ne 0 ]
then
echo "Wrong message."
exit
fi
done
echo "Checking comparison-related constraints..."
# TODO: This should be implemented to be more general.
declare -a PARSERS=("E1105_0" "E1105_1" "E1105_2")
flag=0
for p in "${PARSERS[@]}"
do
./$COMPARISON/$p $1
if [ $? -ne 0 ]
then
flag=1
fi
done
if [ $flag -eq 0 ]
then
echo "1105"
echo "Wrong message."
exit
fi
echo "Checking if the message is chunked..."
./$CHUNKED $1
ret=$?
echo $ret
if [ $ret -eq 1 ]
then
./$PARSER_REQ_CHUNK $1
elif [ $ret -eq 2 ]
then
./$PARSER_CHUNK $1
elif [ $ret -eq 3 ]
then
./$PARSER_RESP_CHUNK $1
elif [ $ret -eq 4 ]
then
./$PARSER_CHUNK $1
else
./$PARSER $1
fi