Branch data Line data Source code
1 : : // $Id: ContentLine.h,v 1.1.2.9 2006/06/01 01:55:42 sommer Exp $
2 : : //
3 : : // Support-analyzer to split a reassembled stream into lines.
4 : :
5 : : #ifndef CONTENTLINE_H
6 : : #define CONTENTLINE_H
7 : :
8 : : #include "TCP.h"
9 : :
10 : : #define CR_as_EOL 1
11 : : #define LF_as_EOL 2
12 : :
13 : : class ContentLine_Analyzer : public TCP_SupportAnalyzer {
14 : : public:
15 : : ContentLine_Analyzer(Connection* conn, bool orig);
16 : : ~ContentLine_Analyzer();
17 : :
18 : : // If enabled, flag (first) line with embedded NUL. Default off.
19 : 8 : void SetIsNULSensitive(bool enable)
20 : 8 : { flag_NULs = enable; }
21 : :
22 : : // If enabled, skip data above a hole. Default off.
23 : 692 : void SetSkipPartial(bool enable)
24 : 692 : { skip_partial = enable; }
25 : :
26 : : // If true, single CR / LF are considered as EOL. Default on for both.
27 : 0 : void SetCRLFAsEOL(int crlf = (CR_as_EOL | LF_as_EOL))
28 : 0 : { CR_LF_as_EOL = crlf; }
29 : :
30 : 0 : int CRLFAsEOL()
31 : 0 : { return CR_LF_as_EOL ; }
32 : :
33 : : int HasPartialLine() const;
34 : :
35 : 20329 : bool SkipDeliveries() const
36 : 20329 : { return skip_deliveries; }
37 : :
38 : 500 : void SetSkipDeliveries(int should_skip)
39 : 500 : { skip_deliveries = should_skip; }
40 : :
41 : : // We actually have two delivery modes: line delivery and plain
42 : : // delivery for data portions which are not line-separated.
43 : : // SetPlainDelivery() keeps the ContentLine_Analyzer in plain delivery
44 : : // mode for next <length> bytes. Plain-delivery data is also passed
45 : : // via DeliverStream() and can differentiated by calling
46 : : // IsPlainDelivery().
47 : : void SetPlainDelivery(int length);
48 : : int GetPlainDeliveryLength() const { return plain_delivery_length; }
49 : 12158 : bool IsPlainDelivery() { return is_plain; }
50 : :
51 : : // Skip <length> bytes after this line.
52 : : // Can be used to skip HTTP data for performance considerations.
53 : : void SkipBytesAfterThisLine(int length);
54 : : void SkipBytes(int length);
55 : :
56 : 338 : bool IsSkippedContents(int seq, int length)
57 : 338 : { return seq + length <= seq_to_skip; }
58 : :
59 : : protected:
60 : : ContentLine_Analyzer(AnalyzerTag::Tag tag, Connection* conn, bool orig);
61 : :
62 : : virtual void DeliverStream(int len, const u_char* data, bool is_orig);
63 : : virtual void Undelivered(int seq, int len, bool orig);
64 : : virtual void EndpointEOF(bool is_orig);
65 : :
66 : : class State;
67 : : void InitState();
68 : : void InitBuffer(int size);
69 : : virtual void DoDeliver(int len, const u_char* data);
70 : : int DoDeliverOnce(int len, const u_char* data);
71 : : void CheckNUL();
72 : :
73 : : // Returns the sequence number delivered so far.
74 : 0 : int SeqDelivered() const { return seq_delivered_in_lines; }
75 : :
76 : : u_char* buf; // where we build up the body of the request
77 : : int offset; // where we are in buf
78 : : int buf_len; // how big buf is, total
79 : : unsigned int last_char; // last (non-option) character scanned
80 : :
81 : : int seq; // last seq number
82 : : int seq_to_skip;
83 : :
84 : : // Seq delivered up to through NewLine() -- it is adjusted
85 : : // *before* NewLine() is called.
86 : : int seq_delivered_in_lines;
87 : :
88 : : // Number of bytes to be skipped after this line. See
89 : : // comments in SkipBytesAfterThisLine().
90 : : int skip_pending;
91 : :
92 : : // Remaining bytes to deliver plain.
93 : : int plain_delivery_length;
94 : : int is_plain;
95 : :
96 : : // Don't deliver further data.
97 : : int skip_deliveries;
98 : :
99 : : // If true, flag (first) line with embedded NUL.
100 : : unsigned int flag_NULs:1;
101 : :
102 : : // Whether single CR / LF are considered as EOL.
103 : : unsigned int CR_LF_as_EOL:2;
104 : :
105 : : // Whether to skip partial conns.
106 : : unsigned int skip_partial:1;
107 : : };
108 : :
109 : : #endif
|