Subversion Repositories Kolibri OS

Rev

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

Rev 3562 Rev 3704
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;                                                                 ;;
6
;;                                                                 ;;
7
;;         GNU GENERAL PUBLIC LICENSE                              ;;
7
;;         GNU GENERAL PUBLIC LICENSE                              ;;
8
;;          Version 2, June 1991                                   ;;
8
;;          Version 2, June 1991                                   ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
 
11
 
12
 
12
 
13
socket_connect:
13
socket_connect:
14
 
14
 
15
;        cmp     [status], STATUS_CONNECTED     ; TODO
15
;        cmp     [status], STATUS_CONNECTED     ; TODO
16
;        je      disconnect
16
;        je      disconnect
17
 
17
 
18
; ignore if status is not "disconnected"
18
; ignore if status is not "disconnected"
19
        cmp     [status], STATUS_DISCONNECTED
19
        cmp     [status], STATUS_DISCONNECTED
20
        jne     .nothing
20
        jne     .nothing
21
 
21
 
22
        mov     esi, str_connecting
22
        mov     esi, str_connecting
23
        call    print_text2
23
        call    print_text2
24
        mov     esi, irc_server_name
24
        mov     esi, irc_server_name
25
        call    print_text2
25
        call    print_text2
26
        mov     esi, str_dotnewline
26
        mov     esi, str_dotnewline
27
        call    print_text2
27
        call    print_text2
28
 
28
 
29
; update status
29
; update status
30
        inc     [status]        ; was STATUS_DISCONNECTED, now STATUS_RESOLVING
30
        inc     [status]        ; was STATUS_DISCONNECTED, now STATUS_RESOLVING
31
 
31
 
32
; resolve name
32
; resolve name
33
        push    esp     ; reserve stack place
33
        push    esp     ; reserve stack place
34
        push    esp     ; fourth parameter
34
        push    esp     ; fourth parameter
35
        push    0       ; third parameter
35
        push    0       ; third parameter
36
        push    0       ; second parameter
36
        push    0       ; second parameter
37
        push    irc_server_name
37
        push    irc_server_name
38
        call    [getaddrinfo]
38
        call    [getaddrinfo]
39
        pop     esi
39
        pop     esi
40
; test for error
40
; test for error
41
        test    eax, eax
41
        test    eax, eax
42
        jnz     .fail_dns
42
        jnz     .fail_dns
43
 
43
 
44
; fill in ip in sockstruct
44
; fill in ip in sockstruct
45
        mov     eax, [esi + addrinfo.ai_addr]
45
        mov     eax, [esi + addrinfo.ai_addr]
46
        mov     eax, [eax + sockaddr_in.sin_addr]
46
        mov     eax, [eax + sockaddr_in.sin_addr]
47
        mov     [sockaddr1.ip], eax
47
        mov     [sockaddr1.ip], eax
48
 
48
 
49
; free allocated memory
49
; free allocated memory
50
        push    esi
50
        push    esi
51
        call    [freeaddrinfo]
51
        call    [freeaddrinfo]
52
 
52
 
53
; update status
53
; update status
54
        inc     [status]
54
        inc     [status]
55
 
55
 
56
; connect
56
; connect
57
        mcall   socket, AF_INET4, SOCK_STREAM, 0
57
        mcall   socket, AF_INET4, SOCK_STREAM, 0
58
        cmp     eax, -1
58
        cmp     eax, -1
59
        jz      .fail
59
        jz      .fail
60
        mov     [socketnum], eax
60
        mov     [socketnum], eax
61
 
61
 
62
        mcall   connect, [socketnum], sockaddr1, 18
62
        mcall   connect, [socketnum], sockaddr1, 18
63
        cmp     eax, -1
63
        cmp     eax, -1
64
        jz      .fail_refused
64
        jz      .fail_refused
65
 
65
 
66
  .nothing:
66
  .nothing:
67
        ret
67
        ret
68
 
68
 
69
  .fail:
69
  .fail:
70
        mov     [status], STATUS_DISCONNECTED
70
        mov     [status], STATUS_DISCONNECTED
71
 
71
 
72
        mov     esi, str_sockerr
72
        mov     esi, str_sockerr
73
        call    print_text2
73
        call    print_text2
74
 
74
 
75
        ret
75
        ret
76
 
76
 
77
  .fail_dns:
77
  .fail_dns:
78
        mov     [status], STATUS_DISCONNECTED
