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