2 * @file upnp_util.cUtility Functions
5 * Gaim is the legal property of its developers, whose names are too numerous
6 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "gnunet_util.h"
28 /* Returns a NULL-terminated string after unescaping an entity
29 * (eg. &, < & etc.) starting at s. Returns NULL on failure.*/
31 detect_entity (const char *text, int *length)
39 if (!text || *text != '&')
42 #define IS_ENTITY(s) (!strncasecmp(text, s, (len = sizeof(s) - 1)))
44 if (IS_ENTITY ("&"))
46 else if (IS_ENTITY ("<"))
48 else if (IS_ENTITY (">"))
50 else if (IS_ENTITY (" "))
52 else if (IS_ENTITY ("©"))
53 pln = "\302\251"; /* or use g_unichar_to_utf8(0xa9); */
54 else if (IS_ENTITY ("""))
56 else if (IS_ENTITY ("®"))
57 pln = "\302\256"; /* or use g_unichar_to_utf8(0xae); */
58 else if (IS_ENTITY ("'"))
60 else if (*(text + 1) == '#' && (sscanf (text, "&#%u;", £) == 1) &&
61 pound != 0 && *(text + 3 + (int) log10 (pound)) == ';')
63 buf = GNUNET_convert_string_to_utf8 (NULL,
64 (const char *) £,
72 while (isdigit ((int) text[len]))
82 return GNUNET_strdup (pln);
86 g_strdup_printf (const char *fmt, ...)
93 size = VSNPRINTF (NULL, 0, fmt, va) + 1;
95 buf = GNUNET_malloc (size);
97 VSNPRINTF (buf, size, fmt, va);
103 gaim_unescape_html (const char *html)
107 const char *c = html;
108 char *ret = GNUNET_strdup ("");
115 if ((ent = detect_entity (c, &len)) != NULL)
117 app = g_strdup_printf ("%s%s", ret, ent);
123 else if (!strncmp (c, "<br>", 4))
125 app = g_strdup_printf ("%s%s", ret, "\n");
132 app = g_strdup_printf ("%s%c", ret, *c);
145 gaim_str_has_prefix (const char *s, const char *p)
147 if ((s == NULL) || (p == NULL))
149 return !strncmp (s, p, strlen (p));