/libsoup/soup-misc.c

https://github.com/ahmedammar/platform_external_gst_libsoup · C · 225 lines · 98 code · 13 blank · 114 comment · 4 complexity · 1e9444398026ba8acd45d8426eaef067 MD5 · raw file

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