1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* soup-uri.c : utility functions to parse URLs */
5 * Copyright 1999-2003 Ximian, Inc.
13 #include "soup-misc-private.h"
14 #include "soup-form.h"
15 #include "soup-misc.h"
19 * @short_description: URIs
21 * A #SoupURI represents a (parsed) URI.
23 * Many applications will not need to use #SoupURI directly at all; on
24 * the client side, soup_message_new() takes a stringified URI, and on
25 * the server side, the path and query components are provided for you
26 * in the server callback.
31 * @scheme: the URI scheme (eg, "http")
32 * @user: a username, or %NULL
33 * @password: a password, or %NULL
34 * @host: the hostname or IP address
35 * @port: the port number on @host
36 * @path: the path on @host
37 * @query: a query for @path, or %NULL
38 * @fragment: a fragment identifier within @path, or %NULL
40 * A #SoupURI represents a (parsed) URI. #SoupURI supports RFC 3986
41 * (URI Generic Syntax), and can parse any valid URI. However, libsoup
42 * only uses "http" and "https" URIs internally; You can use
43 * SOUP_URI_VALID_FOR_HTTP() to test if a #SoupURI is a valid HTTP
46 * @scheme will always be set in any URI. It is an interned string and
47 * is always all lowercase. (If you parse a URI with a non-lowercase
48 * scheme, it will be converted to lowercase.) The macros
49 * %SOUP_URI_SCHEME_HTTP and %SOUP_URI_SCHEME_HTTPS provide the
50 * interned values for "http" and "https" and can be compared against
53 * @user and @password are parsed as defined in the older URI specs
54 * (ie, separated by a colon; RFC 3986 only talks about a single
55 * "userinfo" field). Note that @password is not included in the
56 * output of soup_uri_to_string(). libsoup does not normally use these
57 * fields; authentication is handled via #SoupSession signals.
59 * @host contains the hostname, and @port the port specified in the
60 * URI. If the URI doesn't contain a hostname, @host will be %NULL,
61 * and if it doesn't specify a port, @port may be 0. However, for
62 * "http" and "https" URIs, @host is guaranteed to be non-%NULL
63 * (trying to parse an http URI with no @host will return %NULL), and
64 * @port will always be non-0 (because libsoup knows the default value
65 * to use when it is not specified in the URI).
67 * @path is always non-%NULL. For http/https URIs, @path will never be
68 * an empty string either; if the input URI has no path, the parsed
69 * #SoupURI will have a @path of "/".
71 * @query and @fragment are optional for all URI types.
72 * soup_form_decode() may be useful for parsing @query.
74 * Note that @path, @query, and @fragment may contain
75 * %<!-- -->-encoded characters. soup_uri_new() calls
76 * soup_uri_normalize() on them, but not soup_uri_decode(). This is
77 * necessary to ensure that soup_uri_to_string() will generate a URI
78 * that has exactly the same meaning as the original. (In theory,
79 * #SoupURI should leave @user, @password, and @host partially-encoded
80 * as well, but this would be more annoying than useful.)
84 * SOUP_URI_VALID_FOR_HTTP:
87 * Tests if @uri is a valid #SoupURI for HTTP communication; that is, if
88 * it can be used to construct a #SoupMessage.
90 * Return value: %TRUE if @uri is a valid "http" or "https" URI.
95 static void append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars);
96 static char *uri_normalized_copy (const char *str, int length, const char *unescape_extra);
98 gpointer _SOUP_URI_SCHEME_HTTP, _SOUP_URI_SCHEME_HTTPS;
99 gpointer _SOUP_URI_SCHEME_FTP;
100 gpointer _SOUP_URI_SCHEME_FILE, _SOUP_URI_SCHEME_DATA;
102 static inline const char *
103 soup_uri_parse_scheme (const char *scheme, int len)
105 if (len == 4 && !g_ascii_strncasecmp (scheme, "http", len)) {
106 return SOUP_URI_SCHEME_HTTP;
107 } else if (len == 5 && !g_ascii_strncasecmp (scheme, "https", len)) {
108 return SOUP_URI_SCHEME_HTTPS;
112 lower_scheme = g_ascii_strdown (scheme, len);
113 scheme = g_intern_static_string (lower_scheme);
114 if (scheme != (const char *)lower_scheme)
115 g_free (lower_scheme);
121 soup_scheme_default_port (const char *scheme)
123 if (scheme == SOUP_URI_SCHEME_HTTP)
125 else if (scheme == SOUP_URI_SCHEME_HTTPS)
127 else if (scheme == SOUP_URI_SCHEME_FTP)
134 * soup_uri_new_with_base:
136 * @uri_string: the URI
138 * Parses @uri_string relative to @base.
140 * Return value: a parsed #SoupURI.
143 soup_uri_new_with_base (SoupURI *base, const char *uri_string)
146 const char *end, *hash, *colon, *at, *path, *question;
147 const char *p, *hostend;
148 gboolean remove_dot_segments = TRUE;
151 /* First some cleanup steps (which are supposed to all be no-ops,
152 * but...). Skip initial whitespace, strip out internal tabs and
153 * line breaks, and ignore trailing whitespace.
155 while (g_ascii_isspace (*uri_string))
158 len = strcspn (uri_string, "\t\n\r");
159 if (uri_string[len]) {
160 char *clean = g_malloc (strlen (uri_string) + 1), *d;
163 for (s = uri_string, d = clean; *s; s++) {
164 if (*s != '\t' && *s != '\n' && *s != '\r')
169 uri = soup_uri_new_with_base (base, clean);
173 end = uri_string + len;
174 while (end > uri_string && g_ascii_isspace (end[-1]))
177 uri = g_slice_new0 (SoupURI);
180 hash = strchr (uri_string, '#');
182 uri->fragment = uri_normalized_copy (hash + 1, end - hash + 1,
187 /* Find scheme: initial [a-z+.-]* substring until ":" */
189 while (p < end && (g_ascii_isalnum (*p) ||
190 *p == '.' || *p == '+' || *p == '-'))
193 if (p > uri_string && *p == ':') {
194 uri->scheme = soup_uri_parse_scheme (uri_string, p - uri_string);
198 if (uri_string == end && !base && !uri->fragment) {
199 uri->path = g_strdup ("");
203 /* Check for authority */
204 if (strncmp (uri_string, "//", 2) == 0) {
207 path = uri_string + strcspn (uri_string, "/?#");
210 at = strchr (uri_string, '@');
211 if (at && at < path) {
212 colon = strchr (uri_string, ':');
213 if (colon && colon < at) {
214 uri->password = uri_decoded_copy (colon + 1,
217 uri->password = NULL;
221 uri->user = uri_decoded_copy (uri_string,
225 uri->user = uri->password = NULL;
227 /* Find host and port. */
228 if (*uri_string == '[') {
230 hostend = strchr (uri_string, ']');
231 if (!hostend || hostend > path) {
235 if (*(hostend + 1) == ':')
240 colon = memchr (uri_string, ':', path - uri_string);
241 hostend = colon ? colon : path;
244 uri->host = uri_decoded_copy (uri_string, hostend - uri_string);
246 if (colon && colon != path - 1) {
248 uri->port = strtoul (colon + 1, &portend, 10);
249 if (portend != (char *)path) {
259 question = memchr (uri_string, '?', end - uri_string);
261 uri->query = uri_normalized_copy (question + 1,
262 end - (question + 1),
267 if (end != uri_string) {
268 uri->path = uri_normalized_copy (uri_string, end - uri_string,
272 /* Apply base URI. This is spelled out in RFC 3986. */
273 if (base && !uri->scheme && uri->host)
274 uri->scheme = base->scheme;
275 else if (base && !uri->scheme) {
276 uri->scheme = base->scheme;
277 uri->user = g_strdup (base->user);
278 uri->password = g_strdup (base->password);
279 uri->host = g_strdup (base->host);
280 uri->port = base->port;
283 uri->path = g_strdup (base->path);
285 uri->query = g_strdup (base->query);
286 remove_dot_segments = FALSE;
287 } else if (*uri->path != '/') {
288 char *newpath, *last;
290 last = strrchr (base->path, '/');
292 newpath = g_strdup_printf ("%.*s%s",
293 (int)(last + 1 - base->path),
297 newpath = g_strdup_printf ("/%s", uri->path);
304 if (remove_dot_segments && uri->path && *uri->path) {
307 /* Remove "./" where "." is a complete segment. */
308 for (p = uri->path + 1; *p; ) {
309 if (*(p - 1) == '/' &&
310 *p == '.' && *(p + 1) == '/')
311 memmove (p, p + 2, strlen (p + 2) + 1);
315 /* Remove "." at end. */
316 if (p > uri->path + 2 &&
317 *(p - 1) == '.' && *(p - 2) == '/')
320 /* Remove "<segment>/../" where <segment> != ".." */
321 for (p = uri->path + 1; *p; ) {
322 if (!strncmp (p, "../", 3)) {
326 q = strchr (p + 1, '/');
329 if (strncmp (q, "/../", 4) != 0) {
333 memmove (p, q + 4, strlen (q + 4) + 1);
336 /* Remove "<segment>/.." at end where <segment> != ".." */
337 q = strrchr (uri->path, '/');
338 if (q && !strcmp (q, "/..")) {
340 while (p > uri->path && *p != '/')
342 if (strncmp (p, "/../", 4) != 0)
346 /* Remove extraneous initial "/.."s */
347 while (!strncmp (uri->path, "/../", 4))
348 memmove (uri->path, uri->path + 3, strlen (uri->path) - 2);
349 if (!strcmp (uri->path, "/.."))
353 /* HTTP-specific stuff */
354 if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
355 uri->scheme == SOUP_URI_SCHEME_HTTPS) {
357 uri->path = g_strdup ("/");
358 if (!SOUP_URI_VALID_FOR_HTTP (uri)) {
364 if (uri->scheme == SOUP_URI_SCHEME_FTP) {
372 uri->port = soup_scheme_default_port (uri->scheme);
374 uri->path = g_strdup ("");
383 * Parses an absolute URI.
385 * You can also pass %NULL for @uri_string if you want to get back an
386 * "empty" #SoupURI that you can fill in by hand. (You will need to
387 * call at least soup_uri_set_scheme() and soup_uri_set_path(), since
388 * those fields are required.)
390 * Return value: a #SoupURI, or %NULL.
393 soup_uri_new (const char *uri_string)
398 return g_slice_new0 (SoupURI);
400 uri = soup_uri_new_with_base (NULL, uri_string);
413 * soup_uri_to_string:
415 * @just_path_and_query: if %TRUE, output just the path and query portions
417 * Returns a string representing @uri.
419 * If @just_path_and_query is %TRUE, this concatenates the path and query
420 * together. That is, it constructs the string that would be needed in
421 * the Request-Line of an HTTP request for @uri.
423 * Return value: a string representing @uri, which the caller must free.
426 soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
431 g_return_val_if_fail (uri != NULL, NULL);
433 /* IF YOU CHANGE ANYTHING IN THIS FUNCTION, RUN
434 * tests/uri-parsing AFTERWARD.
437 str = g_string_sized_new (20);
439 if (uri->scheme && !just_path_and_query)
440 g_string_append_printf (str, "%s:", uri->scheme);
441 if (uri->host && !just_path_and_query) {
442 g_string_append (str, "//");
444 append_uri_encoded (str, uri->user, ":;@?/");
445 g_string_append_c (str, '@');
447 if (strchr (uri->host, ':')) {
448 g_string_append_c (str, '[');
449 g_string_append (str, uri->host);
450 g_string_append_c (str, ']');
452 append_uri_encoded (str, uri->host, ":/");
453 if (uri->port && uri->port != soup_scheme_default_port (uri->scheme))
454 g_string_append_printf (str, ":%u", uri->port);
455 if (!uri->path && (uri->query || uri->fragment))
456 g_string_append_c (str, '/');
459 if (uri->path && *uri->path)
460 g_string_append (str, uri->path);
463 g_string_append_c (str, '?');
464 g_string_append (str, uri->query);
466 if (uri->fragment && !just_path_and_query) {
467 g_string_append_c (str, '#');
468 g_string_append (str, uri->fragment);
471 return_result = str->str;
472 g_string_free (str, FALSE);
474 return return_result;
483 * Return value: a copy of @uri, which must be freed with soup_uri_free()
486 soup_uri_copy (SoupURI *uri)
490 g_return_val_if_fail (uri != NULL, NULL);
492 dup = g_slice_new0 (SoupURI);
493 dup->scheme = uri->scheme;
494 dup->user = g_strdup (uri->user);
495 dup->password = g_strdup (uri->password);
496 dup->host = g_strdup (uri->host);
497 dup->port = uri->port;
498 dup->path = g_strdup (uri->path);
499 dup->query = g_strdup (uri->query);
500 dup->fragment = g_strdup (uri->fragment);
505 static inline gboolean
506 parts_equal (const char *one, const char *two, gboolean insensitive)
512 return insensitive ? !g_ascii_strcasecmp (one, two) : !strcmp (one, two);
518 * @uri2: another #SoupURI
520 * Tests whether or not @uri1 and @uri2 are equal in all parts
522 * Return value: %TRUE or %FALSE
525 soup_uri_equal (SoupURI *uri1, SoupURI *uri2)
527 if (uri1->scheme != uri2->scheme ||
528 uri1->port != uri2->port ||
529 !parts_equal (uri1->user, uri2->user, FALSE) ||
530 !parts_equal (uri1->password, uri2->password, FALSE) ||
531 !parts_equal (uri1->host, uri2->host, TRUE) ||
532 !parts_equal (uri1->path, uri2->path, FALSE) ||
533 !parts_equal (uri1->query, uri2->query, FALSE) ||
534 !parts_equal (uri1->fragment, uri2->fragment, FALSE))
547 soup_uri_free (SoupURI *uri)
549 g_return_if_fail (uri != NULL);
552 g_free (uri->password);
556 g_free (uri->fragment);
558 g_slice_free (SoupURI, uri);
562 append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars)
564 const unsigned char *s = (const unsigned char *)in;
567 if (soup_char_is_uri_percent_encoded (*s) ||
568 soup_char_is_uri_gen_delims (*s) ||
569 (extra_enc_chars && strchr (extra_enc_chars, *s)))
570 g_string_append_printf (str, "%%%02X", (int)*s++);
572 g_string_append_c (str, *s++);
579 * @escape_extra: (allow-none): additional reserved characters to
582 * This %<!-- -->-encodes the given URI part and returns the escaped
583 * version in allocated memory, which the caller must free when it is
586 * Return value: the encoded URI part
589 soup_uri_encode (const char *part, const char *escape_extra)
594 str = g_string_new (NULL);
595 append_uri_encoded (str, part, escape_extra);
597 g_string_free (str, FALSE);
602 #define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
603 #define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
606 uri_decoded_copy (const char *part, int length)
608 unsigned char *s, *d;
609 char *decoded = g_strndup (part, length);
611 s = d = (unsigned char *)decoded;
614 if (!g_ascii_isxdigit (s[1]) ||
615 !g_ascii_isxdigit (s[2])) {
632 * Fully %<!-- -->-decodes @part.
634 * In the past, this would return %NULL if @part contained invalid
635 * percent-encoding, but now it just ignores the problem (as
636 * soup_uri_new() already did).
638 * Return value: the decoded URI part.
641 soup_uri_decode (const char *part)
643 return uri_decoded_copy (part, strlen (part));
647 uri_normalized_copy (const char *part, int length,
648 const char *unescape_extra)
650 unsigned char *s, *d, c;
651 char *normalized = g_strndup (part, length);
652 gboolean need_fixup = FALSE;
654 s = d = (unsigned char *)normalized;
657 if (!g_ascii_isxdigit (s[1]) ||
658 !g_ascii_isxdigit (s[2])) {
664 if (soup_char_is_uri_unreserved (c) ||
665 (unescape_extra && strchr (unescape_extra, c))) {
669 /* We leave it unchanged. We used to uppercase percent-encoded
670 * triplets but we do not do it any more as RFC3986 Section 6.2.2.1
671 * says that they only SHOULD be case normalized.
678 if (!g_ascii_isgraph (*s))
687 fixed = g_string_new (NULL);
688 s = (guchar *)normalized;
690 if (g_ascii_isgraph (*s))
691 g_string_append_c (fixed, *s);
693 g_string_append_printf (fixed, "%%%02X", (int)*s);
697 normalized = g_string_free (fixed, FALSE);
704 * soup_uri_normalize:
706 * @unescape_extra: reserved characters to unescape (or %NULL)
708 * %<!-- -->-decodes any "unreserved" characters (or characters in
709 * @unescape_extra) in @part.
711 * "Unreserved" characters are those that are not allowed to be used
712 * for punctuation according to the URI spec. For example, letters are
713 * unreserved, so soup_uri_normalize() will turn
714 * <literal>http://example.com/foo/b%<!-- -->61r</literal> into
715 * <literal>http://example.com/foo/bar</literal>, which is guaranteed
716 * to mean the same thing. However, "/" is "reserved", so
717 * <literal>http://example.com/foo%<!-- -->2Fbar</literal> would not
718 * be changed, because it might mean something different to the
721 * In the past, this would return %NULL if @part contained invalid
722 * percent-encoding, but now it just ignores the problem (as
723 * soup_uri_new() already did).
725 * Return value: the normalized URI part
728 soup_uri_normalize (const char *part, const char *unescape_extra)
730 return uri_normalized_copy (part, strlen (part), unescape_extra);
735 * soup_uri_uses_default_port:
738 * Tests if @uri uses the default port for its scheme. (Eg, 80 for
739 * http.) (This only works for http and https; libsoup does not know
740 * the default ports of other protocols.)
742 * Return value: %TRUE or %FALSE
745 soup_uri_uses_default_port (SoupURI *uri)
747 return uri->port == soup_scheme_default_port (uri->scheme);
751 * SOUP_URI_SCHEME_HTTP:
753 * "http" as an interned string. This can be compared directly against
754 * the value of a #SoupURI's <structfield>scheme</structfield>
758 * SOUP_URI_SCHEME_HTTPS:
760 * "https" as an interned string. This can be compared directly
761 * against the value of a #SoupURI's <structfield>scheme</structfield>
765 * soup_uri_get_scheme:
768 * Gets @uri's scheme.
770 * Return value: @uri's scheme.
775 soup_uri_get_scheme (SoupURI *uri)
781 * soup_uri_set_scheme:
783 * @scheme: the URI scheme
785 * Sets @uri's scheme to @scheme. This will also set @uri's port to
786 * the default port for @scheme, if known.
789 soup_uri_set_scheme (SoupURI *uri, const char *scheme)
791 uri->scheme = soup_uri_parse_scheme (scheme, strlen (scheme));
792 uri->port = soup_scheme_default_port (uri->scheme);
801 * Return value: @uri's user.
806 soup_uri_get_user (SoupURI *uri)
814 * @user: the username, or %NULL
816 * Sets @uri's user to @user.
819 soup_uri_set_user (SoupURI *uri, const char *user)
822 uri->user = g_strdup (user);
826 * soup_uri_get_password:
829 * Gets @uri's password.
831 * Return value: @uri's password.
836 soup_uri_get_password (SoupURI *uri)
838 return uri->password;
842 * soup_uri_set_password:
844 * @password: the password, or %NULL
846 * Sets @uri's password to @password.
849 soup_uri_set_password (SoupURI *uri, const char *password)
851 g_free (uri->password);
852 uri->password = g_strdup (password);
861 * Return value: @uri's host.
866 soup_uri_get_host (SoupURI *uri)
874 * @host: the hostname or IP address, or %NULL
876 * Sets @uri's host to @host.
878 * If @host is an IPv6 IP address, it should not include the brackets
879 * required by the URI syntax; they will be added automatically when
880 * converting @uri to a string.
883 soup_uri_set_host (SoupURI *uri, const char *host)
886 uri->host = g_strdup (host);
895 * Return value: @uri's port.
900 soup_uri_get_port (SoupURI *uri)
908 * @port: the port, or 0
910 * Sets @uri's port to @port. If @port is 0, @uri will not have an
911 * explicitly-specified port.
914 soup_uri_set_port (SoupURI *uri, guint port)
925 * Return value: @uri's path.
930 soup_uri_get_path (SoupURI *uri)
940 * Sets @uri's path to @path.
943 soup_uri_set_path (SoupURI *uri, const char *path)
946 uri->path = g_strdup (path);
950 * soup_uri_get_query:
955 * Return value: @uri's query.
960 soup_uri_get_query (SoupURI *uri)
966 * soup_uri_set_query:
970 * Sets @uri's query to @query.
973 soup_uri_set_query (SoupURI *uri, const char *query)
976 uri->query = g_strdup (query);
980 * soup_uri_set_query_from_form:
982 * @form: (element-type utf8 utf8): a #GHashTable containing HTML form
985 * Sets @uri's query to the result of encoding @form according to the
986 * HTML form rules. See soup_form_encode_hash() for more information.
989 soup_uri_set_query_from_form (SoupURI *uri, GHashTable *form)
992 uri->query = soup_form_encode_hash (form);
996 * soup_uri_set_query_from_fields:
998 * @first_field: name of the first form field to encode into query
999 * @...: value of @first_field, followed by additional field names
1000 * and values, terminated by %NULL.
1002 * Sets @uri's query to the result of encoding the given form fields
1003 * and values according to the * HTML form rules. See
1004 * soup_form_encode() for more information.
1007 soup_uri_set_query_from_fields (SoupURI *uri,
1008 const char *first_field,
1013 g_free (uri->query);
1014 va_start (args, first_field);
1015 uri->query = soup_form_encode_valist (first_field, args);
1020 * soup_uri_get_fragment:
1023 * Gets @uri's fragment.
1025 * Return value: @uri's fragment.
1030 soup_uri_get_fragment (SoupURI *uri)
1032 return uri->fragment;
1036 * soup_uri_set_fragment:
1038 * @fragment: the fragment
1040 * Sets @uri's fragment to @fragment.
1043 soup_uri_set_fragment (SoupURI *uri, const char *fragment)
1045 g_free (uri->fragment);
1046 uri->fragment = g_strdup (fragment);
1050 * soup_uri_copy_host:
1053 * Makes a copy of @uri, considering only the protocol, host, and port
1055 * Return value: the new #SoupURI
1060 soup_uri_copy_host (SoupURI *uri)
1064 g_return_val_if_fail (uri != NULL, NULL);
1066 dup = soup_uri_new (NULL);
1067 dup->scheme = uri->scheme;
1068 dup->host = g_strdup (uri->host);
1069 dup->port = uri->port;
1070 if (dup->scheme == SOUP_URI_SCHEME_HTTP ||
1071 dup->scheme == SOUP_URI_SCHEME_HTTPS)
1072 dup->path = g_strdup ("");
1078 * soup_uri_host_hash:
1079 * @key: (type Soup.URI): a #SoupURI
1081 * Hashes @key, considering only the scheme, host, and port.
1083 * Return value: a hash
1088 soup_uri_host_hash (gconstpointer key)
1090 const SoupURI *uri = key;
1092 g_return_val_if_fail (uri != NULL && uri->host != NULL, 0);
1094 return GPOINTER_TO_UINT (uri->scheme) + uri->port +
1095 soup_str_case_hash (uri->host);
1099 * soup_uri_host_equal:
1100 * @v1: (type Soup.URI): a #SoupURI
1101 * @v2: (type Soup.URI): a #SoupURI
1103 * Compares @v1 and @v2, considering only the scheme, host, and port.
1105 * Return value: whether or not the URIs are equal in scheme, host,
1111 soup_uri_host_equal (gconstpointer v1, gconstpointer v2)
1113 const SoupURI *one = v1;
1114 const SoupURI *two = v2;
1116 g_return_val_if_fail (one != NULL && two != NULL, one == two);
1117 g_return_val_if_fail (one->host != NULL && two->host != NULL, one->host == two->host);
1119 if (one->scheme != two->scheme)
1121 if (one->port != two->port)
1124 return g_ascii_strcasecmp (one->host, two->host) == 0;
1129 soup_uri_get_type (void)
1131 static volatile gsize type_volatile = 0;
1133 if (g_once_init_enter (&type_volatile)) {
1134 GType type = g_boxed_type_register_static (
1135 g_intern_static_string ("SoupURI"),
1136 (GBoxedCopyFunc) soup_uri_copy,
1137 (GBoxedFreeFunc) soup_uri_free);
1138 g_once_init_leave (&type_volatile, type);
1140 return type_volatile;