mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -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;
|
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,
|
char * str_replace(const char *string, const char *substr,
|
||||||
const char *replacement);
|
const char *replacement);
|
||||||
int str_contains(char str[], int size, char ch);
|
int str_contains(char str[], int size, char ch);
|
||||||
|
char* encode_xml(const char * const xml);
|
||||||
|
|
||||||
#endif
|
#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 *encoded_xml = encode_xml(msg);
|
||||||
char *coded_msg2 = str_replace(coded_msg, "<", "<");
|
|
||||||
char *coded_msg3 = str_replace(coded_msg2, ">", ">");
|
|
||||||
|
|
||||||
xmpp_stanza_t *reply, *body, *text, *active;
|
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");
|
xmpp_stanza_set_name(body, "body");
|
||||||
|
|
||||||
text = xmpp_stanza_new(jabber_conn.ctx);
|
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()) {
|
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_send(jabber_conn.conn, reply);
|
||||||
xmpp_stanza_release(reply);
|
xmpp_stanza_release(reply);
|
||||||
free(coded_msg);
|
|
||||||
free(coded_msg2);
|
free(encoded_xml);
|
||||||
free(coded_msg3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
jabber_send_groupchat(const char * const msg, const char * const recipient)
|
jabber_send_groupchat(const char * const msg, const char * const recipient)
|
||||||
{
|
{
|
||||||
char *coded_msg = str_replace(msg, "&", "&");
|
char *encoded_xml = encode_xml(msg);
|
||||||
char *coded_msg2 = str_replace(coded_msg, "<", "<");
|
|
||||||
char *coded_msg3 = str_replace(coded_msg2, ">", ">");
|
|
||||||
|
|
||||||
xmpp_stanza_t *reply, *body, *text;
|
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");
|
xmpp_stanza_set_name(body, "body");
|
||||||
|
|
||||||
text = xmpp_stanza_new(jabber_conn.ctx);
|
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(body, text);
|
||||||
xmpp_stanza_add_child(reply, body);
|
xmpp_stanza_add_child(reply, body);
|
||||||
|
|
||||||
xmpp_send(jabber_conn.conn, reply);
|
xmpp_send(jabber_conn.conn, reply);
|
||||||
xmpp_stanza_release(reply);
|
xmpp_stanza_release(reply);
|
||||||
free(coded_msg);
|
|
||||||
free(coded_msg2);
|
free(encoded_xml);
|
||||||
free(coded_msg3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user