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