diff options
-rw-r--r-- | src/common.c | 13 | ||||
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/jabber.c | 22 |
3 files changed, 22 insertions, 14 deletions
diff --git a/src/common.c b/src/common.c index c9a5612e..840a0803 100644 --- a/src/common.c +++ b/src/common.c @@ -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, "<", "<"); + char *coded_msg3 = str_replace(coded_msg2, ">", ">"); + + free(coded_msg); + free(coded_msg2); + + return coded_msg3; +} diff --git a/src/common.h b/src/common.h index d683ae16..7ee774c4 100644 --- a/src/common.h +++ b/src/common.h @@ -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 diff --git a/src/jabber.c b/src/jabber.c index 3b1b9be3..3f216441 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -144,9 +144,7 @@ jabber_send(const char * const msg, const char * const recipient) } } - char *coded_msg = str_replace(msg, "&", "&"); - char *coded_msg2 = str_replace(coded_msg, "<", "<"); - char *coded_msg3 = str_replace(coded_msg2, ">", ">"); + 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, "&", "&"); - char *coded_msg2 = str_replace(coded_msg, "<", "<"); - char *coded_msg3 = str_replace(coded_msg2, ">", ">"); + 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 |