Subversion Repositories Kolibri OS

Rev

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

Rev 3804 Rev 3813
Line 43... Line 43...
43
include '../../network.inc'
43
include '../../network.inc'
Line 44... Line 44...
44
 
44
 
45
include 'usercommands.inc'
45
include 'usercommands.inc'
Line 46... Line -...
46
include 'servercommands.inc'
-
 
47
 
46
include 'servercommands.inc'
48
; entry point
-
 
-
 
47
 
49
start:
48
start:
50
 
49
; disable all events
51
        mcall   40, 0
50
        mcall   40, 0
52
; load libraries
51
; load libraries
53
        stdcall dll.Load, @IMPORT
52
        stdcall dll.Load, @IMPORT
54
        test    eax, eax
53
        test    eax, eax
55
        jnz     exit
54
        jnz     exit
56
; initialize console
55
; initialize console
57
        invoke  con_start, 1
-
 
58
        invoke  con_init, 80, 25, 80, 250, title
56
        invoke  con_start, 1
59
 
57
        invoke  con_init, 80, 25, 80, 250, str_title
60
; Check for parameters
58
; Check for parameters, if there are some, resolve the address right away
Line 61... Line 59...
61
        cmp     byte [s], 0
59
        cmp     byte [s], 0
-
 
60
        jne     resolve
62
        jne     resolve
61
 
63
 
62
main:
64
main:
63
; Clear screen
65
        invoke  con_cls
-
 
66
; Welcome user
64
        invoke  con_cls
67
        invoke  con_write_asciiz, str1
65
; Welcome user
68
 
66
        invoke  con_write_asciiz, str_welcome
69
; write prompt
67
; write prompt (in green color)
70
        invoke  con_set_flags, 0x0a
-
 
71
        invoke  con_write_asciiz, str2
68
        invoke  con_set_flags, 0x0a
72
; read string
-
 
73
        mov     esi, s
-
 
74
        invoke  con_gets, esi, 256
69
        invoke  con_write_asciiz, str_prompt
75
        invoke  con_write_asciiz, str4  ; newline
70
; read string
76
        invoke  con_set_flags, 0x07
71
        invoke  con_gets, s, 256
77
; check for exit
72
; check for exit
78
        test    eax, eax
73
        test    eax, eax
-
 
74
        jz      done
-
 
75
        cmp     byte [s], 10
-
 
76
        jz      done
Line 79... Line 77...
79
        jz      done
77
; reset color back to grey and print newline
80
        cmp     byte [esi], 10
78
        invoke  con_set_flags, 0x07
81
        jz      done
79
        invoke  con_write_asciiz, str_newline
82
 
80
 
83
resolve:
81
resolve:
84
; delete terminating '\n'
82
; delete terminating '\n'
85
        mov     esi, s
83
        mov     esi, s
86
  @@:
84
  @@:
87
        lodsb
-
 
-
 
85
        lodsb
88
        cmp     al, 0x20
86
        cmp     al, 0x20
89
        ja      @r
87
        ja      @r
90
        mov     byte [esi-1], 0
-
 
91
 
88
        mov     byte [esi-1], 0
92
        invoke  con_write_asciiz, str3
89
; Say to the user that we're resolving
93
        invoke  con_write_asciiz, s
90
        invoke  con_write_asciiz, str_resolve
94
 
91
        invoke  con_write_asciiz, s
95
; resolve name
92
; resolve name
96
        push    esp     ; reserve stack place
93
        push    esp     ; reserve stack place
97
        invoke  getaddrinfo, s, 0, 0, esp
94
        invoke  getaddrinfo, s, 0, 0, esp
98
        pop     esi
-
 
99
; test for error
95
        pop     esi
100
        test    eax, eax
96
; test for error
101
        jnz     fail
97
        test    eax, eax
102
 
98
        jnz     error_resolve
103
; write results
99
; write results
104
        invoke  con_write_asciiz, str8          ; ' (',0
100
        invoke  con_write_asciiz, str8          ; ' (',0
105
        mov     eax, [esi+addrinfo.ai_addr]     ; convert IP address to decimal notation
101
        mov     eax, [esi+addrinfo.ai_addr]     ; convert IP address to decimal notation
106
        mov     eax, [eax+sockaddr_in.sin_addr] ;
102
        mov     eax, [eax+sockaddr_in.sin_addr] ;
