Subversion Repositories Kolibri OS

Rev

Rev 2610 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2610 Rev 2624
Line 60... Line 60...
60
include '../libio.inc'
60
include '../libio.inc'
Line 61... Line 61...
61
 
61
 
62
include '../network.inc'
62
include '../network.inc'
Line 63... Line -...
63
include 'commands.inc'
-
 
64
 
63
include 'commands.inc'
65
align 4
64
 
66
start:
65
start:
Line 67... Line 66...
67
        mcall   68, 11                  ; init heap
66
        mcall   68, 11                  ; init heap
Line 108... Line 107...
108
 
107
 
109
        invoke  ini.get_int, path, str_ftpd, str_port, 21
108
        invoke  ini.get_int, path, str_ftpd, str_port, 21
Line 110... Line 109...
110
        mov     [sockaddr1.port], ax
109
        mov     [sockaddr1.port], ax
-
 
110
 
Line 111... Line 111...
111
 
111
        invoke  con_printf, str1, eax
112
        invoke  con_printf, str1, eax
112
        add     esp, 8
113
 
113
 
114
        mcall   socket, AF_INET4, SOCK_STREAM, 0
114
        mcall   socket, AF_INET4, SOCK_STREAM, 0
Line 143... Line 143...
143
        mov     [pasv_start], ax
143
        mov     [pasv_start], ax
144
        invoke  ini.get_int, path, str_pasv, str_end, 5000
144
        invoke  ini.get_int, path, str_pasv, str_end, 5000
145
        mov     [pasv_end], ax
145
        mov     [pasv_end], ax
Line 146... Line 146...
146
 
146
 
147
mainloop:
147
mainloop:
-
 
148
        mcall   23, 100                         ; Wait here for incoming connections on the base socket (socketnum)
-
 
149
                                                ; One second timeout, we sill use this to check if console is still working
-
 
150
 
-
 
151
        test    eax, 1 shl 7                    ; network event?
Line 148... Line 152...
148
        mcall   10                              ; Wait here for incoming connections on the base socket (socketnum)
152
        jz      .checkconsole
149
 
153
 
150
        mcall   51, 1, threadstart, 0           ; Start a new thread for every incoming connection
154
        mcall   51, 1, threadstart, 0           ; Start a new thread for every incoming connection
Line -... Line 155...
-
 
155
                                                ; NOTE: upon initialisation of the thread, stack will not be available!
-
 
156
        jmp     mainloop
-
 
157
 
-
 
158
  .checkconsole:
-
 
159
 
-
 
160
        invoke  con_get_flags                   ; Is console still running?
-
 
161
        test    eax, 0x0200
-
 
162
        jz      mainloop
151
                                                ; NOTE: upon initialisation of the thread, stack will not be available!
163
        mcall   close, [socketnum]              ; kill the listening socket
-
 
164
        mcall   -1                              ; and exit
152
        jmp     mainloop
165
 
153
 
166
        diff16  "threadstart", 0, $
154
        diff16  "threadstart", 0, $
167
 
155
threadstart:
168
threadstart:
156
;;;        mcall   68, 11                          ; init heap
169
;;;        mcall   68, 11                          ; init heap
Line 161... Line 174...
161
        lea     esp, [eax + thread_data.stack]  ; init stack
174
        lea     esp, [eax + thread_data.stack]  ; init stack
162
        mov     ebp, eax
175
        mov     ebp, eax
Line 163... Line 176...
163
 
176
 
Line -... Line 177...
-
 
177
        mcall   40, 1 shl 7                     ; we only want network events for this thread
-
 
178
 
-
 
179
        lea     ebx, [ebp + thread_data.buffer] ; get information about the current process
-
 
180
        or      ecx, -1
-
 
181
        mcall   9
-
 
182
        mov     eax, dword [ebp + thread_data.buffer + 30]              ; PID is at offset 30
164
        mcall   40, 1 shl 7                     ; we only want network events for this thread
183
        mov     [ebp + thread_data.pid], eax
165
 
184
 
-
 
185
        invoke  con_set_flags, 0x03
166
        invoke  con_set_flags, 0x03
186
        invoke  con_printf, str8, [ebp + thread_data.pid]               ; print on the console that we have created the new thread successfully
Line 167... Line 187...
167
        invoke  con_write_asciiz, str8          ; print on the console that we have created the new thread successfully
187
        add     esp, 8                                                  ; balance stack
168
        invoke  con_set_flags, 0x07
188
        invoke  con_set_flags, 0x07
169
 
189
 
Line 179... Line 199...
179
        mov     [ebp + thread_data.buffer_ptr], eax
199
        mov     [ebp + thread_data.buffer_ptr], eax
180
        mov     [ebp + thread_data.passivesocknum], -1
200
        mov     [ebp + thread_data.passivesocknum], -1
Line 181... Line 201...
181
 
201
 
Line -... Line 202...
-
 
202
        sendFTP "220 Welcome to KolibriOS FTP daemon"
182
        sendFTP "220 Welcome to KolibriOS FTP daemon"
203
 
-
 
204
        diff16  "threadloop", 0, $
-
 
205
threadloop:
183
 
