Mercurial > pidgin
annotate src/protocols/icq/stdpackets.c @ 4288:a723d060620a
[gaim-migrate @ 4541]
Here. Now you can like have lots of themes and like make your own and like
switch them and stuff. It's kidna neat, I suppose.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 11 Jan 2003 04:48:10 +0000 |
parents | 6190f75950ff |
children |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | |
3 /* | |
2387
6190f75950ff
[gaim-migrate @ 2400]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
4 * $Id: stdpackets.c 2400 2001-09-28 23:45:19Z 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 <stdlib.h> | |
26 | |
27 #include "icqlib.h" | |
28 #include "tcp.h" | |
29 #include "stdpackets.h" | |
30 | |
31 icq_Packet *icq_TCPCreateInitPacket(icq_TCPLink *plink) | |
32 { | |
33 icq_Packet *p=icq_PacketNew(); | |
34 | |
35 if(p) | |
36 { | |
37 int type=plink->type; | |
38 | |
39 icq_PacketAppend8(p, 0xFF); | |
40 icq_PacketAppend32(p, ICQ_TCP_VER); | |
41 if(type==TCP_LINK_MESSAGE) | |
42 icq_PacketAppend32n(p, htons(plink->icqlink->icq_TCPSrvPort)); | |
43 else | |
44 icq_PacketAppend32(p, 0x00000000); | |
45 icq_PacketAppend32(p, plink->icqlink->icq_Uin); | |
46 icq_PacketAppend32n(p, htonl(plink->icqlink->icq_OurIP)); | |
47 icq_PacketAppend32n(p, htonl(plink->icqlink->icq_OurIP)); | |
48 icq_PacketAppend8(p, 0x04); | |
49 if(type==TCP_LINK_FILE || type==TCP_LINK_CHAT) | |
50 icq_PacketAppend32(p, ntohs(plink->socket_address.sin_port)); | |
51 else | |
52 icq_PacketAppend32(p, 0x00000000); | |
53 | |
54 } | |
55 | |
56 return p; | |
57 } | |
58 | |
59 icq_Packet *icq_TCPCreateStdPacket(icq_TCPLink *plink, WORD icq_TCPCommand, | |
60 WORD type, const char *msg, WORD status, | |
61 WORD msg_command) | |
62 { | |
63 icq_Packet *p=icq_PacketNew(); | |
64 | |
65 if(p) | |
66 { | |
67 icq_PacketAppend32(p, plink->icqlink->icq_Uin); | |
68 icq_PacketAppend16(p, ICQ_TCP_VER); | |
69 icq_PacketAppend16(p, icq_TCPCommand); | |
70 icq_PacketAppend16(p, 0x0000); | |
71 icq_PacketAppend32(p, plink->icqlink->icq_Uin); | |
72 | |
73 icq_PacketAppend16(p, type); | |
74 icq_PacketAppendString(p, (char*)msg); | |
75 | |
76 /* FIXME: this should be the address the server returns to us, | |
77 * link->icq_OurIp */ | |
78 icq_PacketAppend32(p, plink->socket_address.sin_addr.s_addr); | |
79 icq_PacketAppend32(p, plink->socket_address.sin_addr.s_addr); | |
80 icq_PacketAppend32(p, ntohs(plink->socket_address.sin_port)); | |
81 icq_PacketAppend8(p, 0x04); | |
82 icq_PacketAppend16(p, status); | |
83 icq_PacketAppend16(p, msg_command); | |
84 } | |
85 | |
86 return p; | |
87 } | |
88 | |
89 icq_Packet *icq_TCPCreateMessagePacket(icq_TCPLink *plink, const char *message) | |
90 { | |
91 icq_Packet *p=icq_TCPCreateStdPacket( | |
92 plink, | |
93 ICQ_TCP_MESSAGE, | |
94 ICQ_TCP_MSG_MSG, | |
95 message, | |
96 0, /* status */ | |
97 ICQ_TCP_MSG_REAL); | |
98 | |
99 return p; | |
100 } | |
101 | |
102 icq_Packet *icq_TCPCreateAwayReqPacket(icq_TCPLink *plink, WORD statusMode) | |
103 { | |
104 icq_Packet *p=icq_TCPCreateStdPacket( | |
105 plink, | |
106 ICQ_TCP_MESSAGE, | |
2387
6190f75950ff
[gaim-migrate @ 2400]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
107 statusMode, /* one of the icq_tcp_msg_read... constants */ |
2086 | 108 "", |
109 0, /* status */ | |
110 0); | |
111 | |
112 return p; | |
113 } | |
114 | |
115 icq_Packet *icq_TCPCreateURLPacket(icq_TCPLink *plink, const char *message, | |
116 const char *url) | |
117 { | |
118 icq_Packet *p; | |
119 unsigned char *str=(unsigned char*)malloc(strlen(message)+strlen(url)+2); | |
120 | |
121 strcpy((char*)str, message); | |
122 *(str+strlen(message))=0xFE; | |
123 strcpy((char*)(str+strlen(message)+1), url); | |
124 | |
125 p=icq_TCPCreateStdPacket( | |
126 plink, | |
127 ICQ_TCP_MESSAGE, | |
128 ICQ_TCP_MSG_URL, | |
129 (const char *)str, | |
130 0, /* status */ | |
131 ICQ_TCP_MSG_REAL); | |
132 | |
133 free(str); | |
134 | |
135 return p; | |
136 } | |
137 | |
138 icq_Packet *icq_TCPCreateChatReqPacket(icq_TCPLink *plink, const char *message) | |
139 { | |
140 icq_Packet *p=icq_TCPCreateStdPacket( | |
141 plink, | |
142 ICQ_TCP_MESSAGE, | |
143 ICQ_TCP_MSG_CHAT, | |
144 message, | |
145 0, /* status */ | |
146 ICQ_TCP_MSG_REAL); | |
147 | |
148 icq_PacketAppendString(p, 0); | |
149 | |
150 icq_PacketAppend16(p, 0x0000); | |
151 icq_PacketAppend16(p, 0x0000); | |
152 icq_PacketAppend32(p, 0x00000000); | |
153 | |
154 return p; | |
155 } | |
156 | |
157 icq_Packet *icq_TCPCreateChatReqAck(icq_TCPLink *plink, WORD port) | |
158 { | |
159 icq_Packet *p=icq_TCPCreateStdPacket( | |
160 plink, | |
161 ICQ_TCP_ACK, | |
162 ICQ_TCP_MSG_CHAT, | |
163 0, | |
164 0, /* status */ | |
165 ICQ_TCP_MSG_ACK); | |
166 | |
167 icq_PacketAppendString(p, 0); | |
168 | |
169 icq_PacketAppend16(p, htons(port)); | |
170 icq_PacketAppend16(p, 0x0000); | |
171 icq_PacketAppend32(p, port); | |
172 | |
173 return p; | |
174 } | |
175 | |
176 icq_Packet *icq_TCPCreateChatReqRefuse(icq_TCPLink *plink, WORD port, | |
177 const char *reason) | |
178 { | |
179 icq_Packet *p=icq_TCPCreateStdPacket( | |
180 plink, | |
181 ICQ_TCP_ACK, | |
182 ICQ_TCP_MSG_CHAT, | |
183 reason, | |
184 ICQ_TCP_STATUS_REFUSE, | |
185 ICQ_TCP_MSG_ACK); | |
186 | |
187 icq_PacketAppendString(p, 0); | |
188 | |
189 icq_PacketAppend16(p, htons(port)); | |
190 icq_PacketAppend16(p, 0x0000); | |
191 icq_PacketAppend32(p, port); | |
192 | |
193 return p; | |
194 } | |
195 | |
196 icq_Packet *icq_TCPCreateChatReqCancel(icq_TCPLink *plink, WORD port) | |
197 { | |
198 icq_Packet *p=icq_TCPCreateStdPacket( | |
199 plink, | |
200 ICQ_TCP_CANCEL, | |
201 ICQ_TCP_MSG_CHAT, | |
202 0, | |
203 0, /* status */ | |
204 ICQ_TCP_MSG_ACK); | |
205 | |
206 icq_PacketAppendString(p, 0); | |
207 | |
208 icq_PacketAppend16(p, htons(port)); | |
209 icq_PacketAppend16(p, 0x0000); | |
210 icq_PacketAppend32(p, port); | |
211 | |
212 return p; | |
213 } | |
214 | |
215 icq_Packet *icq_TCPCreateFileReqAck(icq_TCPLink *plink, WORD port) | |
216 { | |
217 icq_Packet *p=icq_TCPCreateStdPacket( | |
218 plink, | |
219 ICQ_TCP_ACK, | |
220 ICQ_TCP_MSG_FILE, | |
221 0, | |
222 0, /* status */ | |
223 ICQ_TCP_MSG_ACK); | |
224 | |
225 icq_PacketAppend16(p, htons(port)); | |
226 icq_PacketAppend16(p, 0x0000); | |
227 icq_PacketAppendString(p, 0); | |
228 icq_PacketAppend32(p, 0x00000000); | |
229 icq_PacketAppend32(p, port); | |
230 | |
231 return p; | |
232 } | |
233 | |
234 icq_Packet *icq_TCPCreateFileReqRefuse(icq_TCPLink *plink, WORD port, | |
235 const char *reason) | |
236 { | |
237 icq_Packet *p=icq_TCPCreateStdPacket( | |
238 plink, | |
239 ICQ_TCP_ACK, | |
240 ICQ_TCP_MSG_FILE, | |
241 reason, | |
242 ICQ_TCP_STATUS_REFUSE, | |
243 ICQ_TCP_MSG_ACK); | |
244 | |
245 icq_PacketAppend16(p, htons(port)); | |
246 icq_PacketAppend16(p, 0x0000); | |
247 icq_PacketAppendString(p, 0); | |
248 icq_PacketAppend32(p, 0x00000000); | |
249 icq_PacketAppend32(p, port); | |
250 | |
251 return p; | |
252 } | |
253 | |
254 icq_Packet *icq_TCPCreateFileReqCancel(icq_TCPLink *plink, WORD port) | |
255 { | |
256 icq_Packet *p=icq_TCPCreateStdPacket( | |
257 plink, | |
258 ICQ_TCP_CANCEL, | |
259 ICQ_TCP_MSG_FILE, | |
260 0, | |
261 0, /* status */ | |
262 ICQ_TCP_MSG_ACK); | |
263 | |
264 icq_PacketAppend16(p, htons(port)); | |
265 icq_PacketAppend16(p, 0x0000); | |
266 icq_PacketAppendString(p, 0); | |
267 icq_PacketAppend32(p, 0x00000000); | |
268 icq_PacketAppend32(p, port); | |
269 | |
270 return p; | |
271 } | |
272 | |
273 icq_Packet *icq_TCPCreateChatInfoPacket(icq_TCPLink *plink, const char *name, | |
274 DWORD foreground, DWORD background) | |
275 { | |
276 icq_Packet *p=icq_PacketNew(); | |
277 | |
278 icq_PacketAppend32(p, 0x00000065); | |
279 icq_PacketAppend32(p, 0xfffffffa); | |
280 icq_PacketAppend32(p, plink->icqlink->icq_Uin); | |
281 icq_PacketAppendString(p, name); | |
282 icq_PacketAppend16(p, plink->socket_address.sin_port); | |
283 icq_PacketAppend32(p, foreground); | |
284 icq_PacketAppend32(p, background); | |
285 icq_PacketAppend8(p, 0x00); | |
286 | |
287 return p; | |
288 | |
289 } | |
290 | |
291 icq_Packet *icq_TCPCreateChatInfo2Packet(icq_TCPLink *plink, const char *name, | |
292 DWORD foreground, DWORD background) | |
293 { | |
294 icq_Packet *p=icq_PacketNew(); | |
295 | |
296 icq_PacketAppend32(p, 0x00000064); | |
297 icq_PacketAppend32(p, plink->icqlink->icq_Uin); | |
298 icq_PacketAppendString(p, name); | |
299 icq_PacketAppend32(p, foreground); | |
300 icq_PacketAppend32(p, background); | |
301 | |
302 icq_PacketAppend32(p, 0x00070004); | |
303 icq_PacketAppend32(p, 0x00000000); | |
304 icq_PacketAppend32n(p, htonl(plink->icqlink->icq_OurIP)); | |
305 icq_PacketAppend32n(p, htonl(plink->icqlink->icq_OurIP)); | |
306 icq_PacketAppend8(p, 0x04); | |
307 icq_PacketAppend16(p, 0x0000); | |
308 icq_PacketAppend32(p, 0x000a); | |
309 icq_PacketAppend32(p, 0x0000); | |
310 icq_PacketAppendString(p, "Courier New"); | |
311 icq_PacketAppend8(p, 204); | |
312 icq_PacketAppend8(p, 49); | |
313 icq_PacketAppend8(p, 0x00); | |
314 | |
315 return p; | |
316 } | |
317 | |
318 icq_Packet *icq_TCPCreateChatFontInfoPacket(icq_TCPLink *plink) | |
319 { | |
320 icq_Packet *p=icq_PacketNew(); | |
321 | |
322 icq_PacketAppend32(p, 0x00070004); | |
323 icq_PacketAppend32(p, 0x00000000); | |
324 icq_PacketAppend32n(p, htonl(plink->icqlink->icq_OurIP)); | |
325 icq_PacketAppend32n(p, htonl(plink->icqlink->icq_OurIP)); | |
326 icq_PacketAppend8(p, 0x04); | |
327 icq_PacketAppend16(p, ntohs(plink->socket_address.sin_port)); /* Zero ? */ | |
328 icq_PacketAppend32(p, 0x000a); | |
329 icq_PacketAppend32(p, 0x0000); | |
330 icq_PacketAppendString(p, "Courier New"); | |
331 icq_PacketAppend8(p, 204); | |
332 icq_PacketAppend8(p, 49); | |
333 icq_PacketAppend8(p, 0x00); | |
334 | |
335 return p; | |
336 } | |
337 | |
338 | |
339 icq_Packet *icq_TCPCreateFileReqPacket(icq_TCPLink *plink, | |
340 const char *message, const char *filename, unsigned long size) | |
341 { | |
342 icq_Packet *p=icq_TCPCreateStdPacket( | |
343 plink, | |
344 ICQ_TCP_MESSAGE, | |
345 ICQ_TCP_MSG_FILE, | |
346 (const char*)message, | |
347 0, /* status */ | |
348 ICQ_TCP_MSG_REAL); | |
349 | |
350 icq_PacketAppend16(p, 0x0000); | |
351 icq_PacketAppend16(p, 0x0000); | |
352 | |
353 icq_PacketAppendString(p, filename); | |
354 | |
355 icq_PacketAppend32(p, size); | |
356 icq_PacketAppend32(p, 0x00000000); | |
357 | |
358 return p; | |
359 } | |
360 | |
361 void icq_TCPAppendSequence(icq_Link *icqlink, icq_Packet *p) | |
362 { | |
363 p->id=icqlink->d->icq_TCPSequence--; | |
364 icq_PacketEnd(p); | |
365 icq_PacketAppend32(p, p->id); | |
366 } | |
367 | |
368 void icq_TCPAppendSequenceN(icq_Link *icqlink, icq_Packet *p, DWORD seq) | |
369 { | |
370 (void)icqlink; | |
371 p->id=seq; | |
372 icq_PacketEnd(p); | |
373 icq_PacketAppend32(p, p->id); | |
374 } | |
375 | |
376 icq_Packet *icq_TCPCreateMessageAck(icq_TCPLink *plink, const char *message) | |
377 { | |
378 icq_Packet *p=icq_TCPCreateStdPacket( | |
379 plink, | |
380 ICQ_TCP_ACK, | |
381 ICQ_TCP_MSG_MSG, | |
382 message, | |
383 0, /* status */ | |
384 ICQ_TCP_MSG_ACK); | |
385 | |
386 return p; | |
387 } | |
388 | |
389 icq_Packet *icq_TCPCreateURLAck(icq_TCPLink *plink, const char *message) | |
390 { | |
391 icq_Packet *p=icq_TCPCreateStdPacket( | |
392 plink, | |
393 ICQ_TCP_ACK, | |
394 ICQ_TCP_MSG_URL, | |
395 message, | |
396 0, /* status */ | |
397 ICQ_TCP_MSG_ACK); | |
398 | |
399 return p; | |
400 } | |
401 | |
402 icq_Packet *icq_TCPCreateContactListAck(icq_TCPLink *plink, const char *message) | |
403 { | |
404 icq_Packet *p=icq_TCPCreateStdPacket( | |
405 plink, | |
406 ICQ_TCP_ACK, | |
407 ICQ_TCP_MSG_CONTACTLIST, | |
408 message, | |
409 0, /* status */ | |
410 ICQ_TCP_MSG_ACK); | |
411 | |
412 return p; | |
413 } | |
414 | |
415 icq_Packet *icq_TCPCreateFile00Packet(DWORD num_files, DWORD total_bytes, | |
416 DWORD speed, const char *name) | |
417 { | |
418 icq_Packet *p=icq_PacketNew(); | |
419 | |
420 if(p) | |
421 { | |
422 icq_PacketAppend8(p, 0x00); | |
423 icq_PacketAppend32(p, 0x00000000); | |
424 icq_PacketAppend32(p, num_files); | |
425 icq_PacketAppend32(p, total_bytes); | |
426 icq_PacketAppend32(p, speed); | |
427 icq_PacketAppendString(p, name); | |
428 } | |
429 | |
430 return p; | |
431 } | |
432 | |
433 icq_Packet *icq_TCPCreateFile01Packet(DWORD speed, const char *name) | |
434 { | |
435 icq_Packet *p=icq_PacketNew(); | |
436 | |
437 if(p) | |
438 { | |
439 icq_PacketAppend8(p, 0x01); | |
440 icq_PacketAppend32(p, speed); | |
441 icq_PacketAppendString(p, name); | |
442 } | |
443 | |
444 return p; | |
445 } | |
446 | |
447 icq_Packet *icq_TCPCreateFile02Packet(const char *filename, DWORD filesize, | |
448 DWORD speed) | |
449 { | |
450 icq_Packet *p=icq_PacketNew(); | |
451 | |
452 if(p) | |
453 { | |
454 icq_PacketAppend8(p, 0x02); | |
455 icq_PacketAppend8(p, 0x00); | |
456 icq_PacketAppendString(p, filename); | |
457 icq_PacketAppendString(p, 0); | |
458 icq_PacketAppend32(p, filesize); | |
459 icq_PacketAppend32(p, 0x00000000); | |
460 icq_PacketAppend32(p, speed); | |
461 } | |
462 | |
463 return p; | |
464 } | |
465 | |
466 icq_Packet *icq_TCPCreateFile03Packet(DWORD filesize, DWORD speed) | |
467 { | |
468 icq_Packet *p=icq_PacketNew(); | |
469 | |
470 if(p) | |
471 { | |
472 icq_PacketAppend8(p, 0x03); | |
473 icq_PacketAppend32(p, filesize); | |
474 icq_PacketAppend32(p, 0x00000000); | |
475 icq_PacketAppend32(p, speed); | |
476 } | |
477 | |
478 return p; | |
479 } | |
480 | |
481 icq_Packet *icq_TCPCreateFile04Packet(DWORD filenum) | |
482 { | |
483 icq_Packet *p=icq_PacketNew(); | |
484 | |
485 if(p) | |
486 { | |
487 icq_PacketAppend8(p, 0x04); | |
488 icq_PacketAppend32(p, filenum); | |
489 } | |
490 | |
491 return p; | |
492 } | |
493 | |
494 icq_Packet *icq_TCPCreateFile05Packet(DWORD speed) | |
495 { | |
496 icq_Packet *p=icq_PacketNew(); | |
497 | |
498 if(p) | |
499 { | |
500 icq_PacketAppend8(p, 0x05); | |
501 icq_PacketAppend32(p, speed); | |
502 } | |
503 | |
504 return p; | |
505 } | |
506 | |
507 icq_Packet *icq_TCPCreateFile06Packet(int length, void *data) | |
508 { | |
509 icq_Packet *p=icq_PacketNew(); | |
510 | |
511 if(p) | |
512 { | |
513 icq_PacketAppend8(p, 0x06); | |
514 icq_PacketAppend(p, data, length); | |
515 } | |
516 | |
517 return p; | |
518 } | |
519 | |
520 icq_Packet *icq_UDPCreateStdPacket(icq_Link *icqlink, WORD cmd) | |
521 { | |
522 icq_Packet *p = icq_PacketNew(); | |
523 | |
524 /* if(!link->d->icq_UDPSession) | |
525 link->d->icq_UDPSession = rand() & 0x3FFFFFFF; | |
526 if(!link->d->icq_UDPSeqNum2) | |
527 link->d->icq_UDPSeqNum2 = rand() & 0x7FFF;*/ | |
528 | |
529 icq_PacketAppend16(p, ICQ_UDP_VER); /* ver */ | |
530 icq_PacketAppend32(p, 0); /* zero */ | |
531 icq_PacketAppend32(p, icqlink->icq_Uin); /* uin */ | |
532 icq_PacketAppend32(p, icqlink->d->icq_UDPSession); /* session */ | |
533 icq_PacketAppend16(p, cmd); /* cmd */ | |
534 icq_PacketAppend16(p, icqlink->d->icq_UDPSeqNum1++); /* seq1 */ | |
535 icq_PacketAppend16(p, icqlink->d->icq_UDPSeqNum2++); /* seq2 */ | |
536 icq_PacketAppend32(p, 0); /* checkcode */ | |
537 | |
538 return p; | |
539 } | |
540 | |
541 icq_Packet *icq_UDPCreateStdSeqPacket(icq_Link *icqlink, WORD cmd, WORD seq) | |
542 { | |
543 icq_Packet *p = icq_PacketNew(); | |
544 | |
545 icq_PacketAppend16(p, ICQ_UDP_VER); /* ver */ | |
546 icq_PacketAppend32(p, 0); /* zero */ | |
547 icq_PacketAppend32(p, icqlink->icq_Uin); /* uin */ | |
548 icq_PacketAppend32(p, icqlink->d->icq_UDPSession); /* session */ | |
549 icq_PacketAppend16(p, cmd); /* cmd */ | |
550 icq_PacketAppend16(p, seq); /* seq1 */ | |
551 icq_PacketAppend16(p, 0); /* seq2 */ | |
552 icq_PacketAppend32(p, 0); /* checkcode */ | |
553 | |
554 return p; | |
555 } |