Rev 3790 | Rev 3800 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3790 | Rev 3792 | ||
---|---|---|---|
1 | server_parser: |
1 | server_parser: |
2 | 2 | ||
3 | ; Commands are always 3 numbers and followed by a space |
3 | ; Commands are always 3 numbers and followed by a space |
4 | ; If a server decides it needs multiline output, |
4 | ; If a server decides it needs multiline output, |
5 | ; first lines will have a dash instead of space after numbers, |
5 | ; first lines will have a dash instead of space after numbers, |
6 | ; thus they are simply ignored in this simple command parser. |
6 | ; thus they are simply ignored in this simple command parser. |
7 | 7 | ||
8 | cmp dword[s], "150 " |
8 | cmp dword[s], "150 " |
9 | je data_ok |
9 | je data_ok |
10 | 10 | ||
11 | cmp dword[s], "220 " |
11 | cmp dword[s], "220 " |
12 | je welcome |
12 | je welcome |
13 | 13 | ||
14 | ; cmp dword[s], "226 " |
14 | ; cmp dword[s], "226 " |
15 | ; je list_ok |
15 | ; je list_ok |
16 | 16 | ||
17 | cmp dword[s], "227 " |
17 | cmp dword[s], "227 " |
18 | je pasv_ok |
18 | je pasv_ok |
19 | 19 | ||
20 | cmp dword[s], "230 " |
20 | cmp dword[s], "230 " |
21 | je login_ok |
21 | je login_ok |
22 | 22 | ||
23 | ; cmp dword[s], "250" |
23 | ; cmp dword[s], "250" |
24 | ; je dir_ok |
24 | ; je dir_ok |
25 | 25 | ||
26 | cmp dword[s], "331 " |
26 | cmp dword[s], "331 " |
27 | je pass |
27 | je pass |
28 | 28 | ||
29 | ; cmp dword[s], "421 " |
29 | ; cmp dword[s], "421 " |
30 | ; je timeout |
30 | ; je timeout |
31 | 31 | ||
32 | cmp dword[s], "530" ; password incorrect |
32 | cmp dword[s], "530" ; password incorrect |
33 | je welcome |
33 | je welcome |
34 | 34 | ||
35 | jmp wait_for_usercommand |
35 | jmp wait_for_usercommand |
36 | 36 | ||
37 | 37 | ||
38 | welcome: |
38 | welcome: |
39 | 39 | ||
40 | mov [status], STATUS_CONNECTED |
40 | mov [status], STATUS_CONNECTED |
41 | jmp wait_for_usercommand |
41 | jmp wait_for_usercommand |
42 | 42 | ||
43 | 43 | ||
44 | pass: |
44 | pass: |
45 | 45 | ||
46 | mov [status], STATUS_NEEDPASSWORD |
46 | mov [status], STATUS_NEEDPASSWORD |
47 | jmp wait_for_usercommand |
47 | jmp wait_for_usercommand |
48 | 48 | ||
49 | 49 | ||
50 | login_ok: |
50 | login_ok: |
51 | 51 | ||
52 | mov [status], STATUS_LOGGED_IN |
52 | mov [status], STATUS_LOGGED_IN |
53 | jmp wait_for_usercommand |
53 | jmp wait_for_usercommand |
54 | 54 | ||
55 | 55 | ||
56 | pasv_ok: |
56 | pasv_ok: |
57 | 57 | ||
58 | sub ecx, 5 |
58 | sub ecx, 5 |
59 | jb .fail |
59 | jb .fail |
60 | mov al, "(" |
60 | mov al, "(" |
61 | mov edi, s + 5 |
61 | mov edi, s + 5 |
62 | repne scasb |
62 | repne scasb |
63 | 63 | ||
64 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
64 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
65 | cmp eax, -1 |
65 | cmp eax, -1 |
66 | je fail |
66 | je fail |
67 | mov [datasocket], eax |
67 | mov [datasocket], eax |
68 | 68 | ||
69 | mov esi, edi |
69 | mov esi, edi |
70 | call ascii_dec |
70 | call ascii_dec |
71 | mov byte[sockaddr2.ip+0], bl |
71 | mov byte[sockaddr2.ip+0], bl |
72 | call ascii_dec |
72 | call ascii_dec |
73 | mov byte[sockaddr2.ip+1], bl |
73 | mov byte[sockaddr2.ip+1], bl |
74 | call ascii_dec |
74 | call ascii_dec |
75 | mov byte[sockaddr2.ip+2], bl |
75 | mov byte[sockaddr2.ip+2], bl |
76 | call ascii_dec |
76 | call ascii_dec |
77 | mov byte[sockaddr2.ip+3], bl |
77 | mov byte[sockaddr2.ip+3], bl |
78 | 78 | ||
79 | call ascii_dec |
79 | call ascii_dec |
80 | mov byte[sockaddr2.port+0], bl |
80 | mov byte[sockaddr2.port+0], bl |
81 | call ascii_dec |
81 | call ascii_dec |
82 | mov byte[sockaddr2.port+1], bl |
82 | mov byte[sockaddr2.port+1], bl |
83 | 83 | ||
84 | invoke con_write_asciiz, str_open |
84 | invoke con_write_asciiz, str_open |
85 | mcall connect, [datasocket], sockaddr2, 18 |
85 | mcall connect, [datasocket], sockaddr2, 18 |
86 | 86 | ||
87 | .fail: |
87 | .fail: |
88 | jmp wait_for_servercommand |
88 | jmp wait_for_servercommand |
89 | 89 | ||
90 | 90 | ||
91 | data_ok: |
91 | data_ok: |
92 | 92 | ||
93 | mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, MSG_DONTWAIT |
- | |
94 | inc eax |
- | |
95 | jz .fail |
93 | mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0 |
96 | dec eax |
94 | test ebx, ebx |
97 | jz .fail |
95 | jnz .fail |
98 | mov byte[buffer_ptr2 + eax], 0 |
96 | mov byte[buffer_ptr2 + eax], 0 |
99 | 97 | ||
100 | invoke con_write_asciiz, buffer_ptr2 |
98 | invoke con_write_asciiz, buffer_ptr2 |
- | 99 | ||
- | 100 | jmp data_ok |
|
101 | 101 | ||
102 | .fail: |
102 | .fail: |
103 | mcall close, [datasocket] |
103 | mcall close, [datasocket] |
104 | jmp wait_for_servercommand |
104 | jmp wait_for_servercommand |
105 | 105 | ||
106 | 106 | ||
107 | ascii_dec: |
107 | ascii_dec: |
108 | 108 | ||
109 | xor ebx, ebx |
109 | xor ebx, ebx |
110 | mov cl, 4 ; max length is 3 digits + 1 separator |
110 | mov cl, 4 ; max length is 3 digits + 1 separator |
111 | .loop: |
111 | .loop: |
112 | lodsb |
112 | lodsb |
113 | sub al, '0' |
113 | sub al, '0' |
114 | jb .done |
114 | jb .done |
115 | cmp al, 9 |
115 | cmp al, 9 |
116 | ja .done |
116 | ja .done |
117 | lea ebx, [ebx*4+ebx] ; ebx *5 |
117 | lea ebx, [ebx*4+ebx] ; ebx *5 |
118 | shl ebx, 1 ; ebx *2 |
118 | shl ebx, 1 ; ebx *2 |
119 | add bl, al |
119 | add bl, al |
120 | dec cl |
120 | dec cl |
121 | jnz .loop |
121 | jnz .loop |
122 | 122 | ||
123 | .done: |
123 | .done: |
124 | ret |
124 | ret |