Mercurial > pidgin.yaz
annotate plugins/icq/tcpchathandle.c @ 1812:b012f6b9095b
[gaim-migrate @ 1822]
flip
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 05 May 2001 22:27:51 +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: tcpchathandle.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.9 2001/01/17 01:29:17 bills |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
9 Rework chat and file session interfaces; implement socket notifications. |
1152 | 10 |
11 Revision 1.8 2000/07/24 03:10:08 bills | |
12 added support for real nickname during TCP transactions like file and | |
13 chat, instead of using Bill all the time (hmm, where'd I get that from? :) | |
14 | |
15 Revision 1.7 2000/07/09 22:19:35 bills | |
16 added new *Close functions, use *Close functions instead of *Delete | |
17 where correct, and misc cleanup | |
18 | |
19 Revision 1.6 2000/05/04 15:57:20 bills | |
20 Reworked file transfer notification, small bugfixes, and cleanups. | |
21 | |
22 Revision 1.5 2000/05/03 18:29:15 denis | |
23 Callbacks have been moved to the ICQLINK structure. | |
24 | |
25 Revision 1.4 2000/04/05 14:37:02 denis | |
26 Applied patch from "Guillaume R." <grs@mail.com> for basic Win32 | |
27 compatibility. | |
28 | |
29 Revision 1.3 2000/02/07 02:54:45 bills | |
30 warning cleanups. | |
31 | |
32 Revision 1.2 2000/02/07 02:43:37 bills | |
33 new code for special chat functions (background, fonts, etc) | |
34 | |
35 Revision 1.1 1999/09/29 19:47:21 bills | |
36 reworked chat/file handling. fixed chat. (it's been broke since I put | |
37 non-blocking connects in) | |
38 | |
39 */ | |
40 | |
41 #include <time.h> | |
42 | |
43 #ifndef _WIN32 | |
44 #include <unistd.h> | |
45 #endif | |
46 | |
47 #include <stdlib.h> | |
48 | |
49 #include "icqtypes.h" | |
50 #include "icq.h" | |
51 #include "icqlib.h" | |
52 | |
53 #include "stdpackets.h" | |
54 #include "tcplink.h" | |
55 #include "chatsession.h" | |
56 | |
57 void icq_HandleChatAck(icq_TCPLink *plink, icq_Packet *p, int port) | |
58 { | |
59 icq_TCPLink *pchatlink; | |
60 icq_ChatSession *pchat; | |
61 icq_Packet *p2; | |
62 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
63 invoke_callback(plink->icqlink, icq_RequestNotify)(plink->icqlink, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
64 p->id, ICQ_NOTIFY_ACK, 0, NULL); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
65 |
1152 | 66 pchatlink=icq_TCPLinkNew(plink->icqlink); |
67 pchatlink->type=TCP_LINK_CHAT; | |
68 pchatlink->id=p->id; | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
69 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
70 /* once the ack packet has been processed, create a new chat session */ |
1152 | 71 pchat=icq_ChatSessionNew(plink->icqlink); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
72 |
1152 | 73 pchat->id=p->id; |
74 pchat->remote_uin=plink->remote_uin; | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
75 pchat->tcplink=pchatlink; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
76 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
77 invoke_callback(plink->icqlink, icq_RequestNotify)(plink->icqlink, p->id, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
78 ICQ_NOTIFY_CHATSESSION, sizeof(icq_ChatSession), pchat); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
79 invoke_callback(plink->icqlink, icq_RequestNotify)(plink->icqlink, p->id, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
80 ICQ_NOTIFY_SUCCESS, 0, NULL); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
81 |
1152 | 82 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_CONNECTING); |
83 icq_TCPLinkConnect(pchatlink, plink->remote_uin, port); | |
84 | |
85 pchatlink->session=pchat; | |
86 | |
87 p2=icq_TCPCreateChatInfoPacket(pchatlink, plink->icqlink->icq_Nick, | |
88 0x00ffffff, 0x00000000); | |
89 icq_TCPLinkSend(pchatlink, p2); | |
90 | |
91 } | |
92 | |
93 void icq_HandleChatHello(icq_TCPLink *plink) | |
94 { | |
95 | |
96 /* once the hello packet has been processed and we know which uin this | |
97 * link is for, we can link up with a chat session */ | |
98 icq_ChatSession *pchat=icq_FindChatSession(plink->icqlink, | |
99 plink->remote_uin); | |
100 | |
101 if(pchat) | |
102 { | |
103 plink->id=pchat->id; | |
104 plink->session=pchat; | |
105 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_WAIT_NAME); | |
106 | |
107 } else { | |
108 | |
109 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, | |
110 "unexpected chat hello received from %d, closing link\n", | |
111 plink->remote_uin); | |
112 icq_TCPLinkClose(plink); | |
113 } | |
114 | |
115 } | |
116 | |
117 void icq_TCPOnChatReqReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id) | |
118 { | |
119 #ifdef TCP_PACKET_TRACE | |
120 printf("chat request packet received from %lu { sequence=%lx, message=%s }\n", | |
121 uin, id, message); | |
122 #endif /* TCP_PACKET_TRACE */ | |
123 | |
124 if(link->icq_RecvChatReq) { | |
125 | |
126 /* use the current system time for time received */ | |
127 time_t t=time(0); | |
128 struct tm *ptime=localtime(&t); | |
129 | |
130 (*link->icq_RecvChatReq)(link, uin, ptime->tm_hour, ptime->tm_min, | |
131 ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, message, id); | |
132 | |
133 /* don't send an acknowledgement to the remote client! | |
134 * GUI is responsible for sending acknowledgement once user accepts | |
135 * or denies using icq_TCPSendChatAck */ | |
136 } | |
137 } | |
138 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
139 void icq_TCPChatUpdateFont(icq_ChatSession *psession, const char *font, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
140 WORD encoding, DWORD style, DWORD size) |
1152 | 141 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
142 ICQLINK *icqlink = psession->icqlink; |
1152 | 143 int packet_len, fontlen; |
144 char *buffer; | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
145 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
146 buffer = malloc(packet_len = (2 + (fontlen = strlen(font) + 1)) + |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
147 2 + 1 + (4+1)*2); |
1152 | 148 buffer[0] = '\x11'; |
149 *((DWORD *)&buffer[1]) = style; | |
150 buffer[5] = '\x12'; | |
151 *((DWORD *)&buffer[6]) = size; | |
152 buffer[10] = '\x10'; | |
153 *((WORD *)&buffer[11]) = fontlen; | |
154 strcpy(&buffer[13], font); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
155 |
1152 | 156 icq_RusConv("wk", &buffer[13]); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
157 |
1152 | 158 *((WORD *)&buffer[13 + fontlen]) = encoding; |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
159 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
160 invoke_callback(icqlink, icq_ChatNotify)(psession, CHAT_NOTIFY_DATA, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
161 packet_len, buffer); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
162 |
1152 | 163 free(buffer); |
164 } | |
165 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
166 void icq_TCPChatUpdateColors(icq_ChatSession *psession, DWORD foreground, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
167 DWORD background) |
1152 | 168 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
169 ICQLINK *icqlink = psession->icqlink; |
1152 | 170 char buffer[10]; |
171 | |
172 buffer[0] = '\x00'; | |
173 *((DWORD *)&buffer[1]) = foreground; | |
174 buffer[5] = '\x01'; | |
175 *((DWORD *)&buffer[6]) = background; | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
176 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
177 invoke_callback(icqlink, icq_ChatNotify)(psession, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
178 CHAT_NOTIFY_DATA, sizeof(buffer), buffer); |
1152 | 179 } |
180 | |
181 void icq_TCPProcessChatPacket(icq_Packet *p, icq_TCPLink *plink) | |
182 { | |
183 DWORD code; | |
184 DWORD remote_uin; | |
185 DWORD ip1, ip2; | |
186 DWORD fg, bg, fontstyle, fontsize; | |
187 WORD port1, encoding; | |
188 icq_Packet *presponse; | |
189 icq_ChatSession *pchat=(icq_ChatSession *)plink->session; | |
190 const char *font, *user; | |
191 | |
192 icq_PacketBegin(p); | |
193 | |
194 code=icq_PacketRead32(p); | |
195 remote_uin=icq_PacketRead32(p); | |
196 | |
197 if(code==0x00000006 || code==0x00070004) | |
198 { | |
199 font = (char *)NULL; | |
200 encoding = 0; | |
201 fontstyle = 0; | |
202 fontsize = 0; | |
203 if(code == 0x00070004) | |
204 { | |
205 ip1 = icq_PacketRead32(p); | |
206 ip2 = icq_PacketRead32(p); | |
207 icq_PacketRead8(p); | |
208 port1 = icq_PacketRead16(p); | |
209 fontsize = icq_PacketRead32(p); | |
210 fontstyle = icq_PacketRead32(p); | |
211 font = icq_PacketReadString(p); | |
212 encoding = icq_PacketRead16(p); | |
213 } | |
214 else | |
215 { | |
216 ip1 = icq_PacketRead32(p); | |
217 ip2 = icq_PacketRead32(p); | |
218 port1 = icq_PacketRead16(p); | |
219 icq_PacketRead8(p); | |
220 fontsize = icq_PacketRead32(p); | |
221 fontstyle = icq_PacketRead32(p); | |
222 font = icq_PacketReadString(p); | |
223 encoding = icq_PacketRead16(p); | |
224 } | |
225 if(font) | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
226 icq_TCPChatUpdateFont(pchat, font, encoding, fontstyle, fontsize); |
1152 | 227 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_READY); |
228 plink->mode|=TCP_LINK_MODE_RAW; | |
229 } | |
230 else | |
231 if(remote_uin>0xffffff00) | |
232 { | |
233 remote_uin=icq_PacketRead32(p); | |
234 user = icq_PacketReadString(p); | |
235 icq_PacketRead16(p); /* Unknown */; | |
236 fg = icq_PacketRead32(p); | |
237 bg = icq_PacketRead32(p); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
238 icq_TCPChatUpdateColors(pchat, fg, bg); |
1152 | 239 |
240 presponse=icq_TCPCreateChatInfo2Packet(plink, plink->icqlink->icq_Nick, | |
241 0x00ffffff, 0x00000000); | |
242 icq_PacketSend(presponse, plink->socket); | |
243 icq_PacketDelete(presponse); | |
244 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_WAIT_FONT); | |
245 } | |
246 else | |
247 { | |
248 user = icq_PacketReadString(p); | |
249 fg = icq_PacketRead32(p); | |
250 bg = icq_PacketRead32(p); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
251 icq_TCPChatUpdateColors(pchat, fg, bg); |
1152 | 252 font = (char *)NULL; |
253 encoding = 0; | |
254 fontstyle = 0; | |
255 fontsize = 0; | |
256 if((code = icq_PacketRead32(p)) == 0x00070004) | |
257 { | |
258 icq_PacketRead32(p); | |
259 ip1 = icq_PacketRead32(p); | |
260 ip2 = icq_PacketRead32(p); | |
261 icq_PacketRead8(p); | |
262 port1 = icq_PacketRead16(p); | |
263 fontsize = icq_PacketRead32(p); | |
264 fontstyle = icq_PacketRead32(p); | |
265 font = icq_PacketReadString(p); | |
266 encoding = icq_PacketRead16(p); | |
267 } | |
268 else if(code == 0x00000006) | |
269 { | |
270 icq_PacketRead32(p); | |
271 ip1 = icq_PacketRead32(p); | |
272 ip2 = icq_PacketRead32(p); | |
273 port1 = icq_PacketRead16(p); | |
274 icq_PacketRead8(p); | |
275 fontsize = icq_PacketRead32(p); | |
276 fontstyle = icq_PacketRead32(p); | |
277 font = icq_PacketReadString(p); | |
278 encoding = icq_PacketRead16(p); | |
279 } | |
280 if(font) | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
281 icq_TCPChatUpdateFont(pchat, font, encoding, fontstyle, fontsize); |
1152 | 282 presponse=icq_TCPCreateChatFontInfoPacket(plink); |
283 icq_PacketSend(presponse, plink->socket); | |
284 icq_PacketDelete(presponse); | |
285 /* notify app that chat connection has been established */ | |
286 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_READY); | |
287 plink->mode|=TCP_LINK_MODE_RAW; | |
288 } | |
289 } | |
290 |