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