Mercurial > pidgin
annotate plugins/icq/tcp.c @ 1684:89c19002e73d
[gaim-migrate @ 1694]
stop getting booted by gabber people
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Thu, 05 Apr 2001 01:04:10 +0000 |
| parents | 0ef6603d986e |
| children | 8ed70631ed15 |
| 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: tcp.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.39 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.38 2001/01/17 01:29:17 bills |
|
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
12 Rework chat and file session interfaces; implement socket notifications. |
|
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
13 |
|
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
14 Revision 1.37 2000/12/19 06:00:07 bills |
|
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
15 moved members from ICQLINK to ICQLINK_private struct |
| 1152 | 16 |
| 17 Revision 1.36 2000/07/09 22:19:35 bills | |
| 18 added new *Close functions, use *Close functions instead of *Delete | |
| 19 where correct, and misc cleanup | |
| 20 | |
| 21 Revision 1.35 2000/06/15 01:52:16 bills | |
| 22 added Cancel and Refuse functions for chat and file reqs, changed packet | |
| 23 sending code to use new icq_TCPLinkSendSeq function to elimitane duplicate | |
| 24 code, removed *Seq functions, renamed chat req functions | |
| 25 | |
| 26 Revision 1.34 2000/05/04 15:57:20 bills | |
| 27 Reworked file transfer notification, small bugfixes, and cleanups. | |
| 28 | |
| 29 Revision 1.33 2000/04/10 18:11:45 denis | |
| 30 ANSI cleanups. | |
| 31 | |
| 32 Revision 1.32 2000/04/10 16:36:04 denis | |
| 33 Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com> | |
| 34 | |
| 35 Revision 1.31 2000/04/06 16:38:04 denis | |
| 36 icq_*Send*Seq() functions with specified sequence number were added. | |
| 37 | |
| 38 Revision 1.30 2000/04/05 14:37:02 denis | |
| 39 Applied patch from "Guillaume R." <grs@mail.com> for basic Win32 | |
| 40 compatibility. | |
| 41 | |
| 42 Revision 1.29 2000/02/15 04:02:41 bills | |
| 43 warning cleanup | |
| 44 | |
| 45 Revision 1.28 2000/02/15 03:58:20 bills | |
| 46 use new icq_ChatRusConv_n function in icq_TCPSendChatData, | |
| 47 new icq_TCPSendChatData_n function | |
| 48 | |
| 49 Revision 1.27 2000/02/07 02:40:23 bills | |
| 50 new code for SOCKS connections, more cyrillic translations | |
| 51 | |
| 52 Revision 1.26 2000/01/20 19:59:15 bills | |
| 53 first implementation of sending file requests | |
| 54 | |
| 55 Revision 1.25 2000/01/16 21:28:24 bills | |
| 56 renamed icq_TCPAcceptFileReq to icq_AcceptFileRequest, moved file request | |
| 57 functions to new file session code | |
| 58 | |
| 59 Revision 1.24 2000/01/16 03:59:10 bills | |
| 60 reworked list code so list_nodes don't need to be inside item structures, | |
| 61 removed strlist code and replaced with generic list calls | |
| 62 | |
| 63 Revision 1.23 1999/12/27 16:10:04 bills | |
| 64 fixed buy in icq_TCPAcceptFileReq, added icq_TCPFileSetSpeed | |
| 65 | |
| 66 Revision 1.22 1999/12/21 00:29:59 bills | |
| 67 moved _process_packet logic into tcplink::icq_TCPLinkProcessReceived, | |
| 68 removed unnecessary icq_TCPSendFile??Packet functions | |
| 69 | |
| 70 Revision 1.21 1999/12/14 03:31:48 bills | |
| 71 fixed double delete bug in _handle_ready_sockets, added code to implement | |
| 72 connect timeout | |
| 73 | |
| 74 Revision 1.20 1999/11/30 09:44:31 bills | |
| 75 added file session logic | |
| 76 | |
| 77 Revision 1.19 1999/09/29 20:07:12 bills | |
| 78 cleanups, moved connect logic from _handle_ready_sockets to | |
| 79 icq_TCPLinkOnConnect, tcp_link->icq_TCPLink | |
| 80 | |
| 81 Revision 1.18 1999/09/29 17:08:48 denis | |
| 82 Cleanups. | |
| 83 | |
| 84 Revision 1.17 1999/07/18 20:19:56 bills | |
| 85 added better log messages | |
| 86 | |
| 87 Revision 1.16 1999/07/16 15:45:56 denis | |
| 88 Cleaned up. | |
| 89 | |
| 90 Revision 1.15 1999/07/16 12:14:13 denis | |
| 91 tcp_packet* functions renamed to icq_Packet* | |
| 92 Cleaned up. | |
| 93 | |
| 94 Revision 1.14 1999/07/12 15:13:34 cproch | |
| 95 - added definition of ICQLINK to hold session-specific global variabled | |
| 96 applications which have more than one connection are now possible | |
| 97 - changed nearly every function defintion to support ICQLINK parameter | |
| 98 | |
| 99 Revision 1.13 1999/07/03 06:33:49 lord | |
| 100 . byte order conversion macros added | |
| 101 . some compilation warnings removed | |
| 102 | |
| 103 Revision 1.12 1999/06/30 13:52:22 bills | |
| 104 implemented non-blocking connects | |
| 105 | |
| 106 Revision 1.11 1999/05/03 21:41:26 bills | |
| 107 initial file xfer support added- untested | |
| 108 | |
| 109 Revision 1.10 1999/04/29 09:35:41 denis | |
| 110 Cleanups, warning removed | |
| 111 | |
| 112 Revision 1.9 1999/04/17 19:30:50 bills | |
| 113 _major_ restructuring. all tcp sockets (including listening sockets) are | |
| 114 kept in global linked list, icq_TCPLinks. accept and listen functions | |
| 115 moved to tcplink.c. changed return values of Send* functions to DWORD. | |
| 116 | |
| 117 Revision 1.8 1999/04/14 14:57:05 denis | |
| 118 Cleanups for "strict" compiling (-ansi -pedantic) | |
| 119 Parameter port added to function icq_TCPCreateListeningSocket() | |
| 120 | |
| 121 */ | |
| 122 | |
| 123 /* | |
| 124 Peer-to-peer ICQ protocol implementation | |
| 125 | |
| 126 Uses version 2 of the ICQ protocol | |
| 127 | |
| 128 Thanks to Douglas F. McLaughlin and many others for | |
| 129 packet details (see tcp02.txt) | |
| 130 | |
| 131 */ | |
| 132 | |
| 133 #include <stdlib.h> | |
| 134 | |
| 135 #include <fcntl.h> | |
| 136 #include <stdarg.h> | |
| 137 #include <errno.h> | |
| 138 | |
| 139 #include <sys/types.h> | |
| 140 | |
| 141 #ifdef _WIN32 | |
| 142 #include <winsock.h> | |
| 143 #else | |
| 144 #include <sys/socket.h> | |
|
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
145 #include <sys/time.h> |
|
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
146 #include <unistd.h> |
| 1152 | 147 #endif |
| 148 | |
| 149 #include <sys/stat.h> | |
| 150 | |
| 151 #include "icqtypes.h" | |
| 152 #include "icqlib.h" | |
| 153 | |
| 154 #include "tcp.h" | |
| 155 #include "stdpackets.h" | |
| 156 #include "list.h" | |
| 157 #include "tcplink.h" | |
| 158 #include "chatsession.h" | |
| 159 #include "filesession.h" | |
| 160 | |
| 161 /** | |
| 162 Initializes structures necessary for TCP use. Not required by user | |
| 163 programs. | |
| 164 | |
| 165 \return true on error | |
| 166 */ | |
| 167 | |
| 168 int icq_TCPInit(ICQLINK *link) | |
| 169 { | |
| 170 icq_TCPLink *plink; | |
| 171 | |
| 172 /* allocate lists */ | |
|
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
173 link->d->icq_TCPLinks=list_new(); |
|
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
174 link->d->icq_ChatSessions=list_new(); |
|
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
175 link->d->icq_FileSessions=list_new(); |
| 1152 | 176 |
| 177 /* only the main listening socket gets created upon initialization - | |
| 178 * the other two are created when necessary */ | |
| 179 plink=icq_TCPLinkNew( link ); | |
| 180 icq_TCPLinkListen(plink); | |
| 181 link->icq_TCPSrvPort=ntohs(plink->socket_address.sin_port); | |
| 182 | |
| 183 /* reset tcp sequence number */ | |
|
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
184 link->d->icq_TCPSequence=0xfffffffe; |
| 1152 | 185 |
| 186 return 0; | |
| 187 } | |
| 188 | |
| 189 void icq_TCPDone(ICQLINK *link) | |
| 190 { | |
| 191 /* close and deallocate all tcp links, this will also close any attached | |
| 192 * file or chat sessions */ | |
|
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
193 list_delete(link->d->icq_TCPLinks, icq_TCPLinkDelete); |
|
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
194 list_delete(link->d->icq_ChatSessions, icq_ChatSessionDelete); |
|
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
195 list_delete(link->d->icq_FileSessions, icq_FileSessionDelete); |
| 1152 | 196 } |
| 197 | |
| 198 icq_TCPLink *icq_TCPCheckLink(ICQLINK *link, DWORD uin, int type) | |
| 199 { | |
| 200 icq_TCPLink *plink=icq_FindTCPLink(link, uin, type); | |
| 201 | |
| 202 if(!plink) | |
| 203 { | |
| 204 plink=icq_TCPLinkNew( link ); | |
| 205 if(type==TCP_LINK_MESSAGE) | |
| 206 icq_TCPLinkConnect(plink, uin, 0); | |
| 207 } | |
| 208 | |
| 209 return plink; | |
| 210 | |
| 211 } | |
| 212 | |
| 213 DWORD icq_TCPSendMessage(ICQLINK *link, DWORD uin, const char *message) | |
| 214 { | |
| 215 icq_TCPLink *plink; | |
| 216 icq_Packet *p; | |
| 217 DWORD sequence; | |
| 218 char data[512] ; | |
| 219 | |
| 220 strncpy(data,message,512) ; | |
| 221 icq_RusConv("kw", data) ; | |
| 222 | |
| 223 plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 224 | |
| 225 /* create and send the message packet */ | |
| 226 p=icq_TCPCreateMessagePacket(plink, (unsigned char *)data); | |
| 227 sequence=icq_TCPLinkSendSeq(plink, p, 0); | |
| 228 | |
| 229 #ifdef TCP_PACKET_TRACE | |
| 230 printf("message packet sent to uin %lu { sequence=%lx }\n", uin, p->id); | |
| 231 #endif | |
| 232 | |
| 233 return sequence; | |
| 234 } | |
| 235 | |
| 236 DWORD icq_TCPSendURL(ICQLINK *link, DWORD uin, const char *message, const char *url) | |
| 237 { | |
| 238 icq_TCPLink *plink; | |
| 239 icq_Packet *p; | |
| 240 DWORD sequence; | |
| 241 char data[512]; | |
| 242 | |
| 243 plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 244 | |
| 245 strncpy(data, message, 512); | |
| 246 data[511] = '\0'; | |
| 247 icq_RusConv("kw", data); | |
| 248 | |
| 249 /* create and send the url packet */ | |
| 250 p=icq_TCPCreateURLPacket(plink, data, url); | |
| 251 sequence=icq_TCPLinkSendSeq(plink, p, 0); | |
| 252 | |
| 253 #ifdef TCP_PACKET_TRACE | |
| 254 printf("url packet queued for uin %lu { sequence=%lx }\n", uin, p->id); | |
| 255 #endif | |
| 256 | |
| 257 return sequence; | |
| 258 } | |
| 259 | |
| 260 DWORD icq_SendChatRequest(ICQLINK *link, DWORD uin, const char *message) | |
| 261 { | |
| 262 icq_TCPLink *plink; | |
| 263 icq_Packet *p; | |
| 264 DWORD sequence; | |
| 265 char data[512]; | |
| 266 | |
| 267 plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 268 | |
| 269 strncpy(data, message, 512); | |
| 270 data[511] = '\0'; | |
| 271 icq_RusConv("kw", data); | |
| 272 | |
| 273 /* create and send the url packet */ | |
| 274 p=icq_TCPCreateChatReqPacket(plink, (unsigned char *)data); | |
| 275 sequence=icq_TCPLinkSendSeq(plink, p, 0); | |
| 276 | |
| 277 #ifdef TCP_PACKET_TRACE | |
| 278 printf("chat req packet sent to uin %lu { sequence=%lx }\n", uin, p->id); | |
| 279 #endif | |
| 280 | |
| 281 return sequence; | |
| 282 } | |
| 283 | |
| 284 unsigned long icq_SendFileRequest(ICQLINK *link, unsigned long uin, | |
| 285 const char *message, char **files) | |
| 286 { | |
| 287 icq_TCPLink *plink; | |
| 288 icq_FileSession *pfile; | |
| 289 icq_Packet *p; | |
| 290 unsigned long sequence; | |
| 291 char filename[64]; | |
| 292 char data[512]; | |
| 293 | |
| 294 plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 295 | |
| 296 /* create the file session, this will be linked to the incoming icq_TCPLink | |
| 297 * in icq_HandleFileAck */ | |
| 298 pfile=icq_FileSessionNew(link); | |
| 299 pfile->remote_uin=uin; | |
| 300 pfile->files=files; | |
| 301 pfile->direction=FILE_STATUS_SENDING; | |
| 302 | |
| 303 /* count the number and size of the files */ | |
| 304 pfile->total_files=0; | |
| 305 while(*files) { | |
| 306 struct stat file_status; | |
| 307 | |
| 308 if(stat(*files, &file_status)==0) { | |
| 309 pfile->total_files++; | |
| 310 pfile->total_bytes+=file_status.st_size; | |
| 311 } | |
| 312 files++; | |
| 313 } | |
| 314 | |
| 315 strncpy(filename, *(pfile->files), 64); | |
| 316 | |
| 317 strncpy(data, message, 512); | |
| 318 data[511] = '\0'; | |
| 319 icq_RusConv("kw", data); | |
| 320 | |
| 321 /* create and send the file req packet */ | |
| 322 p=icq_TCPCreateFileReqPacket(plink, (char *)data, filename, | |
| 323 pfile->total_bytes); | |
| 324 sequence=icq_TCPLinkSendSeq(plink, p, 0); | |
| 325 pfile->id=sequence; | |
| 326 | |
| 327 #ifdef TCP_PACKET_TRACE | |
| 328 printf("file req packet sent to uin %lu { sequence=%lx }\n", uin, p->id); | |
| 329 #endif | |
| 330 | |
| 331 return sequence; | |
| 332 } | |
| 333 | |
| 334 void icq_AcceptChatRequest(ICQLINK *link, DWORD uin, unsigned long sequence) | |
| 335 { | |
| 336 icq_TCPLink *pmessage, *plisten; | |
| 337 icq_ChatSession *pchat; | |
| 338 icq_Packet *p; | |
| 339 | |
| 340 pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 341 | |
| 342 /* create the chat listening socket if necessary */ | |
| 343 if(!(plisten=icq_FindTCPLink(link, 0, TCP_LINK_CHAT))) | |
| 344 { | |
| 345 plisten=icq_TCPLinkNew( link ); | |
| 346 plisten->type=TCP_LINK_CHAT; | |
| 347 icq_TCPLinkListen(plisten); | |
| 348 } | |
| 349 | |
| 350 /* create the chat session, this will be linked to the incoming icq_TCPLink | |
| 351 * in TCPProcessHello */ | |
| 352 pchat=icq_ChatSessionNew(link); | |
| 353 pchat->id=sequence; | |
| 354 pchat->remote_uin=uin; | |
| 355 | |
| 356 /* create and send the ack packet */ | |
| 357 p=icq_TCPCreateChatReqAck(pmessage, | |
| 358 ntohs(plisten->socket_address.sin_port)); | |
| 359 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
| 360 | |
| 361 #ifdef TCP_PACKET_TRACE | |
| 362 printf("chat req ack sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
| 363 #endif | |
| 364 } | |
| 365 | |
| 366 void icq_TCPSendChatData(ICQLINK *link, DWORD uin, const char *data) | |
| 367 { | |
| 368 icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_CHAT); | |
| 369 char data1[512]; | |
| 370 int data1_len; | |
| 371 | |
| 372 if(!plink) | |
| 373 return; | |
| 374 | |
| 375 strncpy(data1,data,512) ; | |
| 376 data1[511] = '\0'; | |
| 377 data1_len = strlen(data); | |
| 378 icq_ChatRusConv_n("kw", data1, data1_len); | |
| 379 | |
| 380 send(plink->socket, data1, data1_len, 0); | |
| 381 | |
| 382 } | |
| 383 | |
| 384 void icq_TCPSendChatData_n(ICQLINK *link, DWORD uin, const char *data, int len) | |
| 385 { | |
| 386 icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_CHAT); | |
| 387 char *data1; | |
| 388 | |
| 389 if(!plink) | |
| 390 return; | |
| 391 | |
| 392 data1 = (char *)malloc(len); | |
| 393 memcpy(data1, data, len); | |
| 394 icq_ChatRusConv_n("kw", data1, len); | |
| 395 | |
| 396 send(plink->socket, data1, len, 0); | |
| 397 | |
| 398 } | |
| 399 | |
| 400 icq_FileSession *icq_AcceptFileRequest(ICQLINK *link, DWORD uin, | |
| 401 unsigned long sequence) | |
| 402 { | |
| 403 icq_TCPLink *pmessage, *plisten; | |
| 404 icq_FileSession *pfile; | |
| 405 icq_Packet *p; | |
| 406 | |
| 407 pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 408 | |
| 409 /* create the file listening socket if necessary */ | |
| 410 if(!(plisten=icq_FindTCPLink(link, 0, TCP_LINK_FILE))) | |
| 411 { | |
| 412 plisten=icq_TCPLinkNew( link ); | |
| 413 plisten->type=TCP_LINK_FILE; | |
| 414 icq_TCPLinkListen(plisten); | |
| 415 } | |
| 416 | |
| 417 /* create the file session, this will be linked to the incoming icq_TCPLink | |
| 418 * in TCPProcessHello */ | |
| 419 pfile=icq_FileSessionNew(link); | |
| 420 pfile->id=sequence; | |
| 421 pfile->remote_uin=uin; | |
| 422 pfile->direction=FILE_STATUS_RECEIVING; | |
| 423 icq_FileSessionSetStatus(pfile, FILE_STATUS_LISTENING); | |
| 424 | |
| 425 /* create and send the ack packet */ | |
| 426 p=icq_TCPCreateFileReqAck(pmessage, | |
| 427 ntohs(plisten->socket_address.sin_port)); | |
| 428 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
| 429 | |
| 430 #ifdef TCP_PACKET_TRACE | |
| 431 printf("file req ack sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
| 432 #endif | |
| 433 | |
| 434 return pfile; | |
| 435 | |
| 436 } | |
| 437 | |
| 438 void icq_RefuseFileRequest(ICQLINK *link, DWORD uin, | |
| 439 unsigned long sequence, const char *reason) | |
| 440 { | |
| 441 icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 442 icq_Packet *p; | |
| 443 | |
| 444 /* create and send the refuse packet */ | |
| 445 p=icq_TCPCreateFileReqRefuse(pmessage, | |
| 446 ntohs(pmessage->socket_address.sin_port), reason); | |
| 447 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
| 448 | |
| 449 #ifdef TCP_PACKET_TRACE | |
| 450 printf("file req refuse sent to uin %lu { sequence=%lx, reason=\"%s\" }\n", | |
| 451 uin, sequence, reason); | |
| 452 #endif | |
| 453 | |
| 454 } | |
| 455 | |
| 456 void icq_CancelFileRequest(ICQLINK *link, DWORD uin, unsigned long sequence) | |
| 457 { | |
| 458 icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 459 icq_FileSession *psession=icq_FindFileSession(link, uin, sequence); | |
| 460 icq_Packet *p; | |
| 461 | |
| 462 if (psession) | |
| 463 icq_FileSessionClose(psession); | |
| 464 | |
| 465 /* create and send the cancel packet */ | |
| 466 p=icq_TCPCreateFileReqCancel(pmessage, | |
| 467 ntohs(pmessage->socket_address.sin_port)); | |
| 468 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
| 469 #ifdef TCP_PACKET_TRACE | |
| 470 printf("file req cancel sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
| 471 #endif | |
| 472 | |
| 473 } | |
| 474 | |
| 475 void icq_RefuseChatRequest(ICQLINK *link, DWORD uin, | |
| 476 unsigned long sequence, const char *reason) | |
| 477 { | |
| 478 icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 479 icq_Packet *p; | |
| 480 | |
| 481 /* create and send the refuse packet */ | |
| 482 p=icq_TCPCreateChatReqRefuse(pmessage, | |
| 483 ntohs(pmessage->socket_address.sin_port), reason); | |
| 484 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
| 485 | |
| 486 #ifdef TCP_PACKET_TRACE | |
| 487 printf("chat req refuse sent to uin %lu { sequence=%lx, reason=\"%s\" }\n", | |
| 488 uin, sequence, reason); | |
| 489 #endif | |
| 490 | |
| 491 } | |
| 492 | |
| 493 void icq_CancelChatRequest(ICQLINK *link, DWORD uin, unsigned long sequence) | |
| 494 { | |
| 495 icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); | |
| 496 icq_FileSession *psession=icq_FindFileSession(link, uin, sequence); | |
| 497 icq_Packet *p; | |
| 498 | |
| 499 if (psession) | |
| 500 icq_FileSessionClose(psession); | |
| 501 | |
| 502 /* create and send the cancel packet */ | |
| 503 p=icq_TCPCreateChatReqCancel(pmessage, | |
| 504 ntohs(pmessage->socket_address.sin_port)); | |
| 505 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
| 506 | |
| 507 #ifdef TCP_PACKET_TRACE | |
| 508 printf("chat req cancel sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
| 509 #endif | |
| 510 | |
| 511 } |
