Mercurial > pidgin
annotate plugins/icq/tcp.c @ 2013:0be1e533036c
[gaim-migrate @ 2023]
wee
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 13 Jun 2001 23:39:26 +0000 |
parents | 7b3f1eb1ef7d |
children |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | |
3 /* | |
2013
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
4 * $Id: tcp.c 2023 2001-06-13 23:39:26Z warmenhoven $ |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
5 * |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
7 * Bill Soudan <soudan@kde.org> |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
8 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
9 * This program is free software; you can redistribute it and/or modify |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
12 * (at your option) any later version. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
13 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
17 * GNU General Public License for more details. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
18 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
20 * along with this program; if not, write to the Free Software |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
22 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
23 */ |
1152 | 24 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
25 /* |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
26 * Peer-to-peer ICQ protocol implementation |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
27 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
28 * Uses version 2 of the ICQ protocol |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
29 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
30 * Thanks to Douglas F. McLaughlin and many others for |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
31 * packet details (see tcp02.txt) |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
32 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
33 */ |
1152 | 34 |
35 #include <stdlib.h> | |
36 | |
37 #include <fcntl.h> | |
38 #include <errno.h> | |
39 | |
40 #ifdef _WIN32 | |
41 #include <winsock.h> | |
42 #endif | |
43 | |
44 #include <sys/stat.h> | |
45 | |
46 #include "icqlib.h" | |
47 | |
48 #include "tcp.h" | |
49 #include "stdpackets.h" | |
50 #include "chatsession.h" | |
51 #include "filesession.h" | |
52 | |
53 /** | |
54 Initializes structures necessary for TCP use. Not required by user | |
55 programs. | |
56 | |
57 \return true on error | |
58 */ | |
59 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
60 int icq_TCPInit(icq_Link *icqlink) |
1152 | 61 { |
62 icq_TCPLink *plink; | |
63 | |
64 /* allocate lists */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
65 icqlink->d->icq_TCPLinks=icq_ListNew(); |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
66 icqlink->d->icq_ChatSessions=icq_ListNew(); |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
67 icqlink->d->icq_FileSessions=icq_ListNew(); |
1152 | 68 |
69 /* only the main listening socket gets created upon initialization - | |
70 * the other two are created when necessary */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
71 plink=icq_TCPLinkNew(icqlink); |
1152 | 72 icq_TCPLinkListen(plink); |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
73 icqlink->icq_TCPSrvPort=ntohs(plink->socket_address.sin_port); |
1152 | 74 |
75 /* reset tcp sequence number */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
76 icqlink->d->icq_TCPSequence=0xfffffffe; |
1152 | 77 |
78 return 0; | |
79 } | |
80 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
81 void icq_TCPDone(icq_Link *icqlink) |
1152 | 82 { |
83 /* close and deallocate all tcp links, this will also close any attached | |
84 * file or chat sessions */ | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
85 if (icqlink->d->icq_TCPLinks) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
86 icq_ListDelete(icqlink->d->icq_TCPLinks, icq_TCPLinkDelete); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
87 icqlink->d->icq_TCPLinks = 0; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
88 } |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
89 if (icqlink->d->icq_ChatSessions) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
90 icq_ListDelete(icqlink->d->icq_ChatSessions, icq_ChatSessionDelete); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
91 icqlink->d->icq_ChatSessions = 0; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
92 } |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
93 if (icqlink->d->icq_FileSessions) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
94 icq_ListDelete(icqlink->d->icq_FileSessions, icq_FileSessionDelete); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
95 icqlink->d->icq_FileSessions = 0; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
96 } |
1152 | 97 } |
98 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
99 icq_TCPLink *icq_TCPCheckLink(icq_Link *icqlink, DWORD uin, int type) |
1152 | 100 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
101 icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, type); |
1152 | 102 |
103 if(!plink) | |
104 { | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
105 plink=icq_TCPLinkNew(icqlink); |
1152 | 106 if(type==TCP_LINK_MESSAGE) |
107 icq_TCPLinkConnect(plink, uin, 0); | |
108 } | |
109 | |
110 return plink; | |
111 } | |
112 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
113 DWORD icq_TCPSendMessage(icq_Link *icqlink, DWORD uin, const char *message) |
1152 | 114 { |
115 icq_TCPLink *plink; | |
116 icq_Packet *p; | |
117 DWORD sequence; | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
118 char data[ICQ_MAX_MESSAGE_SIZE] ; |
1152 | 119 |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
120 strncpy(data,message,sizeof(data)) ; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
121 data[sizeof(data)-1]='\0'; |
1152 | 122 icq_RusConv("kw", data) ; |
123 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
124 plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 125 |
126 /* create and send the message packet */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
127 p=icq_TCPCreateMessagePacket(plink, data); |
1152 | 128 sequence=icq_TCPLinkSendSeq(plink, p, 0); |
129 | |
130 #ifdef TCP_PACKET_TRACE | |
131 printf("message packet sent to uin %lu { sequence=%lx }\n", uin, p->id); | |
132 #endif | |
133 | |
134 return sequence; | |
135 } | |
136 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
137 DWORD icq_TCPSendURL(icq_Link *icqlink, DWORD uin, const char *message, const char *url) |
1152 | 138 { |
139 icq_TCPLink *plink; | |
140 icq_Packet *p; | |
141 DWORD sequence; | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
142 char data[ICQ_MAX_MESSAGE_SIZE]; |
1152 | 143 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
144 plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 145 |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
146 strncpy(data, message, sizeof(data)); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
147 data[sizeof(data)-1] = '\0'; |
1152 | 148 icq_RusConv("kw", data); |
149 | |
150 /* create and send the url packet */ | |
151 p=icq_TCPCreateURLPacket(plink, data, url); | |
152 sequence=icq_TCPLinkSendSeq(plink, p, 0); | |
153 | |
154 #ifdef TCP_PACKET_TRACE | |
155 printf("url packet queued for uin %lu { sequence=%lx }\n", uin, p->id); | |
156 #endif | |
157 | |
158 return sequence; | |
159 } | |
160 | |
2013
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
161 DWORD icq_TCPSendAwayMessageReq(icq_Link *icqlink, DWORD uin, int status) |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
162 { |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
163 icq_TCPLink *plink; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
164 icq_Packet *p; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
165 DWORD sequence; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
166 WORD type; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
167 |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
168 plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
169 |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
170 /* create and send the message packet */ |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
171 switch(status) |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
172 { |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
173 case STATUS_AWAY: |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
174 type=ICQ_TCP_MSG_READAWAY; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
175 break; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
176 case STATUS_DND: |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
177 type=ICQ_TCP_MSG_READDND; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
178 break; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
179 case STATUS_NA: |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
180 type=ICQ_TCP_MSG_READNA; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
181 break; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
182 case STATUS_OCCUPIED: |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
183 type=ICQ_TCP_MSG_READOCCUPIED; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
184 break; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
185 case STATUS_FREE_CHAT: |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
186 type=ICQ_TCP_MSG_READFFC; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
187 break; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
188 default: |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
189 type=ICQ_TCP_MSG_READAWAY; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
190 break; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
191 } |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
192 p=icq_TCPCreateAwayReqPacket(plink, type); |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
193 sequence=icq_TCPLinkSendSeq(plink, p, 0); |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
194 |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
195 #ifdef TCP_PACKET_TRACE |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
196 printf("away msg request packet sent to uin %lu { sequence=%lx }\n", uin, p->id); |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
197 #endif |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
198 |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
199 return sequence; |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
200 } |
0be1e533036c
[gaim-migrate @ 2023]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1977
diff
changeset
|
201 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
202 DWORD icq_SendChatRequest(icq_Link *icqlink, DWORD uin, const char *message) |
1152 | 203 { |
204 icq_TCPLink *plink; | |
205 icq_Packet *p; | |
206 DWORD sequence; | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
207 char data[ICQ_MAX_MESSAGE_SIZE]; |
1152 | 208 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
209 plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 210 |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
211 strncpy(data, message, sizeof(data)); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
212 data[sizeof(data)-1] = '\0'; |
1152 | 213 icq_RusConv("kw", data); |
214 | |
215 /* create and send the url packet */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
216 p=icq_TCPCreateChatReqPacket(plink, data); |
1152 | 217 sequence=icq_TCPLinkSendSeq(plink, p, 0); |
218 | |
219 #ifdef TCP_PACKET_TRACE | |
220 printf("chat req packet sent to uin %lu { sequence=%lx }\n", uin, p->id); | |
221 #endif | |
222 | |
223 return sequence; | |
224 } | |
225 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
226 unsigned long icq_SendFileRequest(icq_Link *icqlink, unsigned long uin, |
1152 | 227 const char *message, char **files) |
228 { | |
229 icq_TCPLink *plink; | |
230 icq_FileSession *pfile; | |
231 icq_Packet *p; | |
232 unsigned long sequence; | |
233 char filename[64]; | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
234 char data[ICQ_MAX_MESSAGE_SIZE]; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
235 char **filesiterator; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
236 char **pfilesiterator; |
1152 | 237 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
238 plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 239 |
240 /* create the file session, this will be linked to the incoming icq_TCPLink | |
241 * in icq_HandleFileAck */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
242 pfile=icq_FileSessionNew(icqlink); |
1152 | 243 pfile->remote_uin=uin; |
244 pfile->files=files; | |
245 pfile->direction=FILE_STATUS_SENDING; | |
246 | |
247 /* count the number and size of the files */ | |
248 pfile->total_files=0; | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
249 filesiterator = files; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
250 while(*filesiterator) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
251 #ifdef _WIN32 |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
252 struct _stat file_status; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
253 if(_stat(*filesiterator, &file_status)==0) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
254 #else |
1152 | 255 struct stat file_status; |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
256 if(stat(*filesiterator, &file_status)==0) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
257 #endif |
1152 | 258 pfile->total_files++; |
259 pfile->total_bytes+=file_status.st_size; | |
260 } | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
261 filesiterator++; |
1152 | 262 } |
263 | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
264 pfile->files=(char **)malloc(sizeof(char *)*(pfile->total_files +1)); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
265 filesiterator = files; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
266 pfilesiterator = pfile->files; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
267 while (*filesiterator) { |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
268 *pfilesiterator=(char *)malloc(strlen(*filesiterator)+1); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
269 strcpy(*pfilesiterator,*filesiterator); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
270 filesiterator++; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
271 pfilesiterator++; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
272 } |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
273 *pfilesiterator = NULL; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
274 |
1152 | 275 strncpy(filename, *(pfile->files), 64); |
276 | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
277 strncpy(data, message, sizeof(data)); |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
278 data[sizeof(data)-1]='\0'; |
1152 | 279 icq_RusConv("kw", data); |
280 | |
281 /* create and send the file req packet */ | |
282 p=icq_TCPCreateFileReqPacket(plink, (char *)data, filename, | |
283 pfile->total_bytes); | |
284 sequence=icq_TCPLinkSendSeq(plink, p, 0); | |
285 pfile->id=sequence; | |
286 | |
287 #ifdef TCP_PACKET_TRACE | |
288 printf("file req packet sent to uin %lu { sequence=%lx }\n", uin, p->id); | |
289 #endif | |
290 | |
291 return sequence; | |
292 } | |
293 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
294 void icq_AcceptChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) |
1152 | 295 { |
296 icq_TCPLink *pmessage, *plisten; | |
297 icq_ChatSession *pchat; | |
298 icq_Packet *p; | |
299 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
300 pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 301 |
302 /* create the chat listening socket if necessary */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
303 if(!(plisten=icq_FindTCPLink(icqlink, 0, TCP_LINK_CHAT))) |
1152 | 304 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
305 plisten=icq_TCPLinkNew(icqlink); |
1152 | 306 plisten->type=TCP_LINK_CHAT; |
307 icq_TCPLinkListen(plisten); | |
308 } | |
309 | |
310 /* create the chat session, this will be linked to the incoming icq_TCPLink | |
311 * in TCPProcessHello */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
312 pchat=icq_ChatSessionNew(icqlink); |
1152 | 313 pchat->id=sequence; |
314 pchat->remote_uin=uin; | |
315 | |
316 /* create and send the ack packet */ | |
317 p=icq_TCPCreateChatReqAck(pmessage, | |
318 ntohs(plisten->socket_address.sin_port)); | |
319 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
320 | |
321 #ifdef TCP_PACKET_TRACE | |
322 printf("chat req ack sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
323 #endif | |
324 } | |
325 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
326 void icq_TCPSendChatData(icq_Link *icqlink, DWORD uin, const char *data) |
1152 | 327 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
328 icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_CHAT); |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
329 char data1[ICQ_MAX_MESSAGE_SIZE]; |
1152 | 330 int data1_len; |
331 | |
332 if(!plink) | |
333 return; | |
334 | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
335 strncpy(data1,data,sizeof(data1)) ; |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
336 data1[sizeof(data1)-1] = '\0'; |
1152 | 337 data1_len = strlen(data); |
338 icq_ChatRusConv_n("kw", data1, data1_len); | |
339 | |
340 send(plink->socket, data1, data1_len, 0); | |
341 } | |
342 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
343 void icq_TCPSendChatData_n(icq_Link *icqlink, DWORD uin, const char *data, int len) |
1152 | 344 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
345 icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_CHAT); |
1152 | 346 char *data1; |
347 | |
348 if(!plink) | |
349 return; | |
350 | |
351 data1 = (char *)malloc(len); | |
352 memcpy(data1, data, len); | |
353 icq_ChatRusConv_n("kw", data1, len); | |
354 | |
355 send(plink->socket, data1, len, 0); | |
356 } | |
357 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
358 icq_FileSession *icq_AcceptFileRequest(icq_Link *icqlink, DWORD uin, |
1152 | 359 unsigned long sequence) |
360 { | |
361 icq_TCPLink *pmessage, *plisten; | |
362 icq_FileSession *pfile; | |
363 icq_Packet *p; | |
364 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
365 pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 366 |
367 /* create the file listening socket if necessary */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
368 if(!(plisten=icq_FindTCPLink(icqlink, 0, TCP_LINK_FILE))) |
1152 | 369 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
370 plisten=icq_TCPLinkNew(icqlink); |
1152 | 371 plisten->type=TCP_LINK_FILE; |
372 icq_TCPLinkListen(plisten); | |
373 } | |
374 | |
375 /* create the file session, this will be linked to the incoming icq_TCPLink | |
376 * in TCPProcessHello */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
377 pfile=icq_FileSessionNew(icqlink); |
1152 | 378 pfile->id=sequence; |
379 pfile->remote_uin=uin; | |
380 pfile->direction=FILE_STATUS_RECEIVING; | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
381 pfile->tcplink=plisten; |
1152 | 382 icq_FileSessionSetStatus(pfile, FILE_STATUS_LISTENING); |
383 | |
384 /* create and send the ack packet */ | |
385 p=icq_TCPCreateFileReqAck(pmessage, | |
386 ntohs(plisten->socket_address.sin_port)); | |
387 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
388 | |
389 #ifdef TCP_PACKET_TRACE | |
390 printf("file req ack sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
391 #endif | |
392 | |
393 return pfile; | |
394 } | |
395 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
396 void icq_RefuseFileRequest(icq_Link *icqlink, DWORD uin, |
1152 | 397 unsigned long sequence, const char *reason) |
398 { | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
399 icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 400 icq_Packet *p; |
401 | |
402 /* create and send the refuse packet */ | |
403 p=icq_TCPCreateFileReqRefuse(pmessage, | |
404 ntohs(pmessage->socket_address.sin_port), reason); | |
405 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
406 | |
407 #ifdef TCP_PACKET_TRACE | |
408 printf("file req refuse sent to uin %lu { sequence=%lx, reason=\"%s\" }\n", | |
409 uin, sequence, reason); | |
410 #endif | |
411 } | |
412 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
413 void icq_CancelFileRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) |
1152 | 414 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
415 icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
416 icq_FileSession *psession=icq_FindFileSession(icqlink, uin, sequence); |
1152 | 417 icq_Packet *p; |
418 | |
419 if (psession) | |
420 icq_FileSessionClose(psession); | |
421 | |
422 /* create and send the cancel packet */ | |
423 p=icq_TCPCreateFileReqCancel(pmessage, | |
424 ntohs(pmessage->socket_address.sin_port)); | |
425 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
426 #ifdef TCP_PACKET_TRACE | |
427 printf("file req cancel sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
428 #endif | |
429 } | |
430 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
431 void icq_RefuseChatRequest(icq_Link *icqlink, DWORD uin, |
1152 | 432 unsigned long sequence, const char *reason) |
433 { | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
434 icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1152 | 435 icq_Packet *p; |
436 | |
437 /* create and send the refuse packet */ | |
438 p=icq_TCPCreateChatReqRefuse(pmessage, | |
439 ntohs(pmessage->socket_address.sin_port), reason); | |
440 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
441 | |
442 #ifdef TCP_PACKET_TRACE | |
443 printf("chat req refuse sent to uin %lu { sequence=%lx, reason=\"%s\" }\n", | |
444 uin, sequence, reason); | |
445 #endif | |
446 } | |
447 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
448 void icq_CancelChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence) |
1152 | 449 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
450 icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE); |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
451 icq_ChatSession *psession=icq_FindChatSession(icqlink, uin); |
1152 | 452 icq_Packet *p; |
453 | |
454 if (psession) | |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
455 icq_ChatSessionClose(psession); |
1152 | 456 |
457 /* create and send the cancel packet */ | |
458 p=icq_TCPCreateChatReqCancel(pmessage, | |
459 ntohs(pmessage->socket_address.sin_port)); | |
460 (void)icq_TCPLinkSendSeq(pmessage, p, sequence); | |
461 | |
462 #ifdef TCP_PACKET_TRACE | |
463 printf("chat req cancel sent to uin %lu { sequence=%lx }\n", uin, sequence); | |
464 #endif | |
465 } |