107
        mov     [sockaddr1.ip], eax             ;
103
        mov     [sockaddr1.ip], eax             ;
108
        invoke  inet_ntoa, eax                  ;
-
 
109
        invoke  con_write_asciiz, eax           ; print ip
104
        invoke  inet_ntoa, eax                  ;
110
        invoke  freeaddrinfo, esi               ; free allocated memory
105
        invoke  con_write_asciiz, eax           ; print ip
111
        invoke  con_write_asciiz, str9          ; ')',10,0
106
        invoke  freeaddrinfo, esi               ; free allocated memory
112
 
107
        invoke  con_write_asciiz, str9          ; ')',10,0
113
; open the socket
108
; open the socket
114
        mcall   socket, AF_INET4, SOCK_STREAM, 0
-
 
115
        cmp     eax, -1
109
        mcall   socket, AF_INET4, SOCK_STREAM, 0
116
        je      socket_error
110
        cmp     eax, -1
117
        mov     [socketnum], eax
111
        je      error_socket
118
 
112
        mov     [socketnum], eax
-
 
113
; connect to the server
-
 
114
        invoke  con_write_asciiz, str_connect
Line 119... Line 115...
119
; connect to the server
115
        mcall   connect, [socketnum], sockaddr1, 18
120
        invoke  con_write_asciiz, str11
-
 
121
        mcall   connect, [socketnum], sockaddr1, 18
116
        mov     [status], STATUS_CONNECTING
Line 122... Line 117...
122
        mov     [status], STATUS_CONNECTING
117
; Tell the user we're waiting for the server now.
123
 
-
 
-
 
118
        invoke  con_write_asciiz, str_waiting
124
        invoke  con_write_asciiz, str12         ; 'waiting for welcome'
119
 
125
 
120
; Reset 'offset' variable, it's used by the data receiver
126
        mov     [offset], 0
121
        mov     [offset], 0
127
 
122
 
128
wait_for_servercommand:
123
wait_for_servercommand:
129
 
124
; Any commands still in our buffer?
130
        cmp     [offset], 0
125
        cmp     [offset], 0
Line 131... Line 126...
131
        je      .receive
126
        je      .receive                        ; nope, receive some more
132
        mov     esi, [offset]
127
        mov     esi, [offset]
133
        mov     edi, s
128
        mov     edi, s
134
        mov     ecx, [size]
129
        mov     ecx, [size]
135
        add     ecx, esi
130
        add     ecx, esi
136
        jmp     .byteloop
131
        jmp     .byteloop
137
 
132
 
Line 138... Line 133...
138
; receive socket data
133
; receive socket data
Line 172... Line 167...
172
        xor     al, al
167
        xor     al, al
173
        stosb
168
        stosb
Line 174... Line 169...
174
 
169
 
175
        invoke  con_set_flags, 0x03             ; change color
170
        invoke  con_set_flags, 0x03             ; change color
176
        invoke  con_write_asciiz, s             ; print servercommand
171
        invoke  con_write_asciiz, s             ; print servercommand
177
        invoke  con_write_asciiz, str4          ; newline
172
        invoke  con_write_asciiz, str_newline
Line 178... Line 173...
178
        invoke  con_set_flags, 0x07             ; reset color
173
        invoke  con_set_flags, 0x07             ; reset color
Line -... Line 174...
-
 
174
 
-
 
175
        jmp     server_parser                   ; parse command
179
 
176
 
Line -... Line 177...
-
 
177
 
180
        jmp     server_parser                   ; parse command
178
 
Line -... Line 179...
-
 
179
wait_for_usercommand:
181
 
180
 
182
wait_for_usercommand:
181
; change color to green for user input
Line 183... Line 182...
183
 
182
        invoke  con_set_flags, 0x0a
184
        invoke  con_set_flags, 0x0a
183
 
Line 185... Line 184...
185
 
184
; If we are not yet connected, request username/password
186
        cmp     [status], STATUS_CONNECTED
185
        cmp     [status], STATUS_CONNECTED
187
        je      .connected
186
        je      .connected
188
 
-
 
189
        cmp     [status], STATUS_NEEDPASSWORD
187
 
Line -... Line 188...
-
 
188
        cmp     [status], STATUS_NEEDPASSWORD
190
        je      .needpass
189
        je      .needpass
191
 
190
 
Line 192... Line -...
192
; write prompt
-
 
193
        invoke  con_write_asciiz, str2
