annotate src/protocols/gg/libgg.c @ 8697:725413cc9fb9

[gaim-migrate @ 9450] WYSIWYG info editing from Jon Oberheide We need separate gc flags for conversation HTML and user info HTML, or something. It seems like there should be a better way to do that... Hint hint wink wink nudge nudge I kick your foot, under the table You kick me back, I can't say I'm able To stand for you, or fall for you Ever again I wish for, a perfect setting Wishing that I'm letting you take me Where you want me, all over again committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 18 Apr 2004 06:22:42 +0000
parents 9860b81548d8
children ce90b119b103
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6247
9860b81548d8 [gaim-migrate @ 6741]
Mark Doliner <mark@kingant.net>
parents: 6063
diff changeset
1 /* $Id: libgg.c 6741 2003-07-20 19:11:13Z thekingant $ */
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * it under the terms of the GNU General Public License Version 2 as
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * published by the Free Software Foundation.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * GNU General Public License for more details.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20
4016
ad31c79c18b7 [gaim-migrate @ 4216]
Luke Schierer <lschiere@pidgin.im>
parents: 3800
diff changeset
21 #include <sys/types.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
22 #ifndef _WIN32
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 #include <sys/socket.h>
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 #include <netinet/in.h>
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #include <arpa/inet.h>
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 #include <sys/ioctl.h>
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #include <sys/wait.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
28 #include <netdb.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
29 #include <pwd.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
30 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
31 #include <fcntl.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
32 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
33
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
34 #include <stdio.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
35 #include <stdlib.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
36 #include <unistd.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
37 #include <stdio.h>
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
38 #include <sys/time.h>
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 #include "libgg.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
53
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
54 #include "internal.h"
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
55 #include "proxy.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
56 #include "debug.h"
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
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
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
67 /* temp -Herman */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
68 static int ping_outstanding = 0;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
69
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
70 #ifndef lint
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
71
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
72 static char rcsid[]
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
73 #ifdef __GNUC__
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
74 __attribute__ ((unused))
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
75 #endif
6247
9860b81548d8 [gaim-migrate @ 6741]
Mark Doliner <mark@kingant.net>
parents: 6063
diff changeset
76 = "$Id: libgg.c 6741 2003-07-20 19:11:13Z thekingant $";
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
78 #endif
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 * fix32() // funkcja wewnźtrzna
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 * dla maszyn big-endianowych zamienia kolejno¶ę bajtów w ,,long''ach.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 static inline unsigned long fix32(unsigned long x)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 {
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
87 #ifndef WORDS_BIGENDIAN
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 return x;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 #else
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
90 return (unsigned long)
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
91 (((x & (unsigned long) 0x000000ffU) << 24) |
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
92 ((x & (unsigned long) 0x0000ff00U) << 8) |
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
93 ((x & (unsigned long) 0x00ff0000U) >> 8) |
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
94 ((x & (unsigned long) 0xff000000U) >> 24));
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
95 #endif
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 * fix16() // funkcja wewnźtrzna
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 * dla maszyn big-endianowych zamienia kolejno¶ę bajtów w ,,short''ach.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 */
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4016
diff changeset
103
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4016
diff changeset
104 /* not currently used
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 static inline unsigned short fix16(unsigned short x)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 {
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
107 #ifndef WORDS_BIGENDIAN
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 return x;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 #else
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
110 return (unsigned short)
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
111 (((x & (unsigned short) 0x00ffU) << 8) |
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
112 ((x & (unsigned short) 0xff00U) >> 8));
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
113 #endif
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 }
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4016
diff changeset
115 */
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
117 #ifndef _WIN32
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 * gg_resolve() // funkcja wewnźtrzna
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 * tworzy pipe'y, forkuje siź i w drugim procesie zaczyna resolvowaę
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 * podanego hosta. zapisuje w sesji deskryptor pipe'u. je¶li co¶ tam
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 * bździe gotowego, znaczy, æe moæna wczytaę ,,struct in_addr''. je¶li
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 * nie znajdzie, zwraca INADDR_NONE.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 * - fd - wska¼nik gdzie wrzucię deskryptor,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 * - pid - gdzie wrzucię pid dzieciaka,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 * - hostname - nazwa hosta do zresolvowania.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 * zwraca 0 je¶li uda³o siź odpalię proces lub -1 w przypadku b³źdu.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 int gg_resolve(int *fd, int *pid, char *hostname)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 int pipes[2], res;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 struct in_addr a;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve(..., \"%s\");\n", hostname);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
138
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 if (!fd | !pid) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 if (pipe(pipes) == -1)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 if ((res = fork()) == -1)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 if (!res) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 if ((a.s_addr = inet_addr(hostname)) == INADDR_NONE) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 struct hostent *he;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
153
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 if (!(he = gethostbyname(hostname)))
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 a.s_addr = INADDR_NONE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 else
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
157 memcpy((char*) &a, he->h_addr, sizeof(a));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 write(pipes[1], &a, sizeof(a));
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 exit(0);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 close(pipes[1]);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 *fd = pipes[0];
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 *pid = res;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 return 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
172 #endif /*!_WIN32*/
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 * gg_recv_packet() // funkcja wewnźtrzna
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 * odbiera jeden pakiet gg i zwraca wska¼nik do niego. pamiźę po nim
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 * wypada³oby uwolnię.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 * - sock - po³±czony socket.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 * je¶li wyst±pi³ b³±d, zwraca NULL. reszta w errno.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 static void *gg_recv_packet(struct gg_session *sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 struct gg_header h;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 char *buf = NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 int ret = 0, offset, size = 0;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
189 int sizeh = sizeof(struct gg_header);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(...);\n");
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
192
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 if (sess->recv_left < 1) {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
199 while (ret != sizeh) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
200 ret = read(sess->fd, &h, sizeh);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
201 gg_debug(GG_DEBUG_MISC, "-- header recv(..., %d) = %d\n", sizeh, ret);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
202 if (ret < sizeh) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 if (errno != EINTR) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
204 gg_debug(GG_DEBUG_MISC, "-- errno = %d (%s)\n", errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 h.type = fix32(h.type);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 h.length = fix32(h.length);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 } else {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
213 memcpy(&h, sess->recv_buf, sizeh);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 /* jakie¶ sensowne limity na rozmiar pakietu */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 if (h.length < 0 || h.length > 65535) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 gg_debug(GG_DEBUG_MISC, "-- invalid packet length (%d)\n", h.length);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 errno = ERANGE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 if (sess->recv_left > 0) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 gg_debug(GG_DEBUG_MISC, "-- resuming last gg_recv_packet()\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 size = sess->recv_left;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 offset = sess->recv_done;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 buf = sess->recv_buf;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 } else {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
229 if (!(buf = malloc(sizeh + h.length + 1))) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
234 memcpy(buf, &h, sizeh);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 offset = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 size = h.length;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 while (size > 0) {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
241 ret = read(sess->fd, buf + sizeh + offset, size);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 gg_debug(GG_DEBUG_MISC, "-- body recv(..., %d) = %d\n", size, ret);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 if (ret > -1 && ret <= size) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 offset += ret;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 size -= ret;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
246 } else if (ret == -1) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 gg_debug(GG_DEBUG_MISC, "-- errno = %d (%s)\n", errno, strerror(errno));
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248 if (errno == EAGAIN) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 gg_debug(GG_DEBUG_MISC, "-- %d bytes received, %d left\n", offset, size);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 sess->recv_buf = buf;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251 sess->recv_left = size;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 sess->recv_done = offset;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
253 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 if (errno != EINTR) {
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 5872
diff changeset
256 /* errno = EINVAL; */
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 free(buf);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 sess->recv_left = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265 if ((gg_debug_level & GG_DEBUG_DUMP)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266 int i;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268 gg_debug(GG_DEBUG_DUMP, ">> received packet (type=%.2x):", h.type);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
269 for (i = 0; i < sizeh + h.length; i++)
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
270 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) buf[i]);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
271 gg_debug(GG_DEBUG_DUMP, "\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 return buf;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 * gg_send_packet() // funkcja wewnźtrzna
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280 * konstruuje pakiet i wysy³a go w do serwera.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282 * - sock - po³±czony socket,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283 * - type - typ pakietu,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 * - packet - wska¼nik do struktury pakietu,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
285 * - length - d³ugo¶ę struktury pakietu,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 * - payload - dodatkowy tekst doklejany do pakietu (np. wiadomo¶ę),
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287 * - payload_length - d³ugo¶ę dodatkowego tekstu.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
288 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
289 * je¶li posz³o dobrze, zwraca 0. w przypadku b³źdu -1. je¶li errno=ENOMEM,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 * zabrak³o pamiźci. inaczej by³ b³±d przy wysy³aniu pakietu. dla errno=0
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291 * nie wys³ano ca³ego pakietu.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292 */
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
293 static int gg_send_packet(int sock, int type, void *packet, int length, void *payload, int payload_length)
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
295 struct gg_header *h;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 int res, plen;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297 char *tmp;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
299 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_packet(0x%.2x, %d, %d);\n", type, length, payload_length);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
300
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 if (length < 0 || payload_length < 0) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 gg_debug(GG_DEBUG_MISC, "-- invalid packet/payload length\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 errno = ERANGE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 if (!(tmp = malloc(sizeof(struct gg_header) + length + payload_length))) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
312 h = (struct gg_header*) tmp;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 h->type = fix32(type);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 h->length = fix32(length + payload_length);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 if (packet)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317 memcpy(tmp + sizeof(struct gg_header), packet, length);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318 if (payload)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319 memcpy(tmp + sizeof(struct gg_header) + length, payload, payload_length);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321 if ((gg_debug_level & GG_DEBUG_DUMP)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322 int i;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324 gg_debug(GG_DEBUG_DUMP, "%%%% sending packet (type=%.2x):", fix32(h->type));
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325 for (i = 0; i < sizeof(struct gg_header) + fix32(h->length); i++)
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
326 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) tmp[i]);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 gg_debug(GG_DEBUG_DUMP, "\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330 plen = sizeof(struct gg_header) + length + payload_length;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331 if ((res = write(sock, tmp, plen)) < plen) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
332 gg_debug(GG_DEBUG_MISC, "-- write() failed. res = %d, errno = %d (%s)\n", res, errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 free(tmp);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
337 free(tmp);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
338 return 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
341 #ifndef _WIN32
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 * gg_login()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345 * rozpoczyna procedurź ³±czenia siź z serwerem. resztź obs³guje siź przez
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346 * gg_watch_event.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348 * - uin - numerek usera,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 * - password - jego hase³ko,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 * - async - ma byę asynchronicznie?
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 * UWAGA! program musi obs³uæyę SIGCHLD, je¶li ³±czy siź asynchronicznie,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 * æeby zrobię pogrzeb zmar³emu procesowi resolvera.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355 * w przypadku b³źdu zwraca NULL, je¶li idzie dobrze (async) albo posz³o
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356 * dobrze (sync), zwróci wska¼nik do zaalokowanej struktury `gg_session'.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 struct gg_session *gg_login(uin_t uin, char *password, int async)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 struct gg_session *sess;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
361 char *hostname;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
362 int port;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
364 gg_debug(GG_DEBUG_FUNCTION, "** gg_login(%u, \"...\", %d);\n", uin, async);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366 if (!(sess = malloc(sizeof(*sess))))
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
367 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
368
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369 sess->uin = uin;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370 if (!(sess->password = strdup(password))) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 sess->state = GG_STATE_RESOLVING;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375 sess->check = GG_CHECK_READ;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 sess->async = async;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
377 sess->seq = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378 sess->recv_left = 0;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
379 sess->last_pong = 0;
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
380 sess->server_ip = 0;
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
381 sess->initial_status = 0;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
382 sess->type = GG_SESSION_GG;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
383
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
384 if (gg_http_use_proxy) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
385 hostname = gg_http_proxy_host;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
386 port = gg_http_proxy_port;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
387 } else {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
388 hostname = GG_APPMSG_HOST;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
389 port = GG_APPMSG_PORT;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
390 };
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 if (async) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
393 if (gg_resolve(&sess->fd, &sess->pid, hostname)) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394 gg_debug(GG_DEBUG_MISC, "-- resolving failed\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 } else {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399 struct in_addr a;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
401 if ((a.s_addr = inet_addr(hostname)) == INADDR_NONE) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402 struct hostent *he;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
403
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
404 if (!(he = gethostbyname(hostname))) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
405 gg_debug(GG_DEBUG_MISC, "-- host %s not found\n", hostname);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408 } else
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
409 memcpy((char*) &a, he->h_addr, sizeof(a));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
412 if (!(sess->fd = gg_connect(&a, port, 0)) == -1) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413 gg_debug(GG_DEBUG_MISC, "-- connection failed\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
418 sess->state = GG_STATE_CONNECTING;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
419
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 while (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
421 struct gg_event *e;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 if (!(e = gg_watch_fd(sess))) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 gg_debug(GG_DEBUG_MISC, "-- some nasty error in gg_watch_fd()\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429 if (e->type == GG_EVENT_CONN_FAILED) {
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
430 errno = EACCES;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 gg_debug(GG_DEBUG_MISC, "-- could not login\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432 gg_free_event(e);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437 gg_free_event(e);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 return sess;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
443 #endif /*!_WIN32*/
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 * gg_free_session()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 * zwalnia pamiźę zajmowan± przez opis sesji.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
449 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
450 * - sess - opis sesji.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
451 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
452 * nie zwraca niczego, bo i po co?
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
453 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
454 void gg_free_session(struct gg_session *sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
456 if (!sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457 return;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
458
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 free(sess->password);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 free(sess);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 * gg_change_status()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 * zmienia status uæytkownika. przydatne do /away i /busy oraz /quit.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468 * - sess - opis sesji,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 * - status - nowy status uæytkownika.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 * je¶li wys³a³ pakiet zwraca 0, je¶li nie uda³o siź, zwraca -1.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 int gg_change_status(struct gg_session *sess, int status)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 struct gg_new_status p;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
478 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
482 if (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483 errno = ENOTCONN;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487 gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status(..., %d);\n", status);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 p.status = fix32(status);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491 return gg_send_packet(sess->fd, GG_NEW_STATUS, &p, sizeof(p), NULL, 0);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
492 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
494 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 * gg_logoff()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
496 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
497 * wylogowuje uæytkownika i zamyka po³±czenie.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499 * - sock - deskryptor socketu.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
500 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 * nie zwraca b³źdów. skoro siź æegnamy, to olewamy wszystko.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
502 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503 void gg_logoff(struct gg_session *sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505 if (!sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 return;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508 gg_debug(GG_DEBUG_FUNCTION, "** gg_logoff(...);\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
509
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
510 if (sess->state == GG_STATE_CONNECTED)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
511 gg_change_status(sess, GG_STATUS_NOT_AVAIL);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
512
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
513 if (sess->fd) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
514 shutdown(sess->fd, 2);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
515 close(sess->fd);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520 * gg_send_message()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 * wysy³a wiadomo¶ę do innego uæytkownika. zwraca losowy numer
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523 * sekwencyjny, który moæna olaę albo wykorzystaę do potwierdzenia.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 * - sess - opis sesji,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526 * - msgclass - rodzaj wiadomo¶ci,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 * - recipient - numer adresata,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 * - message - tre¶ę wiadomo¶ci.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530 * w przypadku b³źdu zwraca -1, inaczej numer sekwencyjny.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 */
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 5872
diff changeset
532 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient, char *message)
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534 struct gg_send_msg s;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
538 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
540
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
541 if (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 errno = ENOTCONN;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
543 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
545
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
546 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message(..., %d, %u, \"...\");\n", msgclass, recipient);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
547
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 s.recipient = fix32(recipient);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 if (!sess->seq)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
550 sess->seq = 0x01740000 | (rand() & 0xffff);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
551 s.seq = fix32(sess->seq);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
552 s.msgclass = fix32(msgclass);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
553 sess->seq += (rand() % 0x300) + 0x300;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
554
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
555 if (gg_send_packet(sess->fd, GG_SEND_MSG, &s, sizeof(s), message, strlen(message) + 1) == -1)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
556 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
557
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 return fix32(s.seq);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
562 * gg_ping()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564 * wysy³a do serwera pakiet typu yeah-i'm-still-alive.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
566 * - sess - zgadnij.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
567 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 * je¶li nie powiod³o siź wys³anie pakietu, zwraca -1. otherwise 0.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
569 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 int gg_ping(struct gg_session *sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
574 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
575 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
576
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
577 if (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
578 errno = ENOTCONN;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
579 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
580 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
581
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
582 gg_debug(GG_DEBUG_FUNCTION, "** gg_ping(...);\n");
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
583
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
584 if(ping_outstanding) {
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
585 gaim_debug(GAIM_DEBUG_INFO, "gg",
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
586 "Trying to send ping, when we havn't been ponged on last ping\n");
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
587 return 1;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
588 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
589 else {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
590 ping_outstanding = 1;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
591 return gg_send_packet(sess->fd, GG_PING, NULL, 0, NULL, 0);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
592 }
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
593 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
594
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
595 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
596 * gg_free_event()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
597 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
598 * zwalnia pamiźę zajmowan± przez informacjź o zdarzeniu
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
599 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
600 * - event - wska¼nik do informacji o zdarzeniu
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
601 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602 * nie ma czego zwracaę.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
603 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
604 void gg_free_event(struct gg_event *e)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
605 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
606 if (!e)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
607 return;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
608 if (e->type == GG_EVENT_MSG)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
609 free(e->event.msg.message);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610 if (e->type == GG_EVENT_NOTIFY)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611 free(e->event.notify);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
612 free(e);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
613 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
616 * gg_notify()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
617 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
618 * wysy³a serwerowi listź ludków, za którymi tźsknimy.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
619 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620 * - sess - identyfikator sesji,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
621 * - userlist - wska¼nik do tablicy numerów,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
622 * - count - ilo¶ę numerków.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
623 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
624 * je¶li uda³o siź, zwraca 0. je¶li b³±d, dostajemy -1.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
625 */
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
626 int gg_notify(struct gg_session *sess, uin_t *userlist, int count)
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
627 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
628 struct gg_notify *n;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
629 uin_t *u;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
630 int i, res = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
631
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
632 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
633 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
634 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
635 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
636
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
637 if (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
638 errno = ENOTCONN;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
639 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
640 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
641
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
642 gg_debug(GG_DEBUG_FUNCTION, "** gg_notify(..., %d);\n", count);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
643
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
644 if (!userlist || !count)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
645 return 0;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
646
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
647 if (!(n = (struct gg_notify*) malloc(sizeof(*n) * count)))
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
648 return -1;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
649
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
650 for (u = userlist, i = 0; i < count; u++, i++) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
651 n[i].uin = fix32(*u);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
652 n[i].dunno1 = 3;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
653 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
654
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
655 if (gg_send_packet(sess->fd, GG_NOTIFY, n, sizeof(*n) * count, NULL, 0) == -1)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
656 res = -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
657
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
658 free(n);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
659
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
660 return res;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
661 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
662
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
663 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
664 * gg_add_notify()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
665 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
666 * dodaje w locie do listy ukochanych dany numerek.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
667 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
668 * - sess - identyfikator sesji,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
669 * - uin - numerek ukochanej.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
670 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
671 * je¶li uda³o siź wys³aę, daje 0. inaczej -1.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
672 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
673 int gg_add_notify(struct gg_session *sess, uin_t uin)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
674 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
675 struct gg_add_remove a;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
676
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
677 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
678 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
679 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
680 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
681
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
682 if (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
683 errno = ENOTCONN;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
684 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
685 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
686
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
687 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
688
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
689 a.uin = fix32(uin);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
690 a.dunno1 = 3;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
691
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
692 return gg_send_packet(sess->fd, GG_ADD_NOTIFY, &a, sizeof(a), NULL, 0);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
693 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
694
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
695 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
696 * gg_remove_notify()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
697 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
698 * w locie usuwa z listy zainteresowanych.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
699 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
700 * - sess - id sesji,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
701 * - uin - numerek.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
702 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
703 * zwraca -1 je¶li by³ b³±d, 0 je¶li siź uda³o wys³aę pakiet.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
704 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
705 int gg_remove_notify(struct gg_session *sess, uin_t uin)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
706 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
707 struct gg_add_remove a;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
708
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
709 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
710 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
711 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
712 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
713
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
714 if (sess->state != GG_STATE_CONNECTED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
715 errno = ENOTCONN;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
716 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
717 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
718
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
719 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
720
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
721 a.uin = fix32(uin);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
722 a.dunno1 = 3;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
723
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
724 return gg_send_packet(sess->fd, GG_REMOVE_NOTIFY, &a, sizeof(a), NULL, 0);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
725 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
726
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
727 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
728 * gg_watch_fd_connected() // funkcja wewnźtrzna
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
729 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
730 * patrzy na socketa, odbiera pakiet i wype³nia strukturź zdarzenia.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
731 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
732 * - sock - lalala, trudno zgadn±ę.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
733 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
734 * je¶li b³±d -1, je¶li dobrze 0.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
735 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
736 static int gg_watch_fd_connected(struct gg_session *sess, struct gg_event *e)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
737 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
738 struct gg_header *h;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
739 void *p;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
740
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
741 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
742 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
743 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
744 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
745
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
746 gg_debug(GG_DEBUG_FUNCTION, "** gg_watch_fd_connected(...);\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
747
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
748 if (!(h = gg_recv_packet(sess))) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
749 gg_debug(GG_DEBUG_MISC, "-- gg_recv_packet failed. errno = %d (%d)\n", errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
750 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
751 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
752
6247
9860b81548d8 [gaim-migrate @ 6741]
Mark Doliner <mark@kingant.net>
parents: 6063
diff changeset
753 p = (void *)h + sizeof(struct gg_header);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
754
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
755 if (h->type == GG_RECV_MSG) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
756 struct gg_recv_msg *r = p;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
757
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
758 gg_debug(GG_DEBUG_MISC, "-- received a message\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
759
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
760 if (h->length >= sizeof(*r)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
761 e->type = GG_EVENT_MSG;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
762 e->event.msg.msgclass = fix32(r->msgclass);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 e->event.msg.sender = fix32(r->sender);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
764 e->event.msg.message = strdup((char*) r + sizeof(*r));
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
765 e->event.msg.time = fix32(r->time);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
766 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
767 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
768
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
769 if (h->type == GG_NOTIFY_REPLY) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
770 struct gg_notify_reply *n = p;
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
771 int count, i;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
772
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
773 gg_debug(GG_DEBUG_MISC, "-- received a notify reply\n");
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
774
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
775 e->type = GG_EVENT_NOTIFY;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
776 if (!(e->event.notify = (void*) malloc(h->length + 2 * sizeof(*n)))) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
777 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
778 free(h);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
779 return -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
780 }
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
781 count = h->length / sizeof(*n);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
782 memcpy(e->event.notify, p, h->length);
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
783 e->event.notify[count].uin = 0;
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
784 for (i = 0; i < count; i++) {
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
785 e->event.notify[i].uin = fix32(e->event.notify[i].uin);
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
786 e->event.notify[i].status = fix32(e->event.notify[i].status);
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
787 }
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
788 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
789
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
790 if (h->type == GG_STATUS) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
791 struct gg_status *s = p;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
792
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
793 gg_debug(GG_DEBUG_MISC, "-- received a status change\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
794
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
795 if (h->length >= sizeof(*s)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
796 e->type = GG_EVENT_STATUS;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
797 memcpy(&e->event.status, p, h->length);
2399
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
798 e->event.status.uin = fix32(e->event.status.uin);
b2926d21f067 [gaim-migrate @ 2412]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2393
diff changeset
799 e->event.status.status = fix32(e->event.status.status);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
800 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
801 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
802
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
803 if (h->type == GG_SEND_MSG_ACK) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
804 struct gg_send_msg_ack *s = p;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
805
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
806 gg_debug(GG_DEBUG_MISC, "-- received a message ack\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
807
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
808 if (h->length >= sizeof(*s)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
809 e->type = GG_EVENT_ACK;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
810 e->event.ack.status = fix32(s->status);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
811 e->event.ack.recipient = fix32(s->recipient);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
812 e->event.ack.seq = fix32(s->seq);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
813 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
814 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
815
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
816 if (h->type == GG_PONG) {
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
817 gg_debug(GG_DEBUG_MISC, "-- received a pong\n");
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
818 ping_outstanding = 0;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
819 sess->last_pong = time(NULL);
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
820 }
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
821
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
822 free(h);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
823
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
824 return 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
825 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
826
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
827 /*
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
828 * gg_watch_fd()
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
829 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
830 * funkcja wywo³ywana, gdy co¶ siź stanie na obserwowanym deskryptorze.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
831 * zwraca klientowi informacjź o tym, co siź dzieje.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
833 * - sess - identyfikator sesji.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
834 *
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
835 * zwraca wska¼nik do struktury gg_event, któr± trzeba zwolnię pó¼niej
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
836 * za pomoc± gg_free_event(). jesli rodzaj zdarzenia jest równy
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
837 * GG_EVENT_NONE, naleæy je olaę kompletnie. je¶li zwróci³o NULL,
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
838 * sta³o siź co¶ niedobrego -- albo brak³o pamiźci albo zerwa³o
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
839 * po³±czenie albo co¶ takiego.
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
840 */
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
841 struct gg_event *gg_watch_fd(struct gg_session *sess)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
842 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
843 struct gg_event *e;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
844 int res = 0;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
845 #ifndef _WIN32
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
846 int port;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
847 #endif
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
848
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
849 if (!sess) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
850 errno = EFAULT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
851 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
852 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
853
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
854 gg_debug(GG_DEBUG_FUNCTION, "** gg_watch_fd(...);\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
855
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
856 if (!(e = (void*) malloc(sizeof(*e)))) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
857 gg_debug(GG_DEBUG_MISC, "-- not enough memory\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
858 return NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
859 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
860
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
861 e->type = GG_EVENT_NONE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
862
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
863 switch (sess->state) {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
864 #ifndef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
865 /* 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
866 using gaim_proxy_connect instead of gg_login - Herman */
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
867 case GG_STATE_RESOLVING:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
868 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
869 struct in_addr a;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
870
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
871 gg_debug(GG_DEBUG_MISC, "== GG_STATE_RESOLVING\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
872
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
873 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
874 gg_debug(GG_DEBUG_MISC, "-- resolving failed\n");
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
875
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
876 errno = ENOENT;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
877 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
878 e->event.failure = GG_FAILURE_RESOLVING;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
879 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
880
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
881 close(sess->fd);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
882
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
883 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
884 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
885
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
886 sess->server_ip = a.s_addr;
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
887
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
888 close(sess->fd);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
889
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
890 waitpid(sess->pid, NULL, 0);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
891
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
892 gg_debug(GG_DEBUG_MISC, "-- resolved, now connecting\n");
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
893
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
894 if (gg_http_use_proxy) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
895 port = gg_http_proxy_port;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
896 } else {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
897 port = GG_APPMSG_PORT;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
898 };
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
899
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
900 if ((sess->fd = gg_connect(&a, port, sess->async)) == -1) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
901 struct in_addr *addr = (struct in_addr*) &sess->server_ip;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
902
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
903 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying direct connection\n");
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
904
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
905 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
906 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n");
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
907 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
908 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
909
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
910 e->type = GG_EVENT_CONN_FAILED;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
911 e->event.failure = GG_FAILURE_CONNECTING;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
912 sess->state = GG_STATE_IDLE;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
913 break;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
914 }
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
915 }
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
916 sess->state = GG_STATE_CONNECTING_GG;
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
917 sess->check = GG_CHECK_WRITE;
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
918 } else {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
919 sess->state = GG_STATE_CONNECTING;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
920 sess->check = GG_CHECK_WRITE;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
921 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
922
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
923 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
924 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
925 #endif /* !_WIN32 */
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
926 case GG_STATE_CONNECTING:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
927 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
928 char buf[1024];
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 5872
diff changeset
929 unsigned int res, res_size = sizeof(res);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
930
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
931 gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTING\n");
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
932
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
933 if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
934 #if 0
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
935 struct in_addr *addr = (struct in_addr*) &sess->server_ip;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
936 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
937 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
938 gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n");
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
939 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
940 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
941
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
942 e->type = GG_EVENT_CONN_FAILED;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
943 e->event.failure = GG_FAILURE_CONNECTING;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
944 sess->state = GG_STATE_IDLE;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
945 break;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
946 }
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
947 }
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
948
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
949 sess->state = GG_STATE_CONNECTING_GG;
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
950 sess->check = GG_CHECK_WRITE;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
951 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
952 gg_debug(GG_DEBUG_MISC, "-- http connection failed, errno = %d\n", res);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
953 e->type = GG_EVENT_CONN_FAILED;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
954 e->event.failure = GG_FAILURE_CONNECTING;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
955 sess->state = GG_STATE_IDLE;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
956 #endif
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
957 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
958 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
959
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
960 gg_debug(GG_DEBUG_MISC, "-- http connection succeded, sending query\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
961
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
962 if (gg_http_use_proxy) {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
963 g_snprintf(buf, sizeof(buf) - 1,
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
964 "GET http://" GG_APPMSG_HOST "/appsvc/appmsg.asp?fmnumber=%lu HTTP/1.0\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
965 "Host: " GG_APPMSG_HOST "\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
966 "User-Agent: " GG_HTTP_USERAGENT "\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
967 "Pragma: no-cache\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
968 "\r\n", sess->uin);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
969 } else {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
970 g_snprintf(buf, sizeof(buf) - 1,
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
971 "GET /appsvc/appmsg.asp?fmnumber=%lu HTTP/1.0\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
972 "Host: " GG_APPMSG_HOST "\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
973 "User-Agent: " GG_HTTP_USERAGENT "\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
974 "Pragma: no-cache\r\n"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
975 "\r\n", sess->uin);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
976 };
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
977
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
978 gg_debug(GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", buf);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
979 if (write(sess->fd, buf, strlen(buf)) < strlen(buf)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
980 gg_debug(GG_DEBUG_MISC, "-- sending query failed\n");
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
981 errno = EIO;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
982 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
983 e->event.failure = GG_FAILURE_WRITING;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
984 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
985 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
986 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
987
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
988 sess->state = GG_STATE_READING_DATA;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
989 sess->check = GG_CHECK_READ;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
990
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
991 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
992 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
993
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
994 case GG_STATE_READING_DATA:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
995 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
996 char buf[1024], *tmp, *host;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
997 int port = GG_DEFAULT_PORT;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
998 struct in_addr a;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
999
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1000 gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_DATA\n");
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1001
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1002 gg_read_line(sess->fd, buf, sizeof(buf) - 1);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1003 gg_chomp(buf);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1004
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1005 gg_debug(GG_DEBUG_TRAFFIC, "-- got http response (%s)\n", buf);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1006 if (strncmp(buf, "HTTP/1.", 7) || strncmp(buf + 9, "200", 3)) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1007 gg_debug(GG_DEBUG_MISC, "-- but that's not what we've expected\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1008
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1009 errno = EINVAL;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1010 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1011 e->event.failure = GG_FAILURE_INVALID;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1012 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1013 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1014 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1015
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1016 while (strcmp(buf, "\r\n") && strcmp(buf, ""))
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1017 gg_read_line(sess->fd, buf, sizeof(buf) - 1);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1018
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1019 gg_read_line(sess->fd, buf, sizeof(buf) - 1);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1020 gg_chomp(buf);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1021
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1022 close(sess->fd);
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1023
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1024 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
1025
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1026 tmp = buf;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1027
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1028 while (*tmp && *tmp != ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1029 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1030 while (*tmp && *tmp == ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1031 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1032 while (*tmp && *tmp != ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1033 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1034 while (*tmp && *tmp == ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1035 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1036 while (*tmp && *tmp != ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1037 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1038 while (*tmp && *tmp == ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1039 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1040 host = tmp;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1041 while (*tmp && *tmp != ' ')
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1042 tmp++;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1043 *tmp = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1044
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1045 if ((tmp = strchr(host, ':'))) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1046 *tmp = 0;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1047 port = atoi(tmp+1);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1048 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1049
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1050 a.s_addr = inet_addr(host);
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1051 sess->server_ip = a.s_addr;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
1052 #if 0
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 4298
diff changeset
1053 /* We need to watch this non-blocking socket so lets use gaim_proxy_connect
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
1054 in gg.c - Herman */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
1055 if((sess->fd = gg_connect(&a, port, sess->assync)) == -1) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1056 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
1057 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
1058 gg_debug(GG_DEBUG_MISC, "-- connection failed, errno = %d (%s)\n", errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1059
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1060 e->type = GG_EVENT_CONN_FAILED;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1061 e->event.failure = GG_FAILURE_CONNECTING;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1062 sess->state = GG_STATE_IDLE;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1063 break;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1064 }
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1065 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
1066 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
1067 sess->port = port;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 2846
diff changeset
1068 #endif
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1069 sess->state = GG_STATE_CONNECTING_GG;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1070 sess->check = GG_CHECK_WRITE;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1071
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1072 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1073 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1074
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1075 case GG_STATE_CONNECTING_GG:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1076 {
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 5872
diff changeset
1077 unsigned int res, res_size = sizeof(res);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1078
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1079 gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTING_GG\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1080
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1081 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
1082 struct in_addr *addr = (struct in_addr*) &sess->server_ip;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1083
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1084 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
1085 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
1086 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
1087
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1088 e->type = GG_EVENT_CONN_FAILED;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1089 e->event.failure = GG_FAILURE_CONNECTING;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1090 sess->state = GG_STATE_IDLE;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1091 break;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1092 }
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1093 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1094
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1095 gg_debug(GG_DEBUG_MISC, "-- connected\n");
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1096
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1097 sess->state = GG_STATE_READING_KEY;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1098 sess->check = GG_CHECK_READ;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1099
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1100 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1101 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1102
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1103 case GG_STATE_READING_KEY:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1104 {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1105 struct gg_header *h;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1106 struct gg_welcome *w;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1107 struct gg_login l;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1108 unsigned int hash;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1109 char *password = sess->password;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1110
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1111 gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_KEY\n");
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1112
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1113 if (!(h = gg_recv_packet(sess))) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1114 gg_debug(GG_DEBUG_MISC, "-- gg_recv_packet() failed. errno = %d (%s)\n", errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1115 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1116 e->event.failure = GG_FAILURE_READING;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1117 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1118 close(sess->fd);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1119 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1120 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1121
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1122 if (h->type != GG_WELCOME) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1123 gg_debug(GG_DEBUG_MISC, "-- invalid packet received\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1124
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1125 free(h);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1126 close(sess->fd);
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1127 errno = EINVAL;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1128 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1129 e->event.failure = GG_FAILURE_INVALID;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1130 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1131 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1132 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1133
6247
9860b81548d8 [gaim-migrate @ 6741]
Mark Doliner <mark@kingant.net>
parents: 6063
diff changeset
1134 w = (struct gg_welcome *)((void *)h + sizeof(struct gg_header));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1135 w->key = fix32(w->key);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1136
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1137 for (hash = 1; *password; password++)
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1138 hash *= (*password) + 1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1139 hash *= w->key;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1140
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1141 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
1142
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1143 free(h);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1144
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1145 free(sess->password);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1146 sess->password = NULL;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1147
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1148 l.uin = fix32(sess->uin);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1149 l.hash = fix32(hash);
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1150 l.status = fix32(sess->initial_status ? sess->initial_status : GG_STATUS_AVAIL);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1151 l.dunno = fix32(0x0b);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1152 l.local_ip = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1153 l.local_port = 0;
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1154
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1155 gg_debug(GG_DEBUG_TRAFFIC, "-- sending GG_LOGIN packet\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1156
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1157 if (gg_send_packet(sess->fd, GG_LOGIN, &l, sizeof(l), NULL, 0) == -1) {
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1158 gg_debug(GG_DEBUG_TRAFFIC, "-- oops, failed. errno = %d (%s)\n", errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1159
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1160 close(sess->fd);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1161 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1162 e->event.failure = GG_FAILURE_WRITING;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1163 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1164 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1165 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1166
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1167 sess->state = GG_STATE_READING_REPLY;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1168
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1169 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1170 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1171
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1172 case GG_STATE_READING_REPLY:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1173 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1174 struct gg_header *h;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1175
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1176 gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_REPLY\n");
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1177
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1178 if (!(h = gg_recv_packet(sess))) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1179 gg_debug(GG_DEBUG_MISC, "-- recv_packet failed\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1180 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1181 e->event.failure = GG_FAILURE_READING;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1182 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1183 close(sess->fd);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1184 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1185 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1186
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1187 if (h->type == GG_LOGIN_OK) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1188 gg_debug(GG_DEBUG_MISC, "-- login succeded\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1189 e->type = GG_EVENT_CONN_SUCCESS;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1190 sess->state = GG_STATE_CONNECTED;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1191 free(h);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1192 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1193 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1194
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1195 if (h->type == GG_LOGIN_FAILED) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1196 gg_debug(GG_DEBUG_MISC, "-- login failed\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1197 e->event.failure = GG_FAILURE_PASSWORD;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1198 errno = EACCES;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1199 } else {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1200 gg_debug(GG_DEBUG_MISC, "-- invalid packet\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1201 e->event.failure = GG_FAILURE_INVALID;
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1202 errno = EINVAL;
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1203 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1204
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1205 e->type = GG_EVENT_CONN_FAILED;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1206 sess->state = GG_STATE_IDLE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1207 close(sess->fd);
2792
9123abd0db92 [gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2595
diff changeset
1208 free(h);
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1209
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1210 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1211 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1212
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1213 case GG_STATE_CONNECTED:
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1214 {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1215 gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTED\n");
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1216
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1217 if ((res = gg_watch_fd_connected(sess, e)) == -1) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1218
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1219 gg_debug(GG_DEBUG_MISC, "-- watch_fd_connected failed. errno = %d (%s)\n", errno, strerror(errno));
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1220
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1221 if (errno == EAGAIN) {
2393
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1222 e->type = GG_EVENT_NONE;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1223 res = 0;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1224 } else
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1225 res = -1;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1226 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1227 break;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1228 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1229 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1230
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1231 if (res == -1) {
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1232 free(e);
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1233 e = NULL;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1234 }
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1235
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1236 return e;
a7ecfd3f7714 [gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1237 }
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1238
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1239 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1240 * Local variables:
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1241 * c-indentation-style: k&r
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1242 * c-basic-offset: 8
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1243 * indent-tabs-mode: notnil
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1244 * End:
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1245 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1246 * vim: shiftwidth=8:
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2792
diff changeset
1247 */