Mercurial > pidgin
comparison plugins/icq/tcphandle.c @ 1912:8ed70631ed15
[gaim-migrate @ 1922]
new icqlib
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 29 May 2001 10:32:53 +0000 |
parents | 4c510ca3563f |
children | 7b3f1eb1ef7d |
comparison
equal
deleted
inserted
replaced
1911:db3104dda736 | 1912:8ed70631ed15 |
---|---|
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | |
2 /* | 3 /* |
3 $Id: tcphandle.c 1442 2001-01-28 01:52:27Z warmenhoven $ | 4 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and |
4 $Log$ | 5 * Bill Soudan <soudan@kde.org> |
5 Revision 1.3 2001/01/28 01:52:27 warmenhoven | 6 * |
6 icqlib 1.1.5 | 7 * This program is free software; you can redistribute it and/or modify |
7 | 8 * it under the terms of the GNU General Public License as published by |
8 Revision 1.16 2001/01/24 05:11:14 bills | 9 * the Free Software Foundation; either version 2 of the License, or |
9 applied patch from Robin Ericsson <lobbin@localhost.nu> which implements | 10 * (at your option) any later version. |
10 receiving contact lists. See new icq_RecvContactList callback. | 11 * |
11 | 12 * This program is distributed in the hope that it will be useful, |
12 Revision 1.15 2001/01/17 01:31:47 bills | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 Rework chat and file interfaces; implement socket notifications. | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 15 * GNU General Public License for more details. |
15 Revision 1.14 2000/12/06 05:15:45 denis | 16 * |
16 Handling for mass TCP messages has been added based on patch by | 17 * You should have received a copy of the GNU General Public License |
17 Konstantin Klyagin <konst@konst.org.ua> | 18 * along with this program; if not, write to the Free Software |
18 | 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 Revision 1.13 2000/08/13 19:44:41 denis | 20 * |
20 Cyrillic recoding on received URL description added. | 21 */ |
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 | 22 |
95 #include <stdlib.h> | 23 #include <stdlib.h> |
96 #include <time.h> | 24 |
97 | |
98 #ifndef _WIN32 | |
99 #include <unistd.h> | |
100 #endif | |
101 | |
102 #include "icqtypes.h" | |
103 #include "icq.h" | |
104 #include "icqlib.h" | 25 #include "icqlib.h" |
105 | 26 |
106 #include "tcp.h" | 27 #include "tcp.h" |
107 #include "stdpackets.h" | 28 #include "stdpackets.h" |
108 #include "tcplink.h" | 29 |
109 | 30 void icq_TCPOnMessageReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink); |
110 void icq_TCPOnMessageReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink); | 31 void icq_TCPOnURLReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id); |
111 void icq_TCPOnURLReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id); | 32 void icq_TCPOnContactListReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id); |
112 void icq_TCPOnContactListReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id); | 33 void icq_TCPOnChatReqReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id); |
113 void icq_TCPOnChatReqReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id); | 34 void icq_TCPOnFileReqReceived(icq_Link *icqlink, DWORD uin, const char *message, |
114 void icq_TCPOnFileReqReceived(ICQLINK *link, DWORD uin, const char *message, | |
115 const char *filename, unsigned long filesize, DWORD id); | 35 const char *filename, unsigned long filesize, DWORD id); |
116 void icq_TCPProcessAck(ICQLINK *link, icq_Packet *p); | 36 void icq_TCPProcessAck(icq_Link *icqlink, icq_Packet *p); |
117 void icq_HandleChatAck(icq_TCPLink *plink, icq_Packet *p, int port); | 37 void icq_HandleChatAck(icq_TCPLink *plink, icq_Packet *p, int port); |
118 void icq_HandleChatHello(icq_TCPLink *plink); | 38 void icq_HandleChatHello(icq_TCPLink *plink); |
119 void icq_HandleFileHello(icq_TCPLink *plink); | 39 void icq_HandleFileHello(icq_TCPLink *plink); |
120 void icq_HandleFileAck(icq_TCPLink *plink, icq_Packet *p, int port); | 40 void icq_HandleFileAck(icq_TCPLink *plink, icq_Packet *p, int port); |
121 | 41 |
310 if(plink->type==TCP_LINK_FILE) icq_HandleFileHello(plink); | 230 if(plink->type==TCP_LINK_FILE) icq_HandleFileHello(plink); |
311 | 231 |
312 return 1; | 232 return 1; |
313 } | 233 } |
314 | 234 |
315 void icq_TCPOnMessageReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink) | 235 void icq_TCPOnMessageReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink) |
316 { | 236 { |
317 char data[512] ; | 237 char data[512]; |
238 | |
239 /* use the current system time for time received */ | |
240 time_t t=time(0); | |
241 struct tm *ptime=localtime(&t); | |
242 icq_Packet *pack; | |
243 | |
318 #ifdef TCP_PACKET_TRACE | 244 #ifdef TCP_PACKET_TRACE |
319 printf("tcp message packet received from %lu { sequence=%x }\n", | 245 printf("tcp message packet received from %lu { sequence=%x }\n", |
320 uin, (int)id); | 246 uin, (int)id); |
321 #endif | 247 #endif |
322 | 248 |
323 if(link->icq_RecvMessage) | 249 strncpy(data,message,512) ; |
324 { | 250 icq_RusConv("wk",data) ; |
325 /* use the current system time for time received */ | 251 |
326 time_t t=time(0); | 252 invoke_callback(icqlink,icq_RecvMessage)(icqlink, uin, ptime->tm_hour, |
327 struct tm *ptime=localtime(&t); | 253 ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, data); |
328 icq_Packet *pack; | 254 |
329 icq_TCPLink *preallink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE); | 255 /* |
330 | 256 icq_TCPLink *preallink=icq_FindTCPLink(icqlink, uin, TCP_LINK_MESSAGE); |
331 strncpy(data,message,512) ; | 257 if(plink != preallink) |
332 icq_RusConv("wk",data) ; | 258 invoke_callback(icqlink,icq_SpoofedMessage)(uin, ...) |
333 | 259 */ |
334 (*link->icq_RecvMessage)(link, uin, ptime->tm_hour, ptime->tm_min, | 260 |
335 ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, data); | 261 /* send an acknowledgement to the remote client */ |
336 | 262 pack=icq_TCPCreateMessageAck(plink,0); |
337 if(plink != preallink) | 263 icq_PacketAppend32(pack, id); |
338 { | 264 icq_PacketSend(pack, plink->socket); |
339 /* if(icq_SpoofedMessage) | 265 #ifdef TCP_PACKET_TRACE |
340 (*icq_SpoofedMessage(uin, ...));*/ | 266 printf("tcp message ack sent to uin %lu { sequence=%lx }\n", uin, id); |
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 | 267 #endif |
352 icq_PacketDelete(pack); | 268 icq_PacketDelete(pack); |
353 } | 269 } |
354 } | 270 |
355 } | 271 void icq_TCPOnURLReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id) |
356 | 272 { |
357 void icq_TCPOnURLReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id) | 273 /* use the current system time for time received */ |
358 { | 274 time_t t=time(0); |
275 struct tm *ptime=localtime(&t); | |
276 icq_Packet *pack; | |
277 char *pfe; | |
278 icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_MESSAGE); | |
279 | |
359 #ifdef TCP_PACKET_TRACE | 280 #ifdef TCP_PACKET_TRACE |
360 printf("tcp url packet received from %lu { sequence=%lx }\n", | 281 printf("tcp url packet received from %lu { sequence=%lx }\n", |
361 uin, id); | 282 uin, id); |
362 #endif /*TCP_PACKET_TRACE*/ | 283 #endif /*TCP_PACKET_TRACE*/ |
363 | 284 |
364 if(link->icq_RecvURL) | 285 /* the URL is split from the description by 0xFE */ |
365 { | 286 pfe=strchr(message, '\xFE'); |
366 /* use the current system time for time received */ | 287 *pfe=0; |
367 time_t t=time(0); | 288 icq_RusConv("wk", (char*)message); |
368 struct tm *ptime=localtime(&t); | 289 |
369 icq_Packet *pack; | 290 invoke_callback(icqlink,icq_RecvURL)(icqlink, uin, ptime->tm_hour, |
370 char *pfe; | 291 ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, |
371 icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE); | 292 pfe+1, message); |
372 | 293 |
373 /* the URL is split from the description by 0xFE */ | 294 /* send an acknowledgement to the remote client */ |
374 pfe=strchr(message, '\xFE'); | 295 pack=icq_TCPCreateURLAck(plink,0); |
375 *pfe=0; | 296 icq_PacketAppend32(pack, id); |
376 icq_RusConv("wk", (char*)message); | 297 icq_PacketSend(pack, plink->socket); |
377 (*link->icq_RecvURL)(link, uin, ptime->tm_hour, ptime->tm_min, | 298 #ifdef TCP_PACKET_TRACE |
378 ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, pfe+1, message); | 299 printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id); |
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 | 300 #endif |
387 icq_PacketDelete(pack); | 301 icq_PacketDelete(pack); |
388 } | 302 } |
389 } | 303 |
390 | 304 void icq_TCPOnContactListReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id) |
391 void icq_TCPOnContactListReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id) | 305 { |
392 { | 306 /* use the current system time for time received */ |
307 time_t t=time(0); | |
308 struct tm *ptime=localtime(&t); | |
309 icq_Packet *pack; | |
310 icq_List *strList = icq_ListNew(); | |
311 int i, k, nr = icq_SplitFields(strList, message); | |
312 const char **contact_uin = (const char **)malloc((nr - 2) /2); | |
313 const char **contact_nick = (const char **)malloc((nr - 2) /2); | |
314 icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_MESSAGE); | |
315 | |
393 #ifdef TCP_PACKET_TRACE | 316 #ifdef TCP_PACKET_TRACE |
394 printf("tcp contactlist packet received from %lu { sequence=%lx }\n", uin, id); | 317 printf("tcp contactlist packet received from %lu { sequence=%lx }\n", uin, id); |
395 #endif /* TCP_PACKET_TRACE */ | 318 #endif /* TCP_PACKET_TRACE */ |
396 | 319 |
397 if (link->icq_RecvContactList) { | 320 /* split message */ |
398 /* use the current system time for time received */ | 321 for (i = 1, k = 0; i < (nr - 1); k++) |
399 time_t t=time(0); | 322 { |
400 struct tm *ptime=localtime(&t); | 323 contact_uin[k] = icq_ListAt(strList, i); |
401 icq_Packet *pack; | 324 contact_nick[k] = icq_ListAt(strList, i + 1); |
402 list *strList = list_new(); | 325 i += 2; |
403 int i, k, nr = icq_SplitFields(strList, message); | 326 } |
404 char *contact_uin[(nr - 2) /2], *contact_nick[(nr - 2) /2]; | 327 |
405 icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE); | 328 invoke_callback(icqlink,icq_RecvContactList)(icqlink, uin, |
406 | 329 ptime->tm_hour, ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, |
407 /* split message */ | 330 ptime->tm_year+1900, k, contact_uin, contact_nick); |
408 for (i = 1, k = 0; i < (nr - 1); k++) | 331 |
409 { | 332 /* send an acknowledement to the remote client */ |
410 contact_uin[k] = list_at(strList, i); | 333 pack=icq_TCPCreateContactListAck(plink, 0); |
411 contact_nick[k] = list_at(strList, i + 1); | 334 icq_PacketAppend32(pack, id); |
412 i += 2; | 335 icq_PacketSend(pack, plink->socket); |
413 } | 336 #ifdef TCP_PACKET_TRACE |
414 | 337 printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id); |
415 (*link->icq_RecvContactList)(link, uin, k, (const char **) | |
416 contact_uin, (const char **) contact_nick); | |
417 /* send an acknowledement to the remote client */ | |
418 pack=icq_TCPCreateContactListAck(plink, 0); | |
419 icq_PacketAppend32(pack, id); | |
420 icq_PacketSend(pack, plink->socket); | |
421 #ifdef TCP_PACKET_TRACE | |
422 printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id); | |
423 #endif /* TCP_PACKE_TRACE */ | 338 #endif /* TCP_PACKE_TRACE */ |
424 icq_PacketDelete(pack); | 339 icq_PacketDelete(pack); |
425 | 340 |
426 list_delete(strList, free); | 341 free(contact_nick); |
427 } | 342 free(contact_uin); |
428 } | 343 icq_ListDelete(strList, free); |
344 } |