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