-
 
194
; read string
-
 
195
        mov     esi, s
-
 
196
        invoke  con_gets, esi, 256
-
 
197
 
-
 
198
        invoke  con_write_asciiz, str4          ; newline
191
; write prompt
199
        invoke  con_set_flags, 0x07
192
        invoke  con_write_asciiz, str_prompt
Line -... Line 193...
-
 
193
; read string
-
 
194
        invoke  con_gets, s, 256
-
 
195
 
200
 
196
; print a newline and reset the color back to grey
201
        cmp     dword[s], "list"
197
        invoke  con_write_asciiz, str_newline
Line 202... Line 198...
202
        je      cmd_list
198
        invoke  con_set_flags, 0x07
203
 
199
 
Line -... Line 200...
-
 
200
        cmp     dword[s], "cwd "
-
 
201
        je      cmd_cwd
-
 
202
 
-
 
203
        cmp     dword[s], "mkd "
-
 
204
        je      cmd_mkd
-
 
205
 
-
 
206
        cmp     dword[s], "rmd "
-
 
207
        je      cmd_rmd
-
 
208
 
-
 
209
        cmp     dword[s], "pwd" + 10 shl 24
-
 
210
        je      cmd_pwd
-
 
211
 
204
        cmp     dword[s], "help"
212
        cmp     dword[s], "bye" + 10 shl 24
205
        je      cmd_help
213
        je      cmd_bye
Line 206... Line 214...
206
 
214
 
207
        cmp     dword[s], "cwd "
215
        cmp     byte[s+4], " "
Line 208... Line -...
208
        je      cmd_cwd
-
 
209
 
-
 
210
        cmp     dword[s], "retr"
216
        jne     @f
211
        je      cmd_retr
217
 
212
 
218
        cmp     dword[s], "lcwd"
Line 213... Line 219...
213
        cmp     dword[s], "pwd" + 10 shl 24
219
        je      cmd_lcwd
214
        je      cmd_pwd
220
 
Line 215... Line 221...
215
 
221
        cmp     dword[s], "retr"
216
        cmp     dword[s], "stor"
222
        je      cmd_retr
Line 217... Line 223...
217
        je      cmd_stor
223
 
218
 
224
        cmp     dword[s], "stor"
Line -... Line 225...
-
 
225
        je      cmd_stor
-
 
226
 
219
        cmp     dword[s], "dele"
227
        cmp     dword[s], "dele"
220
        je      cmd_dele
228
        je      cmd_dele
Line 221... Line 229...
221
 
229
 
222
        cmp     dword[s], "bye" + 10 shl 24
-
 
-
 
230
  @@:
223
        je      cmd_bye
231
        cmp     byte[s+4], 10
224
 
232
        jne     @f
225
        cmp     dword[s], "lcwd"
233
 
226
        je      cmd_lcwd
234
        cmp     dword[s], "list"
Line 227... Line 235...
227
 
235
        je      cmd_list
228
        cmp     dword[s], "mkd "
-
 
-
 
236
 
229
        je      cmd_mkd
237
        cmp     dword[s], "help"
230
 
238
        je      cmd_help
231
        cmp     dword[s], "rmd "
239
 
232
        je      cmd_rmd
240
        cmp     dword[s], "cdup"
Line 265... Line 273...
265
        repne   scasb
273
        repne   scasb
266
        lea     esi, [edi-s-1]
274
        lea     esi, [edi-s-1]
267
; and send it to the server
275
; and send it to the server
268
        mcall   send, [socketnum], s, , 0
276
        mcall   send, [socketnum], s, , 0
Line 269... Line 277...
269
 
277
 
270
        invoke  con_write_asciiz, str4  ; newline
278
        invoke  con_write_asciiz, str_newline
271
        invoke  con_set_flags, 0x07     ; reset color
279
        invoke  con_set_flags, 0x07     ; reset color
Line 281... Line 289...
281
        mov     byte[s+4], 10
289
        mov     byte[s+4], 10
282
        mcall   send, [socketnum], s, 5, 0
290
        mcall   send, [socketnum], s, 5, 0
283
        ret
291
        ret
Line 284... Line 292...
284
 
292
 
285
  .fail:
293
  .fail:
286
        invoke  con_write_asciiz, str6
294
        invoke  con_write_asciiz, str_err_socket
Line 287... Line 295...
287
        ret
295
        ret
