annotate src/protocols/gg/common.c @ 3131:bb7527b5f426

[gaim-migrate @ 3146] I molested GtkTree. committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Thu, 11 Apr 2002 22:40:44 +0000
parents 4b3f17ca66bf
children 7a3f16a375a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2846
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /* $Id: common.c 2859 2001-12-05 09:48:56Z warmenhoven $ */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl>,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 * Robert J. Woźny <speedy@ziew.org>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * it under the terms of the GNU General Public License Version 2 as
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * published by the Free Software Foundation.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * GNU General Public License for more details.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 #include <stdio.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 #include <stdlib.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 #include <unistd.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 #include <stdio.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #include <sys/socket.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 #include <netinet/in.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #include <arpa/inet.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 #include <sys/ioctl.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 #include <sys/wait.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <sys/time.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 #include <netdb.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 #include <errno.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 #ifndef _AIX
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 # include <string.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 #endif
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #include <stdarg.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 #include <pwd.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #include <time.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 #ifdef sun
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 #include <sys/filio.h>
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 #endif
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 #include "libgg.h"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 #include "config.h"
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 * gg_debug()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 * wyrzuca komunikat o danym poziomie, o ile użytkownik sobie tego życzy.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 * - level - poziom wiadomości,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 * - format... - treść wiadomości (printf-alike.)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 * niczego nie zwraca.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 void gg_debug(int level, char *format, ...)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 va_list ap;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 if ((gg_debug_level & level)) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 va_start(ap, format);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 vprintf(format, ap);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 va_end(ap);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 * gg_alloc_sprintf()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 * robi dokładnie to samo, co sprintf(), tyle że alokuje sobie wcześniej
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 * miejsce na dane. powinno działać na tych maszynach, które mają funkcję
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 * vsnprintf() zgodną z C99, jak i na wcześniejszych.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 * - format, ... - parametry takie same jak w innych funkcjach *printf()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 * zwraca zaalokowany buforek, który wypadałoby później zwolnić, lub NULL
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 * jeśli nie udało się wykonać zadania.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 char *gg_alloc_sprintf(char *format, ...)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 va_list ap;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 char *buf = NULL, *tmp;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 int size = 0, res;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 va_start(ap, format);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 if ((size = vsnprintf(buf, 0, format, ap)) < 1) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 size = 128;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 do {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 size *= 2;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 if (!(tmp = realloc(buf, size))) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 free(buf);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 return NULL;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 buf = tmp;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 res = vsnprintf(buf, size, format, ap);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 } while (res == size - 1);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 } else {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 if (!(buf = malloc(size + 1)))
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 return NULL;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 vsnprintf(buf, size + 1, format, ap);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 va_end(ap);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 return buf;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 * gg_get_line()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 * podaje kolejną linię z bufora tekstowego. psuje co bezpowrotnie, dzieląc
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 * na kolejne stringi. zdarza się, nie ma potrzeby pisania funkcji dublującej
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 * bufor żeby tylko mieć nieruszone dane wejściowe, skoro i tak nie będą nam
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 * poźniej potrzebne. obcina `\r\n'.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 * - ptr - wskaźnik do zmiennej, która przechowuje aktualną pozycję
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 * w przemiatanym buforze.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 * wskaźnik do kolejnej linii tekstu lub NULL, jeśli to już koniec bufora.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 char *gg_get_line(char **ptr)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 char *foo, *res;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 if (!ptr || !*ptr || !strcmp(*ptr, ""))
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 return NULL;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 res = *ptr;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 if (!(foo = strchr(*ptr, '\n')))
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 *ptr += strlen(*ptr);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 else {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 *ptr = foo + 1;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 *foo = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 if (res[strlen(res) - 1] == '\r')
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 res[strlen(res) - 1] = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 return res;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 * gg_connect()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 * łączy się z serwerem. pierwszy argument jest typu (void *), żeby nie
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 * musieć niczego inkludować w libgg.h i nie psuć jakiś głupich zależności
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 * na dziwnych systemach.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 * - addr - adres serwera (struct in_addr *),
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 * - port - port serwera,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 * - async - ma być asynchroniczne połączenie?
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 * zwraca połączonego socketa lub -1 w przypadku błędu. zobacz errno.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 int gg_connect(void *addr, int port, int async)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 int sock, one = 1;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 struct sockaddr_in sin;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 struct in_addr *a = addr;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 gg_debug(GG_DEBUG_FUNCTION, "** gg_connect(%s, %d, %d);\n", inet_ntoa(*a), port, async);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 gg_debug(GG_DEBUG_MISC, "-- socket() failed. errno = %d (%s)\n", errno, strerror(errno));
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 return -1;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 if (async) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 if (ioctl(sock, FIONBIO, &one) == -1) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 gg_debug(GG_DEBUG_MISC, "-- ioctl() failed. errno = %d (%s)\n", errno, strerror(errno));
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172 return -1;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 sin.sin_port = htons(port);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 sin.sin_family = AF_INET;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 sin.sin_addr.s_addr = a->s_addr;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 if (connect(sock, (struct sockaddr*) &sin, sizeof(sin)) == -1) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 if (errno && (!async || errno != EINPROGRESS)) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 gg_debug(GG_DEBUG_MISC, "-- connect() failed. errno = %d (%s)\n", errno, strerror(errno));
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 return -1;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 gg_debug(GG_DEBUG_MISC, "-- connect() in progress\n");
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 return sock;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 * gg_read_line()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 * czyta jedną linię tekstu z socketa.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 * - sock - socket,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 * - buf - wskaźnik bufora,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 * - length - długość bufora.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 * olewa błędy. jeśli na jakiś trafi, potraktuje go jako koniec linii.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 void gg_read_line(int sock, char *buf, int length)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 int ret;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 gg_debug(GG_DEBUG_FUNCTION, "** gg_read_line(...);\n");
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 for (; length > 1; buf++, length--) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 do {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 if ((ret = read(sock, buf, 1)) == -1 && errno != EINTR) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 *buf = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 return;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 } while (ret == -1 && errno == EINTR);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 if (*buf == '\n') {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 buf++;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 break;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222 *buf = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 return;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 * gg_chomp()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 * ucina "\r\n" lub "\n" z końca linii.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 * - line - ofiara operacji plastycznej.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233 * niczego nie zwraca.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 void gg_chomp(char *line)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 if (!line || strlen(line) < 1)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 return;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 if (line[strlen(line) - 1] == '\n')
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 line[strlen(line) - 1] = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 if (line[strlen(line) - 1] == '\r')
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 line[strlen(line) - 1] = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248 * gg_urlencode() // funkcja wewnętrzna
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 * zamienia podany tekst na ciąg znaków do formularza http. przydaje się
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251 * przy szukaniu userów z dziwnymi znaczkami.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
253 * - str - ciąg znaków do poprawki.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 * zwraca zaalokowany bufor, który wypadałoby kiedyś zwolnić albo NULL
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 * w przypadku błędu.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 char *gg_urlencode(char *str)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260 char *p, *q, *buf, hex[] = "0123456789abcdef";
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 int size = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 if (!str)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264 str = strdup("");
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266 for (p = str; *p; p++, size++) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267 if (!((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9')))
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268 size += 2;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
270
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
271 if (!(buf = malloc(size + 1)))
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272 return NULL;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 for (p = str, q = buf; *p; p++, q++) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275 if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9'))
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276 *q = *p;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 else {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 *q++ = '%';
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 *q++ = hex[*p >> 4 & 15];
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280 *q = hex[*p & 15];
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 *q = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
285
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 return buf;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
288
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
289 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 * gg_http_hash()
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292 * funkcja, która liczy hash dla adresu e-mail i hasła.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
293 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294 * - email - adres email,
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
295 * - password - hasło.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297 * zwraca hash wykorzystywany przy rejestracji i wszelkich
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 * manipulacjach własnego wpisu w katalogu publicznym.
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 */
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 int gg_http_hash(unsigned char *email, unsigned char *password)
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 unsigned int a, c;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 int b, i;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 b = (-1);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 i = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308 while ((c = (int) email[i++]) != 0) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 a = (c ^ b) + (c << 8);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 b = (a >> 24) | (a << 8);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 i = 0;
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 while ((c = (int) password[i++]) != 0) {
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315 a = (c ^ b) + (c << 8);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 b = (a >> 24) | (a << 8);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319 return (b < 0 ? -b : b);
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320 }
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322 /*
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323 * Local variables:
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324 * c-indentation-style: k&r
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325 * c-basic-offset: 8
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
326 * indent-tabs-mode: notnil
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 * End:
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 *
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329 * vim: shiftwidth=8:
4b3f17ca66bf [gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330 */