Reapplying patch to disable attempts to use gtk-doc
[profile/ivi/libsoup2.4.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 <ctype.h>
9 #include <string.h>
10
11 #include "soup-misc.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 /**
117  * soup_add_completion: (skip)
118  * @async_context: (allow-none): the #GMainContext to dispatch the I/O
119  * watch in, or %NULL for the default context
120  * @function: the callback to invoke
121  * @data: user data to pass to @function
122  *
123  * Adds @function to be executed from inside @async_context with the
124  * default priority. Use this when you want to complete an action in
125  * @async_context's main loop, as soon as possible.
126  *
127  * Return value: a #GSource, which can be removed from @async_context
128  * with g_source_destroy().
129  *
130  * Since: 2.24
131  **/
132 GSource *
133 soup_add_completion (GMainContext *async_context,
134                      GSourceFunc function, gpointer data)
135 {
136         GSource *source = g_idle_source_new ();
137         g_source_set_priority (source, G_PRIORITY_DEFAULT);
138         g_source_set_callback (source, function, data, NULL);
139         g_source_attach (source, async_context);
140         g_source_unref (source);
141         return source;
142 }
143
144 /**
145  * soup_add_timeout: (skip)
146  * @async_context: (allow-none): the #GMainContext to dispatch the I/O
147  * watch in, or %NULL for the default context
148  * @interval: the timeout interval, in milliseconds
149  * @function: the callback to invoke at timeout time
150  * @data: user data to pass to @function
151  *
152  * Adds a timeout as with g_timeout_add(), but using the given
153  * @async_context.
154  *
155  * Return value: a #GSource, which can be removed from @async_context
156  * with g_source_destroy().
157  **/
158 GSource *
159 soup_add_timeout (GMainContext *async_context,
160                   guint interval,
161                   GSourceFunc function, gpointer data)
162 {
163         GSource *source = g_timeout_source_new (interval);
164         g_source_set_callback (source, function, data, NULL);
165         g_source_attach (source, async_context);
166         g_source_unref (source);
167         return source;
168 }
169
170 /* 00 URI_UNRESERVED
171  * 01 URI_PCT_ENCODED
172  * 02 URI_GEN_DELIMS
173  * 04 URI_SUB_DELIMS
174  * 08 HTTP_SEPARATOR
175  * 10 HTTP_CTL
176  */
177 const char soup_char_attributes[] = {
178         /* 0x00 - 0x07 */
179         0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
180         /* 0x08 - 0x0f */
181         0x11, 0x19, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
182         /* 0x10 - 0x17 */
183         0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
184         /* 0x18 - 0x1f */
185         0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
186         /*  !"#$%&' */
187         0x09, 0x04, 0x09, 0x02, 0x04, 0x01, 0x04, 0x04,
188         /* ()*+,-./ */
189         0x0c, 0x0c, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x0a,
190         /* 01234567 */
191         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192         /* 89:;<=>? */
193         0x00, 0x00, 0x0a, 0x0c, 0x09, 0x0a, 0x09, 0x0a,
194         /* @ABCDEFG */
195         0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196         /* HIJKLMNO */
197         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198         /* PQRSTUVW */
199         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200         /* XYZ[\]^_ */
201         0x00, 0x00, 0x00, 0x0a, 0x09, 0x0a, 0x01, 0x00,
202         /* `abcdefg */
203         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204         /* hijklmno */
205         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206         /* pqrstuvw */
207         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208         /* xyz{|}~  */
209         0x00, 0x00, 0x00, 0x09, 0x01, 0x09, 0x00, 0x11,
210         /* 0x80 - 0xFF */
211         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
212         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
213         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
214         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
215         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
216         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
217         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
218         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
219         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
220         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
221         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
222         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
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 };