Mercurial > pidgin.yaz
annotate src/protocols/icq/eventhandle.c @ 7077:6d10bf28be0e
[gaim-migrate @ 7642]
fix a compile warning
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 30 Sep 2003 18:40:18 +0000 |
parents | f0a2a9afdb77 |
children |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | |
3 /* | |
2496
f0a2a9afdb77
[gaim-migrate @ 2509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
4 * $Id: eventhandle.c 2509 2001-10-13 00:06:18Z warmenhoven $ |
2086 | 5 * |
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and | |
7 * Bill Soudan <soudan@kde.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 * | |
23 */ | |
24 | |
25 #include <time.h> | |
26 | |
27 #ifndef _WIN32 | |
28 #include <unistd.h> | |
29 #endif | |
30 | |
31 #include "icqevent.h" | |
32 #include "icqpacket.h" | |
33 #include "tcplink.h" | |
34 #include "chatsession.h" | |
35 #include "filesession.h" | |
36 | |
37 #include "eventhandle.h" | |
38 | |
39 void icq_TCPProcessPacket2(icq_Packet *p, icq_TCPLink *tcplink) | |
40 { | |
41 icq_MessageEvent *pevent=(icq_MessageEvent *)icq_ParsePacket(p); | |
42 icq_Event *pbase=(icq_Event *)pevent; | |
43 | |
44 icq_Link *icqlink=tcplink->icqlink; | |
45 | |
46 if (pbase->uin != tcplink->remote_uin) | |
47 { | |
48 /* TODO: spoofed packet! */ | |
49 } | |
50 | |
51 pbase->handleEvent(pbase, icqlink); | |
52 | |
53 /* notify library client than the ack was received from remote client */ | |
54 if (pbase->subtype==ICQ_EVENT_ACK) | |
55 { | |
56 icq_FmtLog(tcplink->icqlink, ICQ_LOG_MESSAGE, "received ack %d\n", p->id); | |
57 if(icqlink->icq_RequestNotify) | |
58 { | |
59 (*icqlink->icq_RequestNotify)(icqlink, pbase->id, | |
60 ICQ_NOTIFY_ACK, pevent->status, (void *)pevent->message); | |
61 (*icqlink->icq_RequestNotify)(icqlink, pbase->id, | |
62 ICQ_NOTIFY_SUCCESS, 0, 0); | |
63 } | |
64 } | |
65 } | |
66 | |
67 void icq_HandleMessageEvent(icq_Event *pbase, icq_Link *icqlink) | |
68 { | |
69 icq_MessageEvent *pevent=(icq_MessageEvent *)pbase; | |
70 struct tm *ptime=localtime(&(pbase->time)); | |
71 | |
72 if (pbase->subtype==ICQ_EVENT_MESSAGE && icqlink->icq_RecvMessage) | |
73 { | |
74 (*icqlink->icq_RecvMessage)(icqlink, pbase->uin, ptime->tm_hour, | |
75 ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
76 ptime->tm_year+1900, pevent->message); | |
77 /* TODO: send ack */ | |
78 } | |
79 | |
80 } | |
81 | |
82 void icq_HandleURLEvent(icq_Event *pbase, icq_Link *icqlink) | |
83 { | |
84 icq_URLEvent *pevent=(icq_URLEvent *)pbase; | |
85 struct tm *ptime=localtime(&(pbase->time)); | |
86 | |
87 if (pbase->subtype==ICQ_EVENT_MESSAGE && icqlink->icq_RecvURL) | |
88 { | |
89 (*icqlink->icq_RecvURL)(icqlink, pbase->uin, ptime->tm_hour, | |
90 ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
91 ptime->tm_year+1900, pevent->url, pevent->message); | |
92 /* TODO: send ack */ | |
93 } | |
94 } | |
95 | |
96 void icq_HandleChatRequestEvent(icq_Event *pbase, icq_Link *icqlink) | |
97 { | |
98 icq_MessageEvent *pmsgevent=(icq_MessageEvent *)pmsgevent; | |
99 | |
100 struct tm *ptime=localtime(&(pbase->time)); | |
101 | |
102 switch(pbase->subtype) | |
103 { | |
104 case ICQ_EVENT_MESSAGE: | |
105 if (icqlink->icq_RecvChatReq) | |
106 (*icqlink->icq_RecvChatReq)(icqlink, pbase->uin, | |
107 ptime->tm_hour, ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
108 ptime->tm_year+1900, pmsgevent->message, pbase->id); | |
109 /* don't send an ack to the remote client! library client is | |
110 * responsible for sending the ack once the user accepts | |
111 * or denies the request */ | |
112 break; | |
113 case ICQ_EVENT_ACK: | |
114 icq_HandleChatRequestAck(pbase, icqlink); | |
115 break; | |
116 case ICQ_EVENT_CANCEL: | |
117 /* TODO */ | |
118 break; | |
119 default: | |
120 /* TODO */ | |
121 break; | |
122 } | |
123 } | |
124 | |
125 void icq_HandleChatRequestAck(icq_Event *pbase, icq_Link *icqlink) | |
126 { | |
127 icq_ChatRequestEvent *pevent=(icq_ChatRequestEvent *)pbase; | |
128 icq_TCPLink *pchatlink; | |
129 icq_ChatSession *pchat; | |
130 icq_Packet *p2; | |
131 | |
132 /* once a chat request acknowledgement has been received, the remote | |
133 * client opens up a listening port for us. we need to connect to | |
134 * this port and all chat session communication takes place over | |
135 * this new tcp link */ | |
136 pchatlink=icq_TCPLinkNew(icqlink); | |
137 pchatlink->type=TCP_LINK_CHAT; | |
138 pchatlink->id=pbase->id; | |
139 | |
140 /* create a new chat session to manage the communication, and link | |
141 * it to the tcp link */ | |
142 pchat=icq_ChatSessionNew(icqlink); | |
143 pchat->id=pbase->id; | |
144 pchat->remote_uin=pbase->uin; | |
145 pchatlink->session=pchat; | |
146 | |
147 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_CONNECTING); | |
148 | |
149 /* initiate the connection to the remote client's chat session | |
150 * port, which was specified in the ack event they sent */ | |
151 icq_TCPLinkConnect(pchatlink, pbase->uin, pevent->port); | |
152 | |
153 /* send off chat init event */ | |
154 p2=icq_TCPCreateChatInfoPacket(pchatlink, icqlink->icq_Nick, 0x00ffffff, | |
155 0x00000000); | |
156 icq_TCPLinkSend(pchatlink, p2); | |
157 } | |
158 | |
159 | |
160 void icq_HandleFileRequestEvent(icq_Event *pbase, icq_Link *icqlink) | |
161 { | |
162 icq_FileRequestEvent *pevent=(icq_FileRequestEvent *)pbase; | |
163 icq_MessageEvent *pmsgevent=(icq_MessageEvent *)pmsgevent; | |
164 struct tm *ptime=localtime(&(pbase->time)); | |
165 | |
166 switch(pbase->subtype) | |
167 { | |
168 case ICQ_EVENT_MESSAGE: | |
169 if (icqlink->icq_RecvFileReq) | |
170 (*icqlink->icq_RecvFileReq)(icqlink, pbase->uin, | |
171 ptime->tm_hour, ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
172 ptime->tm_year+1900, pmsgevent->message, pevent->filename, | |
173 pevent->filesize, pbase->id); | |
174 /* don't send an ack to the remote client! library client is | |
175 * responsible for sending the ack once the user accepts | |
176 * or denies the request */ | |
177 break; | |
178 case ICQ_EVENT_ACK: | |
179 icq_HandleFileRequestAck(pbase, icqlink); | |
180 break; | |
181 case ICQ_EVENT_CANCEL: | |
182 break; | |
183 default: | |
184 /* TODO */ | |
185 break; | |
186 } | |
187 } | |
188 | |
189 void icq_HandleFileRequestAck(icq_Event *pbase, icq_Link *icqlink) | |
190 { | |
191 icq_FileRequestEvent *pevent=(icq_FileRequestEvent *)pbase; | |
192 icq_TCPLink *pfilelink; | |
193 icq_FileSession *pfile; | |
194 icq_Packet *p2; | |
195 | |
196 /* once a file request acknowledgement has been received, the remote | |
197 * client opens up a listening port for us. we need to connect to | |
198 * this port and all file transfer communication takes place over | |
199 * this new tcp link */ | |
200 pfilelink=icq_TCPLinkNew(icqlink); | |
201 pfilelink->type=TCP_LINK_FILE; | |
202 | |
203 /* a file session was created when the request was initially sent, | |
204 * but it wasn't attached to a tcp link because one did not exist. | |
205 * find the file sesion now and link it to the new tcp link */ | |
206 pfile=icq_FindFileSession(icqlink, pbase->uin, | |
207 pbase->id); /* TODO: make sure find session succeeded */ | |
208 pfile->tcplink=pfilelink; | |
209 pfilelink->id=pfile->id; | |
210 pfilelink->session=pfile; | |
211 | |
212 /* notify the library client of the created file session */ | |
213 if (icqlink->icq_RequestNotify) | |
214 (*icqlink->icq_RequestNotify)(icqlink, pfile->id, | |
215 ICQ_NOTIFY_FILESESSION, sizeof(icq_FileSession), pfile); | |
216 icq_FileSessionSetStatus(pfile, FILE_STATUS_CONNECTING); | |
217 | |
218 /* initiate the connection to the remote client's file session | |
219 * port, which was specified in the ack event they sent */ | |
220 icq_TCPLinkConnect(pfilelink, pbase->uin, pevent->port); | |
221 | |
222 /* send off the file transfer init event */ | |
223 /* TODO: convert file packets to events */ | |
224 p2=icq_TCPCreateFile00Packet( pfile->total_files, | |
225 pfile->total_bytes, pfile->current_speed, icqlink->icq_Nick); | |
226 icq_TCPLinkSend(pfilelink, p2); | |
227 } | |
228 | |
229 | |
230 /* | |
231 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown message type %d!\n", type); | |
232 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown packet command %d!\n", | |
233 command); | |
234 | |
235 TODO: conversion | |
236 strncpy(data,message,512) ; | |
237 icq_RusConv("wk",data) ; | |
238 | |
239 | |
240 TODO: ack code | |
241 | |
242 if(plink) | |
243 { | |
244 pack=icq_TCPCreateMessageAck(plink,0); | |
245 icq_PacketAppend32(pack, id); | |
246 icq_PacketSend(pack, plink->socket); | |
247 icq_PacketDelete(pack); | |
248 } | |
249 */ |