1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * soup-misc.c: Miscellaneous functions
5 * Copyright (C) 2000-2003, Ximian, Inc.
10 #include "soup-misc.h"
11 #include "soup-misc-private.h"
15 * @short_description: Miscellaneous functions
19 const gboolean soup_ssl_supported = TRUE;
23 * @key: ASCII string to hash
25 * Hashes @key in a case-insensitive manner.
27 * Return value: the hash code.
30 soup_str_case_hash (gconstpointer key)
33 guint h = g_ascii_toupper(*p);
36 for (p += 1; *p != '\0'; p++)
37 h = (h << 5) - h + g_ascii_toupper(*p);
43 * soup_str_case_equal:
44 * @v1: an ASCII string
45 * @v2: another ASCII string
47 * Compares @v1 and @v2 in a case-insensitive manner
49 * Return value: %TRUE if they are equal (modulo case)
52 soup_str_case_equal (gconstpointer v1,
55 const char *string1 = v1;
56 const char *string2 = v2;
58 return g_ascii_strcasecmp (string1, string2) == 0;
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
70 * Adds an I/O watch as with g_io_add_watch(), but using the given
73 * Return value: a #GSource, which can be removed from @async_context
74 * with g_source_destroy().
77 soup_add_io_watch (GMainContext *async_context,
78 GIOChannel *chan, GIOCondition condition,
79 GIOFunc function, gpointer data)
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);
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
95 * Adds an idle event as with g_idle_add(), but using the given
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.
102 * Return value: a #GSource, which can be removed from @async_context
103 * with g_source_destroy().
106 soup_add_idle (GMainContext *async_context,
107 GSourceFunc function, gpointer data)
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);
117 soup_add_completion_reffed (GMainContext *async_context,
118 GSourceFunc function,
121 GSource *source = g_idle_source_new ();
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);
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
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.
140 * Return value: a #GSource, which can be removed from @async_context
141 * with g_source_destroy().
146 soup_add_completion (GMainContext *async_context,
147 GSourceFunc function, gpointer data)
151 source = soup_add_completion_reffed (async_context, function, data);
152 g_source_unref (source);
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
164 * Adds a timeout as with g_timeout_add(), but using the given
167 * Return value: a #GSource, which can be removed from @async_context
168 * with g_source_destroy().
171 soup_add_timeout (GMainContext *async_context,
173 GSourceFunc function, gpointer data)
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);
189 const char soup_char_attributes[] = {
191 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
193 0x11, 0x19, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
195 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
197 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
199 0x09, 0x04, 0x09, 0x02, 0x04, 0x01, 0x04, 0x04,
201 0x0c, 0x0c, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x0a,
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x0a, 0x0c, 0x09, 0x0a, 0x09, 0x0a,
207 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x0a, 0x09, 0x0a, 0x01, 0x00,
215 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x09, 0x01, 0x09, 0x00, 0x11,
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