annotate src/protocols/gg/libgg.c @ 10803:3595f818ee37

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