1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Tidied escaping xml

This commit is contained in:
James Booth 2012-11-06 22:53:59 +00:00
parent 9872708755
commit 92ae93de33
3 changed files with 22 additions and 14 deletions

View File

@ -105,3 +105,16 @@ str_contains(char str[], int size, char ch)
return 0;
}
char *
encode_xml(const char * const xml)
{
char *coded_msg = str_replace(xml, "&", "&");
char *coded_msg2 = str_replace(coded_msg, "<", "&lt;");
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
free(coded_msg);
free(coded_msg2);
return coded_msg3;
}

View File

@ -40,5 +40,6 @@ void create_dir(char *name);
char * str_replace(const char *string, const char *substr,
const char *replacement);
int str_contains(char str[], int size, char ch);
char* encode_xml(const char * const xml);
#endif

View File

@ -144,9 +144,7 @@ jabber_send(const char * const msg, const char * const recipient)
}
}
char *coded_msg = str_replace(msg, "&", "&amp;");
char *coded_msg2 = str_replace(coded_msg, "<", "&lt;");
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
char *encoded_xml = encode_xml(msg);
xmpp_stanza_t *reply, *body, *text, *active;
@ -159,7 +157,7 @@ jabber_send(const char * const msg, const char * const recipient)
xmpp_stanza_set_name(body, "body");
text = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_text(text, coded_msg3);
xmpp_stanza_set_text(text, encoded_xml);
if (prefs_get_states()) {
@ -178,17 +176,14 @@ jabber_send(const char * const msg, const char * const recipient)
xmpp_send(jabber_conn.conn, reply);
xmpp_stanza_release(reply);
free(coded_msg);
free(coded_msg2);
free(coded_msg3);
free(encoded_xml);
}
void
jabber_send_groupchat(const char * const msg, const char * const recipient)
{
char *coded_msg = str_replace(msg, "&", "&amp;");
char *coded_msg2 = str_replace(coded_msg, "<", "&lt;");
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
char *encoded_xml = encode_xml(msg);
xmpp_stanza_t *reply, *body, *text;
@ -201,16 +196,15 @@ jabber_send_groupchat(const char * const msg, const char * const recipient)
xmpp_stanza_set_name(body, "body");
text = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_text(text, coded_msg3);
xmpp_stanza_set_text(text, encoded_xml);
xmpp_stanza_add_child(body, text);
xmpp_stanza_add_child(reply, body);
xmpp_send(jabber_conn.conn, reply);
xmpp_stanza_release(reply);
free(coded_msg);
free(coded_msg2);
free(coded_msg3);
free(encoded_xml);
}
void