ref: a5ac48e0d64d20fc0acef12f8639a5613a76c573
parent: ed2752fe715680692023bbcaf85ddf03c2444c2c
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed May 29 16:31:23 EDT 2024
support xep-0280 (message carbons)
--- a/xmpp.c
+++ b/xmpp.c
@@ -24,6 +24,21 @@
char *server, *mydomain, *myjid, *mynick, *myresource, *myplainjid;
static QLock prlock;
+static int
+ismyjid(char *jid)
+{
+ int n;
+
+ n = strlen(myplainjid);
+ if(strncmp(jid, myplainjid, n) == 0 && (jid[n] == 0 || jid[n] == '/'))
+ return 1;
+ n = strlen(myjid);
+ if(strncmp(jid, myjid, n) == 0 && (jid[n] == 0 || jid[n] == '/'))
+ return 1;
+
+ return 0;
+}
+
static void
inerror(Xelem *x)
{
@@ -44,14 +59,28 @@
static void
inmsg(Xelem *x)
{
- Xattr *type, *from, *stamp, *to;
- Xelem *body, *delay, *subj;
+ Xattr *type, *from, *stamp, *to, *ns;
+ Xelem *body, *delay, *subj, *e;
char *s, *nick, *bodyv, tmp[64];
Target *t, *room;
int i;
+ if((from = xmlgetattr(x->a, "from")) == nil)
+ return;
+
+ /* message carbons https://xmpp.org/extensions/xep-0280.html */
+ if((e = xmlget(x->ch, "received")) != nil &&
+ ismyjid(from->v) &&
+ (ns = xmlgetattr(e->a, "xmlns")) != nil &&
+ strncmp(ns->v, "urn:xmpp:carbons:", 17) == 0 &&
+ (e = xmlget(e->ch, "forwarded")) != nil &&
+ (e = xmlget(e->ch, "message")) != nil){
+ x = e;
+ if((from = xmlgetattr(x->a, "from")) == nil)
+ return;
+ }
+
type = xmlgetattr(x->a, "type");
- from = xmlgetattr(x->a, "from");
body = xmlget(x->ch, "body");
subj = xmlget(x->ch, "subject");
/* ignore "composing..." messages */
@@ -59,8 +88,7 @@
return;
to = xmlgetattr(x->a, "to");
- if(to != nil && strncmp(to->v, myjid, strlen(myjid)) != 0 &&
- strncmp(to->v, myplainjid, strlen(myplainjid) != 0))
+ if(to != nil && !ismyjid(to->v))
return;
if((delay = xmlget(x->ch, "delay")) == nil)