diff -r f108642d2da6 -r 77d18e17199b plugins/icq/tcp.c --- a/plugins/icq/tcp.c Tue May 29 09:46:05 2001 +0000 +++ b/plugins/icq/tcp.c Tue May 29 10:32:53 2001 +0000 @@ -1,160 +1,50 @@ /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* -$Id: tcp.c 1508 2001-02-22 23:07:34Z warmenhoven $ -$Log$ -Revision 1.4 2001/02/22 23:07:34 warmenhoven -updating icqlib - -Revision 1.39 2001/02/22 05:40:04 bills -port tcp connect timeout code and UDP queue to new timeout manager - -Revision 1.38 2001/01/17 01:29:17 bills -Rework chat and file session interfaces; implement socket notifications. - -Revision 1.37 2000/12/19 06:00:07 bills -moved members from ICQLINK to ICQLINK_private struct - -Revision 1.36 2000/07/09 22:19:35 bills -added new *Close functions, use *Close functions instead of *Delete -where correct, and misc cleanup - -Revision 1.35 2000/06/15 01:52:16 bills -added Cancel and Refuse functions for chat and file reqs, changed packet -sending code to use new icq_TCPLinkSendSeq function to elimitane duplicate -code, removed *Seq functions, renamed chat req functions - -Revision 1.34 2000/05/04 15:57:20 bills -Reworked file transfer notification, small bugfixes, and cleanups. - -Revision 1.33 2000/04/10 18:11:45 denis -ANSI cleanups. - -Revision 1.32 2000/04/10 16:36:04 denis -Some more Win32 compatibility from Guillaume Rosanis - -Revision 1.31 2000/04/06 16:38:04 denis -icq_*Send*Seq() functions with specified sequence number were added. - -Revision 1.30 2000/04/05 14:37:02 denis -Applied patch from "Guillaume R." for basic Win32 -compatibility. - -Revision 1.29 2000/02/15 04:02:41 bills -warning cleanup - -Revision 1.28 2000/02/15 03:58:20 bills -use new icq_ChatRusConv_n function in icq_TCPSendChatData, -new icq_TCPSendChatData_n function - -Revision 1.27 2000/02/07 02:40:23 bills -new code for SOCKS connections, more cyrillic translations - -Revision 1.26 2000/01/20 19:59:15 bills -first implementation of sending file requests - -Revision 1.25 2000/01/16 21:28:24 bills -renamed icq_TCPAcceptFileReq to icq_AcceptFileRequest, moved file request -functions to new file session code - -Revision 1.24 2000/01/16 03:59:10 bills -reworked list code so list_nodes don't need to be inside item structures, -removed strlist code and replaced with generic list calls - -Revision 1.23 1999/12/27 16:10:04 bills -fixed buy in icq_TCPAcceptFileReq, added icq_TCPFileSetSpeed - -Revision 1.22 1999/12/21 00:29:59 bills -moved _process_packet logic into tcplink::icq_TCPLinkProcessReceived, -removed unnecessary icq_TCPSendFile??Packet functions - -Revision 1.21 1999/12/14 03:31:48 bills -fixed double delete bug in _handle_ready_sockets, added code to implement -connect timeout - -Revision 1.20 1999/11/30 09:44:31 bills -added file session logic - -Revision 1.19 1999/09/29 20:07:12 bills -cleanups, moved connect logic from _handle_ready_sockets to -icq_TCPLinkOnConnect, tcp_link->icq_TCPLink - -Revision 1.18 1999/09/29 17:08:48 denis -Cleanups. - -Revision 1.17 1999/07/18 20:19:56 bills -added better log messages - -Revision 1.16 1999/07/16 15:45:56 denis -Cleaned up. - -Revision 1.15 1999/07/16 12:14:13 denis -tcp_packet* functions renamed to icq_Packet* -Cleaned up. - -Revision 1.14 1999/07/12 15:13:34 cproch -- added definition of ICQLINK to hold session-specific global variabled - applications which have more than one connection are now possible -- changed nearly every function defintion to support ICQLINK parameter - -Revision 1.13 1999/07/03 06:33:49 lord -. byte order conversion macros added -. some compilation warnings removed - -Revision 1.12 1999/06/30 13:52:22 bills -implemented non-blocking connects - -Revision 1.11 1999/05/03 21:41:26 bills -initial file xfer support added- untested - -Revision 1.10 1999/04/29 09:35:41 denis -Cleanups, warning removed - -Revision 1.9 1999/04/17 19:30:50 bills -_major_ restructuring. all tcp sockets (including listening sockets) are -kept in global linked list, icq_TCPLinks. accept and listen functions -moved to tcplink.c. changed return values of Send* functions to DWORD. - -Revision 1.8 1999/04/14 14:57:05 denis -Cleanups for "strict" compiling (-ansi -pedantic) -Parameter port added to function icq_TCPCreateListeningSocket() - -*/ /* - Peer-to-peer ICQ protocol implementation - - Uses version 2 of the ICQ protocol + * Copyright (C) 1998-2001, Denis V. Dmitrienko and + * Bill Soudan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ - Thanks to Douglas F. McLaughlin and many others for - packet details (see tcp02.txt) - -*/ +/* + * Peer-to-peer ICQ protocol implementation + * + * Uses version 2 of the ICQ protocol + * + * Thanks to Douglas F. McLaughlin and many others for + * packet details (see tcp02.txt) + * + */ #include #include -#include #include -#include - #ifdef _WIN32 #include -#else -#include -#include -#include #endif #include -#include "icqtypes.h" #include "icqlib.h" #include "tcp.h" #include "stdpackets.h" -#include "list.h" -#include "tcplink.h" #include "chatsession.h" #include "filesession.h" @@ -165,43 +55,43 @@ \return true on error */ -int icq_TCPInit(ICQLINK *link) +int icq_TCPInit(icq_Link *icqlink) { icq_TCPLink *plink; /* allocate lists */ - link->d->icq_TCPLinks=list_new(); - link->d->icq_ChatSessions=list_new(); - link->d->icq_FileSessions=list_new(); + icqlink->d->icq_TCPLinks=icq_ListNew(); + icqlink->d->icq_ChatSessions=icq_ListNew(); + icqlink->d->icq_FileSessions=icq_ListNew(); /* only the main listening socket gets created upon initialization - * the other two are created when necessary */ - plink=icq_TCPLinkNew( link ); + plink=icq_TCPLinkNew(icqlink); icq_TCPLinkListen(plink); - link->icq_TCPSrvPort=ntohs(plink->socket_address.sin_port); + icqlink->icq_TCPSrvPort=ntohs(plink->socket_address.sin_port); /* reset tcp sequence number */ - link->d->icq_TCPSequence=0xfffffffe; + icqlink->d->icq_TCPSequence=0xfffffffe; return 0; } -void icq_TCPDone(ICQLINK *link) +void icq_TCPDone(icq_Link *icqlink) { /* close and deallocate all tcp links, this will also close any attached * file or chat sessions */ - list_delete(link->d->icq_TCPLinks, icq_TCPLinkDelete); - list_delete(link->d->icq_ChatSessions, icq_ChatSessionDelete); - list_delete(link->d->icq_FileSessions, icq_FileSessionDelete); + icq_ListDelete(icqlink->d->icq_TCPLinks, icq_TCPLinkDelete); + icq_ListDelete(icqlink->d->icq_ChatSessions, icq_ChatSessionDelete); + icq_ListDelete(icqlink->d->icq_FileSessions, icq_FileSessionDelete); } -icq_TCPLink *icq_TCPCheckLink(ICQLINK *link, DWORD uin, int type) +icq_TCPLink *icq_TCPCheckLink(icq_Link *icqlink, DWORD uin, int type) { - icq_TCPLink *plink=icq_FindTCPLink(link, uin, type); + icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, type); if(!plink) { - plink=icq_TCPLinkNew( link ); + plink=icq_TCPLinkNew(icqlink); if(type==TCP_LINK_MESSAGE) icq_TCPLinkConnect(plink, uin, 0); } @@ -210,7 +100,7 @@ } -DWORD icq_TCPSendMessage(ICQLINK *link, DWORD uin, const char *message) +DWORD icq_TCPSendMessage(icq_Link *icqlink, DWORD uin, const char *message) { icq_TCPLink *plink; icq_Packet *p; @@ -220,10 +110,10 @@ strncpy(data,message,512) ; icq_RusConv("kw", data) ; - plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); /* create and send the message packet */ - p=icq_TCPCreateMessagePacket(plink, (unsigned char *)data); + p=icq_TCPCreateMessagePacket(plink, data); sequence=icq_TCPLinkSendSeq(plink, p, 0); #ifdef TCP_PACKET_TRACE @@ -233,14 +123,14 @@ return sequence; } -DWORD icq_TCPSendURL(ICQLINK *link, DWORD uin, const char *message, const char *url) +DWORD icq_TCPSendURL(icq_Link *icqlink, DWORD uin, const char *message, const char *url) { icq_TCPLink *plink; icq_Packet *p; DWORD sequence; char data[512]; - plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); strncpy(data, message, 512); data[511] = '\0'; @@ -257,21 +147,21 @@ return sequence; } -DWORD icq_SendChatRequest(ICQLINK *link, DWORD uin, const char *message) +DWORD icq_SendChatRequest(icq_Link *icqlink, DWORD uin, const char *message) { icq_TCPLink *plink; icq_Packet *p; DWORD sequence; char data[512]; - plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); strncpy(data, message, 512); data[511] = '\0'; icq_RusConv("kw", data); /* create and send the url packet */ - p=icq_TCPCreateChatReqPacket(plink, (unsigned char *)data); + p=icq_TCPCreateChatReqPacket(plink, data); sequence=icq_TCPLinkSendSeq(plink, p, 0); #ifdef TCP_PACKET_TRACE @@ -281,7 +171,7 @@ return sequence; } -unsigned long icq_SendFileRequest(ICQLINK *link, unsigned long uin, +unsigned long icq_SendFileRequest(icq_Link *icqlink, unsigned long uin, const char *message, char **files) { icq_TCPLink *plink; @@ -291,11 +181,11 @@ char filename[64]; char data[512]; - plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); /* create the file session, this will be linked to the incoming icq_TCPLink * in icq_HandleFileAck */ - pfile=icq_FileSessionNew(link); + pfile=icq_FileSessionNew(icqlink); pfile->remote_uin=uin; pfile->files=files; pfile->direction=FILE_STATUS_SENDING; @@ -331,25 +221,25 @@ return sequence; } -void icq_AcceptChatRequest(ICQLINK *link, DWORD uin, unsigned long sequence) +void icq_AcceptChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) { icq_TCPLink *pmessage, *plisten; icq_ChatSession *pchat; icq_Packet *p; - pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); /* create the chat listening socket if necessary */ - if(!(plisten=icq_FindTCPLink(link, 0, TCP_LINK_CHAT))) + if(!(plisten=icq_FindTCPLink(icqlink, 0, TCP_LINK_CHAT))) { - plisten=icq_TCPLinkNew( link ); + plisten=icq_TCPLinkNew(icqlink); plisten->type=TCP_LINK_CHAT; icq_TCPLinkListen(plisten); } /* create the chat session, this will be linked to the incoming icq_TCPLink * in TCPProcessHello */ - pchat=icq_ChatSessionNew(link); + pchat=icq_ChatSessionNew(icqlink); pchat->id=sequence; pchat->remote_uin=uin; @@ -363,9 +253,9 @@ #endif } -void icq_TCPSendChatData(ICQLINK *link, DWORD uin, const char *data) +void icq_TCPSendChatData(icq_Link *icqlink, DWORD uin, const char *data) { - icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_CHAT); + icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_CHAT); char data1[512]; int data1_len; @@ -381,9 +271,9 @@ } -void icq_TCPSendChatData_n(ICQLINK *link, DWORD uin, const char *data, int len) +void icq_TCPSendChatData_n(icq_Link *icqlink, DWORD uin, const char *data, int len) { - icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_CHAT); + icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_CHAT); char *data1; if(!plink) @@ -397,26 +287,26 @@ } -icq_FileSession *icq_AcceptFileRequest(ICQLINK *link, DWORD uin, +icq_FileSession *icq_AcceptFileRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) { icq_TCPLink *pmessage, *plisten; icq_FileSession *pfile; icq_Packet *p; - pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); /* create the file listening socket if necessary */ - if(!(plisten=icq_FindTCPLink(link, 0, TCP_LINK_FILE))) + if(!(plisten=icq_FindTCPLink(icqlink, 0, TCP_LINK_FILE))) { - plisten=icq_TCPLinkNew( link ); + plisten=icq_TCPLinkNew(icqlink); plisten->type=TCP_LINK_FILE; icq_TCPLinkListen(plisten); } /* create the file session, this will be linked to the incoming icq_TCPLink * in TCPProcessHello */ - pfile=icq_FileSessionNew(link); + pfile=icq_FileSessionNew(icqlink); pfile->id=sequence; pfile->remote_uin=uin; pfile->direction=FILE_STATUS_RECEIVING; @@ -435,10 +325,10 @@ } -void icq_RefuseFileRequest(ICQLINK *link, DWORD uin, +void icq_RefuseFileRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence, const char *reason) { - icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); icq_Packet *p; /* create and send the refuse packet */ @@ -453,10 +343,10 @@ } -void icq_CancelFileRequest(ICQLINK *link, DWORD uin, unsigned long sequence) +void icq_CancelFileRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) { - icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); - icq_FileSession *psession=icq_FindFileSession(link, uin, sequence); + icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); + icq_FileSession *psession=icq_FindFileSession(icqlink, uin, sequence); icq_Packet *p; if (psession) @@ -472,10 +362,10 @@ } -void icq_RefuseChatRequest(ICQLINK *link, DWORD uin, +void icq_RefuseChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence, const char *reason) { - icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); + icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); icq_Packet *p; /* create and send the refuse packet */ @@ -490,10 +380,10 @@ } -void icq_CancelChatRequest(ICQLINK *link, DWORD uin, unsigned long sequence) +void icq_CancelChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) { - icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE); - icq_FileSession *psession=icq_FindFileSession(link, uin, sequence); + icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); + icq_FileSession *psession=icq_FindFileSession(icqlink, uin, sequence); icq_Packet *p; if (psession)