288
 
296
 
289
 
297
 
290
 
298
 
291
socket_error:
299
error_socket:
292
        invoke  con_write_asciiz, str6
300
        invoke  con_write_asciiz, str_err_socket
-
 
301
        jmp     wait_for_keypress
293
        jmp     fail.wait
302
 
294
 
303
error_resolve:
295
fail:
304
        invoke  con_write_asciiz, str_err_resolve
296
        invoke  con_write_asciiz, str5
305
 
Line 297... Line 306...
297
  .wait:
306
wait_for_keypress:
298
        invoke  con_write_asciiz, str10
307
        invoke  con_write_asciiz, str_push
Line 307... Line 316...
307
        mcall   -1
316
        mcall   -1
Line 308... Line 317...
308
 
317
 
309
 
318
 
-
 
319
 
-
 
320
; data
310
 
321
str_title       db 'FTP client',0
-
 
322
str_welcome     db 'FTP client for KolibriOS v0.08',10
311
; data
323
                db 10
312
title   db 'FTP client',0
324
                db 'Please enter ftp server address.',10,0
313
str1    db 'FTP client for KolibriOS v0.07',10,10,'Please enter ftp server address.',10,0
325
 
314
str2    db '> ',0
326
str_prompt      db '> ',0
315
str3    db 'Resolving ',0
327
str_resolve     db 'Resolving ',0
316
str4    db 10,0
328
str_newline     db 10,0
317
str5    db 10,'Name resolution failed.',10,0
329
str_err_resolve db 10,'Name resolution failed.',10,0
318
str6    db 10,'Socket error.',10,0
330
str_err_socket  db 10,'Socket error.',10,0
319
str8    db ' (',0
331
str8            db ' (',0
320
str9    db ')',10,0
332
str9            db ')',10,0
321
str10   db 'Push any key to continue.',0
333
str_push        db 'Push any key to continue.',0
322
str11   db 'Connecting...',10,0
334
str_connect     db 'Connecting...',10,0
323
str12   db 'Waiting for welcome message.',10,0
335
str_waiting     db 'Waiting for welcome message.',10,0
324
str_user db "username: ",0
336
str_user        db "username: ",0
-
 
337
str_pass        db "password: ",0
-
 
338
str_unknown     db "Unknown command or insufficient parameters - type help for more information.",10,0
Line 325... Line 339...
325
str_pass db "password: ",0
339
str_lcwd        db "Local working directory is now: ",0
326
str_unknown db "unknown command or insufficient parameters",10,0
-
 
327
str_lcwd db "local working directory is now: ",0
340
 
328
 
341
str_open        db "opening data socket",10,0
329
str_help db "available commands:",10
342
 
330
         db "help - help",10
343
str_help        db "available commands:",10
331
         db 10
344
                db 10
332
         db "bye  - close connection",10
345
                db "bye             - close the connection",10
333
         db "cdup - change to parent of current directory on server",10
346
                db "cdup            - change to parent of current directory on the server",10
334
         db "cwd  - change working directoy on server",10
347
                db "cwd  - change working directoy on the server",10
335
         db "dele - delete file from server",10
348
                db "dele      - delete file from the server",10
336
         db "list - list files and folders in current directory",10
349
                db "list            - list files and folders in current server directory",10
337
         db "lcwd - change local working directory",10
350
                db "lcwd      - change local working directory",10
338
         db "mkd  - make directory on the server",10
351
                db "mkd  - make directory on the server",10
339
         db "pwd  - print working directory",10
352
                db "pwd             - print server working directory",10
Line 340... Line -...
340
         db "retr - retreive file from server",10
-
 
341
         db "rmd  - remove directory from the server",10
-
 
342
         db "stor - store file on server",10
353
                db "retr      - retreive file from the server",10
343
         db 10,0
354
                db "rmd  - remove directory from the server",10
344
 
355
                db "stor      - store file on the server",10
345
str_open db "opening data socket",10,0
356
                db 10,0
346
 
357
 
Line 381... Line 392...
381
        con_set_flags,  'con_set_flags'
392
        con_set_flags,  'con_set_flags'
Line 382... Line 393...
382
 
393
 
Line -... Line 394...
-
 
394
 
-
 
395
i_end:
383
 
396
 
384
i_end:
397
; uninitialised data
Line 385... Line 398...
385
 
398
 
386
status          db ?
399
status          db ?