Subversion Repositories Kolibri OS

Rev

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

Rev 2557 Rev 2560
Line 11... Line 11...
11
STATE_DISCONNECTED      = 0
11
STATE_DISCONNECTED      = 0
12
STATE_CONNECTED         = 1
12
STATE_CONNECTED         = 1
13
STATE_LOGIN             = 2
13
STATE_LOGIN             = 2
14
STATE_ACTIVE            = 3
14
STATE_ACTIVE            = 3
Line -... Line 15...
-
 
15
 
-
 
16
TYPE_UNDEF              = 0
-
 
17
 
-
 
18
TYPE_ASCII              = 00000100b
-
 
19
TYPE_EBDIC              = 00001000b
-
 
20
; subtypes for ascii & ebdic (np = default)
-
 
21
TYPE_NP                 = 00000001b     ; non printable
-
 
22
TYPE_TELNET             = 00000010b
-
 
23
TYPE_ASA                = 00000011b
-
 
24
 
-
 
25
TYPE_IMAGE              = 01000000b     ; binary data
-
 
26
TYPE_LOCAL              = 10000000b     ; bits per byte must be specified
-
 
27
                                        ; lower 4 bits will hold this value
-
 
28
 
-
 
29
MODE_NOTREADY           = 0
-
 
30
MODE_ACTIVE             = 1
Line 15... Line 31...
15
 
31
MODE_PASSIVE            = 2
16
 
32
 
17
use32
33
use32
18
        db      'MENUET01'      ; signature
34
        db      'MENUET01'      ; signature
Line 50... Line 66...
50
        movsb
66
        movsb
Line 51... Line 67...
51
 
67
 
52
; initialize console
68
; initialize console
53
        push    1
69
        push    1
-
 
70
        call    [con_start]
54
        call    [con_start]
71
 
55
        push    title
72
        push    title
56
        push    25
73
        push    -1
57
        push    80
74
        push    -1
58
        push    25
75
        push    -1
59
        push    80
76
        push    -1
Line 60... Line 77...
60
        call    [con_init]
77
        call    [con_init]
Line -... Line 78...
-
 
78
 
-
 
79
        mcall   40, 1 shl 7     ; we only want network events
-
 
80
 
-
 
81
        invoke  ini.get_int, path, str_ftpd, str_port, 21
61
 
82
        mov     [sockaddr1.port], ax
62
        mcall   40, 1 shl 7     ; we only want network events
83
 
Line 63... Line 84...
63
 
84
        push    eax
64
        push    str1
85
        push    str1
65
        call    [con_write_asciiz]
86
        call    [con_printf]
Line 66... Line 87...
66
 
87
 
Line -... Line 88...
-
 
88
        mcall   socket, AF_INET4, SOCK_STREAM, 0
-
 
89
        cmp     eax, -1
-
 
90
        je      sock_err
67
        mcall   socket, AF_INET4, SOCK_STREAM, 0
91
 
68
        cmp     eax, -1
92
        mov     [socketnum], eax
69
        je      sock_err
93
 
Line 70... Line -...
70
 
-
 
71
        mov     [socketnum], eax
-
 
72
 
-
 
73
;;        mcall   setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
94
        push    str2
74
;;        cmp     eax, -1
95
        call    [con_write_asciiz]
75
;;        je      opt_err
96
 
Line -... Line 97...
-
 
97
;;        mcall   setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
-
 
98
;;        cmp     eax, -1
-
 
99
;;        je      opt_err
76
 
100
 
77
        invoke  ini.get_int, path, str_ftpd, str_port, 21
101
        mcall   bind, [socketnum], sockaddr1, sockaddr1.length
-
 
102
        cmp     eax, -1
-
 
103
        je      bind_err
-
 
104
 
-
 
105
        push    str2
78
        mov     [sockaddr1.port], ax
106
        call    [con_write_asciiz]
79
 
107
 
80
        mcall   bind, [socketnum], sockaddr1, sockaddr1.length
108
        invoke  ini.get_int, path, str_ftpd, str_conn, 1        ; Backlog (max connections)
Line 81... Line 109...
81
        cmp     eax, -1
109
        mov     edx, eax
82
        je      bind_err
110
 
Line 83... Line 111...
83
 
111
        push    str2
Line 84... Line 112...
84
        invoke  ini.get_int, path, str_ftpd, str_conn, 1        ; Backlog (max connections)
112
        call    [con_write_asciiz]
Line 106... Line 134...
106
        mcall   recv, [socketnum2], buffer, buffer.length
134
        mcall   recv, [socketnum2], buffer, buffer.length
107
        cmp     eax, -1
135
        cmp     eax, -1
108
        je      .loop
136
        je      .loop
109
        push    eax
137
        push    eax
Line -... Line 138...
-
 
138
 
-
 
139
        mov     byte[buffer+eax], 0
-
 
140
 
-
 
141
 
-
 
142
        pushd   0x0a
-
 
