Mercurial > pidgin.yaz
annotate src/protocols/gg/libgg.c @ 10297:ec140184437b
[gaim-migrate @ 11480]
"After applying this patch, which modifies the make files and makes the
@file/@ingroup markers at the top of several gtk files more uniform,
the following files should be renamed:
dnd-hints.h -> gtkdnd-hints.h
dnd-hints.c -> gtkdnd-hints.c
gaim-disclosure.h -> gtkgaim-disclosure.h
gaim-disclosure.c -> gtkgaim-disclosure.c
stock.h -> gtkstock.h
stock.c -> gtkstock.c
I believe that completes the renaming of files which are explicitly for
gtkgaim; all files in /gaim/src which depend upon gtk should now have
gtk in their name. There are two candidates which might be considered
part of gtkgaim rather than part of the core, but I didn't modify them:
session.c and log.c. Both are quite gaim-UI specific, it seems,
particularly session, but perhaps other UIs could also make use of
their functionality.
-Evan "
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 02 Dec 2004 20:34:19 +0000 |
parents | 0e3a84f18467 |
children | 5976491e07a7 |
rev | line source |
---|---|
9863 | 1 /* $Id: libgg.c 10742 2004-08-25 03:09:08Z thekingant $ */ |
2393 | 2 |
3 /* | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
4 * (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl>, |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
5 * Robert J. Wo¼ny <speedy@ziew.org> |
2393 | 6 * |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License Version 2 as | |
9 * published by the Free Software Foundation. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 */ | |
20 | |
4016 | 21 #include <sys/types.h> |
3630 | 22 #ifndef _WIN32 |
2393 | 23 #include <sys/socket.h> |
24 #include <netinet/in.h> | |
25 #include <arpa/inet.h> | |
26 #include <sys/ioctl.h> | |
27 #include <sys/wait.h> | |
3630 | 28 #include <netdb.h> |
29 #include <pwd.h> | |
30 #else | |
31 #include <fcntl.h> | |
32 #endif | |
33 | |
34 #include <stdio.h> | |
35 #include <stdlib.h> | |
36 #include <unistd.h> | |
37 #include <stdio.h> | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
38 #include <sys/time.h> |
2393 | 39 #include <errno.h> |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
40 #ifndef _AIX |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
41 # include <string.h> |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
42 #endif |
2393 | 43 #include <stdarg.h> |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
44 #include <time.h> |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
45 #ifdef sun |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
46 #include <sys/filio.h> |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
47 #endif |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
48 #include <glib.h> |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
49 #if G_BYTE_ORDER == G_BIG_ENDIAN |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
50 # define WORDS_BIGENDIAN 1 |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
51 #endif |
9265 | 52 #include "internal.h" |
2393 | 53 #include "libgg.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
54 |
3630 | 55 #include "proxy.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
56 #include "debug.h" |
2393 | 57 |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
58 #ifdef _WIN32 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
59 #include "win32dep.h" |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
60 #endif |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
61 |
3630 | 62 int gg_debug_level = (GG_DEBUG_NET | GG_DEBUG_TRAFFIC | GG_DEBUG_DUMP | GG_DEBUG_FUNCTION | GG_DEBUG_MISC); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
63 int gg_http_use_proxy = 0; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
64 int gg_http_proxy_port = 0; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
65 char *gg_http_proxy_host = NULL; |
2393 | 66 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
67 #ifndef lint |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
68 |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
69 static char rcsid[] |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
70 #ifdef __GNUC__ |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
71 __attribute__ ((unused)) |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
72 #endif |
9863 | 73 = "$Id: libgg.c 10742 2004-08-25 03:09:08Z thekingant $"; |
2393 | 74 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
75 #endif |
2393 | 76 |
77 /* | |
78 * fix32() // funkcja wewnźtrzna | |
79 * | |
80 * dla maszyn big-endianowych zamienia kolejno¶ę bajtów w ,,long''ach. | |
81 */ | |
82 static inline unsigned long fix32(unsigned long x) | |
83 { | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
84 #ifndef WORDS_BIGENDIAN |
2393 | 85 return x; |
86 #else | |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
87 return (unsigned long) |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
88 (((x & (unsigned long) 0x000000ffU) << 24) | |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
89 ((x & (unsigned long) 0x0000ff00U) << 8) | |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
90 ((x & (unsigned long) 0x00ff0000U) >> 8) | |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
91 ((x & (unsigned long) 0xff000000U) >> 24)); |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
92 #endif |
2393 | 93 } |
94 | |
95 /* | |
96 * fix16() // funkcja wewnźtrzna | |
97 * | |
98 * dla maszyn big-endianowych zamienia kolejno¶ę bajtów w ,,short''ach. | |
99 */ | |
4298 | 100 |
2393 | 101 static inline unsigned short fix16(unsigned short x) |
102 { | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
103 #ifndef WORDS_BIGENDIAN |
2393 | 104 return x; |
105 #else | |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
106 return (unsigned short) |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
107 (((x & (unsigned short) 0x00ffU) << 8) | |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
108 ((x & (unsigned short) 0xff00U) >> 8)); |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
109 #endif |
2393 | 110 } |
111 | |
3630 | 112 #ifndef _WIN32 |
2393 | 113 /* |
114 * gg_resolve() // funkcja wewnźtrzna | |
115 * | |
116 * tworzy pipe'y, forkuje siź i w drugim procesie zaczyna resolvowaę | |
117 * podanego hosta. zapisuje w sesji deskryptor pipe'u. je¶li co¶ tam | |
118 * bździe gotowego, znaczy, æe moæna wczytaę ,,struct in_addr''. je¶li | |
119 * nie znajdzie, zwraca INADDR_NONE. | |
120 * | |
121 * - fd - wska¼nik gdzie wrzucię deskryptor, | |
122 * - pid - gdzie wrzucię pid dzieciaka, | |
123 * - hostname - nazwa hosta do zresolvowania. | |
124 * | |
125 * zwraca 0 je¶li uda³o siź odpalię proces lub -1 w przypadku b³źdu. | |
126 */ | |
127 int gg_resolve(int *fd, int *pid, char *hostname) | |
128 { | |
129 int pipes[2], res; | |
130 struct in_addr a; | |
131 | |
132 gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve(..., \"%s\");\n", hostname); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
133 |
2393 | 134 if (!fd | !pid) { |
135 errno = EFAULT; | |
136 return -1; | |
137 } | |
138 | |
139 if (pipe(pipes) == -1) | |
140 return -1; | |
141 | |
142 if ((res = fork()) == -1) | |
143 return -1; | |
144 | |
145 if (!res) { | |
146 if ((a.s_addr = inet_addr(hostname)) == INADDR_NONE) { | |
147 struct hostent *he; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
148 |
2393 | 149 if (!(he = gethostbyname(hostname))) |
150 a.s_addr = INADDR_NONE; | |
151 else | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
152 memcpy((char*) &a, he->h_addr, sizeof(a)); |
2393 | 153 } |
154 | |
155 write(pipes[1], &a, sizeof(a)); | |
156 | |
157 exit(0); | |
158 } | |
159 | |
160 close(pipes[1]); | |
161 | |
162 *fd = pipes[0]; | |
163 *pid = res; | |
164 | |
165 return 0; | |
166 } | |
3630 | 167 #endif /*!_WIN32*/ |
2393 | 168 |
169 /* | |
170 * gg_recv_packet() // funkcja wewnźtrzna | |
171 * | |
172 * odbiera jeden pakiet gg i zwraca wska¼nik do niego. pamiźę po nim | |
173 * wypada³oby uwolnię. | |
174 * | |
175 * - sock - po³±czony socket. | |
176 * | |
177 * je¶li wyst±pi³ b³±d, zwraca NULL. reszta w errno. | |
178 */ | |
179 static void *gg_recv_packet(struct gg_session *sess) | |
180 { | |
181 struct gg_header h; | |
182 char *buf = NULL; | |
183 int ret = 0, offset, size = 0; | |
3630 | 184 int sizeh = sizeof(struct gg_header); |
2393 | 185 |
186 gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(...);\n"); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
187 |
2393 | 188 if (!sess) { |
189 errno = EFAULT; | |
190 return NULL; | |
191 } | |
192 | |
193 if (sess->recv_left < 1) { | |
3630 | 194 while (ret != sizeh) { |
195 ret = read(sess->fd, &h, sizeh); | |
196 gg_debug(GG_DEBUG_MISC, "-- header recv(..., %d) = %d\n", sizeh, ret); | |
197 if (ret < sizeh) { | |
2393 | 198 if (errno != EINTR) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
199 gg_debug(GG_DEBUG_MISC, "-- errno = %d (%s)\n", errno, strerror(errno)); |
2393 | 200 return NULL; |
201 } | |
202 } | |
203 } | |
204 | |
205 h.type = fix32(h.type); | |
206 h.length = fix32(h.length); | |
207 } else { | |
3630 | 208 memcpy(&h, sess->recv_buf, sizeh); |
2393 | 209 } |
210 | |
211 /* jakie¶ sensowne limity na rozmiar pakietu */ | |
212 if (h.length < 0 || h.length > 65535) { | |
213 gg_debug(GG_DEBUG_MISC, "-- invalid packet length (%d)\n", h.length); | |
214 errno = ERANGE; | |
215 return NULL; | |
216 } | |
217 | |
218 if (sess->recv_left > 0) { | |
219 gg_debug(GG_DEBUG_MISC, "-- resuming last gg_recv_packet()\n"); | |
220 size = sess->recv_left; | |
221 offset = sess->recv_done; | |
222 buf = sess->recv_buf; | |
223 } else { | |
3630 | 224 if (!(buf = malloc(sizeh + h.length + 1))) { |
2393 | 225 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n"); |
226 return NULL; | |
227 } | |
228 | |
3630 | 229 memcpy(buf, &h, sizeh); |
2393 | 230 |
231 offset = 0; | |
232 size = h.length; | |
233 } | |
234 | |
235 while (size > 0) { | |
3630 | 236 ret = read(sess->fd, buf + sizeh + offset, size); |
2393 | 237 gg_debug(GG_DEBUG_MISC, "-- body recv(..., %d) = %d\n", size, ret); |
238 if (ret > -1 && ret <= size) { | |
239 offset += ret; | |
240 size -= ret; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
241 } else if (ret == -1) { |
2393 | 242 gg_debug(GG_DEBUG_MISC, "-- errno = %d (%s)\n", errno, strerror(errno)); |
243 if (errno == EAGAIN) { | |
244 gg_debug(GG_DEBUG_MISC, "-- %d bytes received, %d left\n", offset, size); | |
245 sess->recv_buf = buf; | |
246 sess->recv_left = size; | |
247 sess->recv_done = offset; | |
248 return NULL; | |
249 } | |
250 if (errno != EINTR) { | |
6063 | 251 /* errno = EINVAL; */ |
2393 | 252 free(buf); |
253 return NULL; | |
254 } | |
255 } | |
256 } | |
257 | |
258 sess->recv_left = 0; | |
259 | |
260 if ((gg_debug_level & GG_DEBUG_DUMP)) { | |
261 int i; | |
262 | |
263 gg_debug(GG_DEBUG_DUMP, ">> received packet (type=%.2x):", h.type); | |
3630 | 264 for (i = 0; i < sizeh + h.length; i++) |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
265 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) buf[i]); |
2393 | 266 gg_debug(GG_DEBUG_DUMP, "\n"); |
267 } | |
268 | |
269 return buf; | |
270 } | |
271 | |
272 /* | |
273 * gg_send_packet() // funkcja wewnźtrzna | |
274 * | |
8775 | 275 * konstruuje pakiet i wysy³a go do serwera. |
2393 | 276 * |
8775 | 277 * - sock - deskryptor gniazda |
278 * - type - typ pakietu | |
279 * - payload_1 - pierwsza czź¶ę pakietu | |
280 * - payload_length_1 - d³ugo¶ę pierwszej czź¶ci | |
281 * - payload_2 - druga czź¶ę pakietu | |
282 * - payload_length_2 - d³ugo¶ę drugiej czź¶ci | |
283 * - ... - kolejne czź¶ci pakietu i ich d³ugo¶ci | |
284 * - NULL - końcowym parametr (konieczny!) | |
2393 | 285 * |
8775 | 286 * je¶li siź powiod³o, zwraca 0, w przypadku b³źdu -1. je¶li errno == ENOMEM, |
287 * zabrak³o pamiźci. inaczej by³ b³±d przy wysy³aniu pakietu. dla errno == 0 | |
2393 | 288 * nie wys³ano ca³ego pakietu. |
289 */ | |
8775 | 290 int gg_send_packet(struct gg_session *sess, int type, ...) |
2393 | 291 { |
292 struct gg_header *h; | |
293 char *tmp; | |
8775 | 294 int tmp_length; |
295 void *payload; | |
296 int payload_length; | |
297 va_list ap; | |
298 int res; | |
2393 | 299 |
8775 | 300 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_packet(%p, 0x%.2x, ...)\n", sess, type); |
2393 | 301 |
8775 | 302 tmp_length = 0; |
303 | |
304 if (!(tmp = malloc(sizeof(struct gg_header)))) { | |
305 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() not enough memory for packet header\n"); | |
2393 | 306 return -1; |
307 } | |
308 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
309 h = (struct gg_header*) tmp; |
2393 | 310 h->type = fix32(type); |
8775 | 311 h->length = fix32(0); |
312 | |
313 va_start(ap, type); | |
314 | |
315 payload = va_arg(ap, void *); | |
316 | |
317 while (payload) { | |
318 char *tmp2; | |
319 | |
320 payload_length = va_arg(ap, int); | |
2393 | 321 |
8775 | 322 if (payload_length < 0) |
323 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() invalid payload length (%d)\n", payload_length); | |
324 | |
325 if (!(tmp2 = realloc(tmp, sizeof(struct gg_header) + tmp_length + payload_length))) { | |
326 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() not enough memory for payload\n"); | |
327 free(tmp); | |
328 va_end(ap); | |
329 return -1; | |
330 } | |
331 | |
332 tmp = tmp2; | |
333 | |
334 memcpy(tmp + sizeof(struct gg_header) + tmp_length, payload, payload_length); | |
335 tmp_length += payload_length; | |
336 | |
337 payload = va_arg(ap, void *); | |
338 } | |
339 | |
340 va_end(ap); | |
341 | |
342 h = (struct gg_header*) tmp; | |
343 h->length = fix32(tmp_length); | |
2393 | 344 |
345 if ((gg_debug_level & GG_DEBUG_DUMP)) { | |
8775 | 346 unsigned int i; |
347 | |
348 gg_debug(GG_DEBUG_DUMP, "// gg_send_packet(0x%.2x)", fix32(h->type)); | |
349 for (i = 0; i < sizeof(struct gg_header) + fix32(h->length); i++) | |
350 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) tmp[i]); | |
351 gg_debug(GG_DEBUG_DUMP, "\n"); | |
352 } | |
353 | |
354 tmp_length += sizeof(struct gg_header); | |
355 | |
356 if ((res = gg_write(sess, tmp, tmp_length)) < tmp_length) { | |
357 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() write() failed. res = %d, errno = %d (%s)\n", res, errno, strerror(errno)); | |
2393 | 358 free(tmp); |
359 return -1; | |
360 } | |
8775 | 361 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
362 free(tmp); |
2393 | 363 return 0; |
364 } | |
365 | |
8775 | 366 /* |
367 * gg_write() // funkcja pomocnicza | |
368 * | |
369 * zapisuje do gniazda okre¶lon± ilo¶ę bajtów. bierze pod uwagź, czy mamy | |
370 * po³±czenie zwyk³e czy TLS. | |
371 * | |
372 * - sess - sesja, | |
373 * - buf - bufor, | |
374 * - length - ilo¶ę bajtów, | |
375 * | |
376 * takie same warto¶ci jak write(). | |
377 */ | |
378 int gg_write(struct gg_session *sess, const char *buf, int length) | |
379 { | |
380 int res; | |
381 | |
382 #ifdef __GG_LIBGADU_HAVE_OPENSSL | |
383 if (sess->ssl) { | |
384 int err; | |
385 | |
386 res = SSL_write(sess->ssl, buf, length); | |
387 | |
388 if (res < 0) { | |
389 err = SSL_get_error(sess->ssl, res); | |
390 | |
391 if (err == SSL_ERROR_WANT_WRITE) | |
392 errno = EAGAIN; | |
393 | |
394 return -1; | |
395 } | |
396 } else | |
397 #endif | |
398 res = write(sess->fd, buf, length); | |
399 | |
400 return res; | |
401 } | |
402 | |
403 | |
3630 | 404 #ifndef _WIN32 |
2393 | 405 /* |
406 * gg_login() | |
407 * | |
408 * rozpoczyna procedurź ³±czenia siź z serwerem. resztź obs³guje siź przez | |
409 * gg_watch_event. | |
410 * | |
411 * - uin - numerek usera, | |
412 * - password - jego hase³ko, | |
413 * - async - ma byę asynchronicznie? | |
414 * | |
415 * UWAGA! program musi obs³uæyę SIGCHLD, je¶li ³±czy siź asynchronicznie, | |
416 * æeby zrobię pogrzeb zmar³emu procesowi resolvera. | |
417 * | |
418 * w przypadku b³źdu zwraca NULL, je¶li idzie dobrze (async) albo posz³o | |
419 * dobrze (sync), zwróci wska¼nik do zaalokowanej struktury `gg_session'. | |
420 */ | |
421 struct gg_session *gg_login(uin_t uin, char *password, int async) | |
422 { | |
423 struct gg_session *sess; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
424 char *hostname; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
425 int port; |
2393 | 426 |
427 gg_debug(GG_DEBUG_FUNCTION, "** gg_login(%u, \"...\", %d);\n", uin, async); | |
428 | |
429 if (!(sess = malloc(sizeof(*sess)))) | |
430 return NULL; | |
431 | |
432 sess->uin = uin; | |
433 if (!(sess->password = strdup(password))) { | |
434 free(sess); | |
435 return NULL; | |
436 } | |
437 sess->state = GG_STATE_RESOLVING; | |
438 sess->check = GG_CHECK_READ; | |
439 sess->async = async; | |
440 sess->seq = 0; | |
441 sess->recv_left = 0; | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
442 sess->last_pong = 0; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
443 sess->server_ip = 0; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
444 sess->initial_status = 0; |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
445 sess->type = GG_SESSION_GG; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
446 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
447 if (gg_http_use_proxy) { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
448 hostname = gg_http_proxy_host; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
449 port = gg_http_proxy_port; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
450 } else { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
451 hostname = GG_APPMSG_HOST; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
452 port = GG_APPMSG_PORT; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
453 }; |
2393 | 454 |
455 if (async) { | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
456 if (gg_resolve(&sess->fd, &sess->pid, hostname)) { |
2393 | 457 gg_debug(GG_DEBUG_MISC, "-- resolving failed\n"); |
458 free(sess); | |
459 return NULL; | |
460 } | |
461 } else { | |
462 struct in_addr a; | |
463 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
464 if ((a.s_addr = inet_addr(hostname)) == INADDR_NONE) { |
2393 | 465 struct hostent *he; |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
466 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
467 if (!(he = gethostbyname(hostname))) { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
468 gg_debug(GG_DEBUG_MISC, "-- host %s not found\n", hostname); |
2393 | 469 free(sess); |
470 return NULL; | |
471 } else | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
472 memcpy((char*) &a, he->h_addr, sizeof(a)); |
2393 | 473 } |
474 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
475 if (!(sess->fd = gg_connect(&a, port, 0)) == -1) { |
2393 | 476 gg_debug(GG_DEBUG_MISC, "-- connection failed\n"); |
477 free(sess); | |
478 return NULL; | |
479 } | |
480 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
481 sess->state = GG_STATE_CONNECTING; |
2393 | 482 |
483 while (sess->state != GG_STATE_CONNECTED) { | |
484 struct gg_event *e; | |
485 | |
486 if (!(e = gg_watch_fd(sess))) { | |
487 gg_debug(GG_DEBUG_MISC, "-- some nasty error in gg_watch_fd()\n"); | |
488 free(sess); | |
489 return NULL; | |
490 } | |
491 | |
492 if (e->type == GG_EVENT_CONN_FAILED) { | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
493 errno = EACCES; |
2393 | 494 gg_debug(GG_DEBUG_MISC, "-- could not login\n"); |
495 gg_free_event(e); | |
496 free(sess); | |
497 return NULL; | |
498 } | |
499 | |
500 gg_free_event(e); | |
501 } | |
502 } | |
503 | |
504 return sess; | |
505 } | |
3630 | 506 #endif /*!_WIN32*/ |
2393 | 507 |
508 /* | |
8775 | 509 * gg_login_hash() // funkcja wewnźtrzna |
510 * | |
511 * liczy hash z has³a i danego seeda. | |
512 * | |
513 * - password - has³o do hashowania | |
514 * - seed - warto¶ę podana przez serwer | |
515 * | |
516 * hash. | |
517 */ | |
518 unsigned int gg_login_hash(const unsigned char *password, unsigned int seed) | |
519 { | |
520 unsigned int x, y, z; | |
521 | |
522 y = seed; | |
523 | |
524 for (x = 0; *password; password++) { | |
525 x = (x & 0xffffff00) | *password; | |
526 y ^= x; | |
527 y += x; | |
528 x <<= 8; | |
529 y ^= x; | |
530 x <<= 8; | |
531 y -= x; | |
532 x <<= 8; | |
533 y ^= x; | |
534 | |
535 z = y & 0x1F; | |
536 y = (y << z) | (y >> (32 - z)); | |
537 } | |
538 | |
539 return y; | |
540 } | |
541 | |
542 /* | |
2393 | 543 * gg_free_session() |
544 * | |
545 * zwalnia pamiźę zajmowan± przez opis sesji. | |
546 * | |
547 * - sess - opis sesji. | |
548 * | |
549 * nie zwraca niczego, bo i po co? | |
550 */ | |
551 void gg_free_session(struct gg_session *sess) | |
552 { | |
553 if (!sess) | |
554 return; | |
555 | |
556 free(sess->password); | |
557 free(sess); | |
558 } | |
559 | |
560 /* | |
561 * gg_change_status() | |
562 * | |
563 * zmienia status uæytkownika. przydatne do /away i /busy oraz /quit. | |
564 * | |
565 * - sess - opis sesji, | |
566 * - status - nowy status uæytkownika. | |
567 * | |
568 * je¶li wys³a³ pakiet zwraca 0, je¶li nie uda³o siź, zwraca -1. | |
569 */ | |
570 int gg_change_status(struct gg_session *sess, int status) | |
571 { | |
572 struct gg_new_status p; | |
573 | |
574 if (!sess) { | |
575 errno = EFAULT; | |
576 return -1; | |
577 } | |
578 | |
579 if (sess->state != GG_STATE_CONNECTED) { | |
580 errno = ENOTCONN; | |
581 return -1; | |
582 } | |
583 | |
584 gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status(..., %d);\n", status); | |
585 | |
586 p.status = fix32(status); | |
587 | |
8775 | 588 return gg_send_packet(sess, GG_NEW_STATUS, &p, sizeof(p), NULL, 0); |
2393 | 589 } |
590 | |
591 /* | |
9415 | 592 * gg_change_status_descr() |
593 * | |
594 * zmienia status uĆøytkownika na opisowy. | |
595 * | |
596 * - sess - opis sesji | |
597 * - status - nowy status uĆøytkownika | |
598 * - descr - opis statusu | |
599 * | |
600 * 0, -1. | |
601 */ | |
602 int gg_change_status_descr(struct gg_session *sess, int status, const char *descr) | |
603 { | |
604 struct gg_new_status p; | |
605 | |
606 gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status_descr(%p, %d, \"%s\");\n", sess, status, descr); | |
607 | |
608 if (!sess || !descr) { | |
609 errno = EFAULT; | |
610 return -1; | |
611 } | |
612 | |
613 if (sess->state != GG_STATE_CONNECTED) { | |
614 errno = ENOTCONN; | |
615 return -1; | |
616 } | |
617 | |
618 p.status = fix32(status); | |
619 | |
620 return gg_send_packet(sess, GG_NEW_STATUS, &p, sizeof(p), descr, (strlen(descr) > GG_STATUS_DESCR_MAXSIZE) ? GG_STATUS_DESCR_MAXSIZE : strlen(descr), NULL); | |
621 } | |
622 | |
623 /* | |
2393 | 624 * gg_logoff() |
625 * | |
626 * wylogowuje uæytkownika i zamyka po³±czenie. | |
627 * | |
628 * - sock - deskryptor socketu. | |
629 * | |
630 * nie zwraca b³źdów. skoro siź æegnamy, to olewamy wszystko. | |
631 */ | |
632 void gg_logoff(struct gg_session *sess) | |
633 { | |
634 if (!sess) | |
635 return; | |
636 | |
637 gg_debug(GG_DEBUG_FUNCTION, "** gg_logoff(...);\n"); | |
638 | |
639 if (sess->state == GG_STATE_CONNECTED) | |
640 gg_change_status(sess, GG_STATUS_NOT_AVAIL); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
641 |
2393 | 642 if (sess->fd) { |
643 shutdown(sess->fd, 2); | |
644 close(sess->fd); | |
645 } | |
646 } | |
647 | |
648 /* | |
649 * gg_send_message() | |
650 * | |
651 * wysy³a wiadomo¶ę do innego uæytkownika. zwraca losowy numer | |
8775 | 652 * sekwencyjny, który moæna zignorowaę albo wykorzystaę do potwierdzenia. |
653 * | |
654 * - sess - opis sesji | |
655 * - msgclass - rodzaj wiadomo¶ci | |
656 * - recipient - numer adresata | |
657 * - message - tre¶ę wiadomo¶ci | |
2393 | 658 * |
8775 | 659 * numer sekwencyjny wiadomo¶ci lub -1 w przypadku b³źdu. |
660 */ | |
661 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message) | |
662 { | |
663 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message(%p, %d, %u, %p)\n", sess, msgclass, recipient, message); | |
664 | |
665 return gg_send_message_richtext(sess, msgclass, recipient, message, NULL, 0); | |
666 } | |
667 | |
668 /* | |
669 * gg_send_message_richtext() | |
2393 | 670 * |
8775 | 671 * wysy³a kolorow± wiadomo¶ę do innego uæytkownika. zwraca losowy numer |
672 * sekwencyjny, który moæna zignorowaę albo wykorzystaę do potwierdzenia. | |
673 * | |
674 * - sess - opis sesji | |
675 * - msgclass - rodzaj wiadomo¶ci | |
676 * - recipient - numer adresata | |
677 * - message - tre¶ę wiadomo¶ci | |
678 * - format - informacje o formatowaniu | |
679 * - formatlen - d³ugo¶ę informacji o formatowaniu | |
680 * | |
681 * numer sekwencyjny wiadomo¶ci lub -1 w przypadku b³źdu. | |
2393 | 682 */ |
8775 | 683 int gg_send_message_richtext(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message, const unsigned char *format, int formatlen) |
2393 | 684 { |
685 struct gg_send_msg s; | |
686 | |
8775 | 687 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message_richtext(%p, %d, %u, %p, %p, %d);\n", sess, msgclass, recipient, message, format, formatlen); |
688 | |
2393 | 689 if (!sess) { |
690 errno = EFAULT; | |
691 return -1; | |
692 } | |
9863 | 693 |
2393 | 694 if (sess->state != GG_STATE_CONNECTED) { |
695 errno = ENOTCONN; | |
696 return -1; | |
697 } | |
698 | |
699 s.recipient = fix32(recipient); | |
700 if (!sess->seq) | |
701 sess->seq = 0x01740000 | (rand() & 0xffff); | |
702 s.seq = fix32(sess->seq); | |
703 s.msgclass = fix32(msgclass); | |
704 sess->seq += (rand() % 0x300) + 0x300; | |
9863 | 705 |
8775 | 706 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen(message) + 1, format, formatlen, NULL) == -1) |
2393 | 707 return -1; |
708 | |
709 return fix32(s.seq); | |
710 } | |
711 | |
712 /* | |
713 * gg_ping() | |
714 * | |
715 * wysy³a do serwera pakiet typu yeah-i'm-still-alive. | |
716 * | |
717 * - sess - zgadnij. | |
718 * | |
719 * je¶li nie powiod³o siź wys³anie pakietu, zwraca -1. otherwise 0. | |
720 */ | |
721 int gg_ping(struct gg_session *sess) | |
722 { | |
723 if (!sess) { | |
724 errno = EFAULT; | |
725 return -1; | |
726 } | |
727 | |
728 if (sess->state != GG_STATE_CONNECTED) { | |
729 errno = ENOTCONN; | |
730 return -1; | |
731 } | |
732 | |
733 gg_debug(GG_DEBUG_FUNCTION, "** gg_ping(...);\n"); | |
9863 | 734 |
8775 | 735 return gg_send_packet(sess, GG_PING, NULL); |
2393 | 736 } |
737 | |
738 /* | |
739 * gg_free_event() | |
740 * | |
741 * zwalnia pamiźę zajmowan± przez informacjź o zdarzeniu | |
742 * | |
743 * - event - wska¼nik do informacji o zdarzeniu | |
744 * | |
745 * nie ma czego zwracaę. | |
746 */ | |
747 void gg_free_event(struct gg_event *e) | |
748 { | |
749 if (!e) | |
750 return; | |
751 if (e->type == GG_EVENT_MSG) | |
752 free(e->event.msg.message); | |
753 if (e->type == GG_EVENT_NOTIFY) | |
754 free(e->event.notify); | |
755 free(e); | |
756 } | |
757 | |
758 /* | |
759 * gg_notify() | |
760 * | |
761 * wysy³a serwerowi listź ludków, za którymi tźsknimy. | |
762 * | |
763 * - sess - identyfikator sesji, | |
764 * - userlist - wska¼nik do tablicy numerów, | |
765 * - count - ilo¶ę numerków. | |
766 * | |
767 * je¶li uda³o siź, zwraca 0. je¶li b³±d, dostajemy -1. | |
768 */ | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
769 int gg_notify(struct gg_session *sess, uin_t *userlist, int count) |
2393 | 770 { |
771 struct gg_notify *n; | |
772 uin_t *u; | |
773 int i, res = 0; | |
774 | |
775 if (!sess) { | |
776 errno = EFAULT; | |
777 return -1; | |
778 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
779 |
2393 | 780 if (sess->state != GG_STATE_CONNECTED) { |
781 errno = ENOTCONN; | |
782 return -1; | |
783 } | |
784 | |
785 gg_debug(GG_DEBUG_FUNCTION, "** gg_notify(..., %d);\n", count); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
786 |
2393 | 787 if (!userlist || !count) |
788 return 0; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
789 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
790 if (!(n = (struct gg_notify*) malloc(sizeof(*n) * count))) |
2393 | 791 return -1; |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
792 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
793 for (u = userlist, i = 0; i < count; u++, i++) { |
2393 | 794 n[i].uin = fix32(*u); |
795 n[i].dunno1 = 3; | |
796 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
797 |
8775 | 798 if (gg_send_packet(sess, GG_NOTIFY, n, sizeof(*n) * count, NULL, 0) == -1) |
2393 | 799 res = -1; |
800 | |
801 free(n); | |
802 | |
803 return res; | |
804 } | |
805 | |
806 /* | |
807 * gg_add_notify() | |
808 * | |
809 * dodaje w locie do listy ukochanych dany numerek. | |
810 * | |
811 * - sess - identyfikator sesji, | |
812 * - uin - numerek ukochanej. | |
813 * | |
814 * je¶li uda³o siź wys³aę, daje 0. inaczej -1. | |
815 */ | |
816 int gg_add_notify(struct gg_session *sess, uin_t uin) | |
817 { | |
818 struct gg_add_remove a; | |
819 | |
820 if (!sess) { | |
821 errno = EFAULT; | |
822 return -1; | |
823 } | |
824 | |
825 if (sess->state != GG_STATE_CONNECTED) { | |
826 errno = ENOTCONN; | |
827 return -1; | |
828 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
829 |
2393 | 830 gg_debug(GG_DEBUG_FUNCTION, "** gg_add_notify(..., %u);\n", uin); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
831 |
2393 | 832 a.uin = fix32(uin); |
833 a.dunno1 = 3; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
834 |
8775 | 835 return gg_send_packet(sess, GG_ADD_NOTIFY, &a, sizeof(a), NULL); |
2393 | 836 } |
837 | |
838 /* | |
839 * gg_remove_notify() | |
840 * | |
841 * w locie usuwa z listy zainteresowanych. | |
842 * | |
843 * - sess - id sesji, | |
844 * - uin - numerek. | |
845 * | |
846 * zwraca -1 je¶li by³ b³±d, 0 je¶li siź uda³o wys³aę pakiet. | |
847 */ | |
848 int gg_remove_notify(struct gg_session *sess, uin_t uin) | |
849 { | |
850 struct gg_add_remove a; | |
851 | |
852 if (!sess) { | |
853 errno = EFAULT; | |
854 return -1; | |
855 } | |
856 | |
857 if (sess->state != GG_STATE_CONNECTED) { | |
858 errno = ENOTCONN; | |
859 return -1; | |
860 } | |
861 | |
862 gg_debug(GG_DEBUG_FUNCTION, "** gg_remove_notify(..., %u);\n", uin); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
863 |
2393 | 864 a.uin = fix32(uin); |
865 a.dunno1 = 3; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
866 |
8775 | 867 return gg_send_packet(sess, GG_REMOVE_NOTIFY, &a, sizeof(a), NULL, 0); |
868 } | |
869 | |
870 /* | |
871 * gg_userlist_request() | |
872 * | |
873 * wysy³a æ±danie/zapytanie listy kontaktów na serwerze. | |
874 * | |
875 * - sess - opis sesji | |
876 * - type - rodzaj zapytania/æ±dania | |
877 * - request - tre¶ę zapytania/æ±dania (moæe byę NULL) | |
878 * | |
879 * 0, -1 | |
880 */ | |
881 int gg_userlist_request(struct gg_session *sess, char type, const char *request) | |
882 { | |
883 int len; | |
884 | |
885 if (!sess) { | |
886 errno = EINVAL; | |
887 return -1; | |
888 } | |
889 | |
890 if (!request) { | |
891 sess->userlist_blocks = 1; | |
892 return gg_send_packet(sess, GG_USERLIST_REQUEST, &type, sizeof(type), NULL); | |
893 } | |
894 | |
895 len = strlen(request); | |
896 | |
897 sess->userlist_blocks = 0; | |
898 | |
899 while (len > 2047) { | |
900 sess->userlist_blocks++; | |
901 | |
902 if (gg_send_packet(sess, GG_USERLIST_REQUEST, &type, sizeof(type), request, 2047, NULL) == -1) | |
903 return -1; | |
904 | |
905 if (type == GG_USERLIST_PUT) | |
906 type = GG_USERLIST_PUT_MORE; | |
907 | |
908 request += 2047; | |
909 len -= 2047; | |
910 } | |
911 | |
912 sess->userlist_blocks++; | |
913 | |
914 return gg_send_packet(sess, GG_USERLIST_REQUEST, &type, sizeof(type), request, len, NULL); | |
2393 | 915 } |
916 | |
917 /* | |
918 * gg_watch_fd_connected() // funkcja wewnźtrzna | |
919 * | |
920 * patrzy na socketa, odbiera pakiet i wype³nia strukturź zdarzenia. | |
921 * | |
922 * - sock - lalala, trudno zgadn±ę. | |
923 * | |
924 * je¶li b³±d -1, je¶li dobrze 0. | |
925 */ | |
926 static int gg_watch_fd_connected(struct gg_session *sess, struct gg_event *e) | |
927 { | |
928 struct gg_header *h; | |
8775 | 929 char *p; |
2393 | 930 |
931 if (!sess) { | |
932 errno = EFAULT; | |
933 return -1; | |
934 } | |
935 | |
936 gg_debug(GG_DEBUG_FUNCTION, "** gg_watch_fd_connected(...);\n"); | |
937 | |
938 if (!(h = gg_recv_packet(sess))) { | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
939 gg_debug(GG_DEBUG_MISC, "-- gg_recv_packet failed. errno = %d (%d)\n", errno, strerror(errno)); |
2393 | 940 return -1; |
941 } | |
942 | |
6247 | 943 p = (void *)h + sizeof(struct gg_header); |
9863 | 944 |
945 | |
8775 | 946 switch (h->type) { |
947 case GG_RECV_MSG: | |
948 { | |
949 struct gg_recv_msg *r = (void *)p; | |
2393 | 950 |
951 gg_debug(GG_DEBUG_MISC, "-- received a message\n"); | |
952 | |
953 if (h->length >= sizeof(*r)) { | |
954 e->type = GG_EVENT_MSG; | |
955 e->event.msg.msgclass = fix32(r->msgclass); | |
956 e->event.msg.sender = fix32(r->sender); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
957 e->event.msg.message = strdup((char*) r + sizeof(*r)); |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
958 e->event.msg.time = fix32(r->time); |
2393 | 959 } |
8775 | 960 break; |
961 } | |
962 case GG_NOTIFY_REPLY: | |
963 { | |
964 struct gg_notify_reply *n = (void *)p; | |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
965 int count, i; |
2393 | 966 |
967 gg_debug(GG_DEBUG_MISC, "-- received a notify reply\n"); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
968 |
2393 | 969 e->type = GG_EVENT_NOTIFY; |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
970 if (!(e->event.notify = (void*) malloc(h->length + 2 * sizeof(*n)))) { |
2393 | 971 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n"); |
972 free(h); | |
973 return -1; | |
974 } | |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
975 count = h->length / sizeof(*n); |
2393 | 976 memcpy(e->event.notify, p, h->length); |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
977 e->event.notify[count].uin = 0; |
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
978 for (i = 0; i < count; i++) { |
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
979 e->event.notify[i].uin = fix32(e->event.notify[i].uin); |
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
980 e->event.notify[i].status = fix32(e->event.notify[i].status); |
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
981 } |
8775 | 982 break; |
983 } | |
984 | |
985 case GG_NOTIFY_REPLY60: | |
986 { | |
987 struct gg_notify_reply60 *n = (void*) p; | |
988 unsigned int length = h->length, i = 0; | |
989 | |
990 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() received a notify reply\n"); | |
991 | |
992 e->type = GG_EVENT_NOTIFY60; | |
993 e->event.notify60 = malloc(sizeof(*e->event.notify60)); | |
994 | |
995 if (!e->event.notify60) { | |
996 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() not enough memory for notify data\n"); | |
997 goto fail; | |
998 } | |
999 | |
1000 e->event.notify60[0].uin = 0; | |
1001 | |
1002 while (length >= sizeof(struct gg_notify_reply60)) { | |
1003 uin_t uin = fix32(n->uin); | |
1004 char *tmp; | |
1005 | |
1006 e->event.notify60[i].uin = uin & 0x00ffffff; | |
1007 e->event.notify60[i].status = n->status; | |
1008 e->event.notify60[i].remote_ip = n->remote_ip; | |
1009 e->event.notify60[i].remote_port = fix16(n->remote_port); | |
1010 e->event.notify60[i].version = n->version; | |
1011 e->event.notify60[i].image_size = n->image_size; | |
1012 e->event.notify60[i].descr = NULL; | |
1013 e->event.notify60[i].time = 0; | |
1014 | |
1015 if (GG_S_D(n->status)) { | |
1016 unsigned char descr_len = *((char*) n + sizeof(struct gg_notify_reply60)); | |
2393 | 1017 |
8775 | 1018 if (descr_len < length) { |
1019 if (!(e->event.notify60[i].descr = malloc(descr_len + 1))) { | |
1020 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() not enough memory for notify data\n"); | |
1021 goto fail; | |
1022 } | |
1023 | |
1024 memcpy(e->event.notify60[i].descr, (char*) n + sizeof(struct gg_notify_reply60) + 1, descr_len); | |
1025 e->event.notify60[i].descr[descr_len] = 0; | |
1026 | |
1027 /* XXX czas */ | |
1028 } | |
1029 | |
1030 length -= sizeof(struct gg_notify_reply60) + descr_len + 1; | |
1031 n = (void*) ((char*) n + sizeof(struct gg_notify_reply60) + descr_len + 1); | |
1032 } else { | |
1033 length -= sizeof(struct gg_notify_reply60); | |
1034 n = (void*) ((char*) n + sizeof(struct gg_notify_reply60)); | |
1035 } | |
1036 | |
1037 if (!(tmp = realloc(e->event.notify60, (i + 2) * sizeof(*e->event.notify60)))) { | |
1038 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() not enough memory for notify data\n"); | |
1039 free(e->event.notify60); | |
1040 goto fail; | |
1041 } | |
1042 | |
1043 e->event.notify60 = (void*) tmp; | |
1044 e->event.notify60[++i].uin = 0; | |
1045 } | |
1046 | |
1047 break; | |
1048 } | |
1049 | |
1050 case GG_STATUS: | |
1051 { | |
1052 struct gg_status *s = (void *)p; | |
2393 | 1053 |
1054 gg_debug(GG_DEBUG_MISC, "-- received a status change\n"); | |
1055 | |
1056 if (h->length >= sizeof(*s)) { | |
1057 e->type = GG_EVENT_STATUS; | |
1058 memcpy(&e->event.status, p, h->length); | |
2399
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
1059 e->event.status.uin = fix32(e->event.status.uin); |
b2926d21f067
[gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
1060 e->event.status.status = fix32(e->event.status.status); |
2393 | 1061 } |
8775 | 1062 break; |
1063 } | |
1064 | |
1065 case GG_STATUS60: | |
1066 { | |
1067 struct gg_status60 *s = (void*) p; | |
1068 uint32_t uin; | |
1069 | |
1070 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() received a status change\n"); | |
1071 | |
1072 if (h->length < sizeof(*s)) | |
1073 break; | |
1074 | |
1075 uin = fix32(s->uin); | |
1076 | |
1077 e->type = GG_EVENT_STATUS60; | |
1078 e->event.status60.uin = uin & 0x00ffffff; | |
1079 e->event.status60.status = s->status; | |
1080 e->event.status60.remote_ip = s->remote_ip; | |
1081 e->event.status60.remote_port = fix16(s->remote_port); | |
1082 e->event.status60.version = s->version; | |
1083 e->event.status60.image_size = s->image_size; | |
1084 e->event.status60.descr = NULL; | |
1085 e->event.status60.time = 0; | |
2393 | 1086 |
8775 | 1087 if (uin & 0x40000000) |
1088 e->event.status60.version |= GG_HAS_AUDIO_MASK; | |
1089 | |
1090 if (h->length > sizeof(*s)) { | |
1091 int len = h->length - sizeof(*s); | |
1092 char *buf = malloc(len + 1); | |
1093 | |
1094 if (buf) { | |
1095 memcpy(buf, (char*) p + sizeof(*s), len); | |
1096 buf[len] = 0; | |
1097 } | |
1098 | |
1099 e->event.status60.descr = buf; | |
1100 | |
1101 if (len > 4 && p[h->length - 5] == 0) | |
1102 e->event.status60.time = *((int*) (p + h->length - 4)); | |
1103 } | |
1104 | |
1105 break; | |
1106 } | |
1107 | |
1108 case GG_SEND_MSG_ACK: | |
1109 { | |
1110 struct gg_send_msg_ack *s = (void *)p; | |
2393 | 1111 |
1112 gg_debug(GG_DEBUG_MISC, "-- received a message ack\n"); | |
1113 | |
1114 if (h->length >= sizeof(*s)) { | |
1115 e->type = GG_EVENT_ACK; | |
1116 e->event.ack.status = fix32(s->status); | |
1117 e->event.ack.recipient = fix32(s->recipient); | |
1118 e->event.ack.seq = fix32(s->seq); | |
1119 } | |
8775 | 1120 break; |
1121 } | |
2393 | 1122 |
8775 | 1123 case GG_PONG: |
1124 { | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1125 gg_debug(GG_DEBUG_MISC, "-- received a pong\n"); |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1126 sess->last_pong = time(NULL); |
8775 | 1127 break; |
1128 } | |
1129 | |
1130 case GG_USERLIST_REPLY: | |
1131 { | |
1132 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() received userlist reply\n"); | |
1133 | |
1134 if (h->length < 1) | |
1135 break; | |
1136 | |
1137 /* je¶li odpowied¼ na eksport, wywo³aj zdarzenie tylko | |
1138 * gdy otrzymano wszystkie odpowiedzi */ | |
1139 if (p[0] == GG_USERLIST_PUT_REPLY || p[0] == GG_USERLIST_PUT_MORE_REPLY) { | |
1140 if (--sess->userlist_blocks) | |
1141 break; | |
1142 | |
1143 p[0] = GG_USERLIST_PUT_REPLY; | |
1144 } | |
1145 | |
1146 if (h->length > 1) { | |
1147 char *tmp; | |
1148 int len = (sess->userlist_reply) ? strlen(sess->userlist_reply) : 0; | |
1149 | |
1150 gg_debug(GG_DEBUG_MISC, "userlist_reply=%p, len=%d\n", sess->userlist_reply, len); | |
1151 | |
1152 if (!(tmp = realloc(sess->userlist_reply, len + h->length))) { | |
1153 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() not enough memory for userlist reply\n"); | |
1154 free(sess->userlist_reply); | |
1155 sess->userlist_reply = NULL; | |
1156 goto fail; | |
1157 } | |
1158 | |
1159 sess->userlist_reply = tmp; | |
1160 sess->userlist_reply[len + h->length - 1] = 0; | |
1161 memcpy(sess->userlist_reply + len, p + 1, h->length - 1); | |
1162 } | |
1163 | |
1164 if (p[0] == GG_USERLIST_GET_MORE_REPLY) | |
1165 break; | |
1166 | |
1167 e->type = GG_EVENT_USERLIST; | |
1168 e->event.userlist.type = p[0]; | |
1169 e->event.userlist.reply = sess->userlist_reply; | |
1170 sess->userlist_reply = NULL; | |
1171 | |
1172 break; | |
1173 } | |
1174 | |
1175 default: | |
1176 gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() received unknown packet 0x%.2x\n", h->type); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1177 } |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1178 |
2393 | 1179 free(h); |
1180 | |
1181 return 0; | |
8775 | 1182 |
1183 fail: | |
1184 free(h); | |
1185 return -1; | |
2393 | 1186 } |
1187 | |
1188 /* | |
1189 * gg_watch_fd() | |
1190 * | |
1191 * funkcja wywo³ywana, gdy co¶ siź stanie na obserwowanym deskryptorze. | |
1192 * zwraca klientowi informacjź o tym, co siź dzieje. | |
1193 * | |
1194 * - sess - identyfikator sesji. | |
1195 * | |
1196 * zwraca wska¼nik do struktury gg_event, któr± trzeba zwolnię pó¼niej | |
1197 * za pomoc± gg_free_event(). jesli rodzaj zdarzenia jest równy | |
1198 * GG_EVENT_NONE, naleæy je olaę kompletnie. je¶li zwróci³o NULL, | |
1199 * sta³o siź co¶ niedobrego -- albo brak³o pamiźci albo zerwa³o | |
1200 * po³±czenie albo co¶ takiego. | |
1201 */ | |
1202 struct gg_event *gg_watch_fd(struct gg_session *sess) | |
1203 { | |
1204 struct gg_event *e; | |
1205 int res = 0; | |
3630 | 1206 #ifndef _WIN32 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1207 int port; |
3630 | 1208 #endif |
2393 | 1209 |
1210 if (!sess) { | |
1211 errno = EFAULT; | |
1212 return NULL; | |
1213 } | |
1214 | |
1215 gg_debug(GG_DEBUG_FUNCTION, "** gg_watch_fd(...);\n"); | |
1216 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1217 if (!(e = (void*) malloc(sizeof(*e)))) { |
2393 | 1218 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n"); |
1219 return NULL; | |
1220 } | |
1221 | |
1222 e->type = GG_EVENT_NONE; | |
1223 | |
1224 switch (sess->state) { | |
3630 | 1225 #ifndef _WIN32 |
1226 /* Apparantly we will never be in this state as long as we are | |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
4298
diff
changeset
|
1227 using gaim_proxy_connect instead of gg_login - Herman */ |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1228 case GG_STATE_RESOLVING: |
2393 | 1229 { |
1230 struct in_addr a; | |
1231 | |
1232 gg_debug(GG_DEBUG_MISC, "== GG_STATE_RESOLVING\n"); | |
1233 | |
1234 if (read(sess->fd, &a, sizeof(a)) < sizeof(a) || a.s_addr == INADDR_NONE) { | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1235 gg_debug(GG_DEBUG_MISC, "-- resolving failed\n"); |
2393 | 1236 |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1237 errno = ENOENT; |
2393 | 1238 e->type = GG_EVENT_CONN_FAILED; |
1239 e->event.failure = GG_FAILURE_RESOLVING; | |
1240 sess->state = GG_STATE_IDLE; | |
1241 | |
1242 close(sess->fd); | |
1243 | |
1244 break; | |
1245 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1246 |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1247 sess->server_ip = a.s_addr; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1248 |
2393 | 1249 close(sess->fd); |
1250 | |
1251 waitpid(sess->pid, NULL, 0); | |
1252 | |
1253 gg_debug(GG_DEBUG_MISC, "-- resolved, now connecting\n"); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1254 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1255 if (gg_http_use_proxy) { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1256 port = gg_http_proxy_port; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1257 } else { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1258 port = GG_APPMSG_PORT; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1259 }; |
2393 | 1260 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1261 if ((sess->fd = gg_connect(&a, port, sess->async)) == -1) { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1262 struct in_addr *addr = (struct in_addr*) &sess->server_ip; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1263 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1264 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying direct connection\n"); |
2393 | 1265 |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1266 if ((sess->fd = gg_connect(addr, GG_DEFAULT_PORT, sess->async)) == -1) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1267 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1268 if ((sess->fd = gg_connect(&a, GG_HTTPS_PORT, sess->async)) == -1) { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1269 gg_debug(GG_DEBUG_MISC, "-- connect() failed. errno = %d (%s)\n", errno, strerror(errno)); |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1270 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1271 e->type = GG_EVENT_CONN_FAILED; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1272 e->event.failure = GG_FAILURE_CONNECTING; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1273 sess->state = GG_STATE_IDLE; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1274 break; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1275 } |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1276 } |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1277 sess->state = GG_STATE_CONNECTING_GG; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1278 sess->check = GG_CHECK_WRITE; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1279 } else { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1280 sess->state = GG_STATE_CONNECTING; |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1281 sess->check = GG_CHECK_WRITE; |
2393 | 1282 } |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1283 |
2393 | 1284 break; |
1285 } | |
3630 | 1286 #endif /* !_WIN32 */ |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1287 case GG_STATE_CONNECTING: |
2393 | 1288 { |
1289 char buf[1024]; | |
6063 | 1290 unsigned int res, res_size = sizeof(res); |
2393 | 1291 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1292 gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTING\n"); |
2393 | 1293 |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1294 if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) { |
3630 | 1295 #if 0 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1296 struct in_addr *addr = (struct in_addr*) &sess->server_ip; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1297 gg_debug(GG_DEBUG_MISC, "-- http connection failed, errno = %d (%s), trying direct connection\n", res, strerror(res)); |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1298 if ((sess->fd = gg_connect(addr, GG_DEFAULT_PORT, sess->async)) == -1) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1299 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1300 if ((sess->fd = gg_connect(addr, GG_HTTPS_PORT, sess->async)) == -1) { |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1301 gg_debug(GG_DEBUG_MISC, "-- connect() failed. errno = %d (%s)\n", errno, strerror(errno)); |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1302 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1303 e->type = GG_EVENT_CONN_FAILED; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1304 e->event.failure = GG_FAILURE_CONNECTING; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1305 sess->state = GG_STATE_IDLE; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1306 break; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1307 } |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1308 } |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1309 |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1310 sess->state = GG_STATE_CONNECTING_GG; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1311 sess->check = GG_CHECK_WRITE; |
3630 | 1312 #else |
1313 gg_debug(GG_DEBUG_MISC, "-- http connection failed, errno = %d\n", res); | |
1314 e->type = GG_EVENT_CONN_FAILED; | |
1315 e->event.failure = GG_FAILURE_CONNECTING; | |
1316 sess->state = GG_STATE_IDLE; | |
1317 #endif | |
2393 | 1318 break; |
1319 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1320 |
2393 | 1321 gg_debug(GG_DEBUG_MISC, "-- http connection succeded, sending query\n"); |
1322 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1323 if (gg_http_use_proxy) { |
3630 | 1324 g_snprintf(buf, sizeof(buf) - 1, |
9663 | 1325 "GET http://" GG_APPMSG_HOST "/appsvc/appmsg2.asp?fmnumber=%lu&version=%s&lastmsg=0 HTTP/1.0\r\n" |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1326 "Host: " GG_APPMSG_HOST "\r\n" |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1327 "User-Agent: " GG_HTTP_USERAGENT "\r\n" |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1328 "Pragma: no-cache\r\n" |
9663 | 1329 "\r\n", sess->uin, gg_urlencode(GG_DEFAULT_CLIENT_VERSION)); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1330 } else { |
3630 | 1331 g_snprintf(buf, sizeof(buf) - 1, |
9663 | 1332 "GET /appsvc/appmsg2.asp?fmnumber=%lu&version=%s&lastmsg=0 HTTP/1.0\r\n" |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1333 "Host: " GG_APPMSG_HOST "\r\n" |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1334 "User-Agent: " GG_HTTP_USERAGENT "\r\n" |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1335 "Pragma: no-cache\r\n" |
9663 | 1336 "\r\n", sess->uin, gg_urlencode(GG_DEFAULT_CLIENT_VERSION)); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1337 }; |
2393 | 1338 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1339 gg_debug(GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", buf); |
2393 | 1340 if (write(sess->fd, buf, strlen(buf)) < strlen(buf)) { |
1341 gg_debug(GG_DEBUG_MISC, "-- sending query failed\n"); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1342 errno = EIO; |
2393 | 1343 e->type = GG_EVENT_CONN_FAILED; |
1344 e->event.failure = GG_FAILURE_WRITING; | |
1345 sess->state = GG_STATE_IDLE; | |
1346 break; | |
1347 } | |
1348 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1349 sess->state = GG_STATE_READING_DATA; |
2393 | 1350 sess->check = GG_CHECK_READ; |
1351 | |
1352 break; | |
1353 } | |
1354 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1355 case GG_STATE_READING_DATA: |
2393 | 1356 { |
1357 char buf[1024], *tmp, *host; | |
1358 int port = GG_DEFAULT_PORT; | |
1359 struct in_addr a; | |
1360 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1361 gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_DATA\n"); |
2393 | 1362 |
1363 gg_read_line(sess->fd, buf, sizeof(buf) - 1); | |
1364 gg_chomp(buf); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1365 |
2393 | 1366 gg_debug(GG_DEBUG_TRAFFIC, "-- got http response (%s)\n", buf); |
1367 if (strncmp(buf, "HTTP/1.", 7) || strncmp(buf + 9, "200", 3)) { | |
1368 gg_debug(GG_DEBUG_MISC, "-- but that's not what we've expected\n"); | |
1369 | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1370 errno = EINVAL; |
2393 | 1371 e->type = GG_EVENT_CONN_FAILED; |
1372 e->event.failure = GG_FAILURE_INVALID; | |
1373 sess->state = GG_STATE_IDLE; | |
1374 break; | |
1375 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1376 |
2393 | 1377 while (strcmp(buf, "\r\n") && strcmp(buf, "")) |
1378 gg_read_line(sess->fd, buf, sizeof(buf) - 1); | |
1379 | |
1380 gg_read_line(sess->fd, buf, sizeof(buf) - 1); | |
1381 gg_chomp(buf); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1382 |
2393 | 1383 close(sess->fd); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1384 |
2393 | 1385 gg_debug(GG_DEBUG_TRAFFIC, "-- received http data (%s)\n", buf); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1386 |
8775 | 1387 /* analizujemy otrzymane dane. */ |
2393 | 1388 tmp = buf; |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1389 |
2393 | 1390 while (*tmp && *tmp != ' ') |
9663 | 1391 tmp++; |
1392 while (*tmp && *tmp == ' ') | |
1393 tmp++; | |
1394 host = tmp; | |
1395 while (*tmp && *tmp != ' ') | |
1396 tmp++; | |
1397 *tmp = 0; | |
2393 | 1398 |
1399 if ((tmp = strchr(host, ':'))) { | |
1400 *tmp = 0; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1401 port = atoi(tmp+1); |
2393 | 1402 } |
1403 | |
1404 a.s_addr = inet_addr(host); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1405 sess->server_ip = a.s_addr; |
8775 | 1406 |
3630 | 1407 #if 0 |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
4298
diff
changeset
|
1408 /* We need to watch this non-blocking socket so lets use gaim_proxy_connect |
3630 | 1409 in gg.c - Herman */ |
1410 if((sess->fd = gg_connect(&a, port, sess->assync)) == -1) { | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1411 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1412 if ((sess->fd = gg_connect(&a, GG_HTTPS_PORT, sess->async)) == -1) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1413 gg_debug(GG_DEBUG_MISC, "-- connection failed, errno = %d (%s)\n", errno, strerror(errno)); |
2393 | 1414 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1415 e->type = GG_EVENT_CONN_FAILED; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1416 e->event.failure = GG_FAILURE_CONNECTING; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1417 sess->state = GG_STATE_IDLE; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1418 break; |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1419 } |
2393 | 1420 } |
3630 | 1421 #else |
1422 sess->port = port; | |
1423 #endif | |
2393 | 1424 sess->state = GG_STATE_CONNECTING_GG; |
1425 sess->check = GG_CHECK_WRITE; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1426 |
2393 | 1427 break; |
1428 } | |
1429 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1430 case GG_STATE_CONNECTING_GG: |
2393 | 1431 { |
6063 | 1432 unsigned int res, res_size = sizeof(res); |
2393 | 1433 |
1434 gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTING_GG\n"); | |
1435 | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1436 if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1437 struct in_addr *addr = (struct in_addr*) &sess->server_ip; |
2393 | 1438 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1439 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1440 if ((sess->fd = gg_connect(addr, GG_HTTPS_PORT, sess->async)) == -1) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1441 gg_debug(GG_DEBUG_MISC, "-- connection failed, errno = %d (%s)\n", errno, strerror(errno)); |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1442 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1443 e->type = GG_EVENT_CONN_FAILED; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1444 e->event.failure = GG_FAILURE_CONNECTING; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1445 sess->state = GG_STATE_IDLE; |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1446 break; |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1447 } |
2393 | 1448 } |
1449 | |
1450 gg_debug(GG_DEBUG_MISC, "-- connected\n"); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1451 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1452 sess->state = GG_STATE_READING_KEY; |
2393 | 1453 sess->check = GG_CHECK_READ; |
1454 | |
1455 break; | |
1456 } | |
1457 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1458 case GG_STATE_READING_KEY: |
2393 | 1459 { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1460 struct gg_header *h; |
2393 | 1461 struct gg_welcome *w; |
8775 | 1462 struct gg_login60 l; |
2393 | 1463 unsigned int hash; |
1464 char *password = sess->password; | |
1465 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1466 gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_KEY\n"); |
2393 | 1467 |
1468 if (!(h = gg_recv_packet(sess))) { | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1469 gg_debug(GG_DEBUG_MISC, "-- gg_recv_packet() failed. errno = %d (%s)\n", errno, strerror(errno)); |
2393 | 1470 e->type = GG_EVENT_CONN_FAILED; |
1471 e->event.failure = GG_FAILURE_READING; | |
1472 sess->state = GG_STATE_IDLE; | |
1473 close(sess->fd); | |
1474 break; | |
1475 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1476 |
2393 | 1477 if (h->type != GG_WELCOME) { |
1478 gg_debug(GG_DEBUG_MISC, "-- invalid packet received\n"); | |
1479 | |
1480 free(h); | |
1481 close(sess->fd); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1482 errno = EINVAL; |
2393 | 1483 e->type = GG_EVENT_CONN_FAILED; |
1484 e->event.failure = GG_FAILURE_INVALID; | |
1485 sess->state = GG_STATE_IDLE; | |
1486 break; | |
1487 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1488 |
6247 | 1489 w = (struct gg_welcome *)((void *)h + sizeof(struct gg_header)); |
2393 | 1490 w->key = fix32(w->key); |
8775 | 1491 |
1492 hash = gg_login_hash(password, w->key); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1493 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1494 gg_debug(GG_DEBUG_DUMP, "%%%% klucz serwera %.4x, hash has³a %.8x\n", w->key, hash); |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1495 |
2393 | 1496 free(h); |
1497 | |
1498 free(sess->password); | |
1499 sess->password = NULL; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1500 |
2393 | 1501 l.uin = fix32(sess->uin); |
1502 l.hash = fix32(hash); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1503 l.status = fix32(sess->initial_status ? sess->initial_status : GG_STATUS_AVAIL); |
8775 | 1504 l.version = fix32(0x20); |
2393 | 1505 l.local_ip = 0; |
1506 l.local_port = 0; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1507 |
2393 | 1508 gg_debug(GG_DEBUG_TRAFFIC, "-- sending GG_LOGIN packet\n"); |
1509 | |
8775 | 1510 if (gg_send_packet(sess, GG_LOGIN60, &l, sizeof(l), NULL, 0) == -1) { |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1511 gg_debug(GG_DEBUG_TRAFFIC, "-- oops, failed. errno = %d (%s)\n", errno, strerror(errno)); |
2393 | 1512 |
1513 close(sess->fd); | |
1514 e->type = GG_EVENT_CONN_FAILED; | |
1515 e->event.failure = GG_FAILURE_WRITING; | |
1516 sess->state = GG_STATE_IDLE; | |
1517 break; | |
1518 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1519 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1520 sess->state = GG_STATE_READING_REPLY; |
2393 | 1521 |
1522 break; | |
1523 } | |
1524 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1525 case GG_STATE_READING_REPLY: |
2393 | 1526 { |
1527 struct gg_header *h; | |
1528 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1529 gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_REPLY\n"); |
2393 | 1530 |
1531 if (!(h = gg_recv_packet(sess))) { | |
1532 gg_debug(GG_DEBUG_MISC, "-- recv_packet failed\n"); | |
1533 e->type = GG_EVENT_CONN_FAILED; | |
1534 e->event.failure = GG_FAILURE_READING; | |
1535 sess->state = GG_STATE_IDLE; | |
1536 close(sess->fd); | |
1537 break; | |
1538 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1539 |
2393 | 1540 if (h->type == GG_LOGIN_OK) { |
1541 gg_debug(GG_DEBUG_MISC, "-- login succeded\n"); | |
1542 e->type = GG_EVENT_CONN_SUCCESS; | |
1543 sess->state = GG_STATE_CONNECTED; | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1544 free(h); |
2393 | 1545 break; |
1546 } | |
1547 | |
1548 if (h->type == GG_LOGIN_FAILED) { | |
1549 gg_debug(GG_DEBUG_MISC, "-- login failed\n"); | |
1550 e->event.failure = GG_FAILURE_PASSWORD; | |
1551 errno = EACCES; | |
1552 } else { | |
1553 gg_debug(GG_DEBUG_MISC, "-- invalid packet\n"); | |
1554 e->event.failure = GG_FAILURE_INVALID; | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1555 errno = EINVAL; |
2393 | 1556 } |
1557 | |
1558 e->type = GG_EVENT_CONN_FAILED; | |
1559 sess->state = GG_STATE_IDLE; | |
1560 close(sess->fd); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2595
diff
changeset
|
1561 free(h); |
2393 | 1562 |
1563 break; | |
1564 } | |
1565 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1566 case GG_STATE_CONNECTED: |
2393 | 1567 { |
1568 gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTED\n"); | |
1569 | |
1570 if ((res = gg_watch_fd_connected(sess, e)) == -1) { | |
1571 | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1572 gg_debug(GG_DEBUG_MISC, "-- watch_fd_connected failed. errno = %d (%s)\n", errno, strerror(errno)); |
2393 | 1573 |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1574 if (errno == EAGAIN) { |
2393 | 1575 e->type = GG_EVENT_NONE; |
1576 res = 0; | |
1577 } else | |
1578 res = -1; | |
1579 } | |
1580 break; | |
1581 } | |
1582 } | |
1583 | |
1584 if (res == -1) { | |
1585 free(e); | |
1586 e = NULL; | |
1587 } | |
1588 | |
1589 return e; | |
1590 } | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1591 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1592 /* |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1593 * Local variables: |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1594 * c-indentation-style: k&r |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1595 * c-basic-offset: 8 |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1596 * indent-tabs-mode: notnil |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1597 * End: |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1598 * |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1599 * vim: shiftwidth=8: |
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
1600 */ |