annotate src/protocols/gg/lib/libgadu.c @ 12007:8724718d387f

[gaim-migrate @ 14300] Further updates to gg from Bartosz Oler. This makes the login and token retrieval processes asynchronous. There are also some encoding fixes and various cleanups. There are some changes from me to make it work on win32. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 08 Nov 2005 19:45:09 +0000
parents 3c536224f0d0
children 9cbc5967fbfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12007
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
1 /* $Id: libgadu.c 14300 2005-11-08 19:45:09Z datallah $ */
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
3 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
4 * (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
5 * Robert J. Woźny <speedy@ziew.org>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
6 * Arkadiusz Miśkiewicz <arekm@pld-linux.org>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
7 * Tomasz Chiliński <chilek@chilan.com>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
8 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
10 * it under the terms of the GNU Lesser General Public License Version
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
11 * 2.1 as published by the Free Software Foundation.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
12 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
16 * GNU Lesser General Public License for more details.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
17 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
19 * License along with this program; if not, write to the Free Software
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
21 * USA.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
22 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
23
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
24 #include <sys/types.h>
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
25 #ifndef _WIN32
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
26 #include <sys/wait.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
27 #include <sys/socket.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
28 #include <netinet/in.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
29 #include <arpa/inet.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
30 #ifdef sun
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
31 # include <sys/filio.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
32 #endif
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
33 #else
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
34 #include <io.h>
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
35 #include <fcntl.h>
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
36 #include <errno.h>
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
37 #define SHUT_RDWR SD_BOTH
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
38 #endif
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
39
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
40 #include "libgadu-config.h"
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
41
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
42 #include <errno.h>
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
43 #ifndef _WIN32
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
44 #include <netdb.h>
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
45 #endif
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
46 #ifdef __GG_LIBGADU_HAVE_PTHREAD
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
47 # include <pthread.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
48 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
49 #include <stdarg.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
50 #include <stdio.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
51 #include <stdlib.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
52 #include <string.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
53 #include <unistd.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
54 #ifdef __GG_LIBGADU_HAVE_OPENSSL
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
55 # include <openssl/err.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
56 # include <openssl/rand.h>
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
57 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
58
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
59 #include "compat.h"
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
60 #include "libgadu.h"
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
61
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
62 int gg_debug_level = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
63 void (*gg_debug_handler)(int level, const char *format, va_list ap) = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
64
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
65 int gg_dcc_port = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
66 unsigned long gg_dcc_ip = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
67
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
68 unsigned long gg_local_ip = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
69 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
70 * zmienne opisujące parametry proxy http.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
71 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
72 char *gg_proxy_host = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
73 int gg_proxy_port = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
74 int gg_proxy_enabled = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
75 int gg_proxy_http_only = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
76 char *gg_proxy_username = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
77 char *gg_proxy_password = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
78
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
79 #ifndef lint
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
80 static char rcsid[]
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
81 #ifdef __GNUC__
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
82 __attribute__ ((unused))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
83 #endif
12007
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
84 = "$Id: libgadu.c 14300 2005-11-08 19:45:09Z datallah $";
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
85 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
86
12007
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
87 #ifdef _WIN32
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
88 /**
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
89 * Deal with the fact that you can't select() on a win32 file fd.
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
90 * This makes it practically impossible to tie into gaim's event loop.
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
91 *
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
92 * -This is thanks to Tor Lillqvist.
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
93 * XXX - Move this to where the rest of the the win32 compatiblity stuff goes when we push the changes back to libgadu.
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
94 */
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
95 static int
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
96 socket_pipe (int *fds)
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
97 {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
98 SOCKET temp, socket1 = -1, socket2 = -1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
99 struct sockaddr_in saddr;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
100 int len;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
101 u_long arg;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
102 fd_set read_set, write_set;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
103 struct timeval tv;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
104
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
105 temp = socket(AF_INET, SOCK_STREAM, 0);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
106
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
107 if (temp == INVALID_SOCKET) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
108 goto out0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
109 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
110
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
111 arg = 1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
112 if (ioctlsocket(temp, FIONBIO, &arg) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
113 goto out0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
114 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
115
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
116 memset(&saddr, 0, sizeof(saddr));
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
117 saddr.sin_family = AF_INET;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
118 saddr.sin_port = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
119 saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
120
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
121 if (bind(temp, (struct sockaddr *)&saddr, sizeof (saddr))) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
122 goto out0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
123 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
124
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
125 if (listen(temp, 1) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
126 goto out0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
127 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
128
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
129 len = sizeof(saddr);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
130 if (getsockname(temp, (struct sockaddr *)&saddr, &len)) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
131 goto out0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
132 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
133
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
134 socket1 = socket(AF_INET, SOCK_STREAM, 0);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
135
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
136 if (socket1 == INVALID_SOCKET) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
137 goto out0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
138 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
139
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
140 arg = 1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
141 if (ioctlsocket(socket1, FIONBIO, &arg) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
142 goto out1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
143 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
144
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
145 if (connect(socket1, (struct sockaddr *)&saddr, len) != SOCKET_ERROR ||
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
146 WSAGetLastError() != WSAEWOULDBLOCK) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
147 goto out1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
148 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
149
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
150 FD_ZERO(&read_set);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
151 FD_SET(temp, &read_set);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
152
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
153 tv.tv_sec = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
154 tv.tv_usec = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
155
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
156 if (select(0, &read_set, NULL, NULL, NULL) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
157 goto out1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
158 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
159
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
160 if (!FD_ISSET(temp, &read_set)) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
161 goto out1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
162 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
163
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
164 socket2 = accept(temp, (struct sockaddr *) &saddr, &len);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
165 if (socket2 == INVALID_SOCKET) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
166 goto out1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
167 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
168
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
169 FD_ZERO(&write_set);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
170 FD_SET(socket1, &write_set);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
171
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
172 tv.tv_sec = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
173 tv.tv_usec = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
174
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
175 if (select(0, NULL, &write_set, NULL, NULL) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
176 goto out2;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
177 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
178
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
179 if (!FD_ISSET(socket1, &write_set)) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
180 goto out2;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
181 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
182
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
183 arg = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
184 if (ioctlsocket(socket1, FIONBIO, &arg) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
185 goto out2;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
186 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
187
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
188 arg = 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
189 if (ioctlsocket(socket2, FIONBIO, &arg) == SOCKET_ERROR) {
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
190 goto out2;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
191 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
192
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
193 fds[0] = socket1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
194 fds[1] = socket2;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
195
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
196 closesocket (temp);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
197
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
198 return 0;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
199
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
200 out2:
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
201 closesocket (socket2);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
202 out1:
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
203 closesocket (socket1);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
204 out0:
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
205 closesocket (temp);
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
206 errno = EIO; /* XXX */
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
207
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
208 return -1;
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
209 }
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
210 #endif
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
211
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
212 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
213 * gg_libgadu_version()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
214 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
215 * zwraca wersję libgadu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
216 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
217 * - brak
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
218 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
219 * wersja libgadu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
220 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
221 const char *gg_libgadu_version()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
222 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
223 return GG_LIBGADU_VERSION;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
224 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
225
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
226 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
227 * gg_fix32()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
228 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
229 * zamienia kolejność bajtów w liczbie 32-bitowej tak, by odpowiadała
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
230 * kolejności bajtów w protokole GG. ze względu na LE-owość serwera,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
231 * zamienia tylko na maszynach BE-wych.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
232 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
233 * - x - liczba do zamiany
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
234 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
235 * liczba z odpowiednią kolejnością bajtów.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
236 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
237 uint32_t gg_fix32(uint32_t x)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
238 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
239 #ifndef __GG_LIBGADU_BIGENDIAN
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
240 return x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
241 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
242 return (uint32_t)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
243 (((x & (uint32_t) 0x000000ffU) << 24) |
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
244 ((x & (uint32_t) 0x0000ff00U) << 8) |
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
245 ((x & (uint32_t) 0x00ff0000U) >> 8) |
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
246 ((x & (uint32_t) 0xff000000U) >> 24));
12007
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
247 #endif
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
248 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
249
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
250 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
251 * gg_fix16()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
252 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
253 * zamienia kolejność bajtów w liczbie 16-bitowej tak, by odpowiadała
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
254 * kolejności bajtów w protokole GG. ze względu na LE-owość serwera,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
255 * zamienia tylko na maszynach BE-wych.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
256 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
257 * - x - liczba do zamiany
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
258 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
259 * liczba z odpowiednią kolejnością bajtów.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
260 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
261 uint16_t gg_fix16(uint16_t x)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
262 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
263 #ifndef __GG_LIBGADU_BIGENDIAN
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
264 return x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
265 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
266 return (uint16_t)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
267 (((x & (uint16_t) 0x00ffU) << 8) |
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
268 ((x & (uint16_t) 0xff00U) >> 8));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
269 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
270 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
271
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
272 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
273 * gg_login_hash() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
274 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
275 * liczy hash z hasła i danego seeda.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
276 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
277 * - password - hasło do hashowania
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
278 * - seed - wartość podana przez serwer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
279 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
280 * hash.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
281 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
282 unsigned int gg_login_hash(const unsigned char *password, unsigned int seed)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
283 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
284 unsigned int x, y, z;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
285
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
286 y = seed;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
287
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
288 for (x = 0; *password; password++) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
289 x = (x & 0xffffff00) | *password;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
290 y ^= x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
291 y += x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
292 x <<= 8;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
293 y ^= x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
294 x <<= 8;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
295 y -= x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
296 x <<= 8;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
297 y ^= x;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
298
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
299 z = y & 0x1F;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
300 y = (y << z) | (y >> (32 - z));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
301 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
302
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
303 return y;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
304 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
305
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
306 #ifndef _WIN32
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
307
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
308 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
309 * gg_resolve() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
310 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
311 * tworzy potok, forkuje się i w drugim procesie zaczyna resolvować
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
312 * podanego hosta. zapisuje w sesji deskryptor potoku. jeśli coś tam
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
313 * będzie gotowego, znaczy, że można wczytać struct in_addr. jeśli
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
314 * nie znajdzie, zwraca INADDR_NONE.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
315 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
316 * - fd - wskaźnik gdzie wrzucić deskryptor
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
317 * - pid - gdzie wrzucić pid procesu potomnego
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
318 * - hostname - nazwa hosta do zresolvowania
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
319 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
320 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
321 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
322 int gg_resolve(int *fd, int *pid, const char *hostname)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
323 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
324 int pipes[2], res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
325 struct in_addr a;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
326 int errno2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
327
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
328 gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve(%p, %p, \"%s\");\n", fd, pid, hostname);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
329
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
330 if (!fd || !pid) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
331 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
332 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
333 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
334
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
335 if (pipe(pipes) == -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
336 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
337
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
338 if ((res = fork()) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
339 errno2 = errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
340 close(pipes[0]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
341 close(pipes[1]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
342 errno = errno2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
343 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
344 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
345
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
346 if (!res) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
347 if ((a.s_addr = inet_addr(hostname)) == INADDR_NONE) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
348 struct in_addr *hn;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
349
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
350 if (!(hn = gg_gethostbyname(hostname)))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
351 a.s_addr = INADDR_NONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
352 else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
353 a.s_addr = hn->s_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
354 free(hn);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
355 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
356 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
357
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
358 write(pipes[1], &a, sizeof(a));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
359
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
360 exit(0);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
361 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
362
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
363 close(pipes[1]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
364
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
365 *fd = pipes[0];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
366 *pid = res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
367
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
368 return 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
369 }
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
370 #endif
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
371
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
372 #ifdef __GG_LIBGADU_HAVE_PTHREAD
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
373
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
374 struct gg_resolve_pthread_data {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
375 char *hostname;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
376 int fd;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
377 };
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
378
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
379 static void *gg_resolve_pthread_thread(void *arg)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
380 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
381 struct gg_resolve_pthread_data *d = arg;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
382 struct in_addr a;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
383
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
384 pthread_detach(pthread_self());
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
385
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
386 if ((a.s_addr = inet_addr(d->hostname)) == INADDR_NONE) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
387 struct in_addr *hn;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
388
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
389 if (!(hn = gg_gethostbyname(d->hostname)))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
390 a.s_addr = INADDR_NONE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
391 else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
392 a.s_addr = hn->s_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
393 free(hn);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
394 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
395 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
396
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
397 write(d->fd, &a, sizeof(a));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
398 close(d->fd);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
399
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
400 free(d->hostname);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
401 d->hostname = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
402
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
403 free(d);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
404
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
405 pthread_exit(NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
406
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
407 return NULL; /* żeby kompilator nie marudził */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
408 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
409
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
410 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
411 * gg_resolve_pthread() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
412 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
413 * tworzy potok, nowy wątek i w nim zaczyna resolvować podanego hosta.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
414 * zapisuje w sesji deskryptor potoku. jeśli coś tam będzie gotowego,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
415 * znaczy, że można wczytać struct in_addr. jeśli nie znajdzie, zwraca
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
416 * INADDR_NONE.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
417 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
418 * - fd - wskaźnik do zmiennej przechowującej desktyptor resolvera
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
419 * - resolver - wskaźnik do wskaźnika resolvera
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
420 * - hostname - nazwa hosta do zresolvowania
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
421 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
422 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
423 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
424 int gg_resolve_pthread(int *fd, void **resolver, const char *hostname)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
425 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
426 struct gg_resolve_pthread_data *d = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
427 pthread_t *tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
428 int pipes[2], new_errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
429
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
430 gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve_pthread(%p, %p, \"%s\");\n", fd, resolver, hostname);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
431
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
432 if (!resolver || !fd || !hostname) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
433 gg_debug(GG_DEBUG_MISC, "// gg_resolve_pthread() invalid arguments\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
434 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
435 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
436 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
437
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
438 if (!(tmp = malloc(sizeof(pthread_t)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
439 gg_debug(GG_DEBUG_MISC, "// gg_resolve_pthread() out of memory for pthread id\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
440 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
441 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
442
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
443 if (pipe(pipes) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
444 gg_debug(GG_DEBUG_MISC, "// gg_resolve_pthread() unable to create pipes (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
445 free(tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
446 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
447 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
448
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
449 if (!(d = malloc(sizeof(*d)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
450 gg_debug(GG_DEBUG_MISC, "// gg_resolve_pthread() out of memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
451 new_errno = errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
452 goto cleanup;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
453 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
454
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
455 d->hostname = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
456
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
457 if (!(d->hostname = strdup(hostname))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
458 gg_debug(GG_DEBUG_MISC, "// gg_resolve_pthread() out of memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
459 new_errno = errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
460 goto cleanup;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
461 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
462
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
463 d->fd = pipes[1];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
464
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
465 if (pthread_create(tmp, NULL, gg_resolve_pthread_thread, d)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
466 gg_debug(GG_DEBUG_MISC, "// gg_resolve_phread() unable to create thread\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
467 new_errno = errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
468 goto cleanup;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
469 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
470
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
471 gg_debug(GG_DEBUG_MISC, "// gg_resolve_pthread() %p\n", tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
472
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
473 *resolver = tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
474
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
475 *fd = pipes[0];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
476
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
477 return 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
478
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
479 cleanup:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
480 if (d) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
481 free(d->hostname);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
482 free(d);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
483 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
484
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
485 close(pipes[0]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
486 close(pipes[1]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
487
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
488 free(tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
489
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
490 errno = new_errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
491
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
492 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
493 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
494
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
495 #elif defined _WIN32
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
496
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
497 struct gg_resolve_win32thread_data {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
498 char *hostname;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
499 int fd;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
500 };
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
501
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
502 static DWORD WINAPI gg_resolve_win32thread_thread(LPVOID arg)
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
503 {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
504 struct gg_resolve_win32thread_data *d = arg;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
505 struct in_addr a;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
506
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
507 if ((a.s_addr = inet_addr(d->hostname)) == INADDR_NONE) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
508 struct in_addr *hn;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
509
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
510 if (!(hn = gg_gethostbyname(d->hostname)))
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
511 a.s_addr = INADDR_NONE;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
512 else {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
513 a.s_addr = hn->s_addr;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
514 free(hn);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
515 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
516 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
517
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
518 write(d->fd, &a, sizeof(a));
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
519 close(d->fd);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
520
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
521 free(d->hostname);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
522 d->hostname = NULL;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
523
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
524 free(d);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
525
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
526 return 0;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
527 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
528
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
529
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
530 int gg_resolve_win32thread(int *fd, void **resolver, const char *hostname)
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
531 {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
532 struct gg_resolve_win32thread_data *d = NULL;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
533 HANDLE h;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
534 DWORD dwTId;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
535 int pipes[2], new_errno;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
536
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
537 gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve_win32thread(%p, %p, \"%s\");\n", fd, resolver, hostname);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
538
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
539 if (!resolver || !fd || !hostname) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
540 gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() invalid arguments\n");
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
541 errno = EFAULT;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
542 return -1;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
543 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
544
12007
8724718d387f [gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11546
diff changeset
545 if (socket_pipe(pipes) == -1) {
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
546 gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() unable to create pipes (errno=%d, %s)\n", errno, strerror(errno));
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
547 return -1;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
548 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
549
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
550 if (!(d = malloc(sizeof(*d)))) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
551 gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() out of memory\n");
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
552 new_errno = GetLastError();
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
553 goto cleanup;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
554 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
555
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
556 d->hostname = NULL;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
557
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
558 if (!(d->hostname = strdup(hostname))) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
559 gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() out of memory\n");
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
560 new_errno = GetLastError();
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
561 goto cleanup;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
562 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
563
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
564 d->fd = pipes[1];
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
565
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
566 h = CreateThread(NULL, 0, gg_resolve_win32thread_thread,
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
567 d, 0, &dwTId);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
568
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
569 if (h == NULL) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
570 gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() unable to create thread\n");
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
571 new_errno = GetLastError();
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
572 goto cleanup;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
573 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
574
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
575 *resolver = h;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
576 *fd = pipes[0];
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
577
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
578 return 0;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
579
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
580 cleanup:
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
581 if (d) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
582 free(d->hostname);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
583 free(d);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
584 }
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
585
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
586 close(pipes[0]);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
587 close(pipes[1]);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
588
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
589 errno = new_errno;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
590
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
591 return -1;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
592
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
593 }
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
594 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
595
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
596 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
597 * gg_read() // funkcja pomocnicza
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
598 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
599 * czyta z gniazda określoną ilość bajtów. bierze pod uwagę, czy mamy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
600 * połączenie zwykłe czy TLS.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
601 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
602 * - sess - sesja,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
603 * - buf - bufor,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
604 * - length - ilość bajtów,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
605 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
606 * takie same wartości jak read().
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
607 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
608 int gg_read(struct gg_session *sess, char *buf, int length)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
609 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
610 int res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
611
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
612 #ifdef __GG_LIBGADU_HAVE_OPENSSL
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
613 if (sess->ssl) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
614 int err;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
615
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
616 res = SSL_read(sess->ssl, buf, length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
617
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
618 if (res < 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
619 err = SSL_get_error(sess->ssl, res);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
620
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
621 if (err == SSL_ERROR_WANT_READ)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
622 errno = EAGAIN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
623
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
624 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
625 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
626 } else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
627 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
628 res = read(sess->fd, buf, length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
629
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
630 return res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
631 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
632
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
633 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
634 * gg_write() // funkcja pomocnicza
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
635 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
636 * zapisuje do gniazda określoną ilość bajtów. bierze pod uwagę, czy mamy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
637 * połączenie zwykłe czy TLS.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
638 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
639 * - sess - sesja,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
640 * - buf - bufor,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
641 * - length - ilość bajtów,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
642 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
643 * takie same wartości jak write().
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
644 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
645 int gg_write(struct gg_session *sess, const char *buf, int length)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
646 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
647 int res = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
648
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
649 #ifdef __GG_LIBGADU_HAVE_OPENSSL
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
650 if (sess->ssl) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
651 int err;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
652
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
653 res = SSL_write(sess->ssl, buf, length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
654
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
655 if (res < 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
656 err = SSL_get_error(sess->ssl, res);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
657
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
658 if (err == SSL_ERROR_WANT_WRITE)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
659 errno = EAGAIN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
660
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
661 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
662 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
663 } else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
664 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
665 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
666 int written = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
667
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
668 while (written < length) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
669 res = write(sess->fd, buf + written, length - written);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
670
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
671 if (res == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
672 if (errno == EAGAIN)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
673 continue;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
674 else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
675 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
676 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
677 written += res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
678 res = written;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
679 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
680 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
681 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
682
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
683 return res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
684 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
685
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
686 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
687 * gg_recv_packet() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
688 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
689 * odbiera jeden pakiet i zwraca wskaźnik do niego. pamięć po nim
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
690 * należy zwolnić za pomocą free().
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
691 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
692 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
693 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
694 * w przypadku błędu NULL, kod błędu w errno. należy zwrócić uwagę, że gdy
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
695 * połączenie jest nieblokujące, a kod błędu wynosi EAGAIN, nie udało się
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
696 * odczytać całego pakietu i nie należy tego traktować jako błąd.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
697 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
698 void *gg_recv_packet(struct gg_session *sess)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
699 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
700 struct gg_header h;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
701 char *buf = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
702 int ret = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
703 unsigned int offset, size = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
704
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
705 gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(%p);\n", sess);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
706
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
707 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
708 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
709 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
710 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
711
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
712 if (sess->recv_left < 1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
713 if (sess->header_buf) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
714 memcpy(&h, sess->header_buf, sess->header_done);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
715 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv: resuming last read (%d bytes left)\n", sizeof(h) - sess->header_done);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
716 free(sess->header_buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
717 sess->header_buf = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
718 } else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
719 sess->header_done = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
720
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
721 while (sess->header_done < sizeof(h)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
722 ret = gg_read(sess, (char*) &h + sess->header_done, sizeof(h) - sess->header_done);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
723
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
724 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv(%d,%p,%d) = %d\n", sess->fd, &h + sess->header_done, sizeof(h) - sess->header_done, ret);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
725
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
726 if (!ret) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
727 errno = ECONNRESET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
728 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() failed: connection broken\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
729 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
730 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
731
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
732 if (ret == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
733 if (errno == EINTR) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
734 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() interrupted system call, resuming\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
735 continue;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
736 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
737
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
738 if (errno == EAGAIN) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
739 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() incomplete header received\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
740
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
741 if (!(sess->header_buf = malloc(sess->header_done))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
742 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() not enough memory\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
743 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
744 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
745
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
746 memcpy(sess->header_buf, &h, sess->header_done);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
747
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
748 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
749 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
750
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
751 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() failed: errno=%d, %s\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
752
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
753 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
754 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
755
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
756 sess->header_done += ret;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
757
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
758 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
759
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
760 h.type = gg_fix32(h.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
761 h.length = gg_fix32(h.length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
762 } else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
763 memcpy(&h, sess->recv_buf, sizeof(h));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
764
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
765 /* jakieś sensowne limity na rozmiar pakietu */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
766 if (h.length > 65535) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
767 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() invalid packet length (%d)\n", h.length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
768 errno = ERANGE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
769 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
770 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
771
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
772 if (sess->recv_left > 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
773 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() resuming last gg_recv_packet()\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
774 size = sess->recv_left;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
775 offset = sess->recv_done;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
776 buf = sess->recv_buf;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
777 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
778 if (!(buf = malloc(sizeof(h) + h.length + 1))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
779 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() not enough memory for packet data\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
780 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
781 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
782
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
783 memcpy(buf, &h, sizeof(h));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
784
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
785 offset = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
786 size = h.length;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
787 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
788
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
789 while (size > 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
790 ret = gg_read(sess, buf + sizeof(h) + offset, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
791 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv(%d,%p,%d) = %d\n", sess->fd, buf + sizeof(h) + offset, size, ret);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
792 if (!ret) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
793 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv() failed: connection broken\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
794 errno = ECONNRESET;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
795 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
796 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
797 if (ret > -1 && ret <= size) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
798 offset += ret;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
799 size -= ret;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
800 } else if (ret == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
801 int errno2 = errno;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
802
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
803 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv() failed (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
804 errno = errno2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
805
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
806 if (errno == EAGAIN) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
807 gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() %d bytes received, %d left\n", offset, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
808 sess->recv_buf = buf;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
809 sess->recv_left = size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
810 sess->recv_done = offset;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
811 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
812 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
813 if (errno != EINTR) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
814 free(buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
815 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
816 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
817 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
818 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
819
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
820 sess->recv_left = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
821
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
822 if ((gg_debug_level & GG_DEBUG_DUMP)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
823 unsigned int i;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
824
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
825 gg_debug(GG_DEBUG_DUMP, "// gg_recv_packet(%.2x)", h.type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
826 for (i = 0; i < sizeof(h) + h.length; i++)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
827 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) buf[i]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
828 gg_debug(GG_DEBUG_DUMP, "\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
829 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
830
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
831 return buf;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
832 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
833
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
834 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
835 * gg_send_packet() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
836 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
837 * konstruuje pakiet i wysyła go do serwera.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
838 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
839 * - sock - deskryptor gniazda
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
840 * - type - typ pakietu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
841 * - payload_1 - pierwsza część pakietu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
842 * - payload_length_1 - długość pierwszej części
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
843 * - payload_2 - druga część pakietu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
844 * - payload_length_2 - długość drugiej części
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
845 * - ... - kolejne części pakietu i ich długości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
846 * - NULL - końcowym parametr (konieczny!)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
847 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
848 * jeśli się powiodło, zwraca 0, w przypadku błędu -1. jeśli errno == ENOMEM,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
849 * zabrakło pamięci. inaczej był błąd przy wysyłaniu pakietu. dla errno == 0
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
850 * nie wysłano całego pakietu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
851 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
852 int gg_send_packet(struct gg_session *sess, int type, ...)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
853 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
854 struct gg_header *h;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
855 char *tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
856 unsigned int tmp_length;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
857 void *payload;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
858 unsigned int payload_length;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
859 va_list ap;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
860 int res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
861
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
862 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_packet(%p, 0x%.2x, ...)\n", sess, type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
863
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
864 tmp_length = sizeof(struct gg_header);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
865
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
866 if (!(tmp = malloc(tmp_length))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
867 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() not enough memory for packet header\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
868 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
869 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
870
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
871 va_start(ap, type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
872
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
873 payload = va_arg(ap, void *);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
874
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
875 while (payload) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
876 char *tmp2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
877
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
878 payload_length = va_arg(ap, unsigned int);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
879
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
880 if (!(tmp2 = realloc(tmp, tmp_length + payload_length))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
881 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() not enough memory for payload\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
882 free(tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
883 va_end(ap);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
884 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
885 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
886
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
887 tmp = tmp2;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
888
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
889 memcpy(tmp + tmp_length, payload, payload_length);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
890 tmp_length += payload_length;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
891
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
892 payload = va_arg(ap, void *);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
893 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
894
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
895 va_end(ap);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
896
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
897 h = (struct gg_header*) tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
898 h->type = gg_fix32(type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
899 h->length = gg_fix32(tmp_length - sizeof(struct gg_header));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
900
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
901 if ((gg_debug_level & GG_DEBUG_DUMP)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
902 unsigned int i;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
903
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
904 gg_debug(GG_DEBUG_DUMP, "// gg_send_packet(0x%.2x)", gg_fix32(h->type));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
905 for (i = 0; i < tmp_length; ++i)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
906 gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) tmp[i]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
907 gg_debug(GG_DEBUG_DUMP, "\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
908 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
909
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
910 if ((res = gg_write(sess, tmp, tmp_length)) < tmp_length) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
911 gg_debug(GG_DEBUG_MISC, "// gg_send_packet() write() failed. res = %d, errno = %d (%s)\n", res, errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
912 free(tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
913 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
914 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
915
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
916 free(tmp);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
917 return 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
918 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
919
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
920 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
921 * gg_session_callback() // funkcja wewnętrzna
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
922 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
923 * wywoływany z gg_session->callback, wykonuje gg_watch_fd() i pakuje
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
924 * do gg_session->event jego wynik.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
925 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
926 static int gg_session_callback(struct gg_session *s)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
927 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
928 if (!s) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
929 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
930 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
931 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
932
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
933 return ((s->event = gg_watch_fd(s)) != NULL) ? 0 : -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
934 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
935
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
936 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
937 * gg_login()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
938 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
939 * rozpoczyna procedurę łączenia się z serwerem. resztę obsługuje się przez
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
940 * gg_watch_fd().
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
941 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
942 * UWAGA! program musi obsłużyć SIGCHLD, jeśli łączy się asynchronicznie,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
943 * żeby poprawnie zamknąć proces resolvera.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
944 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
945 * - p - struktura opisująca początkowy stan. wymagane pola: uin,
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
946 * password
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
947 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
948 * w przypadku błędu NULL, jeśli idzie dobrze (async) albo poszło
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
949 * dobrze (sync), zwróci wskaźnik do zaalokowanej struct gg_session.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
950 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
951 struct gg_session *gg_login(const struct gg_login_params *p)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
952 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
953 struct gg_session *sess = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
954 char *hostname;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
955 int port;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
956
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
957 if (!p) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
958 gg_debug(GG_DEBUG_FUNCTION, "** gg_login(%p);\n", p);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
959 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
960 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
961 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
962
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
963 gg_debug(GG_DEBUG_FUNCTION, "** gg_login(%p: [uin=%u, async=%d, ...]);\n", p, p->uin, p->async);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
964
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
965 if (!(sess = malloc(sizeof(struct gg_session)))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
966 gg_debug(GG_DEBUG_MISC, "// gg_login() not enough memory for session data\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
967 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
968 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
969
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
970 memset(sess, 0, sizeof(struct gg_session));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
971
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
972 if (!p->password || !p->uin) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
973 gg_debug(GG_DEBUG_MISC, "// gg_login() invalid arguments. uin and password needed\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
974 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
975 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
976 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
977
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
978 if (!(sess->password = strdup(p->password))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
979 gg_debug(GG_DEBUG_MISC, "// gg_login() not enough memory for password\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
980 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
981 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
982
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
983 if (p->status_descr && !(sess->initial_descr = strdup(p->status_descr))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
984 gg_debug(GG_DEBUG_MISC, "// gg_login() not enough memory for status\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
985 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
986 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
987
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
988 sess->uin = p->uin;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
989 sess->state = GG_STATE_RESOLVING;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
990 sess->check = GG_CHECK_READ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
991 sess->timeout = GG_DEFAULT_TIMEOUT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
992 sess->async = p->async;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
993 sess->type = GG_SESSION_GG;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
994 sess->initial_status = p->status;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
995 sess->callback = gg_session_callback;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
996 sess->destroy = gg_free_session;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
997 sess->port = (p->server_port) ? p->server_port : ((gg_proxy_enabled) ? GG_HTTPS_PORT : GG_DEFAULT_PORT);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
998 sess->server_addr = p->server_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
999 sess->external_port = p->external_port;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1000 sess->external_addr = p->external_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1001 sess->protocol_version = (p->protocol_version) ? p->protocol_version : GG_DEFAULT_PROTOCOL_VERSION;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1002 if (p->era_omnix)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1003 sess->protocol_version |= GG_ERA_OMNIX_MASK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1004 if (p->has_audio)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1005 sess->protocol_version |= GG_HAS_AUDIO_MASK;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1006 sess->client_version = (p->client_version) ? strdup(p->client_version) : NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1007 sess->last_sysmsg = p->last_sysmsg;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1008 sess->image_size = p->image_size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1009 sess->pid = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1010
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1011 if (p->tls == 1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1012 #ifdef __GG_LIBGADU_HAVE_OPENSSL
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1013 char buf[1024];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1014
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1015 OpenSSL_add_ssl_algorithms();
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1016
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1017 if (!RAND_status()) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1018 char rdata[1024];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1019 struct {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1020 time_t time;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1021 void *ptr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1022 } rstruct;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1023
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1024 time(&rstruct.time);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1025 rstruct.ptr = (void *) &rstruct;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1026
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1027 RAND_seed((void *) rdata, sizeof(rdata));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1028 RAND_seed((void *) &rstruct, sizeof(rstruct));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1029 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1030
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1031 sess->ssl_ctx = SSL_CTX_new(TLSv1_client_method());
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1032
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1033 if (!sess->ssl_ctx) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1034 ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1035 gg_debug(GG_DEBUG_MISC, "// gg_login() SSL_CTX_new() failed: %s\n", buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1036 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1037 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1038
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1039 SSL_CTX_set_verify(sess->ssl_ctx, SSL_VERIFY_NONE, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1040
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1041 sess->ssl = SSL_new(sess->ssl_ctx);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1042
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1043 if (!sess->ssl) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1044 ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1045 gg_debug(GG_DEBUG_MISC, "// gg_login() SSL_new() failed: %s\n", buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1046 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1047 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1048 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1049 gg_debug(GG_DEBUG_MISC, "// gg_login() client requested TLS but no support compiled in\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1050 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1051 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1052
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1053 if (gg_proxy_enabled) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1054 hostname = gg_proxy_host;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1055 sess->proxy_port = port = gg_proxy_port;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1056 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1057 hostname = GG_APPMSG_HOST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1058 port = GG_APPMSG_PORT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1059 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1060
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1061 if (!p->async) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1062 struct in_addr a;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1063
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1064 if (!p->server_addr || !p->server_port) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1065 if ((a.s_addr = inet_addr(hostname)) == INADDR_NONE) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1066 struct in_addr *hn;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1067
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1068 if (!(hn = gg_gethostbyname(hostname))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1069 gg_debug(GG_DEBUG_MISC, "// gg_login() host \"%s\" not found\n", hostname);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1070 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1071 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1072 a.s_addr = hn->s_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1073 free(hn);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1074 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1075 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1076 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1077 a.s_addr = p->server_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1078 port = p->server_port;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1079 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1080
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1081 sess->hub_addr = a.s_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1082
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1083 if (gg_proxy_enabled)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1084 sess->proxy_addr = a.s_addr;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1085
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1086 if ((sess->fd = gg_connect(&a, port, 0)) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1087 gg_debug(GG_DEBUG_MISC, "// gg_login() connection failed (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1088 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1089 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1090
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1091 if (p->server_addr && p->server_port)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1092 sess->state = GG_STATE_CONNECTING_GG;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1093 else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1094 sess->state = GG_STATE_CONNECTING_HUB;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1095
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1096 while (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1097 struct gg_event *e;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1098
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1099 if (!(e = gg_watch_fd(sess))) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1100 gg_debug(GG_DEBUG_MISC, "// gg_login() critical error in gg_watch_fd()\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1101 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1102 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1103
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1104 if (e->type == GG_EVENT_CONN_FAILED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1105 errno = EACCES;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1106 gg_debug(GG_DEBUG_MISC, "// gg_login() could not login\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1107 gg_event_free(e);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1108 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1109 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1110
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1111 gg_event_free(e);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1112 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1113
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1114 return sess;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1115 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1116
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1117 if (!sess->server_addr || gg_proxy_enabled) {
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1118 #ifdef __GG_LIBGADU_HAVE_PTHREAD
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1119 if (gg_resolve_pthread(&sess->fd, &sess->resolver, hostname)) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1120 #elif defined _WIN32
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1121 if (gg_resolve_win32thread(&sess->fd, &sess->resolver, hostname)) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1122 #else
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1123 if (gg_resolve(&sess->fd, &sess->pid, hostname)) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1124 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1125 gg_debug(GG_DEBUG_MISC, "// gg_login() resolving failed (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1126 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1127 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1128 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1129 if ((sess->fd = gg_connect(&sess->server_addr, sess->port, sess->async)) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1130 gg_debug(GG_DEBUG_MISC, "// gg_login() direct connection failed (errno=%d, %s)\n", errno, strerror(errno));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1131 goto fail;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1132 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1133 sess->state = GG_STATE_CONNECTING_GG;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1134 sess->check = GG_CHECK_WRITE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1135 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1136
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1137 return sess;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1138
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1139 fail:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1140 if (sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1141 if (sess->password)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1142 free(sess->password);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1143 if (sess->initial_descr)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1144 free(sess->initial_descr);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1145 free(sess);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1146 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1147
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1148 return NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1149 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1150
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1151 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1152 * gg_free_session()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1153 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1154 * próbuje zamknąć połączenia i zwalnia pamięć zajmowaną przez sesję.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1155 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1156 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1157 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1158 void gg_free_session(struct gg_session *sess)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1159 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1160 if (!sess)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1161 return;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1162
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1163 /* XXX dopisać zwalnianie i zamykanie wszystkiego, co mogło zostać */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1164
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1165 if (sess->password)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1166 free(sess->password);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1167
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1168 if (sess->initial_descr)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1169 free(sess->initial_descr);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1170
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1171 if (sess->client_version)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1172 free(sess->client_version);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1173
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1174 if (sess->header_buf)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1175 free(sess->header_buf);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1176
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1177 #ifdef __GG_LIBGADU_HAVE_OPENSSL
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1178 if (sess->ssl)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1179 SSL_free(sess->ssl);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1180
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1181 if (sess->ssl_ctx)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1182 SSL_CTX_free(sess->ssl_ctx);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1183 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1184
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1185 #ifdef __GG_LIBGADU_HAVE_PTHREAD
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1186 if (sess->resolver) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1187 pthread_cancel(*((pthread_t*) sess->resolver));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1188 free(sess->resolver);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1189 sess->resolver = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1190 }
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1191 #elif defined _WIN32
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1192 if (sess->resolver) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1193 HANDLE h = sess->resolver;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1194 TerminateThread(h, 0);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1195 CloseHandle(h);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1196 sess->resolver = NULL;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1197 }
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1198 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1199 if (sess->pid != -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1200 waitpid(sess->pid, NULL, WNOHANG);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1201 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1202
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1203 if (sess->fd != -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1204 close(sess->fd);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1205
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1206 while (sess->images)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1207 gg_image_queue_remove(sess, sess->images, 1);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1208
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1209 free(sess);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1210 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1211
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1212 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1213 * gg_change_status()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1214 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1215 * zmienia status użytkownika. przydatne do /away i /busy oraz /quit.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1216 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1217 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1218 * - status - nowy status użytkownika
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1219 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1220 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1221 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1222 int gg_change_status(struct gg_session *sess, int status)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1223 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1224 struct gg_new_status p;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1225
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1226 gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status(%p, %d);\n", sess, status);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1227
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1228 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1229 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1230 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1231 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1232
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1233 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1234 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1235 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1236 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1237
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1238 p.status = gg_fix32(status);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1239
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1240 sess->status = status;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1241
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1242 return gg_send_packet(sess, GG_NEW_STATUS, &p, sizeof(p), NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1243 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1244
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1245 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1246 * gg_change_status_descr()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1247 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1248 * zmienia status użytkownika na opisowy.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1249 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1250 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1251 * - status - nowy status użytkownika
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1252 * - descr - opis statusu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1253 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1254 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1255 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1256 int gg_change_status_descr(struct gg_session *sess, int status, const char *descr)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1257 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1258 struct gg_new_status p;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1259
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1260 gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status_descr(%p, %d, \"%s\");\n", sess, status, descr);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1261
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1262 if (!sess || !descr) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1263 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1264 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1265 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1266
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1267 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1268 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1269 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1270 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1271
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1272 p.status = gg_fix32(status);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1273
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1274 sess->status = status;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1275
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1276 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);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1277 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1278
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1279 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1280 * gg_change_status_descr_time()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1281 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1282 * zmienia status użytkownika na opisowy z godziną powrotu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1283 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1284 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1285 * - status - nowy status użytkownika
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1286 * - descr - opis statusu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1287 * - time - czas w formacie uniksowym
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1288 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1289 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1290 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1291 int gg_change_status_descr_time(struct gg_session *sess, int status, const char *descr, int time)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1292 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1293 struct gg_new_status p;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1294 uint32_t newtime;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1295
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1296 gg_debug(GG_DEBUG_FUNCTION, "** gg_change_status_descr_time(%p, %d, \"%s\", %d);\n", sess, status, descr, time);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1297
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1298 if (!sess || !descr || !time) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1299 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1300 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1301 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1302
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1303 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1304 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1305 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1306 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1307
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1308 p.status = gg_fix32(status);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1309
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1310 sess->status = status;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1311
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1312 newtime = gg_fix32(time);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1313
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1314 return gg_send_packet(sess, GG_NEW_STATUS, &p, sizeof(p), descr, (strlen(descr) > GG_STATUS_DESCR_MAXSIZE) ? GG_STATUS_DESCR_MAXSIZE : strlen(descr), &newtime, sizeof(newtime), NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1315 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1316
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1317 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1318 * gg_logoff()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1319 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1320 * wylogowuje użytkownika i zamyka połączenie, ale nie zwalnia pamięci.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1321 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1322 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1323 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1324 void gg_logoff(struct gg_session *sess)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1325 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1326 if (!sess)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1327 return;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1328
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1329 gg_debug(GG_DEBUG_FUNCTION, "** gg_logoff(%p);\n", sess);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1330
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1331 if (GG_S_NA(sess->status & ~GG_STATUS_FRIENDS_MASK))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1332 gg_change_status(sess, GG_STATUS_NOT_AVAIL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1333
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1334 #ifdef __GG_LIBGADU_HAVE_OPENSSL
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1335 if (sess->ssl)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1336 SSL_shutdown(sess->ssl);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1337 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1338
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1339 #ifdef __GG_LIBGADU_HAVE_PTHREAD
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1340 if (sess->resolver) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1341 pthread_cancel(*((pthread_t*) sess->resolver));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1342 free(sess->resolver);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1343 sess->resolver = NULL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1344 }
11546
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1345 #elif defined _WIN32
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1346 if (sess->resolver) {
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1347 HANDLE h = sess->resolver;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1348 TerminateThread(h, 0);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1349 CloseHandle(h);
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1350 sess->resolver = NULL;
3c536224f0d0 [gaim-migrate @ 13801]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11360
diff changeset
1351 }
11360
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1352 #else
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1353 if (sess->pid != -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1354 waitpid(sess->pid, NULL, WNOHANG);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1355 sess->pid = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1356 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1357 #endif
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1358
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1359 if (sess->fd != -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1360 shutdown(sess->fd, SHUT_RDWR);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1361 close(sess->fd);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1362 sess->fd = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1363 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1364 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1365
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1366 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1367 * gg_image_request()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1368 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1369 * wysyła żądanie wysłania obrazka o podanych parametrach.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1370 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1371 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1372 * - recipient - numer adresata
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1373 * - size - rozmiar obrazka
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1374 * - crc32 - suma kontrolna obrazka
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1375 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1376 * 0/-1
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1377 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1378 int gg_image_request(struct gg_session *sess, uin_t recipient, int size, uint32_t crc32)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1379 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1380 struct gg_send_msg s;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1381 struct gg_msg_image_request r;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1382 char dummy = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1383 int res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1384
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1385 gg_debug(GG_DEBUG_FUNCTION, "** gg_image_request(%p, %d, %u, 0x%.4x);\n", sess, recipient, size, crc32);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1386
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1387 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1388 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1389 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1390 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1391
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1392 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1393 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1394 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1395 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1396
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1397 if (size < 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1398 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1399 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1400 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1401
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1402 s.recipient = gg_fix32(recipient);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1403 s.seq = gg_fix32(0);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1404 s.msgclass = gg_fix32(GG_CLASS_MSG);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1405
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1406 r.flag = 0x04;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1407 r.size = gg_fix32(size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1408 r.crc32 = gg_fix32(crc32);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1409
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1410 res = gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), &dummy, 1, &r, sizeof(r), NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1411
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1412 if (!res) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1413 struct gg_image_queue *q = malloc(sizeof(*q));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1414 char *buf;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1415
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1416 if (!q) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1417 gg_debug(GG_DEBUG_MISC, "// gg_image_request() not enough memory for image queue\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1418 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1419 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1420
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1421 buf = malloc(size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1422 if (size && !buf)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1423 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1424 gg_debug(GG_DEBUG_MISC, "// gg_image_request() not enough memory for image\n");
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1425 free(q);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1426 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1427 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1428
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1429 memset(q, 0, sizeof(*q));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1430
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1431 q->sender = recipient;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1432 q->size = size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1433 q->crc32 = crc32;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1434 q->image = buf;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1435
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1436 if (!sess->images)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1437 sess->images = q;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1438 else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1439 struct gg_image_queue *qq;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1440
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1441 for (qq = sess->images; qq->next; qq = qq->next)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1442 ;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1443
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1444 qq->next = q;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1445 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1446 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1447
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1448 return res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1449 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1450
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1451 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1452 * gg_image_reply()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1453 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1454 * wysyła żądany obrazek.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1455 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1456 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1457 * - recipient - numer adresata
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1458 * - filename - nazwa pliku
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1459 * - image - bufor z obrazkiem
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1460 * - size - rozmiar obrazka
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1461 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1462 * 0/-1
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1463 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1464 int gg_image_reply(struct gg_session *sess, uin_t recipient, const char *filename, const char *image, int size)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1465 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1466 struct gg_msg_image_reply *r;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1467 struct gg_send_msg s;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1468 const char *tmp;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1469 char buf[1910];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1470 int res = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1471
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1472 gg_debug(GG_DEBUG_FUNCTION, "** gg_image_reply(%p, %d, \"%s\", %p, %d);\n", sess, recipient, filename, image, size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1473
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1474 if (!sess || !filename || !image) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1475 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1476 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1477 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1478
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1479 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1480 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1481 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1482 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1483
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1484 if (size < 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1485 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1486 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1487 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1488
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1489 /* wytnij ścieżki, zostaw tylko nazwę pliku */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1490 while ((tmp = strrchr(filename, '/')) || (tmp = strrchr(filename, '\\')))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1491 filename = tmp + 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1492
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1493 if (strlen(filename) < 1 || strlen(filename) > 1024) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1494 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1495 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1496 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1497
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1498 s.recipient = gg_fix32(recipient);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1499 s.seq = gg_fix32(0);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1500 s.msgclass = gg_fix32(GG_CLASS_MSG);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1501
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1502 buf[0] = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1503 r = (void*) &buf[1];
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1504
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1505 r->flag = 0x05;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1506 r->size = gg_fix32(size);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1507 r->crc32 = gg_fix32(gg_crc32(0, image, size));
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1508
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1509 while (size > 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1510 int buflen, chunklen;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1511
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1512 /* \0 + struct gg_msg_image_reply */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1513 buflen = sizeof(struct gg_msg_image_reply) + 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1514
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1515 /* w pierwszym kawałku jest nazwa pliku */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1516 if (r->flag == 0x05) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1517 strcpy(buf + buflen, filename);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1518 buflen += strlen(filename) + 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1519 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1520
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1521 chunklen = (size >= sizeof(buf) - buflen) ? (sizeof(buf) - buflen) : size;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1522
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1523 memcpy(buf + buflen, image, chunklen);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1524 size -= chunklen;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1525 image += chunklen;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1526
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1527 res = gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), buf, buflen + chunklen, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1528
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1529 if (res == -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1530 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1531
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1532 r->flag = 0x06;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1533 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1534
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1535 return res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1536 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1537
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1538 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1539 * gg_send_message_ctcp()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1540 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1541 * wysyła wiadomość do innego użytkownika. zwraca losowy numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1542 * sekwencyjny, który można zignorować albo wykorzystać do potwierdzenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1543 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1544 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1545 * - msgclass - rodzaj wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1546 * - recipient - numer adresata
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1547 * - message - treść wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1548 * - message_len - długość
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1549 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1550 * numer sekwencyjny wiadomości lub -1 w przypadku błędu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1551 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1552 int gg_send_message_ctcp(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message, int message_len)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1553 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1554 struct gg_send_msg s;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1555
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1556 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message_ctcp(%p, %d, %u, ...);\n", sess, msgclass, recipient);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1557
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1558 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1559 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1560 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1561 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1562
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1563 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1564 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1565 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1566 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1567
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1568 s.recipient = gg_fix32(recipient);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1569 s.seq = gg_fix32(0);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1570 s.msgclass = gg_fix32(msgclass);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1571
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1572 return gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, message_len, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1573 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1574
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1575 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1576 * gg_send_message()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1577 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1578 * wysyła wiadomość do innego użytkownika. zwraca losowy numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1579 * sekwencyjny, który można zignorować albo wykorzystać do potwierdzenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1580 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1581 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1582 * - msgclass - rodzaj wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1583 * - recipient - numer adresata
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1584 * - message - treść wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1585 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1586 * numer sekwencyjny wiadomości lub -1 w przypadku błędu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1587 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1588 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1589 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1590 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message(%p, %d, %u, %p)\n", sess, msgclass, recipient, message);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1591
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1592 return gg_send_message_richtext(sess, msgclass, recipient, message, NULL, 0);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1593 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1594
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1595 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1596 * gg_send_message_richtext()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1597 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1598 * wysyła kolorową wiadomość do innego użytkownika. zwraca losowy numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1599 * sekwencyjny, który można zignorować albo wykorzystać do potwierdzenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1600 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1601 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1602 * - msgclass - rodzaj wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1603 * - recipient - numer adresata
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1604 * - message - treść wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1605 * - format - informacje o formatowaniu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1606 * - formatlen - długość informacji o formatowaniu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1607 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1608 * numer sekwencyjny wiadomości lub -1 w przypadku błędu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1609 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1610 int gg_send_message_richtext(struct gg_session *sess, int msgclass, uin_t recipient, const unsigned char *message, const unsigned char *format, int formatlen)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1611 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1612 struct gg_send_msg s;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1613
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1614 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message_richtext(%p, %d, %u, %p, %p, %d);\n", sess, msgclass, recipient, message, format, formatlen);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1615
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1616 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1617 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1618 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1619 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1620
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1621 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1622 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1623 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1624 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1625
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1626 if (!message) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1627 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1628 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1629 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1630
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1631 s.recipient = gg_fix32(recipient);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1632 if (!sess->seq)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1633 sess->seq = 0x01740000 | (rand() & 0xffff);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1634 s.seq = gg_fix32(sess->seq);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1635 s.msgclass = gg_fix32(msgclass);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1636 sess->seq += (rand() % 0x300) + 0x300;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1637
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1638 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen(message) + 1, format, formatlen, NULL) == -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1639 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1640
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1641 return gg_fix32(s.seq);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1642 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1643
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1644 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1645 * gg_send_message_confer()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1646 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1647 * wysyła wiadomość do kilku użytkownikow (konferencja). zwraca losowy numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1648 * sekwencyjny, który można zignorować albo wykorzystać do potwierdzenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1649 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1650 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1651 * - msgclass - rodzaj wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1652 * - recipients_count - ilość adresatów
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1653 * - recipients - numerki adresatów
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1654 * - message - treść wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1655 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1656 * numer sekwencyjny wiadomości lub -1 w przypadku błędu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1657 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1658 int gg_send_message_confer(struct gg_session *sess, int msgclass, int recipients_count, uin_t *recipients, const unsigned char *message)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1659 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1660 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message_confer(%p, %d, %d, %p, %p);\n", sess, msgclass, recipients_count, recipients, message);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1661
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1662 return gg_send_message_confer_richtext(sess, msgclass, recipients_count, recipients, message, NULL, 0);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1663 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1664
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1665 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1666 * gg_send_message_confer_richtext()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1667 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1668 * wysyła kolorową wiadomość do kilku użytkownikow (konferencja). zwraca
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1669 * losowy numer sekwencyjny, który można zignorować albo wykorzystać do
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1670 * potwierdzenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1671 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1672 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1673 * - msgclass - rodzaj wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1674 * - recipients_count - ilość adresatów
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1675 * - recipients - numerki adresatów
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1676 * - message - treść wiadomości
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1677 * - format - informacje o formatowaniu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1678 * - formatlen - długość informacji o formatowaniu
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1679 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1680 * numer sekwencyjny wiadomości lub -1 w przypadku błędu.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1681 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1682 int gg_send_message_confer_richtext(struct gg_session *sess, int msgclass, int recipients_count, uin_t *recipients, const unsigned char *message, const unsigned char *format, int formatlen)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1683 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1684 struct gg_send_msg s;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1685 struct gg_msg_recipients r;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1686 int i, j, k;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1687 uin_t *recps;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1688
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1689 gg_debug(GG_DEBUG_FUNCTION, "** gg_send_message_confer_richtext(%p, %d, %d, %p, %p, %p, %d);\n", sess, msgclass, recipients_count, recipients, message, format, formatlen);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1690
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1691 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1692 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1693 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1694 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1695
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1696 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1697 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1698 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1699 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1700
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1701 if (!message || recipients_count <= 0 || recipients_count > 0xffff || !recipients) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1702 errno = EINVAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1703 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1704 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1705
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1706 r.flag = 0x01;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1707 r.count = gg_fix32(recipients_count - 1);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1708
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1709 if (!sess->seq)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1710 sess->seq = 0x01740000 | (rand() & 0xffff);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1711 s.seq = gg_fix32(sess->seq);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1712 s.msgclass = gg_fix32(msgclass);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1713
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1714 recps = malloc(sizeof(uin_t) * recipients_count);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1715 if (!recps)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1716 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1717
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1718 for (i = 0; i < recipients_count; i++) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1719
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1720 s.recipient = gg_fix32(recipients[i]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1721
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1722 for (j = 0, k = 0; j < recipients_count; j++)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1723 if (recipients[j] != recipients[i]) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1724 recps[k] = gg_fix32(recipients[j]);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1725 k++;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1726 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1727
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1728 if (!i)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1729 sess->seq += (rand() % 0x300) + 0x300;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1730
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1731 if (gg_send_packet(sess, GG_SEND_MSG, &s, sizeof(s), message, strlen(message) + 1, &r, sizeof(r), recps, (recipients_count - 1) * sizeof(uin_t), format, formatlen, NULL) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1732 free(recps);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1733 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1734 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1735 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1736
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1737 free(recps);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1738
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1739 return gg_fix32(s.seq);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1740 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1741
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1742 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1743 * gg_ping()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1744 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1745 * wysyła do serwera pakiet ping.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1746 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1747 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1748 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1749 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1750 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1751 int gg_ping(struct gg_session *sess)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1752 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1753 gg_debug(GG_DEBUG_FUNCTION, "** gg_ping(%p);\n", sess);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1754
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1755 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1756 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1757 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1758 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1759
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1760 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1761 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1762 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1763 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1764
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1765 return gg_send_packet(sess, GG_PING, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1766 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1767
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1768 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1769 * gg_notify_ex()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1770 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1771 * wysyła serwerowi listę kontaktów (wraz z odpowiadającymi im typami userów),
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1772 * dzięki czemu wie, czyj stan nas interesuje.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1773 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1774 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1775 * - userlist - wskaźnik do tablicy numerów
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1776 * - types - wskaźnik do tablicy typów użytkowników
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1777 * - count - ilość numerków
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1778 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1779 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1780 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1781 int gg_notify_ex(struct gg_session *sess, uin_t *userlist, char *types, int count)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1782 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1783 struct gg_notify *n;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1784 uin_t *u;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1785 char *t;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1786 int i, res = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1787
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1788 gg_debug(GG_DEBUG_FUNCTION, "** gg_notify_ex(%p, %p, %p, %d);\n", sess, userlist, types, count);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1789
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1790 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1791 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1792 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1793 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1794
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1795 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1796 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1797 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1798 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1799
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1800 if (!userlist || !count)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1801 return gg_send_packet(sess, GG_LIST_EMPTY, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1802
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1803 while (count > 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1804 int part_count, packet_type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1805
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1806 if (count > 400) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1807 part_count = 400;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1808 packet_type = GG_NOTIFY_FIRST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1809 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1810 part_count = count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1811 packet_type = GG_NOTIFY_LAST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1812 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1813
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1814 if (!(n = (struct gg_notify*) malloc(sizeof(*n) * part_count)))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1815 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1816
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1817 for (u = userlist, t = types, i = 0; i < part_count; u++, t++, i++) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1818 n[i].uin = gg_fix32(*u);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1819 n[i].dunno1 = *t;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1820 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1821
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1822 if (gg_send_packet(sess, packet_type, n, sizeof(*n) * part_count, NULL) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1823 free(n);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1824 res = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1825 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1826 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1827
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1828 count -= part_count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1829 userlist += part_count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1830 types += part_count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1831
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1832 free(n);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1833 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1834
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1835 return res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1836 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1837
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1838 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1839 * gg_notify()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1840 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1841 * wysyła serwerowi listę kontaktów, dzięki czemu wie, czyj stan nas
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1842 * interesuje.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1843 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1844 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1845 * - userlist - wskaźnik do tablicy numerów
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1846 * - count - ilość numerków
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1847 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1848 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1849 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1850 int gg_notify(struct gg_session *sess, uin_t *userlist, int count)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1851 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1852 struct gg_notify *n;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1853 uin_t *u;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1854 int i, res = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1855
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1856 gg_debug(GG_DEBUG_FUNCTION, "** gg_notify(%p, %p, %d);\n", sess, userlist, count);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1857
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1858 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1859 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1860 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1861 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1862
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1863 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1864 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1865 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1866 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1867
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1868 if (!userlist || !count)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1869 return gg_send_packet(sess, GG_LIST_EMPTY, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1870
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1871 while (count > 0) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1872 int part_count, packet_type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1873
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1874 if (count > 400) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1875 part_count = 400;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1876 packet_type = GG_NOTIFY_FIRST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1877 } else {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1878 part_count = count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1879 packet_type = GG_NOTIFY_LAST;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1880 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1881
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1882 if (!(n = (struct gg_notify*) malloc(sizeof(*n) * part_count)))
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1883 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1884
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1885 for (u = userlist, i = 0; i < part_count; u++, i++) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1886 n[i].uin = gg_fix32(*u);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1887 n[i].dunno1 = GG_USER_NORMAL;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1888 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1889
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1890 if (gg_send_packet(sess, packet_type, n, sizeof(*n) * part_count, NULL) == -1) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1891 res = -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1892 free(n);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1893 break;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1894 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1895
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1896 free(n);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1897
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1898 userlist += part_count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1899 count -= part_count;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1900 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1901
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1902 return res;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1903 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1904
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1905 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1906 * gg_add_notify_ex()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1907 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1908 * dodaje do listy kontaktów dany numer w trakcie połączenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1909 * dodawanemu użytkownikowi określamy jego typ (patrz protocol.html)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1910 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1911 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1912 * - uin - numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1913 * - type - typ
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1914 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1915 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1916 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1917 int gg_add_notify_ex(struct gg_session *sess, uin_t uin, char type)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1918 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1919 struct gg_add_remove a;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1920
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1921 gg_debug(GG_DEBUG_FUNCTION, "** gg_add_notify_ex(%p, %u, %d);\n", sess, uin, type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1922
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1923 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1924 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1925 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1926 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1927
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1928 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1929 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1930 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1931 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1932
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1933 a.uin = gg_fix32(uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1934 a.dunno1 = type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1935
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1936 return gg_send_packet(sess, GG_ADD_NOTIFY, &a, sizeof(a), NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1937 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1938
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1939 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1940 * gg_add_notify()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1941 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1942 * dodaje do listy kontaktów dany numer w trakcie połączenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1943 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1944 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1945 * - uin - numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1946 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1947 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1948 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1949 int gg_add_notify(struct gg_session *sess, uin_t uin)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1950 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1951 return gg_add_notify_ex(sess, uin, GG_USER_NORMAL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1952 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1953
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1954 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1955 * gg_remove_notify_ex()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1956 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1957 * usuwa z listy kontaktów w trakcie połączenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1958 * usuwanemu użytkownikowi określamy jego typ (patrz protocol.html)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1959 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1960 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1961 * - uin - numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1962 * - type - typ
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1963 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1964 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1965 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1966 int gg_remove_notify_ex(struct gg_session *sess, uin_t uin, char type)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1967 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1968 struct gg_add_remove a;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1969
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1970 gg_debug(GG_DEBUG_FUNCTION, "** gg_remove_notify_ex(%p, %u, %d);\n", sess, uin, type);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1971
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1972 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1973 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1974 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1975 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1976
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1977 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1978 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1979 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1980 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1981
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1982 a.uin = gg_fix32(uin);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1983 a.dunno1 = type;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1984
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1985 return gg_send_packet(sess, GG_REMOVE_NOTIFY, &a, sizeof(a), NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1986 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1987
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1988 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1989 * gg_remove_notify()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1990 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1991 * usuwa z listy kontaktów w trakcie połączenia.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1992 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1993 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1994 * - uin - numer
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1995 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1996 * 0, -1.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1997 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1998 int gg_remove_notify(struct gg_session *sess, uin_t uin)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
1999 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2000 return gg_remove_notify_ex(sess, uin, GG_USER_NORMAL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2001 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2002
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2003 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2004 * gg_userlist_request()
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2005 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2006 * wysyła żądanie/zapytanie listy kontaktów na serwerze.
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2007 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2008 * - sess - opis sesji
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2009 * - type - rodzaj zapytania/żądania
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2010 * - request - treść zapytania/żądania (może być NULL)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2011 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2012 * 0, -1
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2013 */
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2014 int gg_userlist_request(struct gg_session *sess, char type, const char *request)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2015 {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2016 int len;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2017
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2018 if (!sess) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2019 errno = EFAULT;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2020 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2021 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2022
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2023 if (sess->state != GG_STATE_CONNECTED) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2024 errno = ENOTCONN;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2025 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2026 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2027
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2028 if (!request) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2029 sess->userlist_blocks = 1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2030 return gg_send_packet(sess, GG_USERLIST_REQUEST, &type, sizeof(type), NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2031 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2032
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2033 len = strlen(request);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2034
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2035 sess->userlist_blocks = 0;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2036
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2037 while (len > 2047) {
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2038 sess->userlist_blocks++;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2039
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2040 if (gg_send_packet(sess, GG_USERLIST_REQUEST, &type, sizeof(type), request, 2047, NULL) == -1)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2041 return -1;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2042
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2043 if (type == GG_USERLIST_PUT)
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2044 type = GG_USERLIST_PUT_MORE;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2045
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2046 request += 2047;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2047 len -= 2047;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2048 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2049
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2050 sess->userlist_blocks++;
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2051
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2052 return gg_send_packet(sess, GG_USERLIST_REQUEST, &type, sizeof(type), request, len, NULL);
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2053 }
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2054
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2055 /*
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2056 * Local variables:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2057 * c-indentation-style: k&r
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2058 * c-basic-offset: 8
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2059 * indent-tabs-mode: notnil
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2060 * End:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2061 *
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2062 * vim: shiftwidth=8:
cf15c1cdcfbd [gaim-migrate @ 13582]
Bartoz Oler <bartosz@pidgin.im>
parents:
diff changeset
2063 */