Mercurial > pidgin
comparison libpurple/theme.c @ 25119:fc8047e1fa39
fixed some leaks and made theme loading safer
| author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
|---|---|
| date | Fri, 08 Aug 2008 21:26:12 +0000 |
| parents | 748308865dbf |
| children | 1eacf60a73dd |
comparison
equal
deleted
inserted
replaced
| 25118:f76e9db37141 | 25119:fc8047e1fa39 |
|---|---|
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "theme.h" | 24 #include "theme.h" |
| 25 #include "util.h" | |
| 26 | |
| 27 #include <string.h> | |
| 25 | 28 |
| 26 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \ | 29 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \ |
| 27 ((PurpleThemePrivate *) ((PurpleTheme)->priv)) | 30 ((PurpleThemePrivate *) ((PurpleTheme)->priv)) |
| 28 | 31 |
| 29 void purple_theme_set_type_string(PurpleTheme *theme, const gchar *type); | 32 void purple_theme_set_type_string(PurpleTheme *theme, const gchar *type); |
| 228 &info, G_TYPE_FLAG_ABSTRACT); | 231 &info, G_TYPE_FLAG_ABSTRACT); |
| 229 } | 232 } |
| 230 return type; | 233 return type; |
| 231 } | 234 } |
| 232 | 235 |
| 236 /****************************************************************************** | |
| 237 * Helper Functions | |
| 238 *****************************************************************************/ | |
| 239 | |
| 240 static gchar* | |
| 241 theme_clean_text(const gchar *text) | |
| 242 { | |
| 243 gchar *clean_text = g_markup_escape_text(text, strlen(text)); | |
| 244 g_strdelimit(clean_text, "\n", ' '); | |
| 245 purple_str_strip_char(clean_text, '\r'); | |
| 246 return clean_text; | |
| 247 } | |
| 233 | 248 |
| 234 /***************************************************************************** | 249 /***************************************************************************** |
| 235 * Public API functions * | 250 * Public API functions |
| 236 *****************************************************************************/ | 251 *****************************************************************************/ |
| 237 | 252 |
| 238 const gchar * | 253 const gchar * |
| 239 purple_theme_get_name(PurpleTheme *theme) | 254 purple_theme_get_name(PurpleTheme *theme) |
| 240 { | 255 { |
| 254 g_return_if_fail(PURPLE_IS_THEME(theme)); | 269 g_return_if_fail(PURPLE_IS_THEME(theme)); |
| 255 | 270 |
| 256 priv = PURPLE_THEME_GET_PRIVATE(theme); | 271 priv = PURPLE_THEME_GET_PRIVATE(theme); |
| 257 | 272 |
| 258 g_free(priv->name); | 273 g_free(priv->name); |
| 259 priv->name = g_strdup(name); | 274 priv->name = theme_clean_text(name); |
| 260 } | 275 } |
| 261 | 276 |
| 262 const gchar * | 277 const gchar * |
| 263 purple_theme_get_description(PurpleTheme *theme) | 278 purple_theme_get_description(PurpleTheme *theme) |
| 264 { | 279 { |
| 278 g_return_if_fail(PURPLE_IS_THEME(theme)); | 293 g_return_if_fail(PURPLE_IS_THEME(theme)); |
| 279 | 294 |
| 280 priv = PURPLE_THEME_GET_PRIVATE(theme); | 295 priv = PURPLE_THEME_GET_PRIVATE(theme); |
| 281 | 296 |
| 282 g_free(priv->description); | 297 g_free(priv->description); |
| 283 priv->description = g_strdup(description); | 298 priv->description = theme_clean_text(description); |
| 284 } | 299 } |
| 285 | 300 |
| 286 const gchar * | 301 const gchar * |
| 287 purple_theme_get_author(PurpleTheme *theme) | 302 purple_theme_get_author(PurpleTheme *theme) |
| 288 { | 303 { |
| 302 g_return_if_fail(PURPLE_IS_THEME(theme)); | 317 g_return_if_fail(PURPLE_IS_THEME(theme)); |
| 303 | 318 |
| 304 priv = PURPLE_THEME_GET_PRIVATE(theme); | 319 priv = PURPLE_THEME_GET_PRIVATE(theme); |
| 305 | 320 |
| 306 g_free(priv->author); | 321 g_free(priv->author); |
| 307 priv->author = g_strdup(author); | 322 priv->author = theme_clean_text(author); |
| 308 } | 323 } |
| 309 | 324 |
| 310 const gchar * | 325 const gchar * |
| 311 purple_theme_get_type_string(PurpleTheme *theme) | 326 purple_theme_get_type_string(PurpleTheme *theme) |
| 312 { | 327 { |