143
        call    [con_set_flags]
110
 
144
 
111
        push    buffer
145
        push    buffer
Line -... Line 146...
-
 
146
        call    [con_write_asciiz]
-
 
147
 
-
 
148
        pushd   0x07
112
        call    [con_write_asciiz]
149
        call    [con_set_flags]
113
 
150
 
114
        pop     ecx
151
        pop     ecx
Line 115... Line 152...
115
        mov     esi, buffer
152
        mov     esi, buffer
Line 116... Line 153...
116
        call    parse_cmd
153
        call    parse_cmd
-
 
154
 
-
 
155
        jmp     .loop
-
 
156
 
-
 
157
acpt_err:
117
 
158
 
118
        jmp     .loop
159
        pushd   0x0c
119
 
160
        call    [con_set_flags]
Line 120... Line 161...
120
acpt_err:
161
 
-
 
162
        push    str8
-
 
163
        call    [con_write_asciiz]
-
 
164
        jmp     done
-
 
165
 
121
        push    str8
166
listen_err:
122
        call    [con_write_asciiz]
167
 
123
        jmp     done
168
        pushd   0x0c
Line 124... Line 169...
124
 
169
        call    [con_set_flags]
-
 
170
 
-
 
171
        push    str3
-
 
172
        call    [con_write_asciiz]
-
 
173
        jmp     done
125
listen_err:
174
 
126
        push    str3
175
bind_err:
127
        call    [con_write_asciiz]
176
 
Line 128... Line 177...
128
        jmp     done
177
        pushd   0x0c
-
 
178
        call    [con_set_flags]
-
 
179
 
-
 
180
        push    str4
-
 
181
        call    [con_write_asciiz]
129
 
182
        jmp     done
130
bind_err:
183
 
131
        push    str4
184
sock_err:
Line 132... Line 185...
132
        call    [con_write_asciiz]
185
 
Line 146... Line 199...
146
 
199
 
147
 
200
 
148
 
201
 
-
 
202
; data
149
; data
203
title   db      'KolibriOS FTP daemon 0.1', 0
150
title   db      'KolibriOS FTP daemon 0.1',0
204
str1    db      'Starting FTP daemon on port %u', 0
151
str1    db      'Opening socket',10, 0
205
str2    db      '.', 0
152
str2    db      'Listening for incoming connections...',10,0
206
str2b   db      ' OK!',10,10,0
153
str3    db      'Listen error',10,10,0
207
str3    db      'Listen error',10,10,0
154
str4    db      'Bind error',10,10,0
208
str4    db      'Bind error',10,10,0
155
str5    db      'Setsockopt error.',10,10,0
209
str5    db      'Setsockopt error.',10,10,0
Line -... Line 210...
-
 
210
str6    db      'Could not open socket',10,10,0
-
 
211
str7    db      'Got data!',10,10,0
-
 
212
str8    db      'Error accepting connection',10,10,0
156
str6    db      'Could not open socket',10,10,0
213
 
157
str7    db      'Got data!',10,10,0
214
str_logged_in db 'Login ok',10,10,0
158
str8    db      'Error accepting connection',10,10,0
215
str_pass_ok   db 'Password ok - Logged in',10,10,0
159
 
216
 
Line 184... Line 241...
184
        con_exit,       'con_exit',     \
241
        con_exit,       'con_exit',     \
185
        con_gets,       'con_gets',\
242
        con_gets,       'con_gets',\
186
        con_cls,        'con_cls',\
243
        con_cls,        'con_cls',\
187
        con_printf,     'con_printf',\
244
        con_printf,     'con_printf',\
188
        con_getch2,     'con_getch2',\
245
        con_getch2,     'con_getch2',\
189
        con_set_cursor_pos, 'con_set_cursor_pos'
246
        con_set_cursor_pos, 'con_set_cursor_pos',\
-
 
247
        con_set_flags,  'con_set_flags'
Line 190... Line 248...
190
 
248
 
191
import  libini,         \
249
import  libini,         \
192
        ini.get_str,    'ini_get_str',\
250
        ini.get_str,    'ini_get_str',\
Line 206... Line 264...
206
 
264
 
207
 
265
 
208
; thread specific data
266
; thread specific data
-
 
267
socketnum2      dd ?
-
 
268
state           dd ?
-
 
269
home_dir        rb 1024
-
 
270
work_dir        rb 1024
-
 
271
type            db ?
-
 
272
mode            db ?    ; active/passive
-
 
273
 
-
 
274
datasocketnum   dd ?
-
 
275
 
-
 
276
datasock:
-
 
277
        dw AF_INET4
-
 
278
.port   dw ?
-
 
279
.ip     dd ?
Line 209... Line 280...
209
socketnum2      dd ?
280
        rb 10
210
state           dd ?
281
.length = $ - datasock
Line 211... Line 282...
211
 
282
 
212
buffer          rb BUFFERSIZE
283
buffer  rb BUFFERSIZE