206
; Check if our socket is still connected
-
 
207
        mcall   send, [ebp + thread_data.socketnum], 0, 0       ; Try to send zero bytes, if socket is closed, this will return -1
-
 
208
        cmp     eax, -1
-
 
209
        je      thread_exit
Line 184... Line 210...
184
threadloop:
210
 
185
        mcall   10
211
        mcall   10                                              ; Wait for network event
186
 
-
 
187
        cmp     [ebp + thread_data.mode], MODE_PASSIVE_WAIT
212
 
188
        jne     .not_passive
213
        cmp     [ebp + thread_data.mode], MODE_PASSIVE_WAIT
189
        mov     [ebp + thread_data.mode], MODE_PASSIVE_FAILED           ; assume that we will fail
214
        jne     .not_passive
190
        mov     ecx, [ebp + thread_data.passivesocknum]
215
        mov     ecx, [ebp + thread_data.passivesocknum]
191
        lea     edx, [ebp + thread_data.datasock]
216
        lea     edx, [ebp + thread_data.datasock]
Line 248... Line 273...
248
        invoke  con_set_flags, 0x0c                     ; print errors in red
273
        invoke  con_set_flags, 0x0c                     ; print errors in red
249
        invoke  con_write_asciiz, str6
274
        invoke  con_write_asciiz, str6
250
        jmp     done
275
        jmp     done
Line 251... Line 276...
251
 
276
 
252
done:
-
 
253
        invoke  con_getch2
277
done:
254
        invoke  con_exit, 1
278
        invoke  con_exit, 0
255
exit:
279
exit:
Line 256... Line 280...
256
        mcall   -1
280
        mcall   -1
257
 
281
 
258
 
282
 
259
thread_exit:
283
thread_exit:
260
        invoke  con_set_flags, 0x02                     ; print thread info in blue
284
        invoke  con_set_flags, 0x03                             ; print thread info in blue
261
        invoke  con_write_asciiz, str_bye
285
        invoke  con_printf, str_bye, [ebp + thread_data.pid]    ; print on the console that we are about to kill the thread
Line 262... Line 286...
262
        pop     ecx                                     ; get the thread_data pointer from stack
286
        add     esp, 8                                          ; balance stack
Line 263... Line 287...
263
        mcall   68, 13                                  ; free the memory
287
        mcall   68, 13, ebp                                     ; free the memory
264
        mcall   -1                                      ; and kill the thread
288
        mcall   -1                                              ; and kill the thread
265
 
289
 
266
 
290
 
267
; initialized data
291
; initialized data
268
 
292
 
269
title           db 'KolibriOS FTP daemon 0.1', 0
293
title           db 'KolibriOS FTP daemon 0.1', 0
270
str1            db 'Starting FTP daemon on port %u', 0
294
str1            db 'Starting FTP daemon on port %u.', 0
271
str2            db '.', 0
295
str2            db '.', 0
272
str2b           db ' OK!',10,0
296
str2b           db ' OK!',10,0
273
str3            db 'Listen error',10,0
297
str3            db 'Listen error',10,0
Line 274... Line 298...
274
str4            db 'Bind error',10,0
298
str4            db 10,'ERROR: local port is already in use.',10,0
275
;str5            db 'Setsockopt error.',10,10,0
299
;str5            db 'Setsockopt error.',10,10,0
276
str6            db 'Could not open socket',10,0
300
str6            db 'ERROR: Could not open socket.',10,0
277
str7            db 'Got data!',10,10,0
301
str7            db 'Got data!',10,10,0
278
str8            db 10,'New thread created!',10,0
302
str8            db 10,'Thread %d created',10,0
279
str_bye         db 10,'Closing thread!',10,0
303
str_bye         db 10,'Thread %d killed',10,0
280
 
304
 
281
str_logged_in   db 'Login ok',10,0
305
str_logged_in   db 'Login ok',10,0
Line 282... Line 306...
282
str_pass_ok     db 'Password ok',10,0
306
str_pass_ok     db 'Password ok',10,0
283
str_pass_err    db 'Password/Username incorrect',10,0
307
str_pass_err    db 'Password/Username incorrect',10,0
284
str_pwd         db 'Current directory is "%s"\n',0
308
str_pwd         db 'Current directory is "%s"\n',0
Line 344... Line 368...
344
        con_gets,               'con_gets',\
368
        con_gets,               'con_gets',\
345
        con_cls,                'con_cls',\
369
        con_cls,                'con_cls',\
346
        con_printf,             'con_printf',\
370
        con_printf,             'con_printf',\
347
        con_getch2,             'con_getch2',\
371
        con_getch2,             'con_getch2',\
348
        con_set_cursor_pos,     'con_set_cursor_pos',\
372
        con_set_cursor_pos,     'con_set_cursor_pos',\
349
        con_set_flags,          'con_set_flags'
373
        con_set_flags,          'con_set_flags',\
-
 
374
        con_get_flags,          'con_get_flags'
Line 350... Line 375...
350
 
375
 
351
import  libini,\
376
import  libini,\
352
        ini.get_str,            'ini_get_str',\
377
        ini.get_str,            'ini_get_str',\