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