libpurple/protocols/gg/lib/common.c

Fri, 07 Mar 2014 23:17:08 +0100

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Fri, 07 Mar 2014 23:17:08 +0100
branch
release-2.x.y
changeset 35627
fd11790cc4d6
parent 35617
c9069e0e3c36
child 35630
8e5d0d726b09
child 35645
0143226782bb
permissions
-rw-r--r--

Update internal libgadu to the current version from git

35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
1 /* $Id$ */
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
2
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
3 /*
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
4 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl>
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
5 * Robert J. Woźny <speedy@ziew.org>
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
6 *
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU Lesser General Public License Version
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
9 * 2.1 as published by the Free Software Foundation.
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
10 *
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
14 * GNU Lesser General Public License for more details.
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
15 *
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
17 * License along with this program; if not, write to the Free Software
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
19 * USA.
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
20 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
21
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
22 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
23 * \file common.c
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
24 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
25 * \brief Funkcje wykorzystywane przez różne moduły biblioteki
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
26 */
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
27
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
28 #include "network.h"
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
29 #include "strman.h"
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
30 #ifdef sun
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
31 # include <sys/filio.h>
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
32 #endif
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
33
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
34 #include <errno.h>
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
35 #include <stdarg.h>
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
36 #include <stdlib.h>
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
37 #include <string.h>
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
38 #include <ctype.h>
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
39 #include <time.h>
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
40
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
41 #include "config.h"
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
42 #include "libgadu.h"
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
43 #include "internal.h"
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
44
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
45 #ifndef GG_CONFIG_HAVE_VA_COPY
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
46 # ifdef GG_CONFIG_HAVE___VA_COPY
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
47 # define va_copy(dest, src) __va_copy((dest), (src))
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
48 # else
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
49 /* Taka wersja va_copy() działa poprawnie tylko na platformach, które
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
50 * va_copy() de facto wcale nie potrzebują, np. MSVC. Definicja tylko dla
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
51 * przejrzystości kodu. */
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
52 # define va_copy(dest, src) (dest) = (src)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
53 # endif
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
54 #endif
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
55
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
56 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
57 * \internal Odpowiednik funkcji \c vsprintf alokujący miejsce na wynik.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
58 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
59 * Funkcja korzysta z funkcji \c vsnprintf, sprawdzając czy dostępna funkcja
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
60 * systemowa jest zgodna ze standardem C99 czy wcześniejszymi.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
61 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
62 * \param format Format wiadomości (zgodny z \c printf)
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
63 * \param ap Lista argumentów (zgodna z \c printf)
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
64 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
65 * \return Zaalokowany bufor lub NULL, jeśli zabrakło pamięci.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
66 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
67 * \ingroup helper
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
68 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
69 char *gg_vsaprintf(const char *format, va_list ap)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
70 {
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
71 int size;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
72 char *buf = NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
73 va_list aq;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
74
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
75 #if !defined(GG_CONFIG_HAVE_C99_VSNPRINTF) && !defined(HAVE__VSCPRINTF)
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
76 {
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
77 int res = 0;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
78 char *tmp;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
79
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
80 size = 128;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
81 do {
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
82 if (res > size) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
83 /* Jednak zachowanie zgodne z C99. */
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
84 size = res + 1;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
85 } else {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
86 size *= 2;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
87 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
88
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
89 if (!(tmp = realloc(buf, size))) {
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
90 free(buf);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
91 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
92 }
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
93
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
94 buf = tmp;
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
95 va_copy(aq, ap);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
96 res = vsnprintf(buf, size, format, aq);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
97 va_end(aq);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
98 } while (res >= size || res < 0);
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
99 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
100 #else
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
101 va_copy(aq, ap);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
102
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
103 # ifdef HAVE__VSCPRINTF
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
104 size = _vscprintf(format, aq) + 1;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
105 # else
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
106 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
107 char tmp[2];
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
108
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
109 /* libce Solarisa przy buforze NULL zawsze zwracają -1, więc
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
110 * musimy podać coś istniejącego jako cel printf()owania. */
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
111 size = vsnprintf(tmp, sizeof(tmp), format, aq) + 1;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
112 }
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
113 # endif
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
114 va_end(aq);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
115 if (!(buf = malloc(size)))
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
116 return NULL;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
117
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
118 vsnprintf(buf, size, format, ap);
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
119 #endif
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
120
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
121 return buf;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
122 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
123
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
124 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
125 * \internal Odpowiednik funkcji \c sprintf alokujący miejsce na wynik.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
126 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
127 * Funkcja korzysta z funkcji \c vsnprintf, sprawdzając czy dostępna funkcja
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
128 * systemowa jest zgodna ze standardem C99 czy wcześniejszymi.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
129 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
130 * \param format Format wiadomości (zgodny z \c printf)
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
131 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
132 * \return Zaalokowany bufor lub NULL, jeśli zabrakło pamięci.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
133 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
134 * \ingroup helper
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
135 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
136 char *gg_saprintf(const char *format, ...)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
137 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
138 va_list ap;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
139 char *res;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
140
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
141 va_start(ap, format);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
142 res = gg_vsaprintf(format, ap);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
143 va_end(ap);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
144
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
145 return res;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
146 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
147
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
148 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
149 * \internal Pobiera linię tekstu z bufora.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
150 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
151 * Funkcja niszczy bufor źródłowy bezpowrotnie, dzieląc go na kolejne ciągi
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
152 * znaków i obcina znaki końca linii.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
153 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
154 * \param ptr Wskaźnik do zmiennej, która przechowuje aktualne położenie
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
155 * w analizowanym buforze
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
156 *
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
157 * \note Funkcja nie jest już używana. Pozostała dla zachowania ABI.
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
158 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
159 * \return Wskaźnik do kolejnej linii tekstu lub NULL, jeśli to już koniec
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
160 * bufora.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
161 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
162 char *gg_get_line(char **ptr)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
163 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
164 char *foo, *res;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
165
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
166 if (!ptr || !*ptr || !strcmp(*ptr, ""))
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
167 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
168
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
169 res = *ptr;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
170
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
171 if (!(foo = strchr(*ptr, '\n')))
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
172 *ptr += strlen(*ptr);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
173 else {
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
174 size_t len;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
175 *ptr = foo + 1;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
176 *foo = 0;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
177
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
178 len = strlen(res);
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
179
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
180 if (len > 1 && res[len - 1] == '\r')
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
181 res[len - 1] = 0;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
182 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
183
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
184 return res;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
185 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
186
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
187 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
188 * \internal Czyta linię tekstu z gniazda.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
189 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
190 * Funkcja czyta tekst znak po znaku, więc nie jest efektywna, ale dzięki
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
191 * brakowi buforowania, nie koliduje z innymi funkcjami odczytu.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
192 *
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
193 * \note W przypadku zakończenia połączenia przez drugą stronę, ostatnia
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
194 * linia nie jest zwracana.
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
195 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
196 * \param sock Deskryptor gniazda
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
197 * \param buf Wskaźnik do bufora
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
198 * \param length Długość bufora
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
199 *
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
200 * \return Zwraca wskaźnik na koniec odebranej linii jeśli się powiodło,
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
201 * lub \c NULL w przypadku błędu.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
202 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
203 char *gg_read_line(int sock, char *buf, int length)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
204 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
205 int ret;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
206
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
207 if (!buf || length < 0)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
208 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
209
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
210 for (; length > 1; buf++, length--) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
211 do {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
212 if ((ret = recv(sock, buf, 1, 0)) == -1 &&
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
213 errno != EINTR && errno != EAGAIN)
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
214 {
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
215 gg_debug(GG_DEBUG_MISC, "// gg_read_line() "
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
216 "error on read (errno=%d, %s)\n",
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
217 errno, strerror(errno));
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
218 *buf = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
219 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
220 } else if (ret == 0) {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
221 gg_debug(GG_DEBUG_MISC, "// gg_read_line() "
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
222 "eof reached\n");
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
223 *buf = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
224 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
225 }
31609
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
226 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
227
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
228 if (*buf == '\n') {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
229 buf++;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
230 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
231 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
232 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
233
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
234 *buf = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
235 return buf;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
236 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
237
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
238 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
239 * \internal Nawiązuje połączenie TCP.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
240 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
241 * \param addr Wskaźnik na strukturę \c in_addr z adresem serwera
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
242 * \param port Port serwera
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
243 * \param async Flaga asynchronicznego połączenia
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
244 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
245 * \return Deskryptor gniazda lub -1 w przypadku błędu
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
246 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
247 * \ingroup helper
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
248 */
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
249 int gg_connect(void *addr, int port, int async)
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
250 {
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
251 int sock, errno2;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
252 struct sockaddr_in sin;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
253 struct in_addr *a = addr;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
254 struct sockaddr_in myaddr;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
255
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
256 gg_debug(GG_DEBUG_FUNCTION, "** gg_connect(%s, %d, %d);\n", inet_ntoa(*a), port, async);
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
257
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
258 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
259 gg_debug(GG_DEBUG_MISC, "// gg_connect() socket() failed (errno=%d, %s)\n", errno, strerror(errno));
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
260 return -1;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
261 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
262
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
263 memset(&myaddr, 0, sizeof(myaddr));
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
264 myaddr.sin_family = AF_INET;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
265
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
266 myaddr.sin_addr.s_addr = gg_local_ip;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
267
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
268 if (bind(sock, (struct sockaddr *) &myaddr, sizeof(myaddr)) == -1) {
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
269 gg_debug(GG_DEBUG_MISC, "// gg_connect() bind() failed (errno=%d, %s)\n", errno, strerror(errno));
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
270 errno2 = errno;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
271 close(sock);
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
272 errno = errno2;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
273 return -1;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
274 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
275
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
276 if (async) {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
277 if (!gg_fd_set_nonblocking(sock)) {
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
278 gg_debug(GG_DEBUG_MISC, "// gg_connect() can't set "
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
279 "nonblocking (errno=%d, %s)\n",
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
280 errno, strerror(errno));
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
281 errno2 = errno;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
282 close(sock);
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
283 errno = errno2;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
284 return -1;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
285 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
286 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
287
33709
84fb3f1d401b Gadu-Gadu: fix some harmless Coverity issues
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 31826
diff changeset
288 memset(&sin, 0, sizeof(sin));
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
289 sin.sin_port = htons(port);
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
290 sin.sin_family = AF_INET;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
291 sin.sin_addr.s_addr = a->s_addr;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
292
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
293 if (connect(sock, (struct sockaddr*) &sin, sizeof(sin)) == -1) {
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
294 if (errno && (!async || errno != EINPROGRESS)) {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
295 gg_debug(GG_DEBUG_MISC, "// gg_connect() connect() "
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
296 "failed (errno=%d, %s)\n",
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
297 errno, strerror(errno));
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
298 errno2 = errno;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
299 close(sock);
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
300 errno = errno2;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
301 return -1;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
302 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
303 gg_debug(GG_DEBUG_MISC, "// gg_connect() connect() in progress\n");
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
304 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
305
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
306 return sock;
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
307 }
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
308
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
309 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
310 * \internal Usuwa znaki końca linii.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
311 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
312 * Funkcja działa bezpośrednio na buforze.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
313 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
314 * \param line Bufor z tekstem
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
315 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
316 * \ingroup helper
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
317 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
318 void gg_chomp(char *line)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
319 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
320 int len;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
321
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
322 if (!line)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
323 return;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
324
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
325 len = strlen(line);
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
326
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
327 if (len > 0 && line[len - 1] == '\n')
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
328 line[--len] = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
329 if (len > 0 && line[len - 1] == '\r')
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
330 line[--len] = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
331 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
332
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
333 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
334 * \internal Koduje ciąg znaków do postacji adresu HTTP.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
335 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
336 * Zamienia znaki niedrukowalne, spoza ASCII i mające specjalne znaczenie
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
337 * dla protokołu HTTP na encje postaci \c %XX, gdzie \c XX jest szesnastkową
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
338 * wartością znaku.
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
339 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
340 * \param str Ciąg znaków do zakodowania
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
341 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
342 * \return Zaalokowany bufor lub \c NULL w przypadku błędu.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
343 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
344 * \ingroup helper
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
345 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
346 char *gg_urlencode(const char *str)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
347 {
31609
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
348 char *q, *buf;
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
349 const char hex[] = "0123456789abcdef";
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
350 const char *p;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
351 unsigned int size = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
352
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
353 if (!str)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
354 str = "";
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
355
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
356 for (p = str; *p; p++, size++) {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
357 if (!((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') ||
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
358 (*p >= '0' && *p <= '9') || *p == ' ') || (*p == '@') ||
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
359 (*p == '.') || (*p == '-'))
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
360 {
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
361 size += 2;
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
362 }
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
363 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
364
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
365 if (!(buf = malloc(size + 1)))
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
366 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
367
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
368 for (p = str, q = buf; *p; p++, q++) {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
369 if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') ||
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
370 (*p >= '0' && *p <= '9') || (*p == '@') ||
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
371 (*p == '.') || (*p == '-'))
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
372 {
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
373 *q = *p;
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
374 } else {
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
375 if (*p == ' ')
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
376 *q = '+';
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
377 else {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
378 *q++ = '%';
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
379 *q++ = hex[*p >> 4 & 15];
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
380 *q = hex[*p & 15];
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
381 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
382 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
383 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
384
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
385 *q = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
386
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
387 return buf;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
388 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
389
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
390 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
391 * \internal Wyznacza skrót dla usług HTTP.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
392 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
393 * Funkcja jest wykorzystywana do wyznaczania skrótu adresu e-mail, hasła
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
394 * i innych wartości przekazywanych jako parametry usług HTTP.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
395 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
396 * W parametrze \c format należy umieścić znaki określające postać kolejnych
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
397 * parametrów: \c 's' jeśli parametr jest ciągiem znaków, \c 'u' jeśli jest
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
398 * liczbą.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
399 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
400 * \param format Format kolejnych parametrów (niezgodny z \c printf)
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
401 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
402 * \return Wartość skrótu
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
403 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
404 int gg_http_hash(const char *format, ...)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
405 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
406 unsigned int a, c, i, j;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
407 va_list ap;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
408 int b = -1;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
409
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
410 va_start(ap, format);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
411
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
412 for (j = 0; j < strlen(format); j++) {
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
413 const char *arg;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
414 char buf[16];
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
415
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
416 if (format[j] == 'u') {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
417 snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t));
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
418 arg = buf;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
419 } else {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
420 if (!(arg = va_arg(ap, char*)))
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
421 arg = "";
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
422 }
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
423
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
424 i = 0;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
425 while ((c = (unsigned char) arg[i++]) != 0) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
426 a = (c ^ b) + (c << 8);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
427 b = (a >> 24) | (a << 8);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
428 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
429 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
430
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
431 va_end(ap);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
432
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
433 return (b < 0 ? -b : b);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
434 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
435
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
436 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
437 * \internal Zestaw znaków kodowania base64.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
438 */
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
439 static char gg_base64_charset[] =
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
440 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
441
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
442 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
443 * \internal Koduje ciąg znaków do base64.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
444 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
445 * Wynik funkcji należy zwolnić za pomocą \c free.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
446 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
447 * \param buf Bufor z danami do zakodowania
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
448 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
449 * \return Zaalokowany bufor z zakodowanymi danymi
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
450 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
451 * \ingroup helper
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
452 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
453 char *gg_base64_encode(const char *buf)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
454 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
455 char *out, *res;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
456 unsigned int i = 0, j = 0, k = 0, len = strlen(buf);
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
457
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
458 res = out = malloc((len / 3 + 1) * 4 + 2);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
459
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
460 if (!res)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
461 return NULL;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
462
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
463 while (j <= len) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
464 switch (i % 4) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
465 case 0:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
466 k = (buf[j] & 252) >> 2;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
467 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
468 case 1:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
469 if (j < len)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
470 k = ((buf[j] & 3) << 4) | ((buf[j + 1] & 240) >> 4);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
471 else
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
472 k = (buf[j] & 3) << 4;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
473
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
474 j++;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
475 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
476 case 2:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
477 if (j < len)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
478 k = ((buf[j] & 15) << 2) | ((buf[j + 1] & 192) >> 6);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
479 else
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
480 k = (buf[j] & 15) << 2;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
481
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
482 j++;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
483 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
484 case 3:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
485 k = buf[j++] & 63;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
486 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
487 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
488 *out++ = gg_base64_charset[k];
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
489 i++;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
490 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
491
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
492 if (i % 4)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
493 for (j = 0; j < 4 - (i % 4); j++, out++)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
494 *out = '=';
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
495
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
496 *out = 0;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
497
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
498 return res;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
499 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
500
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
501 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
502 * \internal Dekoduje ciąg znaków zapisany w base64.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
503 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
504 * Wynik funkcji należy zwolnić za pomocą \c free.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
505 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
506 * \param buf Bufor źródłowy z danymi do zdekodowania
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
507 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
508 * \return Zaalokowany bufor ze zdekodowanymi danymi
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
509 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
510 * \ingroup helper
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
511 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
512 char *gg_base64_decode(const char *buf)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
513 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
514 char *res, *save, *foo, val;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
515 const char *end;
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
516 unsigned int idx = 0;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
517
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
518 if (!buf)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
519 return NULL;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
520
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
521 save = res = calloc(1, (strlen(buf) / 4 + 1) * 3 + 2);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
522
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
523 if (!save)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
524 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
525
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
526 end = buf + strlen(buf);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
527
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
528 while (*buf && buf < end) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
529 if (*buf == '\r' || *buf == '\n') {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
530 buf++;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
531 continue;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
532 }
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
533 if (!(foo = memchr(gg_base64_charset, *buf, sizeof(gg_base64_charset))))
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
534 foo = gg_base64_charset;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
535 val = (int)(foo - gg_base64_charset);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
536 buf++;
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
537 switch (idx) {
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
538 case 0:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
539 *res |= val << 2;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
540 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
541 case 1:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
542 *res++ |= val >> 4;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
543 *res |= val << 4;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
544 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
545 case 2:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
546 *res++ |= val >> 2;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
547 *res |= val << 6;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
548 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
549 case 3:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
550 *res++ |= val;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
551 break;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
552 }
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
553 idx++;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
554 idx %= 4;
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
555 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
556 *res = 0;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
557
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
558 return save;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
559 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
560
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
561 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
562 * \internal Tworzy nagłówek autoryzacji serwera pośredniczącego.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
563 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
564 * Dane pobiera ze zmiennych globalnych \c gg_proxy_username i
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
565 * \c gg_proxy_password.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
566 *
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
567 * \return Zaalokowany bufor z tekstem lub NULL, jeśli serwer pośredniczący
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
568 * nie jest używany lub nie wymaga autoryzacji.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
569 */
31609
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
570 char *gg_proxy_auth(void)
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
571 {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
572 char *tmp, *enc, *out;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
573 unsigned int tmp_size;
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
574
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
575 if (!gg_proxy_enabled || !gg_proxy_username || !gg_proxy_password)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
576 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
577
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
578 if (!(tmp = malloc((tmp_size = strlen(gg_proxy_username) + strlen(gg_proxy_password) + 2))))
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
579 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
580
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
581 snprintf(tmp, tmp_size, "%s:%s", gg_proxy_username, gg_proxy_password);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
582
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
583 if (!(enc = gg_base64_encode(tmp))) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
584 free(tmp);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
585 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
586 }
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
587
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
588 free(tmp);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
589
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
590 if (!(out = malloc(strlen(enc) + 40))) {
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
591 free(enc);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
592 return NULL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
593 }
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
594
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
595 snprintf(out, strlen(enc) + 40, "Proxy-Authorization: Basic %s\r\n", enc);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
596
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
597 free(enc);
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
598
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
599 return out;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
600 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
601
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
602 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
603 * \internal Tablica pomocnicza do wyznaczania sumy kontrolnej.
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
604 */
31609
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
605 static const uint32_t gg_crc32_table[256] =
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
606 {
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
607 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
608 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
609 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
610 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
611 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
612 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
613 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
614 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
615 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
616 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
617 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
618 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
619 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
620 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
621 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
622 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
623 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
624 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
625 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
626 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
627 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
628 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
629 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
630 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
631 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
632 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
633 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
634 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
635 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
636 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
637 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
638 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
639 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
640 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
641 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
642 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
643 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
644 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
645 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
646 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
647 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
648 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
649 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
650 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
651 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
652 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
653 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
654 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
655 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
656 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
657 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
658 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
659 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
660 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
661 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
662 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
663 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
664 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
665 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
666 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
667 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
668 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
669 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
31609
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
670 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
671 };
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
672
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
673 /**
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
674 * Wyznacza sumę kontrolną CRC32.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
675 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
676 * \param crc Suma kontrola poprzedniego bloku danych lub 0 jeśli liczona
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
677 * jest suma kontrolna pierwszego bloku
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
678 * \param buf Bufor danych
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
679 * \param len Długość bufora danych
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
680 *
29751
438f88ecc11e Update our internal libgadu to 1.9.0-rc2. This does not yet build on Windows.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 29106
diff changeset
681 * \return Suma kontrolna.
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
682 */
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
683 uint32_t gg_crc32(uint32_t crc, const unsigned char *buf, int len)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
684 {
31609
d67fbc90b28a matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 31294
diff changeset
685 if (buf == NULL || len < 0)
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
686 return crc;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
687
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
688 crc ^= 0xffffffffL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
689
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
690 while (len--)
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
691 crc = (crc >> 8) ^ gg_crc32_table[(crc ^ *buf++) & 0xff];
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
692
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
693 return crc ^ 0xffffffffL;
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
694 }
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
695
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
696 /**
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
697 * \internal Parsuje identyfikator użytkownika.
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
698 *
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
699 * \param str Ciąg tekstowy, zawierający identyfikator
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
700 * \param len Długość identyfikatora
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
701 *
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
702 * \return Identyfikator, lub 0, jeżeli nie udało się odczytać
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
703 */
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
704 uin_t gg_str_to_uin(const char *str, int len)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
705 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
706 char buff[11];
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
707 char *endptr;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
708 uin_t uin;
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
709
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
710 if (len < 0)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
711 len = strlen(str);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
712 if (len > 10)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
713 return 0;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
714 memcpy(buff, str, len);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
715 buff[len] = '\0';
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
716
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
717 errno = 0;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
718 uin = strtoul(buff, &endptr, 10);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
719 if (errno == ERANGE || endptr[0] != '\0')
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
720 return 0;
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
721
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
722 return uin;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
723 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
724
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
725 /**
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
726 * Szuka informacji o konferencji o podanym identyfikatorze.
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
727 *
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
728 * \param sess Struktura sesji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
729 * \param id Identyfikator konferencji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
730 *
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
731 * \return Struktura z informacjami o konferencji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
732 */
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
733 gg_chat_list_t *gg_chat_find(struct gg_session *sess, uint64_t id)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
734 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
735 gg_chat_list_t *chat_list = sess->private_data->chat_list;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
736
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
737 while (chat_list != NULL) {
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
738 if (chat_list->id == id)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
739 return chat_list;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
740 chat_list = chat_list->next;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
741 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
742
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
743 return NULL;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
744 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
745
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
746 /**
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
747 * \internal Aktualizuje informacje o konferencji.
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
748 *
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
749 * \param sess Struktura sesji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
750 * \param id Identyfikator konferencji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
751 * \param version Wersja informacji o konferencji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
752 * \param participants Lista uczestników konferencji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
753 * \param participants_count Ilość uczestników konferencji
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
754 *
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
755 * \return Wartość równa 0, jeżeli zakończono powodzeniem
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
756 */
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
757 int gg_chat_update(struct gg_session *sess, uint64_t id, uint32_t version,
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
758 const uin_t *participants, unsigned int participants_count)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
759 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
760 gg_chat_list_t *chat;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
761 uin_t *participants_new;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
762
35627
fd11790cc4d6 Update internal libgadu to the current version from git
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35617
diff changeset
763 if (participants_count >= ~(unsigned int)0 / sizeof(uin_t))
35617
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
764 return -1;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
765
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
766 chat = gg_chat_find(sess, id);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
767
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
768 if (!chat) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
769 chat = malloc(sizeof(gg_chat_list_t));
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
770
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
771 if (!chat)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
772 return -1;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
773
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
774 memset(chat, 0, sizeof(gg_chat_list_t));
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
775 chat->id = id;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
776 chat->next = sess->private_data->chat_list;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
777 sess->private_data->chat_list = chat;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
778 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
779
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
780 participants_new = realloc(chat->participants,
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
781 sizeof(uin_t) * participants_count);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
782
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
783 if (participants_new == NULL)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
784 return -1;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
785
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
786 chat->version = version;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
787 chat->participants = participants_new;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
788 chat->participants_count = participants_count;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
789 memcpy(chat->participants, participants,
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
790 sizeof(uin_t) * participants_count);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
791
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
792 return 0;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
793 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
794
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
795 void gg_connection_failure(struct gg_session *gs, struct gg_event *ge,
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
796 enum gg_failure_t failure)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
797 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
798 gg_close(gs);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
799
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
800 if (ge != NULL) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
801 ge->type = GG_EVENT_CONN_FAILED;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
802 ge->event.failure = failure;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
803 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
804 gs->state = GG_STATE_IDLE;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
805 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
806
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
807 time_t gg_server_time(struct gg_session *gs)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
808 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
809 time_t now = time(NULL);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
810
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
811 if (gs == NULL || gs->private_data == NULL) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
812 gg_debug_session(gs, GG_DEBUG_ERROR, "time diff data is not "
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
813 "accessible\n");
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
814 return now;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
815 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
816
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
817 return now + gs->private_data->time_diff;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
818 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
819
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
820 void gg_strarr_free(char **strarr)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
821 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
822 char **it;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
823
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
824 if (strarr == NULL)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
825 return;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
826
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
827 for (it = strarr; *it != NULL; it++)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
828 free(*it);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
829 free(strarr);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
830 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
831
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
832 char ** gg_strarr_dup(char **strarr)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
833 {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
834 size_t i, len, size;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
835 char **it, **out;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
836
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
837 if (strarr == NULL)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
838 return NULL;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
839
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
840 len = 0;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
841 for (it = strarr; *it != NULL; it++)
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
842 len++;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
843
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
844 size = (len + 1) * sizeof(char*);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
845 out = malloc(size);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
846
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
847 if (out == NULL) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
848 gg_debug(GG_DEBUG_MISC | GG_DEBUG_ERROR, "// gg_strarr_dup() "
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
849 "not enough memory for the array\n");
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
850 return NULL;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
851 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
852 memset(out, 0, size);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
853
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
854 for (i = 0; i < len; i++) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
855 out[i] = strdup(strarr[i]);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
856 if (out[i] == NULL) {
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
857 gg_debug(GG_DEBUG_MISC | GG_DEBUG_ERROR,
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
858 "// gg_strarr_dup() "
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
859 "not enough memory for the array element\n");
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
860 gg_strarr_free(out);
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
861 return NULL;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
862 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
863 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
864
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
865 return out;
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
866 }
c9069e0e3c36 Update internal libgadu to 1.12.0-rc2
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33709
diff changeset
867
11360
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
868 /*
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
869 * Local variables:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
870 * c-indentation-style: k&r
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
871 * c-basic-offset: 8
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
872 * indent-tabs-mode: notnil
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
873 * End:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
874 *
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
875 * vim: shiftwidth=8:
b77fd5a8959a [gaim-migrate @ 13582]
Bartosz Oler <bartosz@pidgin.im>
parents:
diff changeset
876 */

mercurial