Branch data Line data Source code
1 : : // $Id: Finger.cc 6219 2008-10-01 05:39:07Z vern $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #include "config.h"
6 : :
7 : : #include <ctype.h>
8 : :
9 : : #include "NetVar.h"
10 : : #include "Finger.h"
11 : : #include "Event.h"
12 : : #include "TCP_Rewriter.h"
13 : : #include "ContentLine.h"
14 : :
15 : 0 : Finger_Analyzer::Finger_Analyzer(Connection* conn)
16 : 0 : : TCP_ApplicationAnalyzer(AnalyzerTag::Finger, conn)
17 : : {
18 : 0 : did_deliver = 0;
19 : 0 : content_line_orig = new ContentLine_Analyzer(conn, true);
20 : 0 : content_line_orig->SetIsNULSensitive(true);
21 : 0 : content_line_resp = new ContentLine_Analyzer(conn, false);
22 : 0 : AddSupportAnalyzer(content_line_orig);
23 : 0 : AddSupportAnalyzer(content_line_resp);
24 : 0 : }
25 : :
26 : 0 : void Finger_Analyzer::Done()
27 : : {
28 : 0 : TCP_ApplicationAnalyzer::Done();
29 : :
30 [ # # ]: 0 : if ( TCP() )
31 [ # # ][ # # ]: 0 : if ( (! did_deliver || content_line_orig->HasPartialLine()) &&
[ # # ][ # # ]
[ # # ]
32 : : (TCP()->OrigState() == TCP_ENDPOINT_CLOSED ||
33 : : TCP()->OrigPrevState() == TCP_ENDPOINT_CLOSED) )
34 : : // ### should include the partial text
35 : 0 : Weird("partial_finger_request");
36 : 0 : }
37 : :
38 : 0 : void Finger_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig)
39 : : {
40 : 0 : const char* line = (const char*) data;
41 : 0 : const char* end_of_line = line + length;
42 : :
43 [ # # ]: 0 : if ( is_orig )
44 : : {
45 : :
46 [ # # ]: 0 : if ( ! finger_request )
47 : 0 : return;
48 : :
49 : 0 : line = skip_whitespace(line, end_of_line);
50 : :
51 : : // Check for /W.
52 [ # # # # ]: 0 : int long_cnt = (line + 2 <= end_of_line && line[0] == '/' && toupper(line[1]) == 'W');
[ # # ]
53 [ # # ]: 0 : if ( long_cnt )
54 : 0 : line = skip_whitespace(line+2, end_of_line);
55 : :
56 : 0 : const char* at = strchr_n(line, end_of_line, '@');
57 : 0 : const char* host = 0;
58 [ # # ]: 0 : if ( ! at )
59 : 0 : at = host = end_of_line;
60 : : else
61 : 0 : host = at + 1;
62 : :
63 : 0 : val_list* vl = new val_list;
64 : 0 : vl->append(BuildConnVal());
65 : 0 : vl->append(new Val(long_cnt, TYPE_BOOL));
66 : 0 : vl->append(new StringVal(at - line, line));
67 : 0 : vl->append(new StringVal(end_of_line - host, host));
68 : :
69 [ # # ]: 0 : if ( finger_request )
70 : 0 : ConnectionEvent(finger_request, vl);
71 : :
72 : : Conn()->Match(Rule::FINGER, (const u_char *) line,
73 : 0 : end_of_line - line, true, true, 1, true);
74 : :
75 : 0 : did_deliver = 1;
76 : : }
77 : :
78 : : else
79 : : {
80 [ # # ]: 0 : if ( ! finger_reply )
81 : 0 : return;
82 : :
83 : 0 : val_list* vl = new val_list;
84 : 0 : vl->append(BuildConnVal());
85 : 0 : vl->append(new StringVal(end_of_line - line, line));
86 : :
87 : 0 : ConnectionEvent(finger_reply, vl);
88 : : }
89 : : }
90 : :
91 : : #include "finger-rw.bif.func_def"
|