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.
11 #include "soup-misc.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: (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
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.
127 * Return value: a #GSource, which can be removed from @async_context
128 * with g_source_destroy().
133 soup_add_completion (GMainContext *async_context,
134 GSourceFunc function, gpointer data)
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);
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
152 * Adds a timeout as with g_timeout_add(), but using the given
155 * Return value: a #GSource, which can be removed from @async_context
156 * with g_source_destroy().
159 soup_add_timeout (GMainContext *async_context,
161 GSourceFunc function, gpointer data)
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);
177 const char soup_char_attributes[] = {
179 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
181 0x11, 0x19, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
183 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
185 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
187 0x09, 0x04, 0x09, 0x02, 0x04, 0x01, 0x04, 0x04,
189 0x0c, 0x0c, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x0a,
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193 0x00, 0x00, 0x0a, 0x0c, 0x09, 0x0a, 0x09, 0x0a,
195 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 0x00, 0x00, 0x00, 0x0a, 0x09, 0x0a, 0x01, 0x00,
203 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x00, 0x00, 0x00, 0x09, 0x01, 0x09, 0x00, 0x11,
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