|
1 /** |
|
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * FTP server answer parser |
|
16 * Author: Philippe Gabriel |
|
17 * RFC 959 defines the syntax for answers sent back by FTP servers |
|
18 * TFTPServerAnswerParser parses these answers |
|
19 * RFC says answers are: |
|
20 * 1) single line answer |
|
21 * xxx<space><alphadecimal chars><0x0d><0x0a> |
|
22 * 2) multiline answer |
|
23 * xxx-<alphadecimal chars><0x0d><0x0a> |
|
24 * <several lines> |
|
25 * <0x0d><0x0a>xxx<space><alphadecimal chars><0x0d><0x0a> |
|
26 * We parse these regular expressions with the class TFTPServerAnswerParser |
|
27 * implementing an FSM to parse a regular expression |
|
28 * The parser is called with the method: |
|
29 * Parse(const TDesC& aBuffer) |
|
30 * parameter: aBuffer contains an answer to be parsed |
|
31 * returns: |
|
32 * 1) True |
|
33 * a server answer is available |
|
34 * Get the answer with: ServerAnswer(TDes& aServerAnswer) |
|
35 * Get the number of chars from the buffer corresponding to the |
|
36 * parsed answer with NChars() |
|
37 * the NChars first chars can be flushed from the buffer |
|
38 * note: in this case, call the parser again before |
|
39 * we do any more socket receive operation, to parse the rest of the buffer |
|
40 * 2)False |
|
41 * no answer is available yet |
|
42 * buffer can be completely flushed |
|
43 * |
|
44 * |
|
45 */ |
|
46 |
|
47 |
|
48 |
|
49 /** |
|
50 @file ANSPARSE.H |
|
51 @internalComponent |
|
52 */ |
|
53 |
|
54 #if !defined(__ANSPARSE_H__) |
|
55 #define __ANSPARSE_H__ |
|
56 #include "FTPDEF.H" |
|
57 #include "DEBUG.H" |
|
58 #include <e32base.h> |
|
59 |
|
60 ////////////////////////////////////////////////////////////// |
|
61 // Definitions |
|
62 ////////////////////////////////////////////////////////////// |
|
63 |
|
64 class TFTPServerAnswerParser |
|
65 /** |
|
66 @internalComponent |
|
67 */ |
|
68 { |
|
69 |
|
70 public: |
|
71 enum TState |
|
72 { |
|
73 /** Do some clever encoding here |
|
74 */ |
|
75 EIdle=0, |
|
76 /** to simplify parsing code |
|
77 */ |
|
78 EState1=1, |
|
79 EState2=2, |
|
80 EState3=3, |
|
81 EState4,EState5,EState6,EState7, |
|
82 EState8,EState9,EState10,EState11 |
|
83 }; |
|
84 enum TPanic |
|
85 { |
|
86 EPIPanicOutOfState = -1 |
|
87 }; |
|
88 |
|
89 TFTPServerAnswerParser(void); |
|
90 TBool Parse(const TDesC8&); |
|
91 TInt NChars(void) {return iNChars;} |
|
92 void ServerAnswer(TDes8& aServerAnswer) {aServerAnswer.Copy(iDigit);} |
|
93 private: |
|
94 /** The current state of the parser */ |
|
95 TUint iState; |
|
96 /** The answer parsed */ |
|
97 TInt iServerReply; |
|
98 /** The number of chars that can be fetched from the buffer */ |
|
99 TInt iNChars; |
|
100 /** The parsed answer digits */ |
|
101 TBuf<3> iDigit; |
|
102 /** We've completed parsing answer */ |
|
103 TBool iParsingSuccess; |
|
104 }; |
|
105 #endif // __ANSPARSE_H__ |