Mercurial > pidgin.yaz
annotate plugins/icq/tcphandle.c @ 1564:aa69b15d9403
[gaim-migrate @ 1574]
you may want to make distclean after updating, it'll save you some disk space
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 11 Mar 2001 12:38:59 +0000 |
parents | 4c510ca3563f |
children | 8ed70631ed15 |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
3 $Id: tcphandle.c 1442 2001-01-28 01:52:27Z warmenhoven $ |
1152 | 4 $Log$ |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
5 Revision 1.3 2001/01/28 01:52:27 warmenhoven |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
6 icqlib 1.1.5 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
7 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
8 Revision 1.16 2001/01/24 05:11:14 bills |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
9 applied patch from Robin Ericsson <lobbin@localhost.nu> which implements |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
10 receiving contact lists. See new icq_RecvContactList callback. |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
11 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
12 Revision 1.15 2001/01/17 01:31:47 bills |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
13 Rework chat and file interfaces; implement socket notifications. |
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.14 2000/12/06 05:15:45 denis |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
16 Handling for mass TCP messages has been added based on patch by |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
17 Konstantin Klyagin <konst@konst.org.ua> |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
18 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
19 Revision 1.13 2000/08/13 19:44:41 denis |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
20 Cyrillic recoding on received URL description added. |
1152 | 21 |
22 Revision 1.12 2000/07/09 22:19:35 bills | |
23 added new *Close functions, use *Close functions instead of *Delete | |
24 where correct, and misc cleanup | |
25 | |
26 Revision 1.11 2000/06/25 16:36:16 denis | |
27 '\n' was added at the end of log messages. | |
28 | |
29 Revision 1.10 2000/05/04 15:57:20 bills | |
30 Reworked file transfer notification, small bugfixes, and cleanups. | |
31 | |
32 Revision 1.9 2000/05/03 18:29:15 denis | |
33 Callbacks have been moved to the ICQLINK structure. | |
34 | |
35 Revision 1.8 2000/04/05 14:37:02 denis | |
36 Applied patch from "Guillaume R." <grs@mail.com> for basic Win32 | |
37 compatibility. | |
38 | |
39 Revision 1.7 2000/01/20 20:06:00 bills | |
40 removed debugging printfs | |
41 | |
42 Revision 1.6 2000/01/20 19:59:15 bills | |
43 first implementation of sending file requests | |
44 | |
45 Revision 1.5 1999/11/30 09:51:42 bills | |
46 more file xfer logic added | |
47 | |
48 Revision 1.4 1999/11/11 15:10:30 guruz | |
49 - Added Base for Webpager Messages. Please type "make fixme" | |
50 - Removed Segfault when kicq is started the first time | |
51 | |
52 Revision 1.3 1999/10/01 02:28:51 bills | |
53 icq_TCPProcessHello returns something now :) | |
54 | |
55 Revision 1.2 1999/10/01 00:49:20 lord | |
56 some compilation problems are fixed. | |
57 | |
58 Revision 1.1 1999/09/29 19:47:21 bills | |
59 reworked chat/file handling. fixed chat. (it's been broke since I put | |
60 non-blocking connects in) | |
61 | |
62 Revision 1.15 1999/07/16 15:45:59 denis | |
63 Cleaned up. | |
64 | |
65 Revision 1.14 1999/07/16 12:10:10 denis | |
66 tcp_packet* functions renamed to icq_Packet* | |
67 Cleaned up. | |
68 | |
69 Revision 1.13 1999/07/12 15:13:41 cproch | |
70 - added definition of ICQLINK to hold session-specific global variabled | |
71 applications which have more than one connection are now possible | |
72 - changed nearly every function defintion to support ICQLINK parameter | |
73 | |
74 Revision 1.12 1999/06/30 13:51:25 bills | |
75 cleanups | |
76 | |
77 Revision 1.11 1999/05/03 21:41:30 bills | |
78 initial file xfer support added- untested | |
79 | |
80 Revision 1.10 1999/04/29 09:36:06 denis | |
81 Cleanups, warning removed | |
82 | |
83 Revision 1.9 1999/04/17 19:40:33 bills | |
84 reworked code to use icq_TCPLinks instead of icq_ContactItem entries. | |
85 modified ProcessChatPacket to negotiate both sending and receiving chat | |
86 requests properly. | |
87 | |
88 Revision 1.8 1999/04/14 15:12:02 denis | |
89 Cleanups for "strict" compiling (-ansi -pedantic) | |
90 icq_ContactItem parameter added to function icq_TCPOnMessageReceived() | |
91 Segfault fixed on spoofed messages. | |
92 | |
93 */ | |
94 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
95 #include <stdlib.h> |
1152 | 96 #include <time.h> |
97 | |
98 #ifndef _WIN32 | |
99 #include <unistd.h> | |
100 #endif | |
101 | |
102 #include "icqtypes.h" | |
103 #include "icq.h" | |
104 #include "icqlib.h" | |
105 | |
106 #include "tcp.h" | |
107 #include "stdpackets.h" | |
108 #include "tcplink.h" | |
109 | |
110 void icq_TCPOnMessageReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink); | |
111 void icq_TCPOnURLReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
112 void icq_TCPOnContactListReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id); |
1152 | 113 void icq_TCPOnChatReqReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id); |
114 void icq_TCPOnFileReqReceived(ICQLINK *link, DWORD uin, const char *message, | |
115 const char *filename, unsigned long filesize, DWORD id); | |
116 void icq_TCPProcessAck(ICQLINK *link, icq_Packet *p); | |
117 void icq_HandleChatAck(icq_TCPLink *plink, icq_Packet *p, int port); | |
118 void icq_HandleChatHello(icq_TCPLink *plink); | |
119 void icq_HandleFileHello(icq_TCPLink *plink); | |
120 void icq_HandleFileAck(icq_TCPLink *plink, icq_Packet *p, int port); | |
121 | |
122 void icq_TCPProcessPacket(icq_Packet *p, icq_TCPLink *plink) | |
123 { | |
124 DWORD uin; | |
125 WORD version; | |
126 WORD command; | |
127 WORD type; | |
128 WORD status; | |
129 DWORD command_type; | |
130 DWORD filesize = 0; | |
131 DWORD port = 0; | |
132 | |
133 const char *message; | |
134 const char *filename = 0; | |
135 | |
136 icq_PacketBegin(p); | |
137 (void)icq_PacketRead32(p); | |
138 version=icq_PacketRead16(p); | |
139 command=icq_PacketRead16(p); | |
140 (void)icq_PacketRead16(p); | |
141 | |
142 uin=icq_PacketRead32(p); | |
143 type=icq_PacketRead16(p); | |
144 message=icq_PacketReadString(p); | |
145 (void)icq_PacketRead32(p); | |
146 (void)icq_PacketRead32(p); | |
147 (void)icq_PacketRead32(p); | |
148 (void)icq_PacketRead8(p); | |
149 status=icq_PacketRead16(p); | |
150 command_type=icq_PacketRead16(p); | |
151 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
152 switch(type & ~ICQ_TCP_MASS_MASK) |
1152 | 153 { |
154 case ICQ_TCP_MSG_MSG: | |
155 case ICQ_TCP_MSG_URL: | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
156 case ICQ_TCP_MSG_CONTACTLIST: |
1152 | 157 p->id=icq_PacketRead32(p); |
158 break; | |
159 | |
160 case ICQ_TCP_MSG_CHAT: | |
161 (void)icq_PacketReadString(p); | |
162 (void)icq_PacketRead16(p); | |
163 (void)icq_PacketRead16(p); | |
164 port=icq_PacketRead32(p); | |
165 p->id=icq_PacketRead32(p); | |
166 break; | |
167 | |
168 case ICQ_TCP_MSG_FILE: | |
169 (void)icq_PacketRead16(p); | |
170 (void)icq_PacketRead16(p); | |
171 filename=icq_PacketReadString(p); | |
172 filesize=icq_PacketRead32(p); | |
173 port=icq_PacketRead32(p); | |
174 p->id=icq_PacketRead32(p); | |
175 break; | |
176 | |
177 default: | |
178 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown message packet, type %x\n", type); | |
179 } | |
180 | |
181 #ifdef TCP_PROCESS_TRACE | |
182 printf("packet processed from uin: %lu:\n", uin); | |
183 printf(" command: %x\ttype: %x\n", command, type); | |
184 printf(" status: %x\tcommand_type: %x\n", status, (int)command_type); | |
185 printf(" message %s\n", message); | |
186 printf(" id: %x\n", (int)p->id); | |
187 #endif | |
188 | |
189 switch(command) | |
190 { | |
191 case ICQ_TCP_MESSAGE: | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
192 switch(type & ~ICQ_TCP_MASS_MASK) |
1152 | 193 { |
194 case ICQ_TCP_MSG_MSG: | |
195 icq_TCPOnMessageReceived(plink->icqlink, uin, message, p->id, plink); | |
196 break; | |
197 | |
198 case ICQ_TCP_MSG_URL: | |
199 icq_TCPOnURLReceived(plink->icqlink, uin, message, p->id); | |
200 break; | |
201 | |
202 case ICQ_TCP_MSG_CHAT: | |
203 icq_TCPOnChatReqReceived(plink->icqlink, uin, message, p->id); | |
204 break; | |
205 | |
206 case ICQ_TCP_MSG_FILE: | |
207 icq_TCPOnFileReqReceived(plink->icqlink, uin, message, filename, filesize, p->id); | |
208 break; | |
209 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
210 case ICQ_TCP_MSG_CONTACTLIST: |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
211 icq_TCPOnContactListReceived(plink->icqlink, uin, message, p->id); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
212 break; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
213 |
1152 | 214 default: |
215 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown message type %d!\n", type); | |
216 break; | |
217 } | |
218 break; | |
219 | |
220 case ICQ_TCP_ACK: | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
221 switch(type) |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
222 { |
1152 | 223 case ICQ_TCP_MSG_CHAT: |
224 icq_HandleChatAck(plink, p, port); | |
225 break; | |
226 | |
227 case ICQ_TCP_MSG_FILE: | |
228 icq_HandleFileAck(plink, p, port); | |
229 break; | |
230 | |
231 case ICQ_TCP_MSG_MSG: | |
232 case ICQ_TCP_MSG_URL: | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
233 if(plink->icqlink->icq_RequestNotify) |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
234 { |
1152 | 235 icq_FmtLog(plink->icqlink, ICQ_LOG_MESSAGE, "received ack %d\n", p->id); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
236 invoke_callback(plink->icqlink, icq_RequestNotify) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
237 (plink->icqlink, p->id, ICQ_NOTIFY_ACK, status, (void *)message); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
238 invoke_callback(plink->icqlink, icq_RequestNotify) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
239 (plink->icqlink, p->id, ICQ_NOTIFY_SUCCESS, 0, NULL); |
1152 | 240 } |
241 break; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
242 } |
1152 | 243 break; |
244 | |
245 case ICQ_TCP_CANCEL: | |
246 /* icq_TCPProcessCancel(p); */ | |
247 break; | |
248 | |
249 default: | |
250 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
251 "unknown packet command %d!\n", command); |
1152 | 252 } |
253 } | |
254 | |
255 void icq_TCPProcessCancel(icq_Packet *p) | |
256 { | |
257 (void)p; | |
258 | |
259 /* | |
260 find packet in queue | |
261 call notification function | |
262 remove packet from queue | |
263 */ | |
264 } | |
265 | |
266 int icq_TCPProcessHello(icq_Packet *p, icq_TCPLink *plink) | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
267 { |
1152 | 268 /* TCP Hello packet */ |
269 BYTE code; /* 0xFF - init packet code */ | |
270 DWORD version; /* tcp version */ | |
271 DWORD remote_port; /* remote message listen port */ | |
272 DWORD remote_uin; /* remote uin */ | |
273 DWORD remote_ip; /* remote IP as seen by ICQ server */ | |
274 DWORD remote_real_ip; /* remote IP as seen by client */ | |
275 BYTE flags; /* tcp flags */ | |
276 DWORD remote_other_port; /* remote chat or file listen port */ | |
277 | |
278 icq_PacketBegin(p); | |
279 | |
280 code=icq_PacketRead8(p); | |
281 version=icq_PacketRead32(p); | |
282 | |
283 if (!(p->length>=26 && code==ICQ_TCP_HELLO)) | |
284 { | |
285 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, | |
286 "malformed hello packet received from %s:%d, closing link\n", | |
287 inet_ntoa(*((struct in_addr *)(&(plink->remote_address.sin_addr)))), | |
288 ntohs(plink->remote_address.sin_port)); | |
289 | |
290 icq_TCPLinkClose(plink); | |
291 return 0; | |
292 } | |
293 remote_port=icq_PacketRead32(p); | |
294 remote_uin=icq_PacketRead32(p); | |
295 remote_ip=icq_PacketRead32(p); | |
296 remote_real_ip=icq_PacketRead32(p); | |
297 flags=icq_PacketRead8(p); | |
298 remote_other_port=icq_PacketRead32(p); | |
299 | |
300 icq_FmtLog(plink->icqlink, ICQ_LOG_MESSAGE, | |
301 "hello packet received from %lu { version=%d }\n", remote_uin, version); | |
302 | |
303 plink->remote_version=version; | |
304 plink->remote_uin=remote_uin; | |
305 plink->flags=flags; | |
306 plink->mode&=~TCP_LINK_MODE_HELLOWAIT; | |
307 | |
308 /* file and chat sessions require additional handling */ | |
309 if(plink->type==TCP_LINK_CHAT) icq_HandleChatHello(plink); | |
310 if(plink->type==TCP_LINK_FILE) icq_HandleFileHello(plink); | |
311 | |
312 return 1; | |
313 } | |
314 | |
315 void icq_TCPOnMessageReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink) | |
316 { | |
317 char data[512] ; | |
318 #ifdef TCP_PACKET_TRACE | |
319 printf("tcp message packet received from %lu { sequence=%x }\n", | |
320 uin, (int)id); | |
321 #endif | |
322 | |
323 if(link->icq_RecvMessage) | |
324 { | |
325 /* use the current system time for time received */ | |
326 time_t t=time(0); | |
327 struct tm *ptime=localtime(&t); | |
328 icq_Packet *pack; | |
329 icq_TCPLink *preallink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE); | |
330 | |
331 strncpy(data,message,512) ; | |
332 icq_RusConv("wk",data) ; | |
333 | |
334 (*link->icq_RecvMessage)(link, uin, ptime->tm_hour, ptime->tm_min, | |
335 ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, data); | |
336 | |
337 if(plink != preallink) | |
338 { | |
339 /* if(icq_SpoofedMessage) | |
340 (*icq_SpoofedMessage(uin, ...));*/ | |
341 } | |
342 | |
343 if(plink) | |
344 { | |
345 /* send an acknowledgement to the remote client */ | |
346 pack=icq_TCPCreateMessageAck(plink,0); | |
347 icq_PacketAppend32(pack, id); | |
348 icq_PacketSend(pack, plink->socket); | |
349 #ifdef TCP_PACKET_TRACE | |
350 printf("tcp message ack sent to uin %lu { sequence=%lx }\n", uin, id); | |
351 #endif | |
352 icq_PacketDelete(pack); | |
353 } | |
354 } | |
355 } | |
356 | |
357 void icq_TCPOnURLReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id) | |
358 { | |
359 #ifdef TCP_PACKET_TRACE | |
360 printf("tcp url packet received from %lu { sequence=%lx }\n", | |
361 uin, id); | |
362 #endif /*TCP_PACKET_TRACE*/ | |
363 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
364 if(link->icq_RecvURL) |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
365 { |
1152 | 366 /* use the current system time for time received */ |
367 time_t t=time(0); | |
368 struct tm *ptime=localtime(&t); | |
369 icq_Packet *pack; | |
370 char *pfe; | |
371 icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE); | |
372 | |
373 /* the URL is split from the description by 0xFE */ | |
374 pfe=strchr(message, '\xFE'); | |
375 *pfe=0; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
376 icq_RusConv("wk", (char*)message); |
1152 | 377 (*link->icq_RecvURL)(link, uin, ptime->tm_hour, ptime->tm_min, |
378 ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, pfe+1, message); | |
379 | |
380 /* send an acknowledgement to the remote client */ | |
381 pack=icq_TCPCreateURLAck(plink,0); | |
382 icq_PacketAppend32(pack, id); | |
383 icq_PacketSend(pack, plink->socket); | |
384 #ifdef TCP_PACKET_TRACE | |
385 printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id); | |
386 #endif | |
387 icq_PacketDelete(pack); | |
388 } | |
389 } | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
390 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
391 void icq_TCPOnContactListReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
392 { |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
393 #ifdef TCP_PACKET_TRACE |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
394 printf("tcp contactlist packet received from %lu { sequence=%lx }\n", uin, id); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
395 #endif /* TCP_PACKET_TRACE */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
396 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
397 if (link->icq_RecvContactList) { |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
398 /* use the current system time for time received */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
399 time_t t=time(0); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
400 struct tm *ptime=localtime(&t); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
401 icq_Packet *pack; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
402 list *strList = list_new(); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
403 int i, k, nr = icq_SplitFields(strList, message); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
404 char *contact_uin[(nr - 2) /2], *contact_nick[(nr - 2) /2]; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
405 icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
406 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
407 /* split message */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
408 for (i = 1, k = 0; i < (nr - 1); k++) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
409 { |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
410 contact_uin[k] = list_at(strList, i); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
411 contact_nick[k] = list_at(strList, i + 1); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
412 i += 2; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
413 } |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
414 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
415 (*link->icq_RecvContactList)(link, uin, k, (const char **) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
416 contact_uin, (const char **) contact_nick); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
417 /* send an acknowledement to the remote client */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
418 pack=icq_TCPCreateContactListAck(plink, 0); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
419 icq_PacketAppend32(pack, id); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
420 icq_PacketSend(pack, plink->socket); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
421 #ifdef TCP_PACKET_TRACE |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
422 printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
423 #endif /* TCP_PACKE_TRACE */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
424 icq_PacketDelete(pack); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
425 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
426 list_delete(strList, free); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
427 } |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
428 } |