78
        mov     [status], STATUS_DISCONNECTED
79
 
79
 
80
        mov     esi, str_dnserr
80
        mov     esi, str_dnserr
81
        call    print_text2
81
        call    print_text2
82
 
82
 
83
        ret
83
        ret
84
 
84
 
85
  .fail_refused:
85
  .fail_refused:
86
        mov     [status], STATUS_DISCONNECTED
86
        mov     [status], STATUS_DISCONNECTED
87
 
87
 
88
        mov     esi, str_refused
88
        mov     esi, str_refused
89
        call    print_text2
89
        call    print_text2
90
 
90
 
91
        ret
91
        ret
92
 
92
 
93
 
93
 
94
 
94
 
95
socket_write_userinfo:
95
socket_write_userinfo:
96
 
96
 
97
; create packet in packetbuf
97
; create packet in packetbuf
98
        mov     edi, packetbuf
98
        mov     edi, packetbuf
99
 
99
 
100
        mov     eax, 'NICK'
100
        mov     eax, 'NICK'
101
        stosd
101
        stosd
102
        mov     al, ' '
102
        mov     al, ' '
103
        stosb
103
        stosb
104
        mov     esi, user_nick
104
        mov     esi, user_nick
105
        mov     ecx, MAX_NICK_LEN
105
        mov     ecx, MAX_NICK_LEN
106
  .loop:
106
  .loop:
107
        lodsb
107
        lodsb
108
        test    al, al
108
        test    al, al
109
        jz      .done
109
        jz      .done
110
        stosb
110
        stosb
111
        dec     ecx
111
        dec     ecx
112
        jnz     .loop
112
        jnz     .loop
113
  .done:
113
  .done:
114
        mov     ax, 0x0d0a
114
        mov     ax, 0x0d0a
115
        stosw
115
        stosw
116
 
116
 
117
        mov     eax, 'USER'
117
        mov     eax, 'USER'
118
        stosd
118
        stosd
119
        mov     al, ' '
119
        mov     al, ' '
120
        stosb
120
        stosb
121
        mov     esi, user_nick
121
        mov     esi, user_nick
122
        mov     ecx, MAX_NICK_LEN
122
        mov     ecx, MAX_NICK_LEN
123
  .loop2:
123
  .loop2:
124
        lodsb
124
        lodsb
125
        test    al, al
125
        test    al, al
126
        jz      .done2
126
        jz      .done2
127
        stosb
127
        stosb
128
        dec     ecx
128
        dec     ecx
129
        jnz     .loop2
129
        jnz     .loop2
130
  .done2:
130
  .done2:
131
        mov     eax, ' 8 *'
131
        mov     eax, ' 8 *'
132
        stosd
132
        stosd
133
        mov     ax, ' :'
133
        mov     ax, ' :'
134
        stosw
134
        stosw
135
        mov     al, ' '
135
        mov     al, ' '
136
        stosb
136
        stosb
137
        mov     esi, user_real_name
137
        mov     esi, user_real_name
138
        mov     ecx, MAX_REAL_LEN
138
        mov     ecx, MAX_REAL_LEN
139
  .loop3:
139
  .loop3:
140
        lodsb
140
        lodsb
141
        test    al, al
141
        test    al, al
142
        jz      .done3
142
        jz      .done3
143
        stosb
143
        stosb
144
        dec     ecx
144
        dec     ecx
145
        jnz     .loop3
145
        jnz     .loop3
146
  .done3:
146
  .done3:
147
        mov     ax, 0x0d0a
147
        mov     ax, 0x0d0a
148
        stosw
148
        stosw
149
 
149
 
150
        lea     esi, [edi - packetbuf]
150
        lea     esi, [edi - packetbuf]
151
        mcall   send, [socketnum], packetbuf, , 0
151
        mcall   send, [socketnum], packetbuf, , 0
152
 
152
 
153
        ret
153
        ret
154
 
154
 
155
 
155
 
156
 
156
 
157
 
157
 
158
process_network_event:
158
process_network_event:
159
; values for status: 0, 1, 2, 3
159
; values for status: 0, 1, 2, 3
160
        mov     eax, [status]
160
        mov     eax, [status]
161
        dec     eax
161
        dec     eax
162
; 0 = STATUS_DISCONNECTED - do nothing
162
; 0 = STATUS_DISCONNECTED - do nothing
163
; (ignore network events if we are disconnected from network)
163
; (ignore network events if we are disconnected from network)
164
        js      .nothing
