Remove build warning
[platform/upstream/libsoup.git] / libsoup / soup-misc.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * soup-misc.c: Miscellaneous functions
4
5  * Copyright (C) 2000-2003, Ximian, Inc.
6  */
7
8 #include <string.h>
9
10 #include "soup-misc.h"
11 #include "soup-misc-private.h"
12
13 /**
14  * SECTION:soup-misc
15  * @short_description: Miscellaneous functions
16  *
17  **/
18
19 const gboolean soup_ssl_supported = TRUE;
20
21 /**
22  * soup_str_case_hash:
23  * @key: ASCII string to hash
24  *
25  * Hashes @key in a case-insensitive manner.
26  *
27  * Return value: the hash code.
28  **/
29 guint
30 soup_str_case_hash (gconstpointer key)
31 {
32         const char *p = key;
33         guint h = g_ascii_toupper(*p);
34
35         if (h)
36                 for (p += 1; *p != '\0'; p++)
37                         h = (h << 5) - h + g_ascii_toupper(*p);
38
39         return h;
40 }
41
42 /**
43  * soup_str_case_equal:
44  * @v1: an ASCII string
45  * @v2: another ASCII string
46  *
47  * Compares @v1 and @v2 in a case-insensitive manner
48  *
49  * Return value: %TRUE if they are equal (modulo case)
50  **/
51 gboolean
52 soup_str_case_equal (gconstpointer v1,
53                      gconstpointer v2)
54 {
55         const char *string1 = v1;
56         const char *string2 = v2;
57
58         return g_ascii_strcasecmp (string1, string2) == 0;
59 }
60
61 /**
62  * soup_add_io_watch: (skip)
63  * @async_context: (allow-none): the #GMainContext to dispatch the I/O
64  * watch in, or %NULL for the default context
65  * @chan: the #GIOChannel to watch
66  * @condition: the condition to watch for
67  * @function: the callback to invoke when @condition occurs
68  * @data: user data to pass to @function
69  *
70  * Adds an I/O watch as with g_io_add_watch(), but using the given
71  * @async_context.
72  *
73  * Return value: a #GSource, which can be removed from @async_context
74  * with g_source_destroy().
75  **/
76 GSource *
77 soup_add_io_watch (GMainContext *async_context,
78                    GIOChannel *chan, GIOCondition condition,
79                    GIOFunc function, gpointer data)
80 {
81         GSource *watch = g_io_create_watch (chan, condition);
82         g_source_set_callback (watch, (GSourceFunc) function, data, NULL);
83         g_source_attach (watch, async_context);
84         g_source_unref (watch);
85         return watch;
86 }
87
88 /**
89  * soup_add_idle: (skip)
90  * @async_context: (allow-none): the #GMainContext to dispatch the I/O
91  * watch in, or %NULL for the default context
92  * @function: the callback to invoke at idle time
93  * @data: user data to pass to @function
94  *
95  * Adds an idle event as with g_idle_add(), but using the given
96  * @async_context.
97  *
98  * If you want @function to run "right away", use
99  * soup_add_completion(), since that sets a higher priority on the
100  * #GSource than soup_add_idle() does.
101  *
102  * Return value: a #GSource, which can be removed from @async_context
103  * with g_source_destroy().
104  **/
105 GSource *
106 soup_add_idle (GMainContext *async_context,
107                GSourceFunc function, gpointer data)
108 {
109         GSource *source = g_idle_source_new ();
110         g_source_set_callback (source, function, data, NULL);
111         g_source_attach (source, async_context);
112         g_source_unref (source);
113         return source;
114 }
115
116 GSource *
117 soup_add_completion_reffed (GMainContext *async_context,
118                             GSourceFunc   function,
119                             gpointer      data)
120 {
121         GSource *source = g_idle_source_new ();
122
123         g_source_set_priority (source, G_PRIORITY_DEFAULT);
124         g_source_set_callback (source, function, data, NULL);
125         g_source_attach (source, async_context);
126         return source;
127 }
128
129 /**
130  * soup_add_completion: (skip)
131  * @async_context: (allow-none): the #GMainContext to dispatch the I/O
132  * watch in, or %NULL for the default context
133  * @function: the callback to invoke
134  * @data: user data to pass to @function
135  *
136  * Adds @function to be executed from inside @async_context with the
137  * default priority. Use this when you want to complete an action in
138  * @async_context's main loop, as soon as possible.
139  *
140  * Return value: a #GSource, which can be removed from @async_context
141  * with g_source_destroy().
142  *
143  * Since: 2.24
144  **/
145 GSource *
146 soup_add_completion (GMainContext *async_context,
147                      GSourceFunc function, gpointer data)
148 {
149         GSource *source;
150
151         source = soup_add_completion_reffed (async_context, function, data);
152         g_source_unref (source);
153         return source;
154 }
155
156 /**
157  * soup_add_timeout: (skip)
158  * @async_context: (allow-none): the #GMainContext to dispatch the I/O
159  * watch in, or %NULL for the default context
160  * @interval: the timeout interval, in milliseconds
161  * @function: the callback to invoke at timeout time
162  * @data: user data to pass to @function
163  *
164  * Adds a timeout as with g_timeout_add(), but using the given
165  * @async_context.
166  *
167  * Return value: a #GSource, which can be removed from @async_context
168  * with g_source_destroy().
169  **/
170 GSource *
171 soup_add_timeout (GMainContext *async_context,
172                   guint interval,
173                   GSourceFunc function, gpointer data)
174 {
175         GSource *source = g_timeout_source_new (interval);
176         g_source_set_callback (source, function, data, NULL);
177         g_source_attach (source, async_context);
178         g_source_unref (source);
179         return source;
180 }
181
182 /* 00 URI_UNRESERVED
183  * 01 URI_PCT_ENCODED
184  * 02 URI_GEN_DELIMS
185  * 04 URI_SUB_DELIMS
186  * 08 HTTP_SEPARATOR
187  * 10 HTTP_CTL
188  */
189 const char soup_char_attributes[] = {
190         /* 0x00 - 0x07 */
191         0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
192         /* 0x08 - 0x0f */
193         0x11, 0x19, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
194         /* 0x10 - 0x17 */
195         0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
196         /* 0x18 - 0x1f */
197         0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
198         /*  !"#$%&' */
199         0x09, 0x04, 0x09, 0x02, 0x04, 0x01, 0x04, 0x04,
200         /* ()*+,-./ */
201         0x0c, 0x0c, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x0a,
202         /* 01234567 */
203         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204         /* 89:;<=>? */
205         0x00, 0x00, 0x0a, 0x0c, 0x09, 0x0a, 0x09, 0x0a,
206         /* @ABCDEFG */
207         0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208         /* HIJKLMNO */
209         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210         /* PQRSTUVW */
211         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212         /* XYZ[\]^_ */
213         0x00, 0x00, 0x00, 0x0a, 0x09, 0x0a, 0x01, 0x00,
214         /* `abcdefg */
215         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216         /* hijklmno */
217         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218         /* pqrstuvw */
219         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220         /* xyz{|}~  */
221         0x00, 0x00, 0x00, 0x09, 0x01, 0x09, 0x00, 0x11,
222         /* 0x80 - 0xFF */
223         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
224         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
225         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
226         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
227         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
228         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
229         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
230         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
231         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
232         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
233         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
234         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
235         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
236         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
237         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
238         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
239 };