* Pidgin is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #include "smileyparser.h" get_fullpath(const char *filename) if (g_path_is_absolute(filename)) return g_strdup(filename); return g_build_path(g_get_current_dir(), filename, NULL); parse_for_shortcut_plaintext(const char *text, const char *shortcut, const char *file, GString *ret) const char *end = strstr(tmp, shortcut); g_string_append(ret, tmp); path = get_fullpath(file); escaped_path = g_markup_escape_text(path, -1); g_string_append_len(ret, tmp, end-tmp); g_string_append_printf(ret,"<img alt='%s' src='%s' />", g_assert(strlen(tmp) >= strlen(shortcut)); tmp = end + strlen(shortcut); parse_for_shortcut(const char *markup, const char *shortcut, const char *file) GString* ret = g_string_new(""); char *local_markup = g_strdup(markup); char *escaped_shortcut = g_markup_escape_text(shortcut, -1); char *temp = local_markup; char *end = strchr(temp, '<'); parse_for_shortcut_plaintext(temp, escaped_shortcut, file, ret); parse_for_shortcut_plaintext(temp, escaped_shortcut, file, ret); /* if this is well-formed, then there should be no '>' within * the tag. TODO: handle a comment tag better :( */ end_of_tag = strchr(end, '>'); g_string_append(ret, end); g_string_append_len(ret, end, end_of_tag - end + 1); g_free(escaped_shortcut); return g_string_free(ret, FALSE); parse_for_purple_smiley(const char *markup, PurpleSmiley *smiley) char *file = purple_smiley_get_full_path(smiley); char *ret = parse_for_shortcut(markup, purple_smiley_get_shortcut(smiley), file); parse_for_smiley_list(const char *markup, GHashTable *smileys) char *ret = g_strdup(markup); g_hash_table_iter_init(&iter, smileys); while (g_hash_table_iter_next(&iter, (gpointer *)&key, (gpointer *)&value)) char *temp = parse_for_shortcut(ret, key, value); smiley_parse_markup(const char *markup, const char *proto_id) GList *smileys = purple_smileys_get_all(); char *temp = g_strdup(markup), *temp2; struct smiley_list *list; const char *proto_name = "default"; proto = purple_find_prpl(proto_id); proto_name = proto->info->name; /* unnecessarily slow, but lets manage for now. */ for (; smileys; smileys = g_list_next(smileys)) { temp2 = parse_for_purple_smiley(temp, PURPLE_SMILEY(smileys->data)); /* now for each theme smiley, observe that this does look nasty */ if (!current_smiley_theme || !(current_smiley_theme->list)) { purple_debug_warning("smiley", "theme does not exist\n"); for (list = current_smiley_theme->list; list; list = list->next) { if (g_str_equal(list->sml, proto_name)) { temp2 = parse_for_smiley_list(temp, list->files);