Mercurial > pidgin.yaz
annotate plugins/icq/udphandle.c @ 1727:02653161cbce
[gaim-migrate @ 1737]
bleh. this should be handled by write_to_conv.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 19 Apr 2001 03:53:23 +0000 |
parents | 0ef6603d986e |
children | 7ec37e31e5eb |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
3 $Id: udphandle.c 1508 2001-02-22 23:07:34Z warmenhoven $ |
1152 | 4 $Log$ |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
5 Revision 1.4 2001/02/22 23:07:34 warmenhoven |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
6 updating icqlib |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
7 |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
8 Revision 1.31 2001/02/22 05:40:04 bills |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
9 port tcp connect timeout code and UDP queue to new timeout manager |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
10 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
11 Revision 1.30 2001/01/15 06:17:35 denis |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
12 Applied patch from Andrey Chernomyrdin <andrey@excom.spb.su> to |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
13 handle icq2000 specific "You've been added" packet. |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
14 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
15 Revision 1.29 2000/11/02 07:28:30 denis |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
16 Do not ack unhandled protocol version. |
1152 | 17 |
18 Revision 1.28 2000/06/25 17:25:52 denis | |
19 icq_HandleMetaUserInfo() handles all (!) available in original icq2k | |
20 Meta User Info packets along with other useful Meta* packets. (WOW! ;) | |
21 | |
22 Revision 1.27 2000/05/10 18:54:43 denis | |
23 icq_Disconnect() now called before icq_Disconnected callback to | |
24 prevent high CPU usage in kicq's "reconnect on disconnect" code. | |
25 | |
26 Revision 1.26 2000/05/03 18:29:15 denis | |
27 Callbacks have been moved to the ICQLINK structure. | |
28 | |
29 Revision 1.25 2000/02/07 02:48:15 bills | |
30 changed log message in HandleUserOnline | |
31 | |
32 Revision 1.24 2000/01/16 03:59:10 bills | |
33 reworked list code so list_nodes don't need to be inside item structures, | |
34 removed strlist code and replaced with generic list calls | |
35 | |
36 Revision 1.23 1999/12/27 11:12:37 denis | |
37 icq_UpdateMetaInfoSecurity() added for setting "My authorization is | |
38 required", "Web Aware" and "IP Publishing". | |
39 | |
40 Revision 1.22 1999/12/14 03:37:06 bills | |
41 removed old real_ip->ip masq hack, added store to remote_real_ip in | |
42 icq_ContactItem | |
43 | |
44 Revision 1.21 1999/12/12 18:03:58 denis | |
45 Authorization Request packet handling fixed. | |
46 | |
47 Revision 1.20 1999/11/29 17:18:31 denis | |
48 icq_DoMsg() redone using string lists. | |
49 | |
50 Revision 1.18 1999/11/11 15:10:32 guruz | |
51 - Added Base for Webpager Messages. Please type "make fixme" | |
52 - Removed Segfault when kicq is started the first time | |
53 | |
54 Revision 1.17 1999/10/14 11:44:04 denis | |
55 Cleanups. | |
56 | |
57 Revision 1.16 1999/09/29 17:16:08 denis | |
58 MailExpress message handler started. | |
59 | |
60 Revision 1.15 1999/07/18 20:23:54 bills | |
61 fixed tcp port bug in icq_HandleUserOnline, changed to use new byte-order | |
62 & contact list functions | |
63 | |
64 Revision 1.14 1999/07/16 15:46:02 denis | |
65 Cleaned up. | |
66 | |
67 Revision 1.13 1999/07/16 12:40:55 denis | |
68 ICQ UDP v5 implemented. | |
69 Encription for ICQ UDP v5 implemented. | |
70 icq_Packet* unified interface for UDP packets implemented. | |
71 Multipacket support of ICQ UDP v5 support added. | |
72 | |
73 Revision 1.12 1999/07/12 15:13:45 cproch | |
74 - added definition of ICQLINK to hold session-specific global variabled | |
75 applications which have more than one connection are now possible | |
76 - changed nearly every function defintion to support ICQLINK parameter | |
77 | |
78 Revision 1.11 1999/07/03 06:46:54 lord | |
79 converting icq_userOnline callback parameters to correct | |
80 byte order. | |
81 | |
82 Revision 1.10 1999/07/03 02:29:46 bills | |
83 added code to HandleUserOnline to update tcp_flag | |
84 | |
85 Revision 1.9 1999/04/29 09:40:54 denis | |
86 Unsuccessful attempt to implement web presence (webaware) feature | |
87 | |
88 Revision 1.8 1999/04/18 01:58:37 bills | |
89 changed icq_SrvAck call to icq_RequestNotify | |
90 | |
91 Revision 1.7 1999/04/17 19:26:49 bills | |
92 removed *_link entries from icq_ContactItem, including cleaup/init code | |
93 | |
94 Revision 1.6 1999/04/14 15:05:39 denis | |
95 Cleanups for "strict" compiling (-ansi -pedantic) | |
96 Switched from icq_Log callback to icq_Fmt function. | |
97 | |
98 Revision 1.5 1999/04/05 18:47:23 bills | |
99 initial chat support implemented | |
100 | |
101 Revision 1.4 1999/03/31 01:39:50 bills | |
102 added handling of tcp_flag in HandleLogin | |
103 | |
104 Revision 1.3 1999/03/28 03:35:17 bills | |
105 fixed function names so icqlib compiles, fixed bug in HandleUserOnline | |
106 (remote_ip and remote_real_ip were not evaluating correctly), added | |
107 hack so I can test using local network | |
108 | |
109 Revision 1.2 1999/03/25 22:25:02 bills | |
110 modified icq_HandleUserOnline & Offline for new message_link | |
111 | |
112 Revision 1.1 1999/03/24 11:37:38 denis | |
113 Underscored files with TCP stuff renamed. | |
114 TCP stuff cleaned up | |
115 Function names changed to corresponding names. | |
116 icqlib.c splitted to many small files by subject. | |
117 C++ comments changed to ANSI C comments. | |
118 | |
119 */ | |
120 | |
121 #include <stdlib.h> | |
122 | |
123 #include "icqtypes.h" | |
124 #include "icq.h" | |
125 #include "icqlib.h" | |
126 #include "udp.h" | |
127 #include "icqpacket.h" | |
128 #include "queue.h" | |
129 #include "icqbyteorder.h" | |
130 #include "list.h" | |
131 | |
132 int icq_SplitFields(list *strList, const char *str) | |
133 { | |
134 char *tmpBuf, *tmp, *ptr; | |
135 int count = 0; | |
136 | |
137 tmpBuf = (char*)malloc(strlen(str)+1); | |
138 strcpy(tmpBuf, str); | |
139 ptr = tmpBuf; | |
140 | |
141 while(ptr) | |
142 { | |
143 char *p; | |
144 tmp = strchr(ptr, 0xFE); | |
145 if(tmp != 0L) | |
146 { | |
147 *tmp = 0; | |
148 tmp++; | |
149 } | |
150 count++; | |
151 p = (char *)malloc(strlen(ptr)+1); | |
152 strcpy(p, ptr); | |
153 list_enqueue(strList, p); | |
154 ptr = tmp; | |
155 } | |
156 | |
157 free(tmpBuf); | |
158 return count; | |
159 } | |
160 | |
161 void icq_DoMsg(ICQLINK *link, DWORD type, WORD len, char *data, DWORD uin, BYTE hour, | |
162 BYTE minute, BYTE day, BYTE month, WORD year) | |
163 { | |
164 list *strList; | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
165 int fieldCount; |
1152 | 166 |
167 strList = list_new(); | |
168 switch(type) | |
169 { | |
170 case TYPE_ADDED: | |
171 /* Format: Nick, 0xFE, FName, 0xFE, LName, 0xFE, EMail */ | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
172 fieldCount = icq_SplitFields(strList, data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
173 if(fieldCount != 4 && fieldCount != 5) |
1152 | 174 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
175 icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_ADDED packet (expected 4/5 args, received %i)!\n", |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
176 fieldCount); |
1152 | 177 return; |
178 } | |
179 icq_RusConv("wk", list_at(strList, 0)); /* Nick */ | |
180 icq_RusConv("wk", list_at(strList, 1)); /* FName */ | |
181 icq_RusConv("wk", list_at(strList, 2)); /* LName */ | |
182 icq_RusConv("wk", list_at(strList, 3)); /* EMail */ | |
183 icq_FmtLog(link, ICQ_LOG_MESSAGE, "%lu has added you to their contact list, " | |
184 "Nick: %s, First Name: %s, Last Name: %s, EMail: %s\n", | |
185 uin, list_at(strList, 0), list_at(strList, 1), | |
186 list_at(strList, 2), list_at(strList, 3)); | |
187 if(link->icq_RecvAdded) | |
188 (*link->icq_RecvAdded)(link, uin, hour, minute, day, month, year, | |
189 list_at(strList, 0), list_at(strList, 1), | |
190 list_at(strList, 2), list_at(strList, 3)); | |
191 break; | |
192 case TYPE_AUTH_REQ: | |
193 /* Format: Nick, 0xFE, FName, 0xFE, LName, 0xFE, EMail, 0xFE, 0, 0xFE, Reason */ | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
194 fieldCount = icq_SplitFields(strList, data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
195 if(fieldCount != 6) |
1152 | 196 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
197 icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_AUTH_REQ packet (expected 6 args, received %i)!\n", |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
198 fieldCount); |
1152 | 199 return; |
200 } | |
201 icq_RusConv("wk", list_at(strList, 0)); /* Nick */ | |
202 icq_RusConv("wk", list_at(strList, 1)); /* FName */ | |
203 icq_RusConv("wk", list_at(strList, 2)); /* LName */ | |
204 icq_RusConv("wk", list_at(strList, 3)); /* EMail */ | |
205 icq_RusConv("wk", list_at(strList, 5)); /* Reason */ | |
206 icq_FmtLog(link, ICQ_LOG_MESSAGE, "%lu has requested your authorization to be added to " | |
207 "their contact list, Nick: %s, First Name: %s, Last Name: %s, " | |
208 "EMail: %s, Reason: %s\n", uin, list_at(strList, 0), list_at(strList, 1), | |
209 list_at(strList, 2), list_at(strList, 3), list_at(strList, 4)); | |
210 if(link->icq_RecvAuthReq) | |
211 (*link->icq_RecvAuthReq)(link, uin, hour, minute, day, month, year, list_at(strList, 0), | |
212 list_at(strList, 1), list_at(strList, 2), | |
213 list_at(strList, 3), list_at(strList, 5)); | |
214 break; | |
215 case TYPE_URL: | |
216 /* Format: Description, 0xFE, URL */ | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
217 fieldCount = icq_SplitFields(strList, data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
218 if(fieldCount != 2) |
1152 | 219 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
220 icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_URL packet (expected 2 args, recived %i)!\n", fieldCount); |
1152 | 221 return; |
222 } | |
223 icq_RusConv("wk", list_at(strList, 0)); /* Description */ | |
224 icq_FmtLog(link, ICQ_LOG_MESSAGE, "URL received from %lu, URL: %s, Description: %s\n", | |
225 uin, list_at(strList, 1), list_at(strList, 0)); | |
226 if(link->icq_RecvURL) | |
227 (*link->icq_RecvURL)(link, uin, hour, minute, day, month, year, list_at(strList, 1), | |
228 list_at(strList, 0)); | |
229 break; | |
230 case TYPE_WEBPAGER: | |
231 /* Format: Nick, 0xFE, Empty-FName, 0xFE, Empty-LName, 0xFE, EMail, 0xFE, | |
232 * Reason(3), 0xFE, Message with IP & Subject */ | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
233 fieldCount = icq_SplitFields(strList, data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
234 if(fieldCount != 6) |
1152 | 235 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
236 icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_WEBPAGER packet (expected 6 args, received %i)!\n", |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
237 fieldCount); |
1152 | 238 return; |
239 } | |
240 icq_RusConv("wk", list_at(strList, 0)); /* Nick */ | |
241 icq_RusConv("wk", list_at(strList, 5)); /* Message */ | |
242 icq_FmtLog(link, ICQ_LOG_MESSAGE, "WebPager message received, Nick: %s, EMail: %s, " | |
243 "Message:\n%s\n", list_at(strList, 0), list_at(strList, 3), | |
244 list_at(strList, 5)); | |
245 if(link->icq_RecvWebPager) | |
246 (*link->icq_RecvWebPager)(link, hour, minute, day, month, year, list_at(strList, 0), | |
247 list_at(strList, 3), list_at(strList, 5)); | |
248 break; | |
249 case TYPE_EXPRESS: | |
250 /* Format: Nick, 0xFE, Empty-FName, 0xFE, Empty-LName, 0xFE, EMail, 0xFE, | |
251 * Reason(3), 0xFE, Message Subject */ | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
252 fieldCount = icq_SplitFields(strList, data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
253 if(fieldCount != 6) |
1152 | 254 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
255 icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_EXPRESS packet (expected 6 args, received %i)!\n", |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
256 fieldCount); |
1152 | 257 return; |
258 } | |
259 icq_RusConv("wk", list_at(strList, 0)); /* Nick */ | |
260 icq_RusConv("wk", list_at(strList, 5)); /* Message */ | |
261 icq_FmtLog(link, ICQ_LOG_MESSAGE, "MailExpress message received, Nick: %s, EMail: %s, " | |
262 "Message:\n%s\n", list_at(strList, 0), list_at(strList, 3), | |
263 list_at(strList, 5)); | |
264 if(link->icq_RecvMailExpress) | |
265 (*link->icq_RecvMailExpress)(link, hour, minute, day, month, year, list_at(strList, 0), | |
266 list_at(strList, 3), list_at(strList, 5)); | |
267 break; | |
268 default: | |
269 icq_RusConv("wk", data); /* Entire message */ | |
270 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Instant message type %i from %lu:\n%s\n", type, uin, data); | |
271 if(link->icq_RecvMessage) | |
272 (*link->icq_RecvMessage)(link, uin, hour, minute, day, month, year, data); | |
273 } | |
274 list_delete(strList, free); | |
275 } | |
276 | |
277 void icq_HandleInfoReply(ICQLINK *link, icq_Packet *p) | |
278 { | |
279 char *ptr1, *ptr2, *ptr3, *ptr4; | |
280 DWORD uin; | |
281 icq_PacketGotoUDPInData(p, 0); | |
282 uin = icq_PacketRead32(p); | |
283 ptr1 = icq_PacketReadStringNew(p); | |
284 ptr2 = icq_PacketReadStringNew(p); | |
285 ptr3 = icq_PacketReadStringNew(p); | |
286 ptr4 = icq_PacketReadStringNew(p); | |
287 icq_RusConv("wk", ptr1); | |
288 icq_RusConv("wk", ptr2); | |
289 icq_RusConv("wk", ptr3); | |
290 icq_RusConv("wk", ptr4); | |
291 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Info reply for %lu\n", uin); | |
292 if(link->icq_InfoReply) | |
293 (*link->icq_InfoReply)(link, uin, ptr1, ptr2, ptr3, ptr4, icq_PacketRead8(p)); | |
294 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
295 free(ptr1); | |
296 free(ptr2); | |
297 free(ptr3); | |
298 free(ptr4); | |
299 } | |
300 | |
301 void icq_HandleExtInfoReply(ICQLINK *link, icq_Packet *p) | |
302 { | |
303 char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5; | |
304 DWORD uin; | |
305 WORD cnt_code, age; | |
306 char cnt_stat, gender; | |
307 | |
308 icq_PacketGotoUDPInData(p, 0); | |
309 uin = icq_PacketRead32(p); | |
310 ptr1 = icq_PacketReadStringNew(p); | |
311 cnt_code = icq_PacketRead16(p); | |
312 cnt_stat = icq_PacketRead8(p); | |
313 ptr2 = icq_PacketReadStringNew(p); | |
314 age = icq_PacketRead16(p); | |
315 gender = icq_PacketRead8(p); | |
316 ptr3 = icq_PacketReadStringNew(p); | |
317 ptr4 = icq_PacketReadStringNew(p); | |
318 ptr5 = icq_PacketReadStringNew(p); | |
319 icq_RusConv("wk", ptr1); | |
320 icq_RusConv("wk", ptr2); | |
321 icq_RusConv("wk", ptr3); | |
322 icq_RusConv("wk", ptr4); | |
323 icq_RusConv("wk", ptr5); | |
324 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Extended info reply for %lu\n", uin); | |
325 if(link->icq_ExtInfoReply) | |
326 (*link->icq_ExtInfoReply)(link, uin, (char*)ptr1, cnt_code, cnt_stat, (char*)ptr2, age, | |
327 gender, (char*)ptr3, (char*)ptr4, (char*)ptr5); | |
328 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
329 free(ptr1); | |
330 free(ptr2); | |
331 free(ptr3); | |
332 free(ptr4); | |
333 free(ptr5); | |
334 } | |
335 | |
336 void icq_HandleSearchReply(ICQLINK *link, icq_Packet *p) | |
337 { | |
338 char *ptr1, *ptr2, *ptr3, *ptr4, auth; | |
339 DWORD uin; | |
340 icq_PacketGotoUDPInData(p, 0); | |
341 uin = icq_PacketRead32(p); | |
342 ptr1 = icq_PacketReadStringNew(p); | |
343 ptr2 = icq_PacketReadStringNew(p); | |
344 ptr3 = icq_PacketReadStringNew(p); | |
345 ptr4 = icq_PacketReadStringNew(p); | |
346 icq_RusConv("wk", ptr1); | |
347 icq_RusConv("wk", ptr2); | |
348 icq_RusConv("wk", ptr3); | |
349 icq_RusConv("wk", ptr4); | |
350 auth = icq_PacketRead8(p); | |
351 icq_FmtLog(link, ICQ_LOG_MESSAGE, "User found %lu, Nick: %s, First Name: %s, Last Name: %s, " | |
352 "EMail: %s, Auth: %s\n", uin, ptr1, ptr2, ptr3, ptr4, auth==1?"no":"yes"); | |
353 if(link->icq_UserFound) | |
354 (*link->icq_UserFound)(link, uin, (char*)ptr1, (char*)ptr2, (char*)ptr3, (char*)ptr4, auth); | |
355 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
356 free(ptr1); | |
357 free(ptr2); | |
358 free(ptr3); | |
359 free(ptr4); | |
360 } | |
361 | |
362 /************************************************ | |
363 This is called when a user goes offline | |
364 *************************************************/ | |
365 void icq_HandleUserOffline(ICQLINK *link, icq_Packet *p) | |
366 { | |
367 DWORD remote_uin; | |
368 icq_ContactItem *ptr; | |
369 | |
370 icq_PacketGotoUDPInData(p, 0); | |
371 remote_uin = icq_PacketRead32(p); | |
372 icq_FmtLog(link, ICQ_LOG_MESSAGE, "User %lu logged off\n", remote_uin); | |
373 if(link->icq_UserOffline) | |
374 (*link->icq_UserOffline)(link, remote_uin); | |
375 | |
376 ptr=icq_ContactFind(link, remote_uin); | |
377 if(ptr) | |
378 { | |
379 ptr->remote_ip = 0; | |
380 ptr->remote_port = 0; | |
381 } | |
382 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
383 } | |
384 | |
385 void icq_HandleUserOnline(ICQLINK *link, icq_Packet *p) | |
386 { | |
387 DWORD remote_uin, new_status, remote_ip, remote_real_ip; | |
388 DWORD remote_port; /* Why Mirabilis used 4 bytes for port? */ | |
389 BYTE tcp_flag; | |
390 icq_ContactItem *ptr; | |
391 | |
392 icq_PacketGotoUDPInData(p, 0); | |
393 remote_uin = icq_PacketRead32(p); | |
394 remote_ip = ntohl(icq_PacketRead32n(p)); /* icqtohl() */ | |
395 remote_port = icqtohl(icq_PacketRead32n(p)); | |
396 remote_real_ip = ntohl(icq_PacketRead32n(p)); /* icqtohl() */ | |
397 tcp_flag = icq_PacketRead8(p); | |
398 new_status = icq_PacketRead32(p); | |
399 | |
400 icq_FmtLog(link, ICQ_LOG_MESSAGE, | |
401 "User %lu (%s = 0x%X) logged on. tcp_flag=0x%X IP=%08X, real IP=%08X, port=%d\n", | |
402 remote_uin, icq_ConvertStatus2Str(new_status), new_status, tcp_flag, remote_ip, | |
403 remote_real_ip, remote_port); | |
404 if(link->icq_UserOnline) | |
405 (*link->icq_UserOnline)(link, remote_uin, new_status, remote_ip, remote_port, remote_real_ip, tcp_flag); | |
406 | |
407 ptr=icq_ContactFind(link, remote_uin); | |
408 if(ptr) | |
409 { | |
410 ptr->remote_ip=remote_ip; | |
411 ptr->remote_real_ip=remote_real_ip; | |
412 ptr->remote_port = remote_port; | |
413 ptr->tcp_flag = tcp_flag; | |
414 } | |
415 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
416 } | |
417 | |
418 void icq_HandleStatusChange(ICQLINK *link, icq_Packet *p) | |
419 { | |
420 unsigned long remote_uin, new_status; | |
421 | |
422 icq_PacketGotoUDPInData(p, 0); | |
423 remote_uin = icq_PacketRead32(p); | |
424 new_status = icq_PacketRead32(p); | |
425 icq_FmtLog(link, ICQ_LOG_MESSAGE, "%lu changed status to %s (0x%X)\n", remote_uin, | |
426 icq_ConvertStatus2Str(new_status), new_status); | |
427 if(link->icq_UserStatusUpdate) | |
428 (*link->icq_UserStatusUpdate)(link, remote_uin, new_status); | |
429 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
430 } | |
431 | |
432 void icq_HandleMetaUserInfo(ICQLINK *link, icq_Packet *p) | |
433 { | |
434 unsigned short subcmd, country, seq2, age, occupation, wcountry; | |
435 unsigned char res, auth, timezone, webaware, hideip, gender; | |
436 unsigned char *nick, *first, *last, *email, *about, *city; | |
437 unsigned char *pri_eml, *sec_eml, *old_eml; | |
438 unsigned char *phone, *fax, *street, *cellular, *state; | |
439 unsigned char *wcity, *wstate, *wphone, *wfax, *waddress; | |
440 unsigned char *company, *department, *job, *whomepage; | |
441 unsigned char *homepage; | |
442 unsigned char byear, bmonth, bday, lang1, lang2, lang3, inum, i; | |
443 unsigned char anum, bnum, hnum; | |
444 unsigned long uin, zip, wzip; | |
445 unsigned char *empty = ""; | |
446 unsigned char *interests[4] = {0, 0, 0, 0}; | |
447 unsigned short icategory[4] = {0, 0, 0, 0}; | |
448 unsigned char *affiliations[4] = {0, 0, 0, 0}; | |
449 unsigned short acategory[4] = {0, 0, 0, 0}; | |
450 unsigned char *backgrounds[4] = {0, 0, 0, 0}; | |
451 unsigned short bcategory[4] = {0, 0, 0, 0}; | |
452 unsigned char *hpcat[4] = {0, 0, 0, 0}; | |
453 unsigned short hcategory[4] = {0, 0, 0, 0}; | |
454 | |
455 seq2 = icq_PacketReadUDPInSeq2(p); | |
456 icq_PacketGotoUDPInData(p, 0); | |
457 subcmd = icq_PacketRead16(p); | |
458 res = icq_PacketRead8(p); | |
459 if(res == META_SRV_FAILURE) | |
460 { | |
461 icq_FmtLog(link, ICQ_LOG_WARNING, "META failure\n"); | |
462 if(link->icq_RequestNotify) | |
463 (*link->icq_RequestNotify)(link, seq2, ICQ_NOTIFY_FAILED, sizeof(subcmd), &subcmd); | |
464 } | |
465 else | |
466 switch(subcmd) | |
467 { | |
468 case META_SRV_USER_FOUND: | |
469 uin = icq_PacketRead32(p); | |
470 nick = icq_PacketReadStringNew(p); | |
471 first = icq_PacketReadStringNew(p); | |
472 last = icq_PacketReadStringNew(p); | |
473 email = icq_PacketReadStringNew(p); | |
474 auth = icq_PacketRead8(p); | |
475 icq_PacketRead16(p); // ??? | |
476 icq_PacketRead32(p); // ??? | |
477 icq_RusConv("wk", nick); | |
478 icq_RusConv("wk", first); | |
479 icq_RusConv("wk", last); | |
480 icq_RusConv("wk", email); | |
481 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Found %lu, Nick: %s, First Name: %s, "\ | |
482 "Last Name: %s, EMail: %s, Auth: %s\n", seq2, uin, nick, first, last, | |
483 email, auth==1?"no":"yes"); | |
484 if(link->icq_MetaUserFound) | |
485 (*link->icq_MetaUserFound)(link, seq2, uin, nick, first, last, email, auth); | |
486 free(nick); | |
487 free(first); | |
488 free(last); | |
489 free(email); | |
490 break; | |
491 case META_SRV_USER_INFO: // finished! | |
492 nick = icq_PacketReadStringNew(p); | |
493 first = icq_PacketReadStringNew(p); | |
494 last = icq_PacketReadStringNew(p); | |
495 pri_eml = icq_PacketReadStringNew(p); | |
496 sec_eml = icq_PacketReadStringNew(p); | |
497 old_eml = icq_PacketReadStringNew(p); | |
498 city = icq_PacketReadStringNew(p); | |
499 state = icq_PacketReadStringNew(p); | |
500 phone = icq_PacketReadStringNew(p); | |
501 fax = icq_PacketReadStringNew(p); | |
502 street = icq_PacketReadStringNew(p); | |
503 cellular = icq_PacketReadStringNew(p); | |
504 zip = icq_PacketRead32(p); | |
505 country = icq_PacketRead16(p); | |
506 timezone = icq_PacketRead8(p); // +1 = -30min, -1 = +30min (-4 = GMT+0200) | |
507 auth = icq_PacketRead8(p); // 1 - no auth required, 0 - required | |
508 webaware = icq_PacketRead8(p); // 1 - yes, 0 - no | |
509 hideip = icq_PacketRead8(p); // 1 - yes, 0 - no | |
510 icq_RusConv("wk", nick); | |
511 icq_RusConv("wk", first); | |
512 icq_RusConv("wk", last); | |
513 icq_RusConv("wk", pri_eml); | |
514 icq_RusConv("wk", sec_eml); | |
515 icq_RusConv("wk", old_eml); | |
516 icq_RusConv("wk", city); | |
517 icq_RusConv("wk", state); | |
518 icq_RusConv("wk", phone); | |
519 icq_RusConv("wk", fax); | |
520 icq_RusConv("wk", street); | |
521 icq_RusConv("wk", cellular); | |
522 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Info: %s, %s, %s, "\ | |
523 "%s, %s, %s, %s, %s, %s, %s, %s, %s, %lu, %s, %i, %s, %s, %s\n", | |
524 nick, first, last, pri_eml, sec_eml, old_eml, city, state, phone, | |
525 fax, street, cellular, zip, icq_GetCountryName(country), timezone, | |
526 auth?"false":"true", webaware?"true":"false", hideip?"true":"false"); | |
527 if(link->icq_MetaUserInfo) | |
528 (*link->icq_MetaUserInfo)(link, seq2, nick, first, last, pri_eml, sec_eml, | |
529 old_eml, city, state, phone, fax, street, cellular, | |
530 zip, country, timezone, auth, webaware, hideip); | |
531 free(nick); | |
532 free(first); | |
533 free(last); | |
534 free(pri_eml); | |
535 free(sec_eml); | |
536 free(old_eml); | |
537 free(city); | |
538 free(state); | |
539 free(phone); | |
540 free(fax); | |
541 free(street); | |
542 free(cellular); | |
543 break; | |
544 case META_SRV_USER_WORK: // finished! | |
545 wcity = icq_PacketReadStringNew(p); | |
546 wstate = icq_PacketReadStringNew(p); | |
547 wphone = icq_PacketReadStringNew(p); | |
548 wfax = icq_PacketReadStringNew(p); | |
549 waddress = icq_PacketReadStringNew(p); | |
550 wzip = icq_PacketRead32(p); | |
551 wcountry = icq_PacketRead16(p); // icq_GetCountryName() | |
552 company = icq_PacketReadStringNew(p); | |
553 department = icq_PacketReadStringNew(p); | |
554 job = icq_PacketReadStringNew(p); | |
555 occupation = icq_PacketRead16(p); // icq_GetMetaOccupationName() | |
556 whomepage = icq_PacketReadStringNew(p); | |
557 icq_RusConv("wk", wcity); | |
558 icq_RusConv("wk", wstate); | |
559 icq_RusConv("wk", wphone); | |
560 icq_RusConv("wk", wfax); | |
561 icq_RusConv("wk", waddress); | |
562 icq_RusConv("wk", company); | |
563 icq_RusConv("wk", department); | |
564 icq_RusConv("wk", job); | |
565 icq_RusConv("wk", whomepage); | |
566 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Work: %s, %s, %s, "\ | |
567 "%s, %s, %lu, %s, %s, %s, %s, %s, %s\n", wcity, wstate, | |
568 wphone, wfax, waddress, wzip, icq_GetCountryName(wcountry), | |
569 company, department, job, icq_GetMetaOccupationName(occupation), | |
570 whomepage); | |
571 if(link->icq_MetaUserWork) | |
572 (*link->icq_MetaUserWork)(link, seq2, wcity, wstate, wphone, wfax, | |
573 waddress, wzip, wcountry, company, department, | |
574 job, occupation, whomepage); | |
575 free(wcity); | |
576 free(wstate); | |
577 free(wphone); | |
578 free(wfax); | |
579 free(waddress); | |
580 free(company); | |
581 free(department); | |
582 free(job); | |
583 free(whomepage); | |
584 break; | |
585 case META_SRV_USER_MORE: // finished! | |
586 age = icq_PacketRead16(p); // 0xFFFF - not entered | |
587 gender = icq_PacketRead8(p); // 1 - female, 2 - male | |
588 homepage = icq_PacketReadStringNew(p); | |
589 byear = icq_PacketRead8(p); // starting from 1900 | |
590 bmonth = icq_PacketRead8(p); | |
591 bday = icq_PacketRead8(p); | |
592 lang1 = icq_PacketRead8(p); // icq_GetMetaLanguageName() | |
593 lang2 = icq_PacketRead8(p); // icq_GetMetaLanguageName() | |
594 lang3 = icq_PacketRead8(p); // icq_GetMetaLanguageName() | |
595 icq_RusConv("wk", homepage); | |
596 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User More: %i, %s, %s, "\ | |
597 "%02i/%02i/%04i, %s, %s, %s\n", age, | |
598 gender==1?"female":gender==2?"male":"not entered", | |
599 homepage, bday, bmonth, byear+1900, icq_GetMetaLanguageName(lang1), | |
600 icq_GetMetaLanguageName(lang2), icq_GetMetaLanguageName(lang3)); | |
601 if(link->icq_MetaUserMore) | |
602 (*link->icq_MetaUserMore)(link, seq2, age, gender, homepage, byear, | |
603 bmonth, bday, lang1, lang2, lang3); | |
604 free(homepage); | |
605 break; | |
606 case META_SRV_USER_ABOUT: // finished! | |
607 about = icq_PacketReadStringNew(p); | |
608 icq_RusConv("wk", about); | |
609 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User About: %s\n", about); | |
610 if(link->icq_MetaUserAbout) | |
611 (*link->icq_MetaUserAbout)(link, seq2, about); | |
612 free(about); | |
613 break; | |
614 case META_SRV_USER_INTERESTS: // finished! | |
615 inum = icq_PacketRead8(p); | |
616 for(i=0; i<inum && i<4; i++) | |
617 { | |
618 icategory[i] = icq_PacketRead16(p); | |
619 interests[i] = icq_PacketReadStringNew(p); | |
620 icq_RusConv("wk", interests[i]); | |
621 } | |
622 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Interests: %i, %i - %s, "\ | |
623 "%i - %s, %i - %s, %i - %s\n", inum, icategory[0], | |
624 interests[0]?interests[0]:empty, icategory[1], interests[1]?interests[1]:empty, | |
625 icategory[2], interests[2]?interests[2]:empty, icategory[3], | |
626 interests[3]?interests[3]:empty); | |
627 if(link->icq_MetaUserInterests) | |
628 (*link->icq_MetaUserInterests)(link, seq2, inum, icategory[0], interests[0], | |
629 icategory[1], interests[1], icategory[2], | |
630 interests[2], icategory[3], interests[3]); | |
631 for(i=0; i<inum && i<4; i++) | |
632 free(interests[i]); | |
633 break; | |
634 case META_SRV_USER_AFFILIATIONS: // finished! | |
635 bnum = icq_PacketRead8(p); | |
636 for(i=0; i<bnum && i<4; i++) | |
637 { | |
638 bcategory[i] = icq_PacketRead16(p); // icq_GetMetaBackgroundName() | |
639 backgrounds[i] = icq_PacketReadStringNew(p); | |
640 icq_RusConv("wk", backgrounds[i]); | |
641 } | |
642 anum = icq_PacketRead8(p); | |
643 for(i=0; i<anum && i<4; i++) | |
644 { | |
645 acategory[i] = icq_PacketRead16(p); // icq_GetMetaAffiliationName() | |
646 affiliations[i] = icq_PacketReadStringNew(p); | |
647 icq_RusConv("wk", affiliations[i]); | |
648 } | |
649 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Affiliations: %i, %s - %s, "\ | |
650 "%s - %s, %s - %s, %s - %s; Backgrounds: %i, %s - %s, %s - %s, "\ | |
651 "%s - %s, %s - %s\n", anum, | |
652 icq_GetMetaAffiliationName(acategory[0]), affiliations[0]?affiliations[0]:empty, | |
653 icq_GetMetaAffiliationName(acategory[1]), affiliations[1]?affiliations[1]:empty, | |
654 icq_GetMetaAffiliationName(acategory[2]), affiliations[2]?affiliations[2]:empty, | |
655 icq_GetMetaAffiliationName(acategory[3]), affiliations[3]?affiliations[3]:empty, | |
656 bnum, icq_GetMetaBackgroundName(bcategory[0]), backgrounds[0]?backgrounds[0]:empty, | |
657 icq_GetMetaBackgroundName(bcategory[1]), backgrounds[1]?backgrounds[1]:empty, | |
658 icq_GetMetaBackgroundName(bcategory[2]), backgrounds[2]?backgrounds[2]:empty, | |
659 icq_GetMetaBackgroundName(bcategory[3]), backgrounds[3]?backgrounds[3]:empty); | |
660 if(link->icq_MetaUserAffiliations) | |
661 (*link->icq_MetaUserAffiliations)(link, seq2, anum, acategory[0], | |
662 affiliations[0], acategory[1], affiliations[1], acategory[2], | |
663 affiliations[2], acategory[3], affiliations[3], bnum, | |
664 bcategory[0], backgrounds[0], bcategory[1], backgrounds[1], | |
665 bcategory[2], backgrounds[2], bcategory[3], backgrounds[3]); | |
666 for(i=0; i<bnum && i<4; i++) | |
667 free(backgrounds[i]); | |
668 for(i=0; i<anum && i<4; i++) | |
669 free(affiliations[i]); | |
670 break; | |
671 case META_SRV_USER_HPCATEGORY: // finished! | |
672 hnum = icq_PacketRead8(p); | |
673 for(i=0; i<hnum && i<1; i++) | |
674 { | |
675 hcategory[i] = icq_PacketRead16(p); | |
676 hpcat[i] = icq_PacketReadStringNew(p); | |
677 icq_RusConv("wk", hpcat[i]); | |
678 } | |
679 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Homepage Category: %i, %i - %s\n", | |
680 hnum, hcategory[0], hpcat[0]); | |
681 if(link->icq_MetaUserHomePageCategory) | |
682 (*link->icq_MetaUserHomePageCategory)(link, seq2, hnum, hcategory[0], hpcat[0]?hpcat[0]:empty); | |
683 for(i=0; i<hnum && i<1; i++) | |
684 free(hpcat[i]); | |
685 break; | |
686 case META_SRV_RES_INFO: | |
687 case META_SRV_RES_HOMEPAGE: | |
688 case META_SRV_RES_ABOUT: | |
689 case META_SRV_RES_SECURE: | |
690 case META_SRV_RES_PASS: | |
691 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META success\n"); | |
692 if(link->icq_RequestNotify) | |
693 (*link->icq_RequestNotify)(link, seq2, ICQ_NOTIFY_SUCCESS, sizeof(subcmd), &subcmd); | |
694 break; | |
695 default: | |
696 icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User - 0x%04X\n", subcmd); | |
697 icq_PacketUDPDump(p); | |
698 break; | |
699 } | |
700 icq_UDPAck(link, icq_PacketReadUDPInSeq1(p)); | |
701 } | |
702 | |
703 void icq_HandleMultiPacket(ICQLINK *link, icq_Packet *p) | |
704 { | |
705 icq_Packet *tmp; | |
706 int num, i; | |
707 icq_PacketGotoUDPInData(p, 0); | |
708 num = icq_PacketRead8(p); | |
709 | |
710 icq_FmtLog(link, ICQ_LOG_MESSAGE, "MultiPacket: %i packets\n", num); | |
711 | |
712 for(i = 0; i < num; i++) | |
713 { | |
714 tmp = icq_PacketNew(); | |
715 tmp->length = icq_PacketRead16(p); | |
716 memcpy(tmp->data, &(p->data[p->cursor]), tmp->length); | |
717 icq_PacketAdvance(p, tmp->length); | |
718 icq_ServerResponse(link, tmp); | |
719 icq_PacketDelete(tmp); | |
720 } | |
721 } | |
722 | |
723 void icq_ServerResponse(ICQLINK *link, icq_Packet *p) | |
724 { | |
725 time_t cur_time; | |
726 struct tm *tm_str; | |
727 int len; | |
728 struct in_addr in_a; | |
729 DWORD uin; | |
730 WORD year, type, seq, cmd; | |
731 BYTE month, day, hour, minute; | |
732 | |
733 seq = icq_PacketReadUDPInSeq1(p); | |
734 cmd = icq_PacketReadUDPInCmd(p); | |
735 | |
736 if(icq_PacketReadUDPInVer(p) == 5) /* We understand only V5 packets! */ | |
737 { | |
738 switch(cmd) | |
739 { | |
740 case UDP_SRV_ACK: | |
741 icq_FmtLog(link, ICQ_LOG_MESSAGE, "The server acknowledged the command\n"); | |
742 if(link->icq_RequestNotify) | |
743 { | |
744 (*link->icq_RequestNotify)(link, seq, ICQ_NOTIFY_ACK, 0, 0); | |
745 (*link->icq_RequestNotify)(link, seq, ICQ_NOTIFY_SUCCESS, 0, 0); | |
746 } | |
747 icq_UDPQueueDelSeq(link, seq); | |
748 break; | |
749 case UDP_SRV_MULTI_PACKET: | |
750 icq_HandleMultiPacket(link, p); | |
751 break; | |
752 case UDP_SRV_NEW_UIN: | |
753 uin = icq_PacketReadUDPInUIN(p); | |
754 icq_FmtLog(link, ICQ_LOG_MESSAGE, "The new uin is %lu\n", uin); | |
755 icq_UDPAck(link, seq); | |
756 if(link->icq_NewUIN) | |
757 (*link->icq_NewUIN)(link, uin); | |
758 break; | |
759 case UDP_SRV_LOGIN_REPLY: | |
760 icq_PacketGotoUDPInData(p, 0); | |
761 link->icq_OurIP = ntohl(icq_PacketRead32n(p)); | |
762 /* icq_OurIp = icq_PacketRead32(p); */ | |
763 in_a.s_addr = htonl(link->icq_OurIP); | |
764 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Login successful, UIN: %lu, IP: %s\n", | |
765 link->icq_Uin, inet_ntoa(in_a)); | |
766 icq_UDPAck(link, seq); | |
767 icq_SendLogin1(link); | |
768 icq_SendContactList(link); | |
769 icq_SendVisibleList(link); | |
770 if(link->icq_Logged) | |
771 (*link->icq_Logged)(link); | |
772 break; | |
773 case UDP_SRV_OFFLINE_MESSAGE: /* Offline message through the server */ | |
774 icq_PacketGotoUDPInData(p, 0); | |
775 uin = icq_PacketRead32(p); | |
776 year = icq_PacketRead16(p); | |
777 month = icq_PacketRead8(p); | |
778 day = icq_PacketRead8(p); | |
779 hour = icq_PacketRead8(p); | |
780 minute = icq_PacketRead8(p); | |
781 type = icq_PacketRead16(p); | |
782 len = icq_PacketRead16(p); | |
783 icq_DoMsg(link, type, len, (char*)&p->data[p->cursor], uin, hour, minute, day, month, year); | |
784 icq_UDPAck(link, seq); | |
785 break; | |
786 case UDP_SRV_X1: /* unknown message sent after login*/ | |
787 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Acknowleged UDP_SRV_X1 (Begin messages)\n"); | |
788 icq_UDPAck(link, seq); | |
789 break; | |
790 case UDP_SRV_X2: /* unknown message sent after login*/ | |
791 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Acknowleged UDP_SRV_X2 (Done old messages)\n"); | |
792 icq_UDPAck(link, seq); | |
793 icq_SendGotMessages(link); | |
794 break; | |
795 case UDP_SRV_INFO_REPLY: | |
796 icq_HandleInfoReply(link, p); | |
797 break; | |
798 case UDP_SRV_EXT_INFO_REPLY: | |
799 icq_HandleExtInfoReply(link, p); | |
800 break; | |
801 case UDP_SRV_USER_ONLINE: | |
802 icq_HandleUserOnline(link, p); | |
803 break; | |
804 case UDP_SRV_USER_OFFLINE: | |
805 icq_HandleUserOffline(link, p); | |
806 break; | |
807 case UDP_SRV_TRY_AGAIN: | |
808 icq_FmtLog(link, ICQ_LOG_WARNING, "Server is busy, please try again\n"); | |
809 icq_Login(link, link->icq_Status); | |
810 break; | |
811 case UDP_SRV_STATUS_UPDATE: | |
812 icq_HandleStatusChange(link, p); | |
813 break; | |
814 case UDP_SRV_GO_AWAY: | |
815 icq_FmtLog(link, ICQ_LOG_ERROR, "Server has forced us to disconnect\n"); | |
816 if(link->icq_Disconnected) | |
817 (*link->icq_Disconnected)(link); | |
818 break; | |
819 case UDP_SRV_END_OF_SEARCH: | |
820 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Search done\n"); | |
821 if(link->icq_SearchDone) | |
822 (*link->icq_SearchDone)(link); | |
823 icq_UDPAck(link, seq); | |
824 break; | |
825 case UDP_SRV_USER_FOUND: | |
826 icq_HandleSearchReply(link, p); | |
827 break; | |
828 case UDP_SRV_ONLINE_MESSAGE: /* Online message through the server */ | |
829 cur_time = time(0L); | |
830 tm_str = localtime(&cur_time); | |
831 icq_PacketGotoUDPInData(p, 0); | |
832 uin = icq_PacketRead32(p); | |
833 type = icq_PacketRead16(p); | |
834 len = icq_PacketRead16(p); | |
835 icq_DoMsg(link, type, len, (char*)&p->data[p->cursor], uin, tm_str->tm_hour, | |
836 tm_str->tm_min, tm_str->tm_mday, tm_str->tm_mon+1, tm_str->tm_year+1900); | |
837 icq_UDPAck(link, seq); | |
838 break; | |
839 case UDP_SRV_WRONG_PASSWORD: | |
840 icq_FmtLog(link, ICQ_LOG_ERROR, "Wrong password\n"); | |
841 if(link->icq_WrongPassword) | |
842 (*link->icq_WrongPassword)(link); | |
843 icq_UDPAck(link, seq); | |
844 break; | |
845 case UDP_SRV_INVALID_UIN: | |
846 icq_FmtLog(link, ICQ_LOG_WARNING, "Invalid UIN\n"); | |
847 if(link->icq_InvalidUIN) | |
848 (*link->icq_InvalidUIN)(link); | |
849 icq_UDPAck(link, seq); | |
850 break; | |
851 case UDP_SRV_META_USER: | |
852 icq_HandleMetaUserInfo(link, p); | |
853 break; | |
854 default: /* commands we dont handle yet */ | |
855 icq_FmtLog(link, ICQ_LOG_WARNING, "Unhandled message %04x, Version: %x, " | |
856 "Sequence: %04x, Size: %d\n", cmd, icq_PacketReadUDPInVer(p), | |
857 seq, p->length); | |
858 icq_UDPAck(link, seq); /* fake like we know what we're doing */ | |
859 break; | |
860 } | |
861 } | |
862 else | |
863 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
864 icq_FmtLog(link, ICQ_LOG_WARNING, "Unhandled protocol version! Message %04x, Version: %x, " |
1152 | 865 "Sequence: %04x, Size: %d\n", cmd, icq_PacketReadUDPInVer(p), |
866 seq, p->length); | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
867 /* icq_UDPAck(link, seq); DO NOT ACK unhandled protocol version! */ |
1152 | 868 } |
869 } | |
870 | |
871 /****************************************** | |
872 Handles packets that the server sends to us. | |
873 *******************************************/ | |
874 void icq_HandleServerResponse(ICQLINK *link) | |
875 { | |
876 WORD seq, cmd; | |
877 int s; | |
878 icq_Packet *p; | |
879 | |
880 p = icq_PacketNew(); | |
881 s = icq_UDPSockRead(link, p); | |
882 p->length = s; | |
883 if(s<=0) | |
884 { | |
885 icq_FmtLog(link, ICQ_LOG_FATAL, "Connection terminated\n"); | |
886 icq_Disconnect(link); | |
887 if(link->icq_Disconnected) | |
888 (*link->icq_Disconnected)(link); | |
889 } | |
890 seq = icq_PacketReadUDPInSeq1(p); | |
891 cmd = icq_PacketReadUDPInCmd(p); | |
892 if(icq_GetServMess(link, seq) && cmd != UDP_SRV_NEW_UIN && cmd != UDP_SRV_GO_AWAY && cmd != UDP_SRV_ACK) | |
893 { | |
894 icq_FmtLog(link, ICQ_LOG_WARNING, "Ignored a message cmd %04x, seq %04x\n", cmd, seq); | |
895 icq_UDPAck(link, seq); /* LAGGGGG!! */ | |
896 icq_PacketDelete(p); | |
897 return; | |
898 } | |
899 if(cmd != UDP_SRV_ACK) | |
900 icq_SetServMess(link, seq); | |
901 | |
902 icq_ServerResponse(link, p); | |
903 | |
904 icq_PacketDelete(p); | |
905 } |