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:
parent
9872708755
commit
92ae93de33
13
src/common.c
13
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
22
src/jabber.c
22
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
|
||||
|
Loading…
Reference in New Issue
Block a user