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