annotate src/protocols/gg/lib/dcc.c @ 13967:99b9b58b19dd

[gaim-migrate @ 16523] Fix a crazy MSN crash. Basically it's possible to have more than one slplink associated with a given switchboard, but our code did not allow for that. I think it happens when you're in a multi-user chat and you do stuff with multiple users that involves slplinks. Like maybe file transfer and buddy icon related stuff. Tracking this down took an ungodly amount of time, but thanks to Meebo for letting me do it :-) committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 20 Jul 2006 07:31:15 +0000
parents fc464a0abccc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12323
fc464a0abccc [gaim-migrate @ 14627]
Richard Laager <rlaager@wiktel.com>
parents: 12218
diff changeset
1 /* $Id: dcc.c 14627 2005-12-04 18:19:56Z rlaager $ */
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
3 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
4 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
5 * Tomasz Chiliński <chilek@chilan.com>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
6 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU Lesser General Public License Version
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
9 * 2.1 as published by the Free Software Foundation.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
10 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
14 * GNU Lesser General Public License for more details.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
15 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
17 * License along with this program; if not, write to the Free Software
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
19 * USA.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
20 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
21
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
22 #include <sys/types.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
23 #include <sys/stat.h>
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
24 #ifndef _WIN32
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
25 #include <sys/ioctl.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
26 #include <sys/socket.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
27 #include <netinet/in.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
28 #include <arpa/inet.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
29 #ifdef sun
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
30 # include <sys/filio.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
31 #endif
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
32 #endif
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
33
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
34 #include <ctype.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
35 #include <errno.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
36 #include <fcntl.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
37 #include <stdarg.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
38 #include <string.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
39 #include <stdio.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
40 #include <stdlib.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
41 #include <unistd.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
42
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
43 #include "compat.h"
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
44 #include "libgadu.h"
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
45
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
46 #ifndef GG_DEBUG_DISABLE
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
47 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
48 * gg_dcc_debug_data() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
49 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
50 * wyświetla zrzut pakietu w hexie.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
51 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
52 * - prefix - prefiks zrzutu pakietu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
53 * - fd - deskryptor gniazda
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
54 * - buf - bufor z danymi
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
55 * - size - rozmiar danych
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
56 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
57 static void gg_dcc_debug_data(const char *prefix, int fd, const void *buf, unsigned int size)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
58 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
59 unsigned int i;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
60
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
61 gg_debug(GG_DEBUG_MISC, "++ gg_dcc %s (fd=%d,len=%d)", prefix, fd, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
62
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
63 for (i = 0; i < size; i++)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
64 gg_debug(GG_DEBUG_MISC, " %.2x", ((unsigned char*) buf)[i]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
65
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
66 gg_debug(GG_DEBUG_MISC, "\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
67 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
68 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
69 #define gg_dcc_debug_data(a,b,c,d) do { } while (0)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
70 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
71
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
72 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
73 * gg_dcc_request()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
74 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
75 * wysyła informację o tym, że dany klient powinien się z nami połączyć.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
76 * wykorzystywane, kiedy druga strona, której chcemy coś wysłać jest za
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
77 * maskaradą.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
78 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
79 * - sess - struktura opisująca sesję GG
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
80 * - uin - numerek odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
81 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
82 * patrz gg_send_message_ctcp().
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
83 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
84 int gg_dcc_request(struct gg_session *sess, uin_t uin)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
85 {
12218
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
86 return gg_send_message_ctcp(sess, GG_CLASS_CTCP, uin, (const unsigned char *)"\002", 1);
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
87 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
88
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
89 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
90 * gg_dcc_fill_filetime() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
91 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
92 * zamienia czas w postaci unixowej na windowsowy.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
93 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
94 * - unix - czas w postaci unixowej
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
95 * - filetime - czas w postaci windowsowej
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
96 */
12323
fc464a0abccc [gaim-migrate @ 14627]
Richard Laager <rlaager@wiktel.com>
parents: 12218
diff changeset
97 static void gg_dcc_fill_filetime(uint32_t ut, uint32_t *ft)
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
98 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
99 #ifdef __GG_LIBGADU_HAVE_LONG_LONG
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
100 unsigned long long tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
101
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
102 tmp = ut;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
103 tmp += 11644473600LL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
104 tmp *= 10000000LL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
105
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
106 #ifndef __GG_LIBGADU_BIGENDIAN
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
107 ft[0] = (uint32_t) tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
108 ft[1] = (uint32_t) (tmp >> 32);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
109 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
110 ft[0] = gg_fix32((uint32_t) (tmp >> 32));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
111 ft[1] = gg_fix32((uint32_t) tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
112 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
113
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
114 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
115 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
116
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
117 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
118 * gg_dcc_fill_file_info()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
119 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
120 * wypełnia pola struct gg_dcc niezbędne do wysłania pliku.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
121 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
122 * - d - struktura opisująca połączenie DCC
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
123 * - filename - nazwa pliku
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
124 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
125 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
126 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
127 int gg_dcc_fill_file_info(struct gg_dcc *d, const char *filename)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
128 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
129 return gg_dcc_fill_file_info2(d, filename, filename);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
130 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
131
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
132 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
133 * gg_dcc_fill_file_info2()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
134 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
135 * wypełnia pola struct gg_dcc niezbędne do wysłania pliku.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
136 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
137 * - d - struktura opisująca połączenie DCC
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
138 * - filename - nazwa pliku
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
139 * - local_filename - nazwa na lokalnym systemie plików
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
140 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
141 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
142 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
143 int gg_dcc_fill_file_info2(struct gg_dcc *d, const char *filename, const char *local_filename)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
144 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
145 struct stat st;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
146 const char *name, *ext, *p;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
147 unsigned char *q;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
148 int i, j;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
149
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
150 gg_debug(GG_DEBUG_FUNCTION, "** gg_dcc_fill_file_info2(%p, \"%s\", \"%s\");\n", d, filename, local_filename);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
151
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
152 if (!d || d->type != GG_SESSION_DCC_SEND) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
153 gg_debug(GG_DEBUG_MISC, "// gg_dcc_fill_file_info2() invalid arguments\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
154 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
155 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
156 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
157
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
158 if (stat(local_filename, &st) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
159 gg_debug(GG_DEBUG_MISC, "// gg_dcc_fill_file_info2() stat() failed (%s)\n", strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
160 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
161 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
162
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
163 if ((st.st_mode & S_IFDIR)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
164 gg_debug(GG_DEBUG_MISC, "// gg_dcc_fill_file_info2() that's a directory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
165 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
166 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
167 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
168
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
169 if ((d->file_fd = open(local_filename, O_RDONLY)) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
170 gg_debug(GG_DEBUG_MISC, "// gg_dcc_fill_file_info2() open() failed (%s)\n", strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
171 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
172 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
173
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
174 memset(&d->file_info, 0, sizeof(d->file_info));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
175
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
176 if (!(st.st_mode & S_IWUSR))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
177 d->file_info.mode |= gg_fix32(GG_DCC_FILEATTR_READONLY);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
178
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
179 gg_dcc_fill_filetime(st.st_atime, d->file_info.atime);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
180 gg_dcc_fill_filetime(st.st_mtime, d->file_info.mtime);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
181 gg_dcc_fill_filetime(st.st_ctime, d->file_info.ctime);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
182
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
183 d->file_info.size = gg_fix32(st.st_size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
184 d->file_info.mode = gg_fix32(0x20); /* FILE_ATTRIBUTE_ARCHIVE */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
185
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
186 if (!(name = strrchr(filename, '/')))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
187 name = filename;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
188 else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
189 name++;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
190
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
191 if (!(ext = strrchr(name, '.')))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
192 ext = name + strlen(name);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
193
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
194 for (i = 0, p = name; i < 8 && p < ext; i++, p++)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
195 d->file_info.short_filename[i] = toupper(name[i]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
196
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
197 if (i == 8 && p < ext) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
198 d->file_info.short_filename[6] = '~';
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
199 d->file_info.short_filename[7] = '1';
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
200 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
201
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
202 if (strlen(ext) > 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
203 for (j = 0; *ext && j < 4; j++, p++)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
204 d->file_info.short_filename[i + j] = toupper(ext[j]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
205 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
206
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
207 for (q = d->file_info.short_filename; *q; q++) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
208 if (*q == 185) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
209 *q = 165;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
210 } else if (*q == 230) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
211 *q = 198;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
212 } else if (*q == 234) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
213 *q = 202;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
214 } else if (*q == 179) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
215 *q = 163;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
216 } else if (*q == 241) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
217 *q = 209;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
218 } else if (*q == 243) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
219 *q = 211;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
220 } else if (*q == 156) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
221 *q = 140;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
222 } else if (*q == 159) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
223 *q = 143;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
224 } else if (*q == 191) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
225 *q = 175;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
226 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
227 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
228
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
229 gg_debug(GG_DEBUG_MISC, "// gg_dcc_fill_file_info2() short name \"%s\", dos name \"%s\"\n", name, d->file_info.short_filename);
12218
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
230 strncpy((char *)d->file_info.filename, name, sizeof(d->file_info.filename) - 1);
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
231
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
232 return 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
233 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
234
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
235 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
236 * gg_dcc_transfer() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
237 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
238 * inicjuje proces wymiany pliku z danym klientem.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
239 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
240 * - ip - adres ip odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
241 * - port - port odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
242 * - my_uin - własny numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
243 * - peer_uin - numer obiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
244 * - type - rodzaj wymiany (GG_SESSION_DCC_SEND lub GG_SESSION_DCC_GET)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
245 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
246 * zaalokowana struct gg_dcc lub NULL jeśli wystąpił błąd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
247 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
248 static struct gg_dcc *gg_dcc_transfer(uint32_t ip, uint16_t port, uin_t my_uin, uin_t peer_uin, int type)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
249 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
250 struct gg_dcc *d = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
251 struct in_addr addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
252
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
253 addr.s_addr = ip;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
254
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
255 gg_debug(GG_DEBUG_FUNCTION, "** gg_dcc_transfer(%s, %d, %ld, %ld, %s);\n", inet_ntoa(addr), port, my_uin, peer_uin, (type == GG_SESSION_DCC_SEND) ? "SEND" : "GET");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
256
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
257 if (!ip || ip == INADDR_NONE || !port || !my_uin || !peer_uin) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
258 gg_debug(GG_DEBUG_MISC, "// gg_dcc_transfer() invalid arguments\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
259 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
260 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
261 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
262
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
263 if (!(d = (void*) calloc(1, sizeof(*d)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
264 gg_debug(GG_DEBUG_MISC, "// gg_dcc_transfer() not enough memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
265 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
266 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
267
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
268 d->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
269 d->state = GG_STATE_CONNECTING;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
270 d->type = type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
271 d->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
272 d->file_fd = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
273 d->active = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
274 d->fd = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
275 d->uin = my_uin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
276 d->peer_uin = peer_uin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
277
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
278 if ((d->fd = gg_connect(&addr, port, 1)) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
279 gg_debug(GG_DEBUG_MISC, "// gg_dcc_transfer() connection failed\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
280 free(d);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
281 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
282 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
283
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
284 return d;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
285 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
286
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
287 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
288 * gg_dcc_get_file()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
289 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
290 * inicjuje proces odbierania pliku od danego klienta, gdy ten wysłał do
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
291 * nas żądanie połączenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
292 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
293 * - ip - adres ip odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
294 * - port - port odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
295 * - my_uin - własny numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
296 * - peer_uin - numer obiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
297 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
298 * zaalokowana struct gg_dcc lub NULL jeśli wystąpił błąd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
299 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
300 struct gg_dcc *gg_dcc_get_file(uint32_t ip, uint16_t port, uin_t my_uin, uin_t peer_uin)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
301 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
302 gg_debug(GG_DEBUG_MISC, "// gg_dcc_get_file() handing over to gg_dcc_transfer()\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
303
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
304 return gg_dcc_transfer(ip, port, my_uin, peer_uin, GG_SESSION_DCC_GET);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
305 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
306
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
307 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
308 * gg_dcc_send_file()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
309 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
310 * inicjuje proces wysyłania pliku do danego klienta.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
311 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
312 * - ip - adres ip odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
313 * - port - port odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
314 * - my_uin - własny numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
315 * - peer_uin - numer obiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
316 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
317 * zaalokowana struct gg_dcc lub NULL jeśli wystąpił błąd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
318 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
319 struct gg_dcc *gg_dcc_send_file(uint32_t ip, uint16_t port, uin_t my_uin, uin_t peer_uin)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
320 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
321 gg_debug(GG_DEBUG_MISC, "// gg_dcc_send_file() handing over to gg_dcc_transfer()\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
322
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
323 return gg_dcc_transfer(ip, port, my_uin, peer_uin, GG_SESSION_DCC_SEND);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
324 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
325
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
326 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
327 * gg_dcc_voice_chat()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
328 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
329 * próbuje nawiązać połączenie głosowe.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
330 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
331 * - ip - adres ip odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
332 * - port - port odbiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
333 * - my_uin - własny numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
334 * - peer_uin - numer obiorcy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
335 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
336 * zaalokowana struct gg_dcc lub NULL jeśli wystąpił błąd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
337 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
338 struct gg_dcc *gg_dcc_voice_chat(uint32_t ip, uint16_t port, uin_t my_uin, uin_t peer_uin)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
339 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
340 gg_debug(GG_DEBUG_MISC, "// gg_dcc_voice_chat() handing over to gg_dcc_transfer()\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
341
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
342 return gg_dcc_transfer(ip, port, my_uin, peer_uin, GG_SESSION_DCC_VOICE);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
343 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
344
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
345 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
346 * gg_dcc_set_type()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
347 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
348 * po zdarzeniu GG_EVENT_DCC_CALLBACK należy ustawić typ połączenia za
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
349 * pomocą tej funkcji.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
350 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
351 * - d - struktura opisująca połączenie
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
352 * - type - typ połączenia (GG_SESSION_DCC_SEND lub GG_SESSION_DCC_VOICE)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
353 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
354 void gg_dcc_set_type(struct gg_dcc *d, int type)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
355 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
356 d->type = type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
357 d->state = (type == GG_SESSION_DCC_SEND) ? GG_STATE_SENDING_FILE_INFO : GG_STATE_SENDING_VOICE_REQUEST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
358 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
359
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
360 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
361 * gg_dcc_callback() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
362 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
363 * wywoływana z struct gg_dcc->callback, odpala gg_dcc_watch_fd i umieszcza
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
364 * rezultat w struct gg_dcc->event.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
365 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
366 * - d - structura opisująca połączenie
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
367 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
368 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
369 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
370 static int gg_dcc_callback(struct gg_dcc *d)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
371 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
372 struct gg_event *e = gg_dcc_watch_fd(d);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
373
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
374 d->event = e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
375
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
376 return (e != NULL) ? 0 : -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
377 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
378
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
379 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
380 * gg_dcc_socket_create()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
381 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
382 * tworzy gniazdo dla bezpośredniej komunikacji między klientami.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
383 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
384 * - uin - własny numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
385 * - port - preferowany port, jeśli równy 0 lub -1, próbuje domyślnego
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
386 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
387 * zaalokowana struct gg_dcc, którą poźniej należy zwolnić funkcją
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
388 * gg_dcc_free(), albo NULL jeśli wystąpił błąd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
389 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
390 struct gg_dcc *gg_dcc_socket_create(uin_t uin, uint16_t port)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
391 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
392 struct gg_dcc *c;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
393 struct sockaddr_in sin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
394 int sock, bound = 0, errno2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
395
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
396 gg_debug(GG_DEBUG_FUNCTION, "** gg_create_dcc_socket(%d, %d);\n", uin, port);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
397
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
398 if (!uin) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
399 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() invalid arguments\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
400 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
401 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
402 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
403
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
404 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
405 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() can't create socket (%s)\n", strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
406 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
407 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
408
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
409 if (!port)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
410 port = GG_DEFAULT_DCC_PORT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
411
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
412 while (!bound) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
413 sin.sin_family = AF_INET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
414 sin.sin_addr.s_addr = INADDR_ANY;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
415 sin.sin_port = htons(port);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
416
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
417 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() trying port %d\n", port);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
418 if (!bind(sock, (struct sockaddr*) &sin, sizeof(sin)))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
419 bound = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
420 else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
421 if (++port == 65535) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
422 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() no free port found\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
423 close(sock);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
424 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
425 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
426 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
427 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
428
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
429 if (listen(sock, 10)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
430 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() unable to listen (%s)\n", strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
431 errno2 = errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
432 close(sock);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
433 errno = errno2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
434 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
435 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
436
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
437 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() bound to port %d\n", port);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
438
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
439 if (!(c = malloc(sizeof(*c)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
440 gg_debug(GG_DEBUG_MISC, "// gg_create_dcc_socket() not enough memory for struct\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
441 close(sock);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
442 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
443 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
444 memset(c, 0, sizeof(*c));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
445
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
446 c->port = c->id = port;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
447 c->fd = sock;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
448 c->type = GG_SESSION_DCC_SOCKET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
449 c->uin = uin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
450 c->timeout = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
451 c->state = GG_STATE_LISTENING;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
452 c->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
453 c->callback = gg_dcc_callback;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
454 c->destroy = gg_dcc_free;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
455
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
456 return c;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
457 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
458
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
459 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
460 * gg_dcc_voice_send()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
461 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
462 * wysyła ramkę danych dla rozmowy głosowej.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
463 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
464 * - d - struktura opisująca połączenie dcc
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
465 * - buf - bufor z danymi
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
466 * - length - rozmiar ramki
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
467 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
468 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
469 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
470 int gg_dcc_voice_send(struct gg_dcc *d, char *buf, int length)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
471 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
472 struct packet_s {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
473 uint8_t type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
474 uint32_t length;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
475 } GG_PACKED;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
476 struct packet_s packet;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
477
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
478 gg_debug(GG_DEBUG_FUNCTION, "++ gg_dcc_voice_send(%p, %p, %d);\n", d, buf, length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
479 if (!d || !buf || length < 0 || d->type != GG_SESSION_DCC_VOICE) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
480 gg_debug(GG_DEBUG_MISC, "// gg_dcc_voice_send() invalid argument\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
481 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
482 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
483 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
484
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
485 packet.type = 0x03; /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
486 packet.length = gg_fix32(length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
487
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
488 if (write(d->fd, &packet, sizeof(packet)) < (signed)sizeof(packet)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
489 gg_debug(GG_DEBUG_MISC, "// gg_dcc_voice_send() write() failed\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
490 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
491 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
492 gg_dcc_debug_data("write", d->fd, &packet, sizeof(packet));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
493
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
494 if (write(d->fd, buf, length) < length) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
495 gg_debug(GG_DEBUG_MISC, "// gg_dcc_voice_send() write() failed\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
496 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
497 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
498 gg_dcc_debug_data("write", d->fd, buf, length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
499
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
500 return 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
501 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
502
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
503 #define gg_read(fd, buf, size) \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
504 { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
505 int tmp = read(fd, buf, size); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
506 \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
507 if (tmp < (int) size) { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
508 if (tmp == -1) { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
509 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed (errno=%d, %s)\n", errno, strerror(errno)); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
510 } else if (tmp == 0) { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
511 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed, connection broken\n"); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
512 } else { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
513 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed (%d bytes, %d needed)\n", tmp, size); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
514 } \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
515 e->type = GG_EVENT_DCC_ERROR; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
516 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
517 return e; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
518 } \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
519 gg_dcc_debug_data("read", fd, buf, size); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
520 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
521
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
522 #define gg_write(fd, buf, size) \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
523 { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
524 int tmp; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
525 gg_dcc_debug_data("write", fd, buf, size); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
526 tmp = write(fd, buf, size); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
527 if (tmp < (int) size) { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
528 if (tmp == -1) { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
529 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() write() failed (errno=%d, %s)\n", errno, strerror(errno)); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
530 } else { \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
531 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() write() failed (%d needed, %d done)\n", size, tmp); \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
532 } \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
533 e->type = GG_EVENT_DCC_ERROR; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
534 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
535 return e; \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
536 } \
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
537 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
538
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
539 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
540 * gg_dcc_watch_fd()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
541 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
542 * funkcja, którą należy wywołać, gdy coś się zmieni na gg_dcc->fd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
543 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
544 * - h - struktura zwrócona przez gg_create_dcc_socket()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
545 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
546 * zaalokowana struct gg_event lub NULL, jeśli zabrakło pamięci na nią.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
547 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
548 struct gg_event *gg_dcc_watch_fd(struct gg_dcc *h)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
549 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
550 struct gg_event *e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
551 int foo;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
552
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
553 gg_debug(GG_DEBUG_FUNCTION, "** gg_dcc_watch_fd(%p);\n", h);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
554
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
555 if (!h || (h->type != GG_SESSION_DCC && h->type != GG_SESSION_DCC_SOCKET && h->type != GG_SESSION_DCC_SEND && h->type != GG_SESSION_DCC_GET && h->type != GG_SESSION_DCC_VOICE)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
556 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() invalid argument\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
557 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
558 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
559 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
560
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
561 if (!(e = (void*) calloc(1, sizeof(*e)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
562 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() not enough memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
563 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
564 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
565
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
566 e->type = GG_EVENT_NONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
567
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
568 if (h->type == GG_SESSION_DCC_SOCKET) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
569 struct sockaddr_in sin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
570 struct gg_dcc *c;
12218
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
571 int fd;
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
572 socklen_t sin_len = sizeof(sin);
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
573 int one = 1;
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
574
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
575 if ((fd = accept(h->fd, (struct sockaddr*) &sin, &sin_len)) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
576 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() can't accept() new connection (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
577 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
578 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
579
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
580 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() new direct connection from %s:%d\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
581
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
582 #ifdef FIONBIO
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
583 if (ioctl(fd, FIONBIO, &one) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
584 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
585 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
586 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
587 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() can't set nonblocking (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
588 close(fd);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
589 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
590 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
591 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
592 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
593
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
594 if (!(c = (void*) calloc(1, sizeof(*c)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
595 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() not enough memory for client data\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
596
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
597 free(e);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
598 close(fd);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
599 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
600 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
601
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
602 c->fd = fd;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
603 c->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
604 c->state = GG_STATE_READING_UIN_1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
605 c->type = GG_SESSION_DCC;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
606 c->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
607 c->file_fd = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
608 c->remote_addr = sin.sin_addr.s_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
609 c->remote_port = ntohs(sin.sin_port);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
610
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
611 e->type = GG_EVENT_DCC_NEW;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
612 e->event.dcc_new = c;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
613
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
614 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
615 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
616 struct gg_dcc_tiny_packet tiny;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
617 struct gg_dcc_small_packet small;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
618 struct gg_dcc_big_packet big;
12218
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
619 int size, tmp, res;
9cbc5967fbfd [gaim-migrate @ 14520]
Richard Laager <rlaager@wiktel.com>
parents: 11546
diff changeset
620 socklen_t res_size = sizeof(res);
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
621 unsigned int utmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
622 char buf[1024], ack[] = "UDAG";
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
623
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
624 struct gg_dcc_file_info_packet {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
625 struct gg_dcc_big_packet big;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
626 struct gg_file_info file_info;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
627 } GG_PACKED;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
628 struct gg_dcc_file_info_packet file_info_packet;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
629
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
630 switch (h->state) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
631 case GG_STATE_READING_UIN_1:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
632 case GG_STATE_READING_UIN_2:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
633 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
634 uin_t uin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
635
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
636 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_READING_UIN_%d\n", (h->state == GG_STATE_READING_UIN_1) ? 1 : 2);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
637
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
638 gg_read(h->fd, &uin, sizeof(uin));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
639
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
640 if (h->state == GG_STATE_READING_UIN_1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
641 h->state = GG_STATE_READING_UIN_2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
642 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
643 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
644 h->peer_uin = gg_fix32(uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
645 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
646 h->state = GG_STATE_SENDING_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
647 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
648 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
649 h->uin = gg_fix32(uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
650 e->type = GG_EVENT_DCC_CLIENT_ACCEPT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
651 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
652
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
653 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
654 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
655
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
656 case GG_STATE_SENDING_ACK:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
657 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_SENDING_ACK\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
658
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
659 gg_write(h->fd, ack, 4);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
660
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
661 h->state = GG_STATE_READING_TYPE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
662 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
663 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
664
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
665 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
666
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
667 case GG_STATE_READING_TYPE:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
668 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_TYPE\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
669
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
670 gg_read(h->fd, &small, sizeof(small));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
671
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
672 small.type = gg_fix32(small.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
673
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
674 switch (small.type) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
675 case 0x0003: /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
676 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() callback\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
677 h->type = GG_SESSION_DCC_SEND;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
678 h->state = GG_STATE_SENDING_FILE_INFO;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
679 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
680 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
681
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
682 e->type = GG_EVENT_DCC_CALLBACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
683
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
684 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
685
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
686 case 0x0002: /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
687 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() dialin\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
688 h->type = GG_SESSION_DCC_GET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
689 h->state = GG_STATE_READING_REQUEST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
690 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
691 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
692 h->incoming = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
693
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
694 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
695
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
696 default:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
697 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() unknown dcc type (%.4x) from %ld\n", small.type, h->peer_uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
698 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
699 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
700 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
701
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
702 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
703
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
704 case GG_STATE_READING_REQUEST:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
705 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_REQUEST\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
706
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
707 gg_read(h->fd, &small, sizeof(small));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
708
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
709 small.type = gg_fix32(small.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
710
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
711 switch (small.type) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
712 case 0x0001: /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
713 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() file transfer request\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
714 h->state = GG_STATE_READING_FILE_INFO;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
715 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
716 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
717 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
718
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
719 case 0x0003: /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
720 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() voice chat request\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
721 h->state = GG_STATE_SENDING_VOICE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
722 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
723 h->timeout = GG_DCC_TIMEOUT_VOICE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
724 h->type = GG_SESSION_DCC_VOICE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
725 e->type = GG_EVENT_DCC_NEED_VOICE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
726
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
727 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
728
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
729 default:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
730 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() unknown dcc request (%.4x) from %ld\n", small.type, h->peer_uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
731 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
732 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
733 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
734
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
735 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
736
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
737 case GG_STATE_READING_FILE_INFO:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
738 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_FILE_INFO\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
739
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
740 gg_read(h->fd, &file_info_packet, sizeof(file_info_packet));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
741
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
742 memcpy(&h->file_info, &file_info_packet.file_info, sizeof(h->file_info));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
743
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
744 h->file_info.mode = gg_fix32(h->file_info.mode);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
745 h->file_info.size = gg_fix32(h->file_info.size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
746
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
747 h->state = GG_STATE_SENDING_FILE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
748 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
749 h->timeout = GG_DCC_TIMEOUT_FILE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
750
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
751 e->type = GG_EVENT_DCC_NEED_FILE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
752
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
753 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
754
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
755 case GG_STATE_SENDING_FILE_ACK:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
756 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_FILE_ACK\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
757
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
758 big.type = gg_fix32(0x0006); /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
759 big.dunno1 = gg_fix32(h->offset);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
760 big.dunno2 = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
761
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
762 gg_write(h->fd, &big, sizeof(big));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
763
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
764 h->state = GG_STATE_READING_FILE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
765 h->chunk_size = sizeof(big);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
766 h->chunk_offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
767 if (!(h->chunk_buf = malloc(sizeof(big)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
768 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() out of memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
769 free(e);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
770 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
771 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
772 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
773 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
774
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
775 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
776
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
777 case GG_STATE_SENDING_VOICE_ACK:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
778 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_VOICE_ACK\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
779
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
780 tiny.type = 0x01; /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
781
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
782 gg_write(h->fd, &tiny, sizeof(tiny));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
783
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
784 h->state = GG_STATE_READING_VOICE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
785 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
786 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
787
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
788 h->offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
789
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
790 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
791
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
792 case GG_STATE_READING_FILE_HEADER:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
793 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_FILE_HEADER\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
794
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
795 tmp = read(h->fd, h->chunk_buf + h->chunk_offset, h->chunk_size - h->chunk_offset);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
796
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
797 if (tmp == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
798 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd() read() failed (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
799 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
800 e->event.dcc_error = GG_ERROR_DCC_NET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
801 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
802 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
803
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
804 gg_dcc_debug_data("read", h->fd, h->chunk_buf + h->chunk_offset, h->chunk_size - h->chunk_offset);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
805
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
806 h->chunk_offset += tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
807
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
808 if (h->chunk_offset < h->chunk_size)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
809 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
810
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
811 memcpy(&big, h->chunk_buf, sizeof(big));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
812 free(h->chunk_buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
813 h->chunk_buf = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
814
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
815 big.type = gg_fix32(big.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
816 h->chunk_size = gg_fix32(big.dunno1);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
817 h->chunk_offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
818
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
819 if (big.type == 0x0005) { /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
820 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() transfer refused\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
821 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
822 e->event.dcc_error = GG_ERROR_DCC_REFUSED;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
823 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
824 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
825
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
826 if (h->chunk_size == 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
827 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() empty chunk, EOF\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
828 e->type = GG_EVENT_DCC_DONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
829 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
830 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
831
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
832 h->state = GG_STATE_GETTING_FILE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
833 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
834 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
835 h->established = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
836
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
837 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
838
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
839 case GG_STATE_READING_VOICE_HEADER:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
840 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_VOICE_HEADER\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
841
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
842 gg_read(h->fd, &tiny, sizeof(tiny));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
843
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
844 switch (tiny.type) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
845 case 0x03: /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
846 h->state = GG_STATE_READING_VOICE_SIZE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
847 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
848 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
849 h->established = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
850 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
851 case 0x04: /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
852 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() peer breaking connection\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
853 /* XXX zwracać odpowiedni event */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
854 default:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
855 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() unknown request (%.2x)\n", tiny.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
856 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
857 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
858 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
859
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
860 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
861
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
862 case GG_STATE_READING_VOICE_SIZE:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
863 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_VOICE_SIZE\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
864
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
865 gg_read(h->fd, &small, sizeof(small));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
866
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
867 small.type = gg_fix32(small.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
868
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
869 if (small.type < 16 || small.type > sizeof(buf)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
870 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() invalid voice frame size (%d)\n", small.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
871 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
872 e->event.dcc_error = GG_ERROR_DCC_NET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
873
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
874 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
875 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
876
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
877 h->chunk_size = small.type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
878 h->chunk_offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
879
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
880 if (!(h->voice_buf = malloc(h->chunk_size))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
881 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() out of memory for voice frame\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
882 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
883 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
884
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
885 h->state = GG_STATE_READING_VOICE_DATA;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
886 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
887 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
888
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
889 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
890
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
891 case GG_STATE_READING_VOICE_DATA:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
892 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_VOICE_DATA\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
893
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
894 tmp = read(h->fd, h->voice_buf + h->chunk_offset, h->chunk_size - h->chunk_offset);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
895 if (tmp < 1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
896 if (tmp == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
897 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
898 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
899 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed, connection broken\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
900 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
901 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
902 e->event.dcc_error = GG_ERROR_DCC_NET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
903 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
904 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
905
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
906 gg_dcc_debug_data("read", h->fd, h->voice_buf + h->chunk_offset, tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
907
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
908 h->chunk_offset += tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
909
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
910 if (h->chunk_offset >= h->chunk_size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
911 e->type = GG_EVENT_DCC_VOICE_DATA;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
912 e->event.dcc_voice_data.data = h->voice_buf;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
913 e->event.dcc_voice_data.length = h->chunk_size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
914 h->state = GG_STATE_READING_VOICE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
915 h->voice_buf = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
916 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
917
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
918 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
919 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
920
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
921 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
922
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
923 case GG_STATE_CONNECTING:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
924 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
925 uin_t uins[2];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
926
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
927 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_CONNECTING\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
928
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
929 res = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
930 if ((foo = getsockopt(h->fd, SOL_SOCKET, SO_ERROR, &res, &res_size)) || res) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
931 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() connection failed (fd=%d,errno=%d(%s),foo=%d,res=%d(%s))\n", h->fd, errno, strerror(errno), foo, res, strerror(res));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
932 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
933 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
934 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
935 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
936
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
937 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() connected, sending uins\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
938
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
939 uins[0] = gg_fix32(h->uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
940 uins[1] = gg_fix32(h->peer_uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
941
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
942 gg_write(h->fd, uins, sizeof(uins));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
943
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
944 h->state = GG_STATE_READING_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
945 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
946 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
947
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
948 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
949 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
950
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
951 case GG_STATE_READING_ACK:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
952 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_ACK\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
953
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
954 gg_read(h->fd, buf, 4);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
955
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
956 if (strncmp(buf, ack, 4)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
957 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() did't get ack\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
958
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
959 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
960 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
961 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
962 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
963
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
964 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
965 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
966 h->state = GG_STATE_SENDING_REQUEST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
967
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
968 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
969
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
970 case GG_STATE_SENDING_VOICE_REQUEST:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
971 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_VOICE_REQUEST\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
972
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
973 small.type = gg_fix32(0x0003);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
974
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
975 gg_write(h->fd, &small, sizeof(small));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
976
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
977 h->state = GG_STATE_READING_VOICE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
978 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
979 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
980
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
981 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
982
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
983 case GG_STATE_SENDING_REQUEST:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
984 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_REQUEST\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
985
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
986 small.type = (h->type == GG_SESSION_DCC_GET) ? gg_fix32(0x0003) : gg_fix32(0x0002); /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
987
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
988 gg_write(h->fd, &small, sizeof(small));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
989
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
990 switch (h->type) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
991 case GG_SESSION_DCC_GET:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
992 h->state = GG_STATE_READING_REQUEST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
993 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
994 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
995 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
996
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
997 case GG_SESSION_DCC_SEND:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
998 h->state = GG_STATE_SENDING_FILE_INFO;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
999 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1000 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1001
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1002 if (h->file_fd == -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1003 e->type = GG_EVENT_DCC_NEED_FILE_INFO;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1004 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1005
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1006 case GG_SESSION_DCC_VOICE:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1007 h->state = GG_STATE_SENDING_VOICE_REQUEST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1008 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1009 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1010 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1011 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1012
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1013 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1014
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1015 case GG_STATE_SENDING_FILE_INFO:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1016 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_FILE_INFO\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1017
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1018 if (h->file_fd == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1019 e->type = GG_EVENT_DCC_NEED_FILE_INFO;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1020 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1021 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1022
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1023 small.type = gg_fix32(0x0001); /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1024
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1025 gg_write(h->fd, &small, sizeof(small));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1026
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1027 file_info_packet.big.type = gg_fix32(0x0003); /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1028 file_info_packet.big.dunno1 = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1029 file_info_packet.big.dunno2 = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1030
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1031 memcpy(&file_info_packet.file_info, &h->file_info, sizeof(h->file_info));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1032
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1033 /* zostają teraz u nas, więc odwracamy z powrotem */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1034 h->file_info.size = gg_fix32(h->file_info.size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1035 h->file_info.mode = gg_fix32(h->file_info.mode);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1036
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1037 gg_write(h->fd, &file_info_packet, sizeof(file_info_packet));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1038
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1039 h->state = GG_STATE_READING_FILE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1040 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1041 h->timeout = GG_DCC_TIMEOUT_FILE_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1042
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1043 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1044
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1045 case GG_STATE_READING_FILE_ACK:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1046 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_FILE_ACK\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1047
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1048 gg_read(h->fd, &big, sizeof(big));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1049
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1050 /* XXX sprawdzać wynik */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1051 h->offset = gg_fix32(big.dunno1);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1052
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1053 h->state = GG_STATE_SENDING_FILE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1054 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1055 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1056
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1057 e->type = GG_EVENT_DCC_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1058
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1059 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1060
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1061 case GG_STATE_READING_VOICE_ACK:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1062 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_READING_VOICE_ACK\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1063
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1064 gg_read(h->fd, &tiny, sizeof(tiny));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1065
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1066 if (tiny.type != 0x01) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1067 gg_debug(GG_DEBUG_MISC, "// invalid reply (%.2x), connection refused\n", tiny.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1068 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1069 e->event.dcc_error = GG_ERROR_DCC_REFUSED;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1070 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1071 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1072
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1073 h->state = GG_STATE_READING_VOICE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1074 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1075 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1076
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1077 e->type = GG_EVENT_DCC_ACK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1078
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1079 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1080
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1081 case GG_STATE_SENDING_FILE_HEADER:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1082 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_FILE_HEADER\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1083
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1084 h->chunk_offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1085
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1086 if ((h->chunk_size = h->file_info.size - h->offset) > 4096) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1087 h->chunk_size = 4096;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1088 big.type = gg_fix32(0x0003); /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1089 } else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1090 big.type = gg_fix32(0x0002); /* XXX */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1091
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1092 big.dunno1 = gg_fix32(h->chunk_size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1093 big.dunno2 = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1094
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1095 gg_write(h->fd, &big, sizeof(big));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1096
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1097 h->state = GG_STATE_SENDING_FILE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1098 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1099 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1100 h->established = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1101
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1102 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1103
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1104 case GG_STATE_SENDING_FILE:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1105 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_SENDING_FILE\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1106
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1107 if ((utmp = h->chunk_size - h->chunk_offset) > sizeof(buf))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1108 utmp = sizeof(buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1109
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1110 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() offset=%d, size=%d\n", h->offset, h->file_info.size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1111
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1112 /* koniec pliku? */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1113 if (h->file_info.size == 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1114 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() reached eof on empty file\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1115 e->type = GG_EVENT_DCC_DONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1116
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1117 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1118 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1119
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1120 lseek(h->file_fd, h->offset, SEEK_SET);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1121
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1122 size = read(h->file_fd, buf, utmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1123
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1124 /* błąd */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1125 if (size == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1126 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed. (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1127
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1128 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1129 e->event.dcc_error = GG_ERROR_DCC_FILE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1130
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1131 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1132 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1133
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1134 /* koniec pliku? */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1135 if (size == 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1136 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() reached eof\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1137 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1138 e->event.dcc_error = GG_ERROR_DCC_EOF;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1139
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1140 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1141 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1142
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1143 /* jeśli wczytaliśmy więcej, utnijmy. */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1144 if (h->offset + size > h->file_info.size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1145 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() too much (read=%d, ofs=%d, size=%d)\n", size, h->offset, h->file_info.size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1146 size = h->file_info.size - h->offset;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1147
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1148 if (size < 1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1149 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() reached EOF after cutting\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1150 e->type = GG_EVENT_DCC_DONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1151 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1152 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1153 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1154
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1155 tmp = write(h->fd, buf, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1156
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1157 if (tmp == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1158 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() write() failed (%s)\n", strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1159 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1160 e->event.dcc_error = GG_ERROR_DCC_NET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1161 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1162 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1163
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1164 h->offset += size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1165
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1166 if (h->offset >= h->file_info.size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1167 e->type = GG_EVENT_DCC_DONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1168 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1169 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1170
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1171 h->chunk_offset += size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1172
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1173 if (h->chunk_offset >= h->chunk_size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1174 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() chunk finished\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1175 h->state = GG_STATE_SENDING_FILE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1176 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1177 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1178 h->state = GG_STATE_SENDING_FILE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1179 h->timeout = GG_DCC_TIMEOUT_SEND;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1180 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1181
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1182 h->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1183
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1184 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1185
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1186 case GG_STATE_GETTING_FILE:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1187 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_GETTING_FILE\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1188
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1189 if ((utmp = h->chunk_size - h->chunk_offset) > sizeof(buf))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1190 utmp = sizeof(buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1191
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1192 size = read(h->fd, buf, utmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1193
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1194 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() ofs=%d, size=%d, read()=%d\n", h->offset, h->file_info.size, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1195
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1196 /* błąd */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1197 if (size == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1198 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() failed. (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1199
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1200 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1201 e->event.dcc_error = GG_ERROR_DCC_NET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1202
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1203 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1204 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1205
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1206 /* koniec? */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1207 if (size == 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1208 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() read() reached eof\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1209 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1210 e->event.dcc_error = GG_ERROR_DCC_EOF;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1211
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1212 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1213 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1214
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1215 tmp = write(h->file_fd, buf, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1216
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1217 if (tmp == -1 || tmp < size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1218 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() write() failed (%d:fd=%d:res=%d:%s)\n", tmp, h->file_fd, size, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1219 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1220 e->event.dcc_error = GG_ERROR_DCC_NET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1221 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1222 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1223
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1224 h->offset += size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1225
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1226 if (h->offset >= h->file_info.size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1227 e->type = GG_EVENT_DCC_DONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1228 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1229 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1230
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1231 h->chunk_offset += size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1232
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1233 if (h->chunk_offset >= h->chunk_size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1234 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() chunk finished\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1235 h->state = GG_STATE_READING_FILE_HEADER;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1236 h->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1237 h->chunk_offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1238 h->chunk_size = sizeof(big);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1239 if (!(h->chunk_buf = malloc(sizeof(big)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1240 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() out of memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1241 free(e);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1242 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1243 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1244 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1245 h->state = GG_STATE_GETTING_FILE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1246 h->timeout = GG_DCC_TIMEOUT_GET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1247 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1248
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1249 h->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1250
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1251 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1252
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1253 default:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1254 gg_debug(GG_DEBUG_MISC, "// gg_dcc_watch_fd() GG_STATE_???\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1255 e->type = GG_EVENT_DCC_ERROR;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1256 e->event.dcc_error = GG_ERROR_DCC_HANDSHAKE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1257
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1258 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1259 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1260 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1261
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1262 return e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1263 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1264
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1265 #undef gg_read
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1266 #undef gg_write
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1267
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1268 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1269 * gg_dcc_free()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1270 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1271 * zwalnia pamięć po strukturze połączenia dcc.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1272 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1273 * - d - zwalniana struktura
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1274 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1275 void gg_dcc_free(struct gg_dcc *d)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1276 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1277 gg_debug(GG_DEBUG_FUNCTION, "** gg_dcc_free(%p);\n", d);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1278
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1279 if (!d)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1280 return;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1281
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1282 if (d->fd != -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1283 close(d->fd);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1284
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1285 if (d->chunk_buf) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1286 free(d->chunk_buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1287 d->chunk_buf = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1288 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1289
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1290 free(d);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1291 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1292
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1293 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1294 * Local variables:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1295 * c-indentation-style: k&r
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1296 * c-basic-offset: 8
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1297 * indent-tabs-mode: notnil
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1298 * End:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1299 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1300 * vim: shiftwidth=8:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1301 */