Mon, 13 Jun 2011 19:22:24 +0000
No more warnings when receiving Gadu-Gadu system messages - fixes #13914
|
31826
0f6ab56fbf9d
Update libgadu to 0.11.0 plus local changes; thanks to Tomasz Wasilczyk.
Ethan Blanton <elb@pidgin.im>
parents:
31609
diff
changeset
|
1 | /* $Id: common.c 1101 2011-05-05 21:17:28Z wojtekka $ */ |
| 11360 | 2 | |
| 3 | /* | |
| 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 | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU Lesser General Public License Version | |
| 9 | * 2.1 as published by the Free Software Foundation. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU Lesser General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU Lesser General Public | |
| 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 | 19 | * USA. |
| 20 | */ | |
| 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 | */ |
|
29752
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
27 | #ifndef _WIN32 |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
28 | # include <sys/types.h> |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
29 | # include <sys/ioctl.h> |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
30 | # include <sys/socket.h> |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
31 | # include <netinet/in.h> |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
32 | # include <arpa/inet.h> |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
33 | # ifdef sun |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
34 | # include <sys/filio.h> |
|
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
35 | # endif |
| 11360 | 36 | #endif |
| 37 | ||
| 38 | #include <errno.h> | |
| 39 | #include <fcntl.h> | |
|
29752
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
40 | #ifndef _WIN32 |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
41 | # include <netdb.h> |
|
29752
5cb6314b2477
Partially fix libgadu build on Win32. Refs #10542. I'm still not sure how to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
29751
diff
changeset
|
42 | #endif |
| 11360 | 43 | #include <stdarg.h> |
| 44 | #include <stdio.h> | |
| 45 | #include <stdlib.h> | |
| 46 | #include <string.h> | |
| 47 | #include <unistd.h> | |
| 48 | ||
|
31826
0f6ab56fbf9d
Update libgadu to 0.11.0 plus local changes; thanks to Tomasz Wasilczyk.
Ethan Blanton <elb@pidgin.im>
parents:
31609
diff
changeset
|
49 | #include "libgadu.h" |
| 11360 | 50 | |
|
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
|
51 | /** |
|
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
|
52 | * \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
|
53 | * |
|
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
|
54 | * 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
|
55 | * systemowa jest zgodna ze standardem C99 czy wcześniejszymi. |
| 11360 | 56 | * |
|
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
|
57 | * \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
|
58 | * \param ap Lista argumentów (zgodna z \c printf) |
| 11360 | 59 | * |
|
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
|
60 | * \return Zaalokowany bufor lub NULL, jeśli zabrakło pamięci. |
| 11360 | 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 | * \ingroup helper |
| 11360 | 63 | */ |
| 64 | char *gg_vsaprintf(const char *format, va_list ap) | |
| 65 | { | |
| 66 | int size = 0; | |
| 67 | char *buf = 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
|
68 | |
|
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
|
69 | #ifdef GG_CONFIG_HAVE_VA_COPY |
| 11360 | 70 | va_list aq; |
| 71 | ||
| 72 | va_copy(aq, ap); | |
| 73 | #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
|
74 | # ifdef GG_CONFIG_HAVE___VA_COPY |
| 11360 | 75 | va_list aq; |
| 76 | ||
| 77 | __va_copy(aq, ap); | |
| 78 | # endif | |
| 79 | #endif | |
| 80 | ||
|
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
|
81 | #ifndef GG_CONFIG_HAVE_C99_VSNPRINTF |
| 11360 | 82 | { |
| 83 | int res; | |
| 84 | 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
|
85 | |
| 11360 | 86 | size = 128; |
| 87 | do { | |
| 88 | size *= 2; | |
| 89 | if (!(tmp = realloc(buf, size))) { | |
| 90 | free(buf); | |
| 91 | return NULL; | |
| 92 | } | |
| 93 | buf = tmp; | |
| 94 | res = vsnprintf(buf, size, format, ap); | |
| 95 | } while (res == size - 1 || res == -1); | |
| 96 | } | |
| 97 | #else | |
| 98 | { | |
| 99 | 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
|
100 | |
|
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
|
101 | /* 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
|
102 | * musimy podać coś istniejącego jako cel printf()owania. */ |
| 11360 | 103 | size = vsnprintf(tmp, sizeof(tmp), format, ap); |
| 104 | if (!(buf = malloc(size + 1))) | |
| 105 | return NULL; | |
| 106 | } | |
| 107 | #endif | |
| 108 | ||
|
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
|
109 | #ifdef GG_CONFIG_HAVE_VA_COPY |
| 11360 | 110 | vsnprintf(buf, size + 1, format, aq); |
| 111 | va_end(aq); | |
| 112 | #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
|
113 | # ifdef GG_CONFIG_HAVE___VA_COPY |
| 11360 | 114 | vsnprintf(buf, size + 1, format, aq); |
| 115 | va_end(aq); | |
| 116 | # else | |
| 117 | vsnprintf(buf, size + 1, format, ap); | |
| 118 | # endif | |
| 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 | 121 | return buf; |
| 122 | } | |
| 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 | 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 | 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 | 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 | 135 | */ |
| 136 | char *gg_saprintf(const char *format, ...) | |
| 137 | { | |
| 138 | va_list ap; | |
| 139 | char *res; | |
| 140 | ||
| 141 | va_start(ap, format); | |
| 142 | res = gg_vsaprintf(format, ap); | |
| 143 | va_end(ap); | |
| 144 | ||
| 145 | return res; | |
| 146 | } | |
| 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 | * |
|
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
|
157 | * \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
|
158 | * bufora. |
| 11360 | 159 | */ |
| 160 | char *gg_get_line(char **ptr) | |
| 161 | { | |
| 162 | char *foo, *res; | |
| 163 | ||
| 164 | if (!ptr || !*ptr || !strcmp(*ptr, "")) | |
| 165 | return NULL; | |
| 166 | ||
| 167 | res = *ptr; | |
| 168 | ||
| 169 | if (!(foo = strchr(*ptr, '\n'))) | |
| 170 | *ptr += strlen(*ptr); | |
| 171 | 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
|
172 | size_t len; |
| 11360 | 173 | *ptr = foo + 1; |
| 174 | *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
|
175 | |
|
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
|
176 | 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
|
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 | 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
|
179 | res[len - 1] = 0; |
| 11360 | 180 | } |
| 181 | ||
| 182 | return res; | |
| 183 | } | |
| 184 | ||
|
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
|
185 | /** |
|
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
|
186 | * \internal Czyta linię tekstu z gniazda. |
| 11360 | 187 | * |
|
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
|
188 | * 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
|
189 | * brakowi buforowania, nie koliduje z innymi funkcjami odczytu. |
| 11360 | 190 | * |
|
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
|
191 | * \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
|
192 | * \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
|
193 | * \param length Długość bufora |
| 11360 | 194 | * |
|
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
|
195 | * \return Zwraca \c buf jeśli się powiodło, lub \c NULL w przypadku błędu. |
| 11360 | 196 | */ |
| 197 | char *gg_read_line(int sock, char *buf, int length) | |
| 198 | { | |
| 199 | int ret; | |
| 200 | ||
| 201 | if (!buf || length < 0) | |
| 202 | return NULL; | |
| 203 | ||
| 204 | for (; length > 1; buf++, length--) { | |
| 205 | do { | |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
206 | if ((ret = read(sock, buf, 1)) == -1 && errno != EINTR && errno != EAGAIN) { |
| 11360 | 207 | gg_debug(GG_DEBUG_MISC, "// gg_read_line() error on read (errno=%d, %s)\n", errno, strerror(errno)); |
| 208 | *buf = 0; | |
| 209 | return NULL; | |
| 210 | } else if (ret == 0) { | |
| 211 | gg_debug(GG_DEBUG_MISC, "// gg_read_line() eof reached\n"); | |
| 212 | *buf = 0; | |
| 213 | return NULL; | |
| 214 | } | |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
215 | } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); |
| 11360 | 216 | |
| 217 | if (*buf == '\n') { | |
| 218 | buf++; | |
| 219 | break; | |
| 220 | } | |
| 221 | } | |
| 222 | ||
| 223 | *buf = 0; | |
| 224 | return buf; | |
| 225 | } | |
| 226 | ||
|
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
|
227 | /** |
|
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
|
228 | * \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
|
229 | * |
|
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
|
230 | * \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
|
231 | * \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
|
232 | * \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
|
233 | * |
|
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
|
234 | * \return Deskryptor gniazda lub -1 w przypadku błędu |
| 11360 | 235 | * |
|
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
|
236 | * \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
|
237 | */ |
|
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 | 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
|
239 | { |
|
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 | int sock, one = 1, 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
|
241 | 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
|
242 | 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
|
243 | 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
|
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 | 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
|
246 | |
|
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 | 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
|
248 | 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
|
249 | 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
|
250 | } |
|
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
|
251 | |
|
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 | 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
|
253 | 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
|
254 | |
|
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 | 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
|
256 | |
|
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 | 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
|
258 | 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
|
259 | 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
|
260 | 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
|
261 | 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
|
262 | 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
|
263 | } |
|
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 | |
|
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 | if (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
|
266 | #ifdef FIONBIO |
|
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 | if (ioctl(sock, FIONBIO, &one) == -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
|
268 | #else |
|
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 | if (fcntl(sock, F_SETFL, O_NONBLOCK) == -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
|
270 | #endif |
|
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 | gg_debug(GG_DEBUG_MISC, "// gg_connect() ioctl() 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
|
272 | 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
|
273 | 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
|
274 | 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
|
275 | 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
|
276 | } |
|
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
|
277 | } |
|
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
|
278 | |
|
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
|
279 | 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
|
280 | 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
|
281 | 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
|
282 | |
|
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 | 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
|
284 | if (errno && (!async || errno != EINPROGRESS)) { |
|
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 | gg_debug(GG_DEBUG_MISC, "// gg_connect() connect() 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
|
286 | 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
|
287 | 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
|
288 | 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
|
289 | 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
|
290 | } |
|
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 | 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
|
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 | |
|
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 | 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
|
295 | } |
|
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
|
296 | |
|
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
|
297 | /** |
|
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 | * \internal Usuwa znaki końca linii. |
| 11360 | 299 | * |
|
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
|
300 | * 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
|
301 | * |
|
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 | * \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
|
303 | * |
|
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 | * \ingroup helper |
| 11360 | 305 | */ |
| 306 | void gg_chomp(char *line) | |
| 307 | { | |
| 308 | 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
|
309 | |
| 11360 | 310 | if (!line) |
| 311 | return; | |
| 312 | ||
| 313 | 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
|
314 | |
| 11360 | 315 | if (len > 0 && line[len - 1] == '\n') |
| 316 | line[--len] = 0; | |
| 317 | if (len > 0 && line[len - 1] == '\r') | |
| 318 | line[--len] = 0; | |
| 319 | } | |
| 320 | ||
|
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 | /** |
|
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
|
322 | * \internal Koduje ciąg znaków do postacji adresu HTTP. |
| 11360 | 323 | * |
|
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
|
324 | * 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
|
325 | * 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
|
326 | * wartością znaku. |
|
31826
0f6ab56fbf9d
Update libgadu to 0.11.0 plus local changes; thanks to Tomasz Wasilczyk.
Ethan Blanton <elb@pidgin.im>
parents:
31609
diff
changeset
|
327 | * |
|
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
|
328 | * \param str Ciąg znaków do zakodowania |
| 11360 | 329 | * |
|
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
|
330 | * \return Zaalokowany bufor lub \c NULL w przypadku błędu. |
| 11360 | 331 | * |
|
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
|
332 | * \ingroup helper |
| 11360 | 333 | */ |
| 334 | char *gg_urlencode(const char *str) | |
| 335 | { | |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
336 | 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
|
337 | const char hex[] = "0123456789abcdef"; |
| 11360 | 338 | const char *p; |
| 339 | unsigned int size = 0; | |
| 340 | ||
| 341 | if (!str) | |
| 342 | str = ""; | |
| 343 | ||
| 344 | for (p = str; *p; p++, size++) { | |
| 345 | if (!((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == ' ') || (*p == '@') || (*p == '.') || (*p == '-')) | |
| 346 | size += 2; | |
| 347 | } | |
| 348 | ||
| 349 | if (!(buf = malloc(size + 1))) | |
| 350 | return NULL; | |
| 351 | ||
| 352 | for (p = str, q = buf; *p; p++, q++) { | |
| 353 | if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || (*p == '@') || (*p == '.') || (*p == '-')) | |
| 354 | *q = *p; | |
| 355 | else { | |
| 356 | if (*p == ' ') | |
| 357 | *q = '+'; | |
| 358 | else { | |
| 359 | *q++ = '%'; | |
| 360 | *q++ = hex[*p >> 4 & 15]; | |
| 361 | *q = hex[*p & 15]; | |
| 362 | } | |
| 363 | } | |
| 364 | } | |
| 365 | ||
| 366 | *q = 0; | |
| 367 | ||
| 368 | return buf; | |
| 369 | } | |
| 370 | ||
|
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
|
371 | /** |
|
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
|
372 | * \internal Wyznacza skrót dla usług HTTP. |
| 11360 | 373 | * |
|
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
|
374 | * 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
|
375 | * i innych wartości przekazywanych jako parametry usług HTTP. |
| 11360 | 376 | * |
|
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
|
377 | * 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
|
378 | * 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
|
379 | * liczbą. |
| 11360 | 380 | * |
|
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
|
381 | * \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
|
382 | * |
|
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
|
383 | * \return Wartość skrótu |
| 11360 | 384 | */ |
| 385 | int gg_http_hash(const char *format, ...) | |
| 386 | { | |
| 387 | unsigned int a, c, i, j; | |
| 388 | va_list ap; | |
| 389 | int b = -1; | |
| 390 | ||
| 391 | va_start(ap, format); | |
| 392 | ||
| 393 | for (j = 0; j < strlen(format); j++) { | |
| 394 | char *arg, buf[16]; | |
| 395 | ||
| 396 | if (format[j] == 'u') { | |
| 397 | snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t)); | |
| 398 | arg = buf; | |
| 399 | } else { | |
| 400 | if (!(arg = va_arg(ap, char*))) | |
| 401 | 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
|
402 | } |
| 11360 | 403 | |
| 404 | i = 0; | |
| 405 | while ((c = (unsigned char) arg[i++]) != 0) { | |
| 406 | a = (c ^ b) + (c << 8); | |
| 407 | b = (a >> 24) | (a << 8); | |
| 408 | } | |
| 409 | } | |
| 410 | ||
| 411 | va_end(ap); | |
| 412 | ||
| 413 | return (b < 0 ? -b : b); | |
| 414 | } | |
| 415 | ||
|
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
|
416 | /** |
|
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
|
417 | * \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
|
418 | */ |
| 11360 | 419 | static char gg_base64_charset[] = |
| 420 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | |
| 421 | ||
|
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 | /** |
|
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
|
423 | * \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
|
424 | * |
|
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
|
425 | * Wynik funkcji należy zwolnić za pomocą \c free. |
| 11360 | 426 | * |
|
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
|
427 | * \param buf Bufor z danami do zakodowania |
| 11360 | 428 | * |
|
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
|
429 | * \return Zaalokowany bufor z zakodowanymi danymi |
| 11360 | 430 | * |
|
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
|
431 | * \ingroup helper |
| 11360 | 432 | */ |
| 433 | char *gg_base64_encode(const char *buf) | |
| 434 | { | |
| 435 | char *out, *res; | |
| 436 | 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
|
437 | |
| 11360 | 438 | res = out = malloc((len / 3 + 1) * 4 + 2); |
| 439 | ||
| 440 | if (!res) | |
| 441 | 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
|
442 | |
| 11360 | 443 | while (j <= len) { |
| 444 | switch (i % 4) { | |
| 445 | case 0: | |
| 446 | k = (buf[j] & 252) >> 2; | |
| 447 | break; | |
| 448 | case 1: | |
| 449 | if (j < len) | |
| 450 | k = ((buf[j] & 3) << 4) | ((buf[j + 1] & 240) >> 4); | |
| 451 | else | |
| 452 | k = (buf[j] & 3) << 4; | |
| 453 | ||
| 454 | j++; | |
| 455 | break; | |
| 456 | case 2: | |
| 457 | if (j < len) | |
| 458 | k = ((buf[j] & 15) << 2) | ((buf[j + 1] & 192) >> 6); | |
| 459 | else | |
| 460 | k = (buf[j] & 15) << 2; | |
| 461 | ||
| 462 | j++; | |
| 463 | break; | |
| 464 | case 3: | |
| 465 | k = buf[j++] & 63; | |
| 466 | break; | |
| 467 | } | |
| 468 | *out++ = gg_base64_charset[k]; | |
| 469 | i++; | |
| 470 | } | |
| 471 | ||
| 472 | if (i % 4) | |
| 473 | for (j = 0; j < 4 - (i % 4); j++, out++) | |
| 474 | *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
|
475 | |
| 11360 | 476 | *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
|
477 | |
| 11360 | 478 | return res; |
| 479 | } | |
| 480 | ||
|
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
|
481 | /** |
|
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
|
482 | * \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
|
483 | * |
|
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
|
484 | * Wynik funkcji należy zwolnić za pomocą \c free. |
| 11360 | 485 | * |
|
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
|
486 | * \param buf Bufor źródłowy z danymi do zdekodowania |
| 11360 | 487 | * |
|
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
|
488 | * \return Zaalokowany bufor ze zdekodowanymi danymi |
| 11360 | 489 | * |
|
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
|
490 | * \ingroup helper |
| 11360 | 491 | */ |
| 492 | char *gg_base64_decode(const char *buf) | |
| 493 | { | |
| 494 | char *res, *save, *foo, val; | |
| 495 | const char *end; | |
| 496 | unsigned int index = 0; | |
| 497 | ||
| 498 | if (!buf) | |
| 499 | 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
|
500 | |
| 11360 | 501 | save = res = calloc(1, (strlen(buf) / 4 + 1) * 3 + 2); |
| 502 | ||
| 503 | if (!save) | |
| 504 | return NULL; | |
| 505 | ||
| 506 | end = buf + strlen(buf); | |
| 507 | ||
| 508 | while (*buf && buf < end) { | |
| 509 | if (*buf == '\r' || *buf == '\n') { | |
| 510 | buf++; | |
| 511 | continue; | |
| 512 | } | |
| 513 | if (!(foo = strchr(gg_base64_charset, *buf))) | |
| 514 | foo = gg_base64_charset; | |
| 515 | val = (int)(foo - gg_base64_charset); | |
| 516 | buf++; | |
| 517 | switch (index) { | |
| 518 | case 0: | |
| 519 | *res |= val << 2; | |
| 520 | break; | |
| 521 | case 1: | |
| 522 | *res++ |= val >> 4; | |
| 523 | *res |= val << 4; | |
| 524 | break; | |
| 525 | case 2: | |
| 526 | *res++ |= val >> 2; | |
| 527 | *res |= val << 6; | |
| 528 | break; | |
| 529 | case 3: | |
| 530 | *res++ |= val; | |
| 531 | break; | |
| 532 | } | |
| 533 | index++; | |
| 534 | index %= 4; | |
| 535 | } | |
| 536 | *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
|
537 | |
| 11360 | 538 | return save; |
| 539 | } | |
| 540 | ||
|
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
|
541 | /** |
|
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
|
542 | * \internal Tworzy nagłówek autoryzacji serwera pośredniczącego. |
| 11360 | 543 | * |
|
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
|
544 | * 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
|
545 | * \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
|
546 | * |
|
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
|
547 | * \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
|
548 | * nie jest używany lub nie wymaga autoryzacji. |
| 11360 | 549 | */ |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
550 | char *gg_proxy_auth(void) |
| 11360 | 551 | { |
| 552 | char *tmp, *enc, *out; | |
| 553 | 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
|
554 | |
| 11360 | 555 | if (!gg_proxy_enabled || !gg_proxy_username || !gg_proxy_password) |
| 556 | return NULL; | |
| 557 | ||
| 558 | if (!(tmp = malloc((tmp_size = strlen(gg_proxy_username) + strlen(gg_proxy_password) + 2)))) | |
| 559 | return NULL; | |
| 560 | ||
| 561 | snprintf(tmp, tmp_size, "%s:%s", gg_proxy_username, gg_proxy_password); | |
| 562 | ||
| 563 | if (!(enc = gg_base64_encode(tmp))) { | |
| 564 | free(tmp); | |
| 565 | return NULL; | |
| 566 | } | |
|
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
|
567 | |
| 11360 | 568 | free(tmp); |
| 569 | ||
| 570 | if (!(out = malloc(strlen(enc) + 40))) { | |
| 571 | free(enc); | |
| 572 | return NULL; | |
| 573 | } | |
|
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 | 575 | snprintf(out, strlen(enc) + 40, "Proxy-Authorization: Basic %s\r\n", enc); |
| 576 | ||
| 577 | free(enc); | |
| 578 | ||
| 579 | return out; | |
| 580 | } | |
| 581 | ||
|
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
|
582 | /** |
|
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
|
583 | * \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
|
584 | */ |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
585 | static const uint32_t gg_crc32_table[256] = |
| 11360 | 586 | { |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
587 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
588 | 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
589 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
590 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
591 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
592 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
593 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
594 | 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
595 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
596 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
597 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
598 | 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
599 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
600 | 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
601 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
602 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
603 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
604 | 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
605 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
606 | 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
607 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
608 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
609 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
610 | 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
611 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
612 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
613 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
614 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
615 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
616 | 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
617 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
618 | 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
619 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
620 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
621 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
622 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
623 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
624 | 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
625 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
626 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
627 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
628 | 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
629 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
630 | 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
631 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
632 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
633 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
634 | 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
635 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
636 | 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
637 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
638 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
639 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
640 | 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
641 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
642 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
643 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
644 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
645 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
646 | 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
647 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
648 | 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
649 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
|
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
650 | 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
|
651 | }; |
| 11360 | 652 | |
|
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
|
653 | /** |
|
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
|
654 | * Wyznacza sumę kontrolną CRC32. |
| 11360 | 655 | * |
|
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
|
656 | * \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
|
657 | * 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
|
658 | * \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
|
659 | * \param len Długość bufora danych |
| 11360 | 660 | * |
|
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
|
661 | * \return Suma kontrolna. |
| 11360 | 662 | */ |
| 663 | uint32_t gg_crc32(uint32_t crc, const unsigned char *buf, int len) | |
| 664 | { | |
|
31609
d67fbc90b28a
matekm and kkszysiu collaborated on this patch to update our internal libgadu
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
31294
diff
changeset
|
665 | if (buf == NULL || len < 0) |
| 11360 | 666 | return crc; |
| 667 | ||
| 668 | crc ^= 0xffffffffL; | |
| 669 | ||
| 670 | while (len--) | |
| 671 | crc = (crc >> 8) ^ gg_crc32_table[(crc ^ *buf++) & 0xff]; | |
| 672 | ||
| 673 | return crc ^ 0xffffffffL; | |
| 674 | } | |
| 675 | ||
| 676 | /* | |
| 677 | * Local variables: | |
| 678 | * c-indentation-style: k&r | |
| 679 | * c-basic-offset: 8 | |
| 680 | * indent-tabs-mode: notnil | |
| 681 | * End: | |
| 682 | * | |
| 683 | * vim: shiftwidth=8: | |
| 684 | */ |