comparison plugins/icq/tcpfilehandle.c @ 1432:4c510ca3563f

[gaim-migrate @ 1442] icqlib 1.1.5 committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 28 Jan 2001 01:52:27 +0000
parents 0a766047b4fd
children 8ed70631ed15
comparison
equal deleted inserted replaced
1431:0137bacd63c8 1432:4c510ca3563f
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* 2 /*
3 $Id: tcpfilehandle.c 1319 2000-12-19 10:08:29Z warmenhoven $ 3 $Id: tcpfilehandle.c 1442 2001-01-28 01:52:27Z warmenhoven $
4 $Log$ 4 $Log$
5 Revision 1.2 2000/12/19 10:08:29 warmenhoven 5 Revision 1.3 2001/01/28 01:52:27 warmenhoven
6 Yay, new icqlib 6 icqlib 1.1.5
7
8 Revision 1.16 2001/01/17 01:29:17 bills
9 Rework chat and file session interfaces; implement socket notifications.
7 10
8 Revision 1.15 2000/07/24 03:10:08 bills 11 Revision 1.15 2000/07/24 03:10:08 bills
9 added support for real nickname during TCP transactions like file and 12 added support for real nickname during TCP transactions like file and
10 chat, instead of using Bill all the time (hmm, where'd I get that from? :) 13 chat, instead of using Bill all the time (hmm, where'd I get that from? :)
11 14
108 } 111 }
109 112
110 void icq_TCPProcessFilePacket(icq_Packet *p, icq_TCPLink *plink) 113 void icq_TCPProcessFilePacket(icq_Packet *p, icq_TCPLink *plink)
111 { 114 {
112 icq_FileSession *psession=(icq_FileSession *)plink->session; 115 icq_FileSession *psession=(icq_FileSession *)plink->session;
116 ICQLINK *icqlink = plink->icqlink;
113 BYTE type; 117 BYTE type;
114 DWORD num_files; 118 DWORD num_files;
115 DWORD total_bytes; 119 DWORD total_bytes;
116 DWORD speed; 120 DWORD speed;
117 DWORD filesize; 121 DWORD filesize;
134 name=icq_PacketReadString(p); 138 name=icq_PacketReadString(p);
135 psession->total_files=num_files; 139 psession->total_files=num_files;
136 psession->total_bytes=total_bytes; 140 psession->total_bytes=total_bytes;
137 psession->current_speed=speed; 141 psession->current_speed=speed;
138 icq_FileSessionSetHandle(psession, name); 142 icq_FileSessionSetHandle(psession, name);
139 icq_FileSessionSetStatus(psession, FILE_STATUS_INITIALIZED); 143 icq_FileSessionSetStatus(psession, FILE_STATUS_INITIALIZING);
140 144
141 /* respond */ 145 /* respond */
142 presponse=icq_TCPCreateFile01Packet(speed, plink->icqlink->icq_Nick); 146 presponse=icq_TCPCreateFile01Packet(speed, icqlink->icq_Nick);
143 147
144 icq_TCPLinkSend(plink, presponse); 148 icq_TCPLinkSend(plink, presponse);
145 #ifdef TCP_PACKET_TRACE 149 #ifdef TCP_PACKET_TRACE
146 printf("file 01 packet sent to uin %lu\n", plink->remote_uin); 150 printf("file 01 packet sent to uin %lu\n", plink->remote_uin);
147 #endif 151 #endif
151 case 0x01: 155 case 0x01:
152 speed=icq_PacketRead32(p); 156 speed=icq_PacketRead32(p);
153 name=icq_PacketReadString(p); 157 name=icq_PacketReadString(p);
154 psession->current_speed=speed; 158 psession->current_speed=speed;
155 icq_FileSessionSetHandle(psession, name); 159 icq_FileSessionSetHandle(psession, name);
156 icq_FileSessionSetStatus(psession, FILE_STATUS_INITIALIZED); 160 icq_FileSessionSetStatus(psession, FILE_STATUS_INITIALIZING);
157 161
158 /* respond */ 162 /* respond */
159 icq_FileSessionPrepareNextFile(psession); 163 icq_FileSessionPrepareNextFile(psession);
160 presponse=icq_TCPCreateFile02Packet(psession->current_file, 164 presponse=icq_TCPCreateFile02Packet(psession->current_file,
161 psession->current_file_size, psession->current_speed); 165 psession->current_file_size, psession->current_speed);
191 icq_TCPLinkSend(plink, presponse); 195 icq_TCPLinkSend(plink, presponse);
192 #ifdef TCP_PACKET_TRACE 196 #ifdef TCP_PACKET_TRACE
193 printf("file 03 packet sent to uin %lu\n", plink->remote_uin); 197 printf("file 03 packet sent to uin %lu\n", plink->remote_uin);
194 #endif 198 #endif
195 break; 199 break;
196 200
197 case 0x03: 201 case 0x03:
198 filesize=icq_PacketRead32(p); 202 filesize=icq_PacketRead32(p);
199 (void)icq_PacketRead32(p); 203 (void)icq_PacketRead32(p);
200 speed=icq_PacketRead32(p); 204 speed=icq_PacketRead32(p);
201 psession->current_file_progress=filesize; 205 psession->current_file_progress=filesize;
206 icq_FileSessionSetStatus(psession, FILE_STATUS_SENDING); 210 icq_FileSessionSetStatus(psession, FILE_STATUS_SENDING);
207 break; 211 break;
208 212
209 case 0x04: 213 case 0x04:
210 (void)icq_PacketRead32(p); 214 (void)icq_PacketRead32(p);
211 icq_FileSessionSetStatus(psession, FILE_STATUS_STOP_FILE); 215 invoke_callback(icqlink, icq_FileNotify)(psession,
216 FILE_NOTIFY_STOP_FILE, 0, NULL);
212 break; 217 break;
213 218
214 case 0x05: 219 case 0x05:
215 speed=icq_PacketRead32(p); 220 speed=icq_PacketRead32(p);
216 psession->current_speed=speed; 221 psession->current_speed=speed;
217 if(plink->icqlink->icq_RequestNotify) 222 invoke_callback(icqlink, icq_FileNotify)(psession,
218 (*plink->icqlink->icq_RequestNotify)(plink->icqlink, plink->id, 223 FILE_NOTIFY_NEW_SPEED, speed, NULL);
219 ICQ_NOTIFY_FILE, FILE_STATUS_NEW_SPEED, 0);
220 break; 224 break;
221 225
222 case 0x06: 226 case 0x06:
223 if(plink->icqlink->icq_RequestNotify) 227 {
224 (*plink->icqlink->icq_RequestNotify)(plink->icqlink, plink->id, ICQ_NOTIFY_FILEDATA, 228 void *data = p->data+sizeof(BYTE);
225 p->length-sizeof(BYTE), p->data+sizeof(BYTE)); 229 int length = p->length-sizeof(BYTE);
230
231 invoke_callback(icqlink, icq_FileNotify)(psession,
232 FILE_NOTIFY_DATAPACKET, length, data);
226 icq_FileSessionSetStatus(psession, FILE_STATUS_RECEIVING); 233 icq_FileSessionSetStatus(psession, FILE_STATUS_RECEIVING);
227 result=write(psession->current_fd, p->data+sizeof(BYTE), p->length-sizeof(BYTE)); 234 result=write(psession->current_fd, data, length);
228 psession->current_file_progress+=p->length-sizeof(BYTE); 235 psession->current_file_progress+=length;
229 psession->total_transferred_bytes+=p->length-sizeof(BYTE); 236 psession->total_transferred_bytes+=length;
230 break; 237 break;
238 }
231 239
232 default: 240 default:
233 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown file packet type %d!\n", type); 241 icq_FmtLog(icqlink, ICQ_LOG_WARNING, "unknown file packet type %d!\n", type);
234 242
235 } 243 }
236 } 244 }
237 245
238 void icq_HandleFileHello(icq_TCPLink *plink) 246 void icq_HandleFileHello(icq_TCPLink *plink)
264 { 272 {
265 icq_TCPLink *pfilelink; 273 icq_TCPLink *pfilelink;
266 icq_FileSession *pfile; 274 icq_FileSession *pfile;
267 icq_Packet *p2; 275 icq_Packet *p2;
268 276
269 if(plink->icqlink->icq_RequestNotify) 277 invoke_callback(plink->icqlink, icq_RequestNotify)(plink->icqlink,
270 (*plink->icqlink->icq_RequestNotify)(plink->icqlink, p->id, ICQ_NOTIFY_ACK, 0, 0); 278 p->id, ICQ_NOTIFY_ACK, 0, NULL);
279
271 pfilelink=icq_TCPLinkNew(plink->icqlink); 280 pfilelink=icq_TCPLinkNew(plink->icqlink);
272 pfilelink->type=TCP_LINK_FILE; 281 pfilelink->type=TCP_LINK_FILE;
273 pfilelink->id=p->id; 282 pfilelink->id=p->id;
274 283
275 /* once the ack packet has been processed, link up with the file session */ 284 /* once the ack packet has been processed, link up with the file session */
276 pfile=icq_FindFileSession(plink->icqlink, plink->remote_uin, 0); 285 pfile=icq_FindFileSession(plink->icqlink, plink->remote_uin, 0);
277 286
278 pfile->tcplink=pfilelink; 287 pfile->tcplink=pfilelink;
279 pfilelink->id=pfile->id; 288 pfilelink->id=pfile->id;
280 289
281 if (plink->icqlink->icq_RequestNotify) 290 invoke_callback(plink->icqlink, icq_RequestNotify)(plink->icqlink,
282 (*plink->icqlink->icq_RequestNotify)(plink->icqlink, pfile->id, 291 pfile->id, ICQ_NOTIFY_FILESESSION, sizeof(icq_FileSession), pfile);
283 ICQ_NOTIFY_FILESESSION, sizeof(icq_FileSession), pfile); 292 invoke_callback(plink->icqlink, icq_RequestNotify)(plink->icqlink,
293 pfile->id, ICQ_NOTIFY_SUCCESS, 0, NULL);
284 294
285 icq_FileSessionSetStatus(pfile, FILE_STATUS_CONNECTING); 295 icq_FileSessionSetStatus(pfile, FILE_STATUS_CONNECTING);
286 icq_TCPLinkConnect(pfilelink, plink->remote_uin, port); 296 icq_TCPLinkConnect(pfilelink, plink->remote_uin, port);
287 297
288 pfilelink->session=pfile; 298 pfilelink->session=pfile;