diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-06-28 19:38:25 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-06-28 19:38:25 +0200 |
commit | 9b41192b25579dc745bf2e96bc4696deca792d1a (patch) | |
tree | 3e6a003db09aff1e32f36aa1ef19b7f5e5d3a3fa | |
parent | now that's just commit spamming, isn't it (diff) | |
download | ircxmpp-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 |
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | ircxmpp.c | 59 |
2 files changed, 39 insertions, 22 deletions
@@ -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/ @@ -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) { |