1 /* GLIB - Library of useful routines for C programming
3 * gconvert.c: Convert between character sets using iconv
4 * Copyright Red Hat Inc., 2000
5 * Authors: Havoc Pennington <hp@redhat.com>, Owen Taylor <otaylor@redhat.com
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
26 UNSAFE_ALL = 0x1, /* Escape all unsafe characters */
27 UNSAFE_ALLOW_PLUS = 0x2, /* Allows '+' */
28 UNSAFE_PATH = 0x4, /* Allows '/' and '?' and '&' and '=' */
29 UNSAFE_DOS_PATH = 0x8, /* Allows '/' and '?' and '&' and '=' and ':' */
30 UNSAFE_HOST = 0x10, /* Allows '/' and ':' and '@' */
31 UNSAFE_SLASHES = 0x20 /* Allows all characters except for '/' and '%' */
34 static const guchar acceptable[96] = {
35 /* A table of the ASCII chars from space (32) to DEL (127) */
36 /* ! " # $ % & ' ( ) * + , - . / */
37 0x00,0x3F,0x20,0x20,0x20,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x22,0x20,0x3F,0x3F,0x1C,
38 /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
39 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x2C,
40 /* @ A B C D E F G H I J K L M N O */
41 0x30,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
42 /* P Q R S T U V W X Y Z [ \ ] ^ _ */
43 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
44 /* ` a b c d e f g h i j k l m n o */
45 0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
46 /* p q r s t u v w x y z { | } ~ DEL */
47 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20
50 static const gchar hex[] = "0123456789ABCDEF";
52 /* Note: This escape function works on file: URIs, but if you want to
53 * escape something else, please read RFC-2396 */
55 mono_escape_uri_string (const gchar *string)
57 #define ACCEPTABLE(a) ((a)>=32 && (a)<128 && (acceptable[(a)-32] & use_mask))
64 UnsafeCharacterSet use_mask;
67 use_mask = UNSAFE_DOS_PATH;
68 for (p = string; *p != '\0'; p++)
75 result = g_malloc (p - string + unacceptable * 2 + 1);
77 for (q = result, p = string; *p != '\0'; p++)
83 *q++ = '%'; /* means hex coming */