shithub: xmpp

Download patch

ref: 458a91724a672b45602ef8cbd6093b6f8c76fef6
parent: a5ac48e0d64d20fc0acef12f8639a5613a76c573
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu May 30 10:17:26 EDT 2024

enable message carbons if server advertises the extension

--- a/xmpp.c
+++ b/xmpp.c
@@ -72,7 +72,7 @@
 	if((e = xmlget(x->ch, "received")) != nil &&
 	   ismyjid(from->v) &&
 	   (ns = xmlgetattr(e->a, "xmlns")) != nil &&
-	   strncmp(ns->v, "urn:xmpp:carbons:", 17) == 0 &&
+	   strcmp(ns->v, "urn:xmpp:carbons:2") == 0 &&
 	   (e = xmlget(e->ch, "forwarded")) != nil &&
 	   (e = xmlget(e->ch, "message")) != nil){
 		x = e;
@@ -151,7 +151,7 @@
 iniq(Xelem *x, int fd)
 {
 	Xelem *e;
-	Xattr *a, *from, *id;
+	Xattr *a, *from, *id, *var;
 	int isget, isset;
 
 	a = xmlgetattr(x->a, "type");
@@ -202,6 +202,25 @@
 				"<query xmlns='jabber:iq:roster'/></iq>",
 				myjid) < 0)
 				return -1;
+
+			/* enable message carbons https://xmpp.org/extensions/xep-0280.html */
+			if(x->ch != nil)
+			for(e = x->ch->ch; e != nil; e = e->next){
+				if(strcmp(e->n, "feature") != 0)
+					continue;
+				if((var = xmlgetattr(e->a, "var")) == nil)
+					continue;
+				if(strcmp(var->v, "urn:xmpp:carbons:2") != 0)
+					continue;
+				
+				if(fprint(pfd,
+					"<iq type='set' from='%Ӽ' id='lotsofcarbs' xmlns='jabber:client'>"
+					"<enable xmlns='urn:xmpp:carbons:2'/>"
+					"</iq>",
+					myjid) < 0)
+					return -1;
+				break;
+			}
 		}
 	}