gossip r2859 - in trunk: . libgossip src
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: gossip r2859 - in trunk: . libgossip src
- Date: Sat, 29 Nov 2008 16:51:16 +0000 (UTC)
Author: mr
Date: Sat Nov 29 16:51:16 2008
New Revision: 2859
URL: http://svn.gnome.org/viewvc/gossip?rev=2859&view=rev
Log:
* libgossip/gossip-contact-manager.c: When using
xmlNodeSetContent() make sure we escape strings first, since this
function doesn't do that for us.
* libgossip/gossip-jabber.c:
* libgossip/gossip-utils.[ch]: Added gossip_markup_unescape_text()
to handle unescaped strings returned to us from Loudmouth. More
specifially groups and contact names. So now if you save a contact
as "Foo & Bar", it will not return it when you restart Gossip as
"Foo & Bar".
* src/gossip-status-presets.c: Code improvements.
* src/gossip-chat-invite.c:
* src/gossip-contact-list.c:
* src/gossip-edit-contact-dialog.c:
* src/gossip-theme-boxes.c: Make use of g_markup_printf_escaped()
and fixed a couple of crashers too.
Modified:
trunk/ChangeLog
trunk/libgossip/gossip-contact-manager.c
trunk/libgossip/gossip-jabber.c
trunk/libgossip/gossip-presence.c
trunk/libgossip/gossip-utils.c
trunk/libgossip/gossip-utils.h
trunk/src/gossip-chat-invite.c
trunk/src/gossip-contact-list.c
trunk/src/gossip-edit-contact-dialog.c
trunk/src/gossip-status-presets.c
trunk/src/gossip-theme-boxes.c
trunk/src/gossip-transport-add-window.c
Modified: trunk/libgossip/gossip-contact-manager.c
==============================================================================
--- trunk/libgossip/gossip-contact-manager.c (original)
+++ trunk/libgossip/gossip-contact-manager.c Sat Nov 29 16:51:16 2008
@@ -550,10 +550,10 @@
xmlNodePtr node)
{
GossipContactManagerPrivate *priv;
- GossipContact *own_contact;
- const gchar *id;
- const gchar *name;
- gchar *new_name;
+ GossipContact *own_contact;
+ const gchar *id;
+ const gchar *name;
+ gchar *new_name;
new_name = gossip_xml_node_get_child_content (node, "name");
if (!new_name) {
@@ -806,11 +806,11 @@
xmlNodePtr node, child, p;
GossipContact *own_contact;
const gchar *name;
+ gchar *str;
account = l->data;
own_contact = gossip_contact_manager_get_own_contact (manager, account);
-
name = gossip_contact_get_name (own_contact);
node = g_hash_table_lookup (nodes, account);
@@ -830,7 +830,9 @@
child = p;
}
- xmlNodeSetContent (child, name);
+ str = g_markup_escape_text (name, -1);
+ xmlNodeSetContent (child, str);
+ g_free (str);
}
contacts = g_hash_table_get_keys (priv->contacts);
@@ -841,6 +843,7 @@
GossipContactType type;
const gchar *id;
const gchar *name;
+ gchar *str;
contact = l->data;
@@ -888,8 +891,10 @@
} else {
child = p;
}
-
- xmlNodeSetContent (child, name);
+
+ str = g_markup_escape_text (name, -1);
+ xmlNodeSetContent (child, str);
+ g_free (str);
}
g_list_free (contacts);
Modified: trunk/libgossip/gossip-jabber.c
==============================================================================
--- trunk/libgossip/gossip-jabber.c (original)
+++ trunk/libgossip/gossip-jabber.c Sat Nov 29 16:51:16 2008
@@ -2607,11 +2607,9 @@
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
-
/*
* Requests
*/
-
static void
jabber_request_version (GossipJabber *jabber,
LmMessage *m)
@@ -2666,7 +2664,6 @@
lm_message_unref (r);
}
-
static void
jabber_request_ping (GossipJabber *jabber, LmMessage *m)
{
@@ -2695,7 +2692,6 @@
lm_message_unref (reply);
}
-
static void
jabber_request_roster (GossipJabber *jabber,
LmMessage *m)
@@ -2784,20 +2780,28 @@
name = lm_message_node_get_attribute (node, "name");
if (name) {
- gossip_contact_set_name (contact, name);
+ gchar *str;
+
+ str = gossip_markup_unescape_text (name);
+ gossip_contact_set_name (contact, str);
+ g_free (str);
}
groups = NULL;
for (child = node->children; child; child = child->next) {
/* FIXME: unescape the markup here: #342927 */
if (strcmp (child->name, "group") == 0 && child->value) {
- groups = g_list_prepend (groups, child->value);
+ gchar *str;
+
+ str = gossip_markup_unescape_text (child->value);
+ groups = g_list_prepend (groups, str);
}
}
if (groups) {
groups = g_list_reverse (groups);
gossip_contact_set_groups (contact, groups);
+ g_list_foreach (groups, (GFunc) g_free, NULL);
g_list_free (groups);
}
Modified: trunk/libgossip/gossip-presence.c
==============================================================================
--- trunk/libgossip/gossip-presence.c (original)
+++ trunk/libgossip/gossip-presence.c Sat Nov 29 16:51:16 2008
@@ -43,15 +43,15 @@
GossipTime timestamp;
};
-static void presence_finalize (GObject *object);
-static void presence_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void presence_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
+static void presence_finalize (GObject *object);
+static void presence_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void presence_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
enum {
PROP_0,
Modified: trunk/libgossip/gossip-utils.c
==============================================================================
--- trunk/libgossip/gossip-utils.c (original)
+++ trunk/libgossip/gossip-utils.c Sat Nov 29 16:51:16 2008
@@ -286,3 +286,42 @@
return found;
}
+gchar *
+gossip_markup_unescape_text (const gchar *markup)
+{
+ gchar *text, *p, c;
+
+ if (!markup) {
+ return NULL;
+ }
+
+ p = text = g_malloc (strlen (markup) + 1);
+
+ while ((c = *markup++)) {
+ if (G_LIKELY (c != '&')) {
+ *p++ = c;
+ continue;
+ }
+
+ if (!memcmp (markup, "amp;", 4)) {
+ *p++ = '&';
+ markup += 4;
+ } else if (!memcmp (markup, "lt;", 3)) {
+ *p++ = '<';
+ markup += 3;
+ } else if (!memcmp (markup, "gt;", 3)) {
+ *p++ = '>';
+ markup += 3;
+ } else if (!memcmp (markup, "quot;", 5)) {
+ *p++ = '"';
+ markup += 5;
+ } else if (!memcmp (markup, "apos;", 5)) {
+ *p++ = '\'';
+ markup += 5;
+ }
+ }
+
+ *p = 0;
+
+ return text;
+}
Modified: trunk/libgossip/gossip-utils.h
==============================================================================
--- trunk/libgossip/gossip-utils.h (original)
+++ trunk/libgossip/gossip-utils.h Sat Nov 29 16:51:16 2008
@@ -66,6 +66,9 @@
const gchar *prop_name,
const gchar *prop_value);
+/* Markup */
+gchar * gossip_markup_unescape_text (const gchar *markup);
+
G_END_DECLS
#endif /* __GOSSIP_UTILS_H__ */
Modified: trunk/src/gossip-chat-invite.c
==============================================================================
--- trunk/src/gossip-chat-invite.c (original)
+++ trunk/src/gossip-chat-invite.c Sat Nov 29 16:51:16 2008
@@ -293,7 +293,6 @@
{
GossipChatInviteDialog *dialog;
GladeXML *gui;
- gchar *name;
gchar *str;
g_return_if_fail (GOSSIP_IS_CONTACT (contact));
@@ -333,21 +332,17 @@
provider = gossip_session_get_chatroom_provider (session, account);
chatroom = gossip_chatroom_provider_find_by_id (provider, dialog->chatroom_id);
- name = g_markup_escape_text (gossip_chatroom_get_name (chatroom), -1);
- str = g_strdup_printf ("%s\n<b>%s</b>",
- _("Select who would you like to invite to room:"),
- name);
+ str = g_markup_printf_escaped ("%s\n<b>%s</b>",
+ _("Select who would you like to invite to room:"),
+ gossip_chatroom_get_name (chatroom));
} else {
/* Show a list of rooms */
- name = g_markup_escape_text (gossip_contact_get_name (dialog->contact), -1);
- str = g_strdup_printf ("%s\n<b>%s</b>",
- _("Select which room you would like to invite:"),
- name);
+ str = g_markup_printf_escaped ("%s\n<b>%s</b>",
+ _("Select which room you would like to invite:"),
+ gossip_contact_get_name (dialog->contact));
}
gtk_label_set_markup (GTK_LABEL (dialog->label), str);
-
- g_free (name);
g_free (str);
chat_invite_dialog_model_setup (dialog);
Modified: trunk/src/gossip-contact-list.c
==============================================================================
--- trunk/src/gossip-contact-list.c (original)
+++ trunk/src/gossip-contact-list.c Sat Nov 29 16:51:16 2008
@@ -3228,12 +3228,12 @@
GTK_BUTTONS_NONE,
NULL);
- str = g_strdup_printf ("%s\n\n"
- "<b>%s</b>\n"
- "%s\n",
- _("Do you want to remove this contact from your roster?"),
- gossip_contact_get_name (contact),
- gossip_contact_get_id (contact));
+ str = g_markup_printf_escaped ("%s\n\n"
+ "<b>%s</b>\n"
+ "%s\n",
+ _("Do you want to remove this contact from your roster?"),
+ gossip_contact_get_name (contact),
+ gossip_contact_get_id (contact));
gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), str);
g_free (str);
@@ -3313,9 +3313,9 @@
GTK_BUTTONS_NONE,
NULL);
- str = g_strdup_printf ("%s\n<b>%s</b>",
- _("Please enter a new name for the group:"),
- group);
+ str = g_markup_printf_escaped ("%s\n<b>%s</b>",
+ _("Please enter a new name for the group:"),
+ group);
gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), str);
g_free (str);
Modified: trunk/src/gossip-edit-contact-dialog.c
==============================================================================
--- trunk/src/gossip-edit-contact-dialog.c (original)
+++ trunk/src/gossip-edit-contact-dialog.c Sat Nov 29 16:51:16 2008
@@ -658,7 +658,6 @@
GladeXML *glade;
GList *groups;
GtkSizeGroup *size_group;
- gchar *id_escaped;
gchar *str;
g_return_if_fail (GOSSIP_IS_CONTACT (contact));
@@ -712,14 +711,11 @@
gossip_contact_get_name (dialog->contact));
gtk_editable_select_region (GTK_EDITABLE (dialog->entry_name), 0, -1);
- id_escaped = g_markup_escape_text (gossip_contact_get_id (contact), -1);
- str = g_strdup_printf (_("Set the alias you want to use for:\n"
- "<b>%s</b>\n"
- "\n"
- "You can retrieve contact information from the server."),
- id_escaped);
- g_free (id_escaped);
-
+ str = g_markup_printf_escaped (_("Set the alias you want to use for:\n"
+ "<b>%s</b>\n"
+ "\n"
+ "You can retrieve contact information from the server."),
+ gossip_contact_get_id (contact));
gtk_label_set_markup (GTK_LABEL (dialog->label_name), str);
g_free (str);
Modified: trunk/src/gossip-status-presets.c
==============================================================================
--- trunk/src/gossip-status-presets.c (original)
+++ trunk/src/gossip-status-presets.c Sat Nov 29 16:51:16 2008
@@ -52,7 +52,6 @@
static void status_preset_free (StatusPreset *status);
static void status_presets_file_parse (const gchar *filename);
static gboolean status_presets_file_save (void);
-const gchar * status_presets_get_state_as_str (GossipPresenceState state);
static void status_presets_set_default (GossipPresenceState state,
const gchar *status);
@@ -114,49 +113,46 @@
while (node) {
if (strcmp ((gchar *) node->name, "status") == 0 ||
strcmp ((gchar *) node->name, "default") == 0) {
- GossipPresenceState state;
- gchar *status;
- gchar *state_str;
- StatusPreset *preset;
- gboolean is_default = FALSE;
+ StatusPreset *preset;
+ gchar *str;
+ gboolean is_default = FALSE;
if (strcmp ((gchar *) node->name, "default") == 0) {
is_default = TRUE;
}
- status = (gchar *) xmlNodeGetContent (node);
- state_str = (gchar *) xmlGetProp (node, "presence");
+ str = (gchar *) xmlGetProp (node, "presence");
- if (state_str) {
- if (strcmp (state_str, "available") == 0) {
+ if (str) {
+ GossipPresenceState state;
+
+ /* Now get the state */
+ if (strcmp (str, "available") == 0) {
state = GOSSIP_PRESENCE_STATE_AVAILABLE;
- }
- else if (strcmp (state_str, "busy") == 0) {
+ } else if (strcmp (str, "busy") == 0) {
state = GOSSIP_PRESENCE_STATE_BUSY;
- }
- else if (strcmp (state_str, "away") == 0) {
+ } else if (strcmp (str, "away") == 0) {
state = GOSSIP_PRESENCE_STATE_AWAY;
- }
- else if (strcmp (state_str, "ext_away") == 0) {
+ } else if (strcmp (str, "ext_away") == 0) {
state = GOSSIP_PRESENCE_STATE_EXT_AWAY;
} else {
state = GOSSIP_PRESENCE_STATE_AVAILABLE;
}
- if (is_default) {
- gossip_debug (DEBUG_DOMAIN,
- "Default status preset state is:'%s', status:'%s'",
- state_str, status);
+ xmlFree (str);
+
+ /* Now get the status text */
+ str = (gchar *) xmlNodeGetContent (node);
- status_presets_set_default (state, status);
+ if (is_default) {
+ status_presets_set_default (state, str);
} else {
- preset = status_preset_new (state, status);
+ preset = status_preset_new (state, str);
presets = g_list_append (presets, preset);
}
- }
- xmlFree (status);
- xmlFree (state_str);
+ xmlFree (str);
+ }
}
node = node->next;
@@ -198,8 +194,8 @@
g_free (file_with_path);
}
-const gchar *
-status_presets_get_state_as_str (GossipPresenceState state)
+static const gchar *
+status_presets_state_to_string (GossipPresenceState state)
{
switch (state) {
case GOSSIP_PRESENCE_STATE_AVAILABLE:
@@ -235,32 +231,25 @@
xmlDocSetRootElement (doc, root);
if (default_preset) {
- xmlNodePtr subnode;
- xmlChar *state;
-
- state = (gchar*) status_presets_get_state_as_str (default_preset->state);
+ xmlNodePtr subnode;
- subnode = xmlNewTextChild (root, NULL, "default",
- default_preset->status);
- xmlNewProp (subnode, "presence", state);
+ subnode = xmlNewTextChild (root, NULL, "default", default_preset->status);
+ xmlNewProp (subnode, "presence", status_presets_state_to_string (default_preset->state));
}
for (l = presets; l; l = l->next) {
StatusPreset *sp;
xmlNodePtr subnode;
- xmlChar *state;
sp = l->data;
- state = (gchar*) status_presets_get_state_as_str (sp->state);
count[sp->state]++;
if (count[sp->state] > STATUS_PRESETS_MAX_EACH) {
continue;
}
- subnode = xmlNewTextChild (root, NULL,
- "status", sp->status);
- xmlNewProp (subnode, "presence", state);
+ subnode = xmlNewTextChild (root, NULL, "status", sp->status);
+ xmlNewProp (subnode, "presence", status_presets_state_to_string (sp->state));
}
/* Make sure the XML is indented properly */
Modified: trunk/src/gossip-theme-boxes.c
==============================================================================
--- trunk/src/gossip-theme-boxes.c (original)
+++ trunk/src/gossip-theme-boxes.c Sat Nov 29 16:51:16 2008
@@ -689,7 +689,7 @@
G_CALLBACK (table_size_allocate_cb),
box, 0);
- str = g_strdup_printf ("<b>%s</b>", name);
+ str = g_markup_printf_escaped ("<b>%s</b>", name);
label1 = g_object_new (GTK_TYPE_LABEL,
"label", str,
Modified: trunk/src/gossip-transport-add-window.c
==============================================================================
--- trunk/src/gossip-transport-add-window.c (original)
+++ trunk/src/gossip-transport-add-window.c Sat Nov 29 16:51:16 2008
@@ -692,7 +692,6 @@
_("Unable to Register"),
error_reason);
gtk_label_set_markup (GTK_LABEL (window->label_requirements_result), str);
-
g_free (str);
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]