Subversion Repositories Kolibri OS

Rev

Rev 3818 | Rev 4920 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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