164
        js      .nothing
165
; 1 = STATUS_RESOLVING
165
; 1 = STATUS_RESOLVING
166
        jz      .nothing
166
        jz      .nothing
167
; 2 = STATUS_CONNECTING
167
; 2 = STATUS_CONNECTING
168
        dec     eax
168
        dec     eax
169
        jz      .connecting
169
        jz      .connecting
170
; 3 = STATUS_CONNECTED
170
; 3 = STATUS_CONNECTED
171
        jmp     .connected
171
        jmp     .connected
172
 
172
 
173
  .nothing:
173
  .nothing:
174
        ret
174
        ret
175
 
175
 
176
  .connecting:
176
  .connecting:
177
        call    socket_write_userinfo
177
        call    socket_write_userinfo
178
 
178
 
179
; The connection has been established, change status from "connecting" to "connected".
179
; The connection has been established, change status from "connecting" to "connected".
180
        inc     [status]
180
        inc     [status]
181
 
181
 
182
  .connected:
182
  .connected:
183
        call    read_incoming_data
183
        call    read_incoming_data
184
        ret
184
        ret
185
 
185
 
186
 
186
 
187
disconnect:
187
disconnect:
188
 
188
 
189
        cmp     [status], STATUS_DISCONNECTED
189
        cmp     [status], STATUS_DISCONNECTED
190
        je      .nothing
190
        je      .nothing
191
 
191
 
192
        mcall   close, [socketnum]
192
        mcall   close, [socketnum]
193
 
193
 
194
        mov     [status], STATUS_DISCONNECTED
194
        mov     [status], STATUS_DISCONNECTED
195
 
195
 
196
  .nothing:
196
  .nothing:
197
        ret
197
        ret
198
 
198
 
199
 
199
 
200
 
200
 
201
read_incoming_data:
201
read_incoming_data:
202
 
202
 
203
        pusha
203
        pusha
204
 
204
 
205
; TODO: read more data if we receive one full packet
205
; TODO: read more data if we receive one full packet
206
 
206
 
207
  .nextpacket:
207
  .nextpacket:
208
        mcall   recv, [socketnum], packetbuf, 1024, 0   ; read a packet
208
        mcall   recv, [socketnum], packetbuf, 1024, MSG_DONTWAIT        ; read a packet
209
        inc     eax                                     ; check if we got one
209
        inc     eax                                                     ; check if we got one
210
        jz      .done
210
        jz      .done
211
        dec     eax
211
        dec     eax
212
        jz      .done
212
        jz      .done                                                   ; TODO: check for errors!
213
 
213
 
214
; ok we have data, now feed it to the recoder
214
; ok we have data, now feed it to the recoder
215
 
215
 
216
        lea     edx, [packetbuf + eax]                  ; edx = end pointer
216
        lea     edx, [packetbuf + eax]                  ; edx = end pointer
217
        mov     esi, packetbuf                          ; esi = start pointer
217
        mov     esi, packetbuf                          ; esi = start pointer
218
  .nextcommand:
218
  .nextcommand:
219
        mov     edi, servercommand
219
        mov     edi, servercommand
220
  .byteloop:
220
  .byteloop:
221
        call    get_next_byte                           ; reads byte from [esi] to al
221
        call    get_next_byte                           ; reads byte from [esi] to al
222
        jnc     .nextpacket                             ; if CF is set, we need more data
222
        jnc     .nextpacket                             ; if CF is set, we need more data
223
        cmp     al, 10
223
        cmp     al, 10
224
        je      .got_command
224
        je      .got_command
225
        cmp     al, 13
225
        cmp     al, 13
226
        je      .got_command
226
        je      .got_command
227
        stosb
227
        stosb
228
        jmp     .byteloop
228
        jmp     .byteloop
229
 
229
 
230
; we have a command, call the serverparser
230
; we have a command, call the serverparser
231
 
231
 
232
  .got_command:
232
  .got_command:
233
        mov     byte[edi], 0                            ; mark the end of the command
233
        mov     byte[edi], 0                            ; mark the end of the command
234
        push    esi edx
234
        push    esi edx
235
        call    server_parser
235
        call    server_parser
236
        pop     edx esi
236
        pop     edx esi
237
        jmp     .nextcommand
237
        jmp     .nextcommand
238
 
238
 
239
  .done:
239
  .done:
240
        popa
240
        popa
241
 
241
 
242
        ret
242
        ret