1 /* libquvi
2  * Copyright (C) 2013  Toni Gundogdu <legatvs@gmail.com>
3  *
4  * This file is part of libquvi <http://quvi.sourceforge.net/>.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public
17  * License along with this program.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "config.h"
22 
23 #include <glib.h>
24 /* -- */
25 #include "misc/url.h"
26 
_is_unescaped(const gchar * s)27 static gboolean _is_unescaped(const gchar *s)
28 {
29   gboolean r;
30   gchar *u;
31   u = g_uri_unescape_string(s, NULL);
32   r = g_strcmp0(u,s) == 0 ? TRUE:FALSE;
33   g_free(u);
34   return (r);
35 }
36 
m_url_unescaped_form(const gchar * s)37 gchar *m_url_unescaped_form(const gchar *s)
38 {
39   gchar *r = g_strdup(s);
40   do
41     {
42       gchar *u = g_uri_unescape_string(r, NULL);
43       if (u == NULL)
44         break;
45       g_free(r);
46       r = u;
47     }
48   while (_is_unescaped(r) == FALSE);
49   return (r);
50 }
51 
m_url_escaped_form(const gchar * s)52 gchar *m_url_escaped_form(const gchar *s)
53 {
54   static const gchar *reserved_chars = "!*'();:@&=+$,/?#[]";
55   gchar *u, *r;
56   u = m_url_unescaped_form(s);
57   r = g_uri_escape_string(u, reserved_chars, FALSE);
58   g_free(u);
59   return (r);
60 }
61 
62 /* vim: set ts=2 sw=2 tw=72 expandtab: */
63