Rev 2602 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2602 | Rev 2609 | ||
---|---|---|---|
Line 62... | Line 62... | ||
62 | include '../network.inc' |
62 | include '../network.inc' |
63 | include 'commands.inc' |
63 | include 'commands.inc' |
Line 64... | Line 64... | ||
64 | 64 | ||
65 | align 4 |
65 | align 4 |
- | 66 | start: |
|
- | 67 | mcall 68, 11 ; init heap |
|
- | 68 | mcall 40, 1 shl 7 ; we only want network events |
|
66 | start: |
69 | |
67 | ; load libraries |
70 | ; load libraries |
68 | stdcall dll.Load, @IMPORT |
71 | stdcall dll.Load, @IMPORT |
69 | test eax, eax |
72 | test eax, eax |
Line 70... | Line -... | ||
70 | jnz exit |
- | |
71 | - | ||
72 | mcall 68, 11 ; init heap |
73 | jnz exit |
73 | 74 | ||
74 | ; find path to main settings file (ftpd.ini) |
75 | ; find path to main settings file (ftpd.ini) |
75 | mov edi, path ; Calculate the length of zero-terminated string |
76 | mov edi, path ; Calculate the length of zero-terminated string |
76 | xor al, al |
77 | xor al, al |
Line 97... | Line 98... | ||
97 | 98 | ||
98 | ; initialize console |
99 | ; initialize console |
99 | invoke con_start, 1 |
100 | invoke con_start, 1 |
Line 100... | Line -... | ||
100 | invoke con_init, -1, -1, -1, -1, title |
- | |
101 | - | ||
102 | mcall 40, 1 shl 7 ; we only want network events |
101 | invoke con_init, -1, -1, -1, -1, title |
103 | 102 | ||
104 | invoke ini.get_str, path, str_ftpd, str_ip, ini_buf, 16, 0 |
103 | invoke ini.get_str, path, str_ftpd, str_ip, ini_buf, 16, 0 |
105 | mov esi, ini_buf |
104 | mov esi, ini_buf |
Line 137... | Line 136... | ||
137 | cmp eax, -1 |
136 | cmp eax, -1 |
138 | je listen_err |
137 | je listen_err |
Line 139... | Line 138... | ||
139 | 138 | ||
Line -... | Line 139... | ||
- | 139 | invoke con_write_asciiz, str2b |
|
- | 140 | ||
140 | invoke con_write_asciiz, str2b |
141 | mov [pasvport], 2000 ;;;;;; FIXME |
141 | 142 | ||
Line 142... | Line 143... | ||
142 | mainloop: |
143 | mainloop: |
143 | mcall 10 ; Wait here for incoming connections on the base socket (socketnum) |
144 | mcall 10 ; Wait here for incoming connections on the base socket (socketnum) |
144 | 145 | ||
Line 145... | Line 146... | ||
145 | mcall 51, 1, threadstart, 0 ; Start a new thread for every incoming connection |
146 | mcall 51, 1, threadstart, 0 ; Start a new thread for every incoming connection |
146 | ; NOTE: upon initialisation of the thread, stack will not be available! |
147 | ; NOTE: upon initialisation of the thread, stack will not be available! |
- | 148 | jmp mainloop |
|
147 | jmp mainloop |
149 | |
148 | 150 | diff16 "threadstart", 0, $ |
|
149 | diff16 "threadstart", 0, $ |
151 | threadstart: |
Line 150... | Line 152... | ||
150 | threadstart: |
152 | ;;; mcall 68, 11 ; init heap |
151 | mcall 68, 12, sizeof.thread_data ; allocate the thread data struct |
- | |
152 | cmp eax, -1 |
153 | mcall 68, 12, sizeof.thread_data ; allocate the thread data struct |
Line 153... | Line 154... | ||
153 | je exit |
154 | test eax, eax |
Line 154... | Line 155... | ||
154 | 155 | je exit |
|
155 | lea esp, [eax + thread_data.stack] ; init stack |
156 | |
156 | push eax ; save pointer to thread_data on stack |
157 | lea esp, [eax + thread_data.stack] ; init stack |
Line 157... | Line 158... | ||
157 | mov ebp, esp |
158 | mov ebp, eax |
158 | 159 | ||
159 | mcall 40, 1 shl 7 ; we only want network events for this thread |
160 | mcall 40, 1 shl 7 ; we only want network events for this thread |
160 | - | ||
161 | invoke con_set_flags, 0x03 |
161 | |
Line 162... | Line 162... | ||
162 | invoke con_write_asciiz, str8 ; print on the console that we have created the new thread successfully |
162 | invoke con_set_flags, 0x03 |
163 | invoke con_set_flags, 0x07 |
163 | invoke con_write_asciiz, str8 ; print on the console that we have created the new thread successfully |
164 | 164 | invoke con_set_flags, 0x07 |
|
165 | mcall accept, [socketnum], sockaddr1, sockaddr1.length ; time to accept the awaiting connection.. |
165 | |
166 | cmp eax, -1 |
166 | mcall accept, [socketnum], sockaddr1, sockaddr1.length ; time to accept the awaiting connection.. |
Line 167... | Line 167... | ||
167 | je thread_exit |
167 | cmp eax, -1 |
Line 168... | Line 168... | ||
168 | mov edx, [ebp] ; pointer to thread_data |
168 | je thread_exit |
169 | mov [edx + thread_data.socketnum], eax |
169 | mov [ebp + thread_data.socketnum], eax |
170 | 170 | ||
Line 171... | Line 171... | ||
171 | mov [edx + thread_data.state], STATE_CONNECTED |
171 | mov [ebp + thread_data.state], STATE_CONNECTED |
172 | mov [edx + thread_data.permissions], 0 |
172 | mov [ebp + thread_data.permissions], 0 |
173 | mov [edx + thread_data.mode], MODE_NOTREADY |
173 | mov [ebp + thread_data.mode], MODE_NOTREADY |
174 | lea eax, [edx + thread_data.buffer] |
174 | lea eax, [ebp + thread_data.buffer] |
175 | mov [edx + thread_data.buffer_ptr], eax |
175 | mov [ebp + thread_data.buffer_ptr], eax |
176 | 176 | ||
177 | sendFTP "220 Welcome to KolibriOS FTP daemon" |
177 | sendFTP "220 Welcome to KolibriOS FTP daemon" |
178 | - | ||
179 | threadloop: |
178 | |
180 | mcall 10 |
179 | threadloop: |
181 | mov edx, [ebp] ; pointer to thread_data |
180 | mcall 10 |
182 | 181 | mov edx, [ebp] ; pointer to thread_data |
|
Line 183... | Line 182... | ||
183 | cmp [edx + thread_data.mode], MODE_PASSIVE_WAIT |
182 | |
184 | jne .not_passive |
183 | cmp [ebp + thread_data.mode], MODE_PASSIVE_WAIT |
Line 185... | Line 184... | ||
185 | mov [edx + thread_data.mode], MODE_PASSIVE_FAILED ; assume that we will fail |
184 | jne .not_passive |
186 | mov ecx, [edx + thread_data.passivesocknum] |
185 | mov [ebp + thread_data.mode], MODE_PASSIVE_FAILED ; assume that we will fail |
187 | lea edx, [edx + thread_data.datasock] |
186 | mov ecx, [ebp + thread_data.passivesocknum] |
188 | mov esi, sizeof.thread_data.datasock |
187 | lea edx, [ebp + thread_data.datasock] |
189 | mcall accept |
188 | mov esi, sizeof.thread_data.datasock |
190 | mov edx, [ebp] ; pointer to thread_data |
189 | mcall accept |
191 | cmp eax, -1 |
190 | cmp eax, -1 |
192 | je .not_passive |
191 | je .not_passive |
Line 193... | Line -... | ||
193 | mov [edx + thread_data.datasocketnum], eax |
- | |
194 | mov [edx + thread_data.mode], MODE_PASSIVE_OK |
192 | mov [ebp + thread_data.datasocketnum], eax |
195 | 193 | mov [ebp + thread_data.mode], MODE_PASSIVE_OK |
|
Line 196... | Line 194... | ||
196 | invoke con_write_asciiz, str_datasock |
194 | |
197 | .not_passive: |
195 | invoke con_write_asciiz, str_datasock |
198 | 196 | .not_passive: |
|
199 | mov ecx, [edx + thread_data.socketnum] |
197 | |
200 | mov edx, [edx + thread_data.buffer_ptr] |
198 | mov ecx, [ebp + thread_data.socketnum] |
Line 201... | Line 199... | ||
201 | mov esi, sizeof.thread_data.buffer ;;; FIXME |
199 | mov edx, [ebp + thread_data.buffer_ptr] |
202 | mcall recv |
200 | mov esi, sizeof.thread_data.buffer ;;; FIXME |
203 | inc eax ; error? (-1) |
201 | mcall recv |
204 | jz threadloop |
202 | inc eax ; error? (-1) |
205 | dec eax ; 0 bytes read? |
203 | jz threadloop |
206 | jz threadloop |
204 | dec eax ; 0 bytes read? |
Line 207... | Line 205... | ||
207 | 205 | jz threadloop |
|
208 | mov edx, [ebp] ; pointer to thread_data |
206 | |
209 | mov edi, [edx + thread_data.buffer_ptr] |
207 | mov edi, [ebp + thread_data.buffer_ptr] |
210 | add [edx + thread_data.buffer_ptr], eax |
208 | add [ebp + thread_data.buffer_ptr], eax |
Line 283... | Line 281... | ||
283 | str_notfound db 'ERROR: file not found',10,0 |
281 | str_notfound db 'ERROR: file not found',10,0 |
284 | str_sockerr db 'ERROR: socket error',10,0 |
282 | str_sockerr db 'ERROR: socket error',10,0 |
Line 285... | Line 283... | ||
285 | 283 | ||
Line -... | Line 284... | ||
- | 284 | str_login_invalid db 'Login invalid',10,0 |
|
- | 285 | ||
286 | str_login_invalid db 'Login invalid',10,0 |
286 | str_test db 'test: %x ', 0 |
287 | 287 | ||
288 | str_newline db 10, 0 |
288 | str_newline db 10, 0 |
Line 289... | Line 289... | ||
289 | str_mask db '*', 0 |
289 | str_mask db '*', 0 |
Line 323... | Line 323... | ||
323 | ; import |
323 | ; import |
Line 324... | Line 324... | ||
324 | 324 | ||
325 | align 4 |
325 | align 4 |
Line -... | Line 326... | ||
- | 326 | @IMPORT: |
|
- | 327 | ||
326 | @IMPORT: |
328 | diff16 "import", 0, $ |
327 | 329 | ||
328 | library console, 'console.obj',\ |
330 | library console, 'console.obj',\ |
Line 329... | Line 331... | ||
329 | libini, 'libini.obj', \ |
331 | libini, 'libini.obj', \ |
Line 356... | Line 358... | ||
356 | file.find.close, 'file_find_close' |
358 | file.find.close, 'file_find_close' |
Line 357... | Line 359... | ||
357 | 359 | ||
Line -... | Line 360... | ||
- | 360 | ||
- | 361 | i_end: |
|
358 | 362 | ||
Line 359... | Line 363... | ||
359 | i_end: |
363 | diff16 "i_end", 0, $ |
360 | 364 | ||
361 | ; uninitialised data |
365 | ; uninitialised data |
362 | 366 | ||
363 | socketnum dd ? |
367 | socketnum dd ? |
- | 368 | path rb 1024 |
|
Line 364... | Line 369... | ||
364 | path rb 1024 |
369 | path2 rb 1024 |
Line 365... | Line 370... | ||
365 | path2 rb 1024 |
370 | params rb 1024 |