summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-06-28 19:38:25 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2022-06-28 19:38:25 +0200
commit9b41192b25579dc745bf2e96bc4696deca792d1a (patch)
tree3e6a003db09aff1e32f36aa1ef19b7f5e5d3a3fa
parentnow that's just commit spamming, isn't it (diff)
downloadircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.tar
ircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.tar.gz
ircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.tar.bz2
ircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.tar.lz
ircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.tar.xz
ircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.tar.zst
ircxmpp-9b41192b25579dc745bf2e96bc4696deca792d1a.zip
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--ircxmpp.c59
2 files changed, 39 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 33347ba..c4cc7f9 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ PROJ = ircxmpp
default:
$(CC) -c -DIX_LIB $(cflags) $(CFLAGS) $(PROJ).c
$(CC) -shared -olib$(PROJ).so $(PROJ).o
- $(CC) -L. $(cflags) $(CFLAGS) $(PROJ).c -l$(PROJ) $(ldflags) -o$(PROJ)
+ $(CC) -L. $(cflags) $(CFLAGS) $(PROJ).c -l$(PROJ) $(ldflags) $(LDFLAGS) -o$(PROJ)
install:
mkdir -p $(DESTDIR)/usr/bin $(DESTDIR)/etc $(DESTDIR)/usr/include $(DESTDIR)/usr/lib
cp $(PROJ) $(DESTDIR)/usr/bin/
diff --git a/ircxmpp.c b/ircxmpp.c
index 2afaa13..e8d8e97 100644
--- a/ircxmpp.c
+++ b/ircxmpp.c
@@ -163,15 +163,21 @@ static void bridge_forward (const char * f, const char * m, struct ircxmpp * irc
if (s == IRC) {
irc_cmd_join(bridge->irc, ircxmpp->channel, ircxmpp->channel_password);
irc_run_once(bridge);
- if (m) {
- char b[1024];
- strncpy(b, m, 1023);
- b[1023] = '\0';
- char * c = b;
- while (*++c != '\0')
- if (!(isprint(*c) || * (unsigned char *) c > 0x7F /* UTF-8 */))
- *c = ' '; /* to prevent newline message smuggling */
- irc_cmd_msg(bridge->irc, ircxmpp->channel, m);
+ if (m && strlen(m) < 65535) {
+ char * msg = alloca(strlen(m)+1);
+ {
+ char * w = msg;
+ char * r = msg;
+ do // odstranimo crje
+ if (*r != '\r')
+ w++[0] = *r;
+ while (++r[0]);
+ w++[0] = '\0';
+ }
+ char * send;
+ while ((send = strtok(msg, "\n"))) {
+ irc_cmd_msg(bridge->irc, ircxmpp->channel, send+1);
+ }
}
irc_run_once(bridge);
} else if (m) {
@@ -702,18 +708,29 @@ static void obdelaj_bridge (const void * nodep, VISIT which __attribute__((unuse
free_bridge(bridge, "xmpp connection dropped");
return;
}
- while (bridge->conn && xmpp_conn_is_connected(bridge->conn) && bridge->messages_length
- && xmpp_conn_get_bound_jid(bridge->conn)) {
- char id[64];
- LOG(bridge->ircxmpp, IRCXMPP_DEBUG, "sending xmpp msg from %s", bridge->identifier);
- sprintf(id, "ircxmpp-%x", rand());
- xmpp_stanza_t * stan = xmpp_message_new(
- bridge->ircxmpp->ctx, "groupchat", bridge->ircxmpp->muc, id);
- xmpp_message_set_body(stan, bridge->messages[bridge->messages_length-1]);
- xmpp_stanza_set_from(stan, xmpp_conn_get_bound_jid(bridge->conn));
- xmpp_send(bridge->conn, stan);
- xmpp_stanza_release(stan);
- free(bridge->messages[--bridge->messages_length]);
+ const char * jid = NULL;
+ if (bridge->conn && xmpp_conn_is_connected(bridge->conn) // TODO: test this
+ && (jid = xmpp_conn_get_bound_jid(bridge->conn))) {
+ for (size_t i = 0; i < bridge->messages_length; i++) {
+ if (!bridge->conn || !xmpp_conn_is_connected(bridge->conn)) {
+ LOG(bridge->ircxmpp, IRCXMPP_WARN, "message for bridge %s dropped",
+ bridge->identifier);
+ free(bridge->messages[i]);
+ continue;
+ }
+ char id[64];
+ LOG(bridge->ircxmpp, IRCXMPP_DEBUG, "sending xmpp msg from %s",
+ bridge->identifier);
+ sprintf(id, "ircxmpp-%x", rand());
+ xmpp_stanza_t * stan = xmpp_message_new(bridge->ircxmpp->ctx, "groupchat",
+ bridge->ircxmpp->muc, id);
+ xmpp_message_set_body(stan, bridge->messages[bridge->messages_length-1]);
+ xmpp_stanza_set_from(stan, xmpp_conn_get_bound_jid(bridge->conn));
+ xmpp_send(bridge->conn, stan);
+ xmpp_stanza_release(stan);
+ free(bridge->messages[i]);
+ }
+ bridge->messages_length = 0;
}
}
void ircxmpp_run_once (struct ircxmpp * ircxmpp) {