comparison src/protocols/gg/lib/libgadu.c @ 12218:9cbc5967fbfd

[gaim-migrate @ 14520] Crush some warnings. I ran this by Bartosz Oler and made some corrections at his suggestion. I'll be submitting this upstream and merging any changes they suggest/make-when-accepting. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Fri, 25 Nov 2005 00:32:45 +0000
parents 8724718d387f
children 4661eefa0840
comparison
equal deleted inserted replaced
12217:029802981b81 12218:9cbc5967fbfd
1 /* $Id: libgadu.c 14300 2005-11-08 19:45:09Z datallah $ */ 1 /* $Id: libgadu.c 14520 2005-11-25 00:32:45Z rlaager $ */
2 2
3 /* 3 /*
4 * (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl> 4 * (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl>
5 * Robert J. Wo¼ny <speedy@ziew.org> 5 * Robert J. Wo¼ny <speedy@ziew.org>
6 * Arkadiusz Mi¶kiewicz <arekm@pld-linux.org> 6 * Arkadiusz Mi¶kiewicz <arekm@pld-linux.org>
79 #ifndef lint 79 #ifndef lint
80 static char rcsid[] 80 static char rcsid[]
81 #ifdef __GNUC__ 81 #ifdef __GNUC__
82 __attribute__ ((unused)) 82 __attribute__ ((unused))
83 #endif 83 #endif
84 = "$Id: libgadu.c 14300 2005-11-08 19:45:09Z datallah $"; 84 = "$Id: libgadu.c 14520 2005-11-25 00:32:45Z rlaager $";
85 #endif 85 #endif
86 86
87 #ifdef _WIN32 87 #ifdef _WIN32
88 /** 88 /**
89 * Deal with the fact that you can't select() on a win32 file fd. 89 * Deal with the fact that you can't select() on a win32 file fd.
697 */ 697 */
698 void *gg_recv_packet(struct gg_session *sess) 698 void *gg_recv_packet(struct gg_session *sess)
699 { 699 {
700 struct gg_header h; 700 struct gg_header h;
701 char *buf = NULL; 701 char *buf = NULL;
702 int ret = 0; 702 int ret = 0, offset, size = 0;
703 unsigned int offset, size = 0;
704 703
705 gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(%p);\n", sess); 704 gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(%p);\n", sess);
706 705
707 if (!sess) { 706 if (!sess) {
708 errno = EFAULT; 707 errno = EFAULT;
851 */ 850 */
852 int gg_send_packet(struct gg_session *sess, int type, ...) 851 int gg_send_packet(struct gg_session *sess, int type, ...)
853 { 852 {
854 struct gg_header *h; 853 struct gg_header *h;
855 char *tmp; 854 char *tmp;
856 unsigned int tmp_length; 855 int tmp_length;
857 void *payload; 856 void *payload;
858 unsigned int payload_length; 857 unsigned int payload_length;
859 va_list ap; 858 va_list ap;
860 int res; 859 int res;
861 860
897 h = (struct gg_header*) tmp; 896 h = (struct gg_header*) tmp;
898 h->type = gg_fix32(type); 897 h->type = gg_fix32(type);
899 h->length = gg_fix32(tmp_length - sizeof(struct gg_header)); 898 h->length = gg_fix32(tmp_length - sizeof(struct gg_header));
900 899
901 if ((gg_debug_level & GG_DEBUG_DUMP)) { 900 if ((gg_debug_level & GG_DEBUG_DUMP)) {
902 unsigned int i; 901 int i;
903 902
904 gg_debug(GG_DEBUG_DUMP, "// gg_send_packet(0x%.2x)", gg_fix32(h->type)); 903 gg_debug(GG_DEBUG_DUMP, "// gg_send_packet(0x%.2x)", gg_fix32(h->type));
905 for (i = 0; i < tmp_length; ++i) 904 for (i = 0; i < tmp_length; ++i)
906 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) tmp[i]); 905 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) tmp[i]);
907 gg_debug(GG_DEBUG_DUMP, "\n"); 906 gg_debug(GG_DEBUG_DUMP, "\n");
1459 * - image - bufor z obrazkiem 1458 * - image - bufor z obrazkiem
1460 * - size - rozmiar obrazka 1459 * - size - rozmiar obrazka
1461 * 1460 *
1462 * 0/-1 1461 * 0/-1
1463 */ 1462 */
1464 int gg_image_reply(struct gg_session *sess, uin_t recipient, const char *filename, const char *image, int size) 1463 int gg_image_reply(struct gg_session *sess, uin_t recipient, const char *filename, const unsigned char *image, int size)
1465 { 1464 {
1466 struct gg_msg_image_reply *r; 1465 struct gg_msg_image_reply *r;
1467 struct gg_send_msg s; 1466 struct gg_send_msg s;
1468 const char *tmp; 1467 const char *tmp;
1469 char buf[1910]; 1468 char buf[1910];
1505 r->flag = 0x05; 1504 r->flag = 0x05;
1506 r->size = gg_fix32(size); 1505 r->size = gg_fix32(size);
1507 r->crc32 = gg_fix32(gg_crc32(0, image, size)); 1506 r->crc32 = gg_fix32(gg_crc32(0, image, size));
1508 1507
1509 while (size > 0) { 1508 while (size > 0) {
1510 int buflen, chunklen; 1509 size_t buflen, chunklen;
1511 1510
1512 /* \0 + struct gg_msg_image_reply */ 1511 /* \0 + struct gg_msg_image_reply */
1513 buflen = sizeof(struct gg_msg_image_reply) + 1; 1512 buflen = sizeof(struct gg_msg_image_reply) + 1;
1514 1513
1515 /* w pierwszym kawa³ku jest nazwa pliku */ 1514 /* w pierwszym kawa³ku jest nazwa pliku */
1516 if (r->flag == 0x05) { 1515 if (r->flag == 0x05) {
1517 strcpy(buf + buflen, filename); 1516 strcpy(buf + buflen, filename);
1518 buflen += strlen(filename) + 1; 1517 buflen += strlen(filename) + 1;
1519 } 1518 }
1520 1519
1521 chunklen = (size >= sizeof(buf) - buflen) ? (sizeof(buf) - buflen) : size; 1520 chunklen = ((size_t)size >= sizeof(buf) - buflen) ? (sizeof(buf) - buflen) : (size_t)size;
1522 1521
1523 memcpy(buf + buflen, image, chunklen); 1522 memcpy(buf + buflen, image, chunklen);
1524 size -= chunklen; 1523 size -= chunklen;
1525 image += chunklen; 1524 image += chunklen;
1526 1525
1633 sess->seq = 0x01740000 | (rand() & 0xffff); 1632 sess->seq = 0x01740000 | (rand() & 0xffff);
1634 s.seq = gg_fix32(sess->seq); 1633 s.seq = gg_fix32(sess->seq);
1635 s.msgclass = gg_fix32(msgclass); 1634 s.msgclass = gg_fix32(msgclass);
1636 sess->seq += (rand() % 0x300) + 0x300; 1635 sess->seq += (rand() % 0x300) + 0x300;
1637 1636
1638 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen(message) + 1, format, formatlen, NULL) == -1) 1637 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen((const char *)message) + 1, format, formatlen, NULL) == -1)
1639 return -1; 1638 return -1;
1640 1639
1641 return gg_fix32(s.seq); 1640 return gg_fix32(s.seq);
1642 } 1641 }
1643 1642
1726 } 1725 }
1727 1726
1728 if (!i) 1727 if (!i)
1729 sess->seq += (rand() % 0x300) + 0x300; 1728 sess->seq += (rand() % 0x300) + 0x300;
1730 1729
1731 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen(message) + 1, &r, sizeof(r), recps, (recipients_count - 1) * sizeof(uin_t), format, formatlen, NULL) == -1) { 1730 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen((const char *)message) + 1, &r, sizeof(r), recps, (recipients_count - 1) * sizeof(uin_t), format, formatlen, NULL) == -1) {
1732 free(recps); 1731 free(recps);
1733 return -1; 1732 return -1;
1734 } 1733 }
1735 } 1734 }
1736 1735