Rev 3792 | Rev 3813 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3701 | hidnplayr | 1 | server_parser: |
2 | |||
3 | ; Commands are always 3 numbers and followed by a space |
||
4 | ; If a server decides it needs multiline output, |
||
5 | ; first lines will have a dash instead of space after numbers, |
||
3789 | hidnplayr | 6 | ; thus they are simply ignored in this simple command parser. |
3701 | hidnplayr | 7 | |
8 | cmp dword[s], "150 " |
||
9 | je data_ok |
||
10 | |||
11 | cmp dword[s], "220 " |
||
12 | je welcome |
||
13 | |||
3790 | hidnplayr | 14 | ; cmp dword[s], "226 " |
3789 | hidnplayr | 15 | ; je list_ok |
16 | |||
3701 | hidnplayr | 17 | cmp dword[s], "227 " |
18 | je pasv_ok |
||
19 | |||
20 | cmp dword[s], "230 " |
||
21 | je login_ok |
||
22 | |||
3790 | hidnplayr | 23 | ; cmp dword[s], "250" |
3800 | hidnplayr | 24 | ; je op_ok |
3790 | hidnplayr | 25 | |
3701 | hidnplayr | 26 | cmp dword[s], "331 " |
27 | je pass |
||
28 | |||
3790 | hidnplayr | 29 | ; cmp dword[s], "421 " |
3789 | hidnplayr | 30 | ; je timeout |
3701 | hidnplayr | 31 | |
3800 | hidnplayr | 32 | cmp dword[s], "530 " ; password incorrect |
3789 | hidnplayr | 33 | je welcome |
3701 | hidnplayr | 34 | |
3800 | hidnplayr | 35 | cmp dword[s], "550 " |
36 | je close_datacon |
||
37 | |||
3789 | hidnplayr | 38 | jmp wait_for_usercommand |
39 | |||
40 | |||
3701 | hidnplayr | 41 | welcome: |
42 | |||
43 | mov [status], STATUS_CONNECTED |
||
3789 | hidnplayr | 44 | jmp wait_for_usercommand |
3701 | hidnplayr | 45 | |
46 | |||
47 | pass: |
||
48 | |||
49 | mov [status], STATUS_NEEDPASSWORD |
||
3789 | hidnplayr | 50 | jmp wait_for_usercommand |
3701 | hidnplayr | 51 | |
52 | |||
53 | login_ok: |
||
54 | |||
55 | mov [status], STATUS_LOGGED_IN |
||
3789 | hidnplayr | 56 | jmp wait_for_usercommand |
3701 | hidnplayr | 57 | |
58 | |||
59 | pasv_ok: |
||
60 | |||
61 | sub ecx, 5 |
||
62 | jb .fail |
||
63 | mov al, "(" |
||
64 | mov edi, s + 5 |
||
65 | repne scasb |
||
66 | |||
67 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
||
68 | cmp eax, -1 |
||
69 | je fail |
||
70 | mov [datasocket], eax |
||
71 | |||
72 | mov esi, edi |
||
73 | call ascii_dec |
||
74 | mov byte[sockaddr2.ip+0], bl |
||
75 | call ascii_dec |
||
76 | mov byte[sockaddr2.ip+1], bl |
||
77 | call ascii_dec |
||
78 | mov byte[sockaddr2.ip+2], bl |
||
79 | call ascii_dec |
||
80 | mov byte[sockaddr2.ip+3], bl |
||
81 | |||
82 | call ascii_dec |
||
3789 | hidnplayr | 83 | mov byte[sockaddr2.port+0], bl |
84 | call ascii_dec |
||
3701 | hidnplayr | 85 | mov byte[sockaddr2.port+1], bl |
86 | |||
3789 | hidnplayr | 87 | invoke con_write_asciiz, str_open |
3701 | hidnplayr | 88 | mcall connect, [datasocket], sockaddr2, 18 |
89 | |||
90 | .fail: |
||
3789 | hidnplayr | 91 | jmp wait_for_servercommand |
3701 | hidnplayr | 92 | |
93 | |||
94 | data_ok: |
||
95 | |||
3800 | hidnplayr | 96 | cmp [operation], OPERATION_STOR |
97 | je .stor |
||
98 | |||
99 | ; we are receiving data |
||
3792 | hidnplayr | 100 | mcall recv, [datasocket], buffer_ptr2, BUFFERSIZE, 0 |
101 | test ebx, ebx |
||
3800 | hidnplayr | 102 | jnz .done |
3790 | hidnplayr | 103 | mov byte[buffer_ptr2 + eax], 0 |
3701 | hidnplayr | 104 | |
3800 | hidnplayr | 105 | cmp [operation], OPERATION_RETR |
106 | je .retr |
||
107 | |||
108 | ; not retreiving, just print to console |
||
3790 | hidnplayr | 109 | invoke con_write_asciiz, buffer_ptr2 |
3800 | hidnplayr | 110 | jmp data_ok |
3789 | hidnplayr | 111 | |
3800 | hidnplayr | 112 | ; retreiving, save to file |
113 | .retr: |
||
114 | mov [filestruct.ptr], buffer_ptr2 |
||
115 | mov [filestruct.size], eax |
||
116 | push eax |
||
117 | mcall 70, filestruct |
||
118 | pop eax |
||
119 | add [filestruct.offset], eax |
||
3792 | hidnplayr | 120 | jmp data_ok |
121 | |||
3800 | hidnplayr | 122 | ; storing, send all data |
123 | .stor: |
||
124 | mcall 70, filestruct |
||
125 | cmp eax, 6 ; end of file |
||
126 | je .last_call |
||
127 | test eax, eax ; error |
||
128 | ; jne .fileerror |
||
129 | add [filestruct.offset], ebx |
||
130 | mov esi, ebx |
||
131 | mcall send, [datasocket], buffer_ptr2, , 0 |
||
132 | jmp .stor |
||
133 | |||
134 | .last_call: |
||
135 | mov esi, ebx |
||
136 | mcall send, [datasocket], buffer_ptr2, , 0 |
||
137 | |||
138 | .done: |
||
3789 | hidnplayr | 139 | mcall close, [datasocket] |
140 | jmp wait_for_servercommand |
||
3701 | hidnplayr | 141 | |
142 | |||
3800 | hidnplayr | 143 | |
144 | close_datacon: |
||
145 | mcall close, [datasocket] |
||
146 | jmp wait_for_usercommand |
||
147 | |||
148 | |||
149 | |||
3701 | hidnplayr | 150 | ascii_dec: |
151 | |||
152 | xor ebx, ebx |
||
3789 | hidnplayr | 153 | mov cl, 4 ; max length is 3 digits + 1 separator |
3701 | hidnplayr | 154 | .loop: |
155 | lodsb |
||
156 | sub al, '0' |
||
157 | jb .done |
||
158 | cmp al, 9 |
||
159 | ja .done |
||
3789 | hidnplayr | 160 | lea ebx, [ebx*4+ebx] ; ebx *5 |
161 | shl ebx, 1 ; ebx *2 |
||
3701 | hidnplayr | 162 | add bl, al |
163 | dec cl |
||
164 | jnz .loop |
||
165 | |||
166 | .done: |
||
167 | ret |