Subversion Repositories Kolibri OS

Rev

Rev 3813 | Rev 4729 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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