xmpp: Implement the basis for XEP-0446 and XEP-0447

This commit is contained in:
PapaTutuWawa 2022-02-26 18:41:34 +01:00
parent b5e1da839a
commit 150df70b11
4 changed files with 101 additions and 0 deletions

View File

@ -32,3 +32,12 @@ const csiXmlns = "urn:xmpp:csi:0";
// XEP-0359
const stableIdXmlns = "urn:xmpp:sid:0";
// XEP-0446
const fileMetadataXmlns = "urn:xmpp:file:metadata:0";
// XEP-0447
const sfsXmlns = "urn:xmpp:sfs:0";
// ???
const urlDataXmlns = "http://jabber.org/protocol/url-data";

View File

@ -0,0 +1,51 @@
import "package:moxxyv2/xmpp/stringxml.dart";
import "package:moxxyv2/xmpp/namespaces.dart";
// TODO: Thumbnail
class FileMetadataData {
final String? mediaType;
// TODO: Maybe create a special type for this
final String? dimensions;
final String? desc;
final Map<String, String>? hashes;
final int? length;
final String? name;
final int? size;
const FileMetadataData({
this.mediaType,
this.dimensions,
this.desc,
this.hashes,
this.length,
this.name,
this.size
});
}
FileMetadataData parseFileMetadataElement(XMLNode node) {
assert(node.attributes["xmlns"] == fileMetadataXmlns);
assert(node.tag == "file");
final lengthElement = node.firstTag("length");
final int? length = lengthElement != null ? int.parse(lengthElement.innerText()) : null;
final sizeElement = node.firstTag("size");
final int? size = sizeElement != null ? int.parse(sizeElement.innerText()) : null;
final Map<String, String> hashes = {};
for (final e in node.findTags("hash")) {
hashes[e.attributes["algo"]] = e.innerText();
}
return FileMetadataData(
mediaType: node.firstTag("media-type")?.innerText(),
dimensions: node.firstTag("dimensions")?.innerText(),
desc: node.firstTag("desc")?.innerText(),
hashes: hashes,
length: length,
name: node.firstTag("name")?.innerText(),
size: size
);
}

View File

@ -0,0 +1,25 @@
import "package:moxxyv2/xmpp/stringxml.dart";
import "package:moxxyv2/xmpp/namespaces.dart";
import "package:moxxyv2/xmpp/xeps/xep_0446.dart";
class StatelessFileSharingData {
final FileMetadataData metadata;
final String url;
const StatelessFileSharingData({ required this.metadata, required this.url });
}
StatelessFileSharingData parseSFSElement(XMLNode node) {
assert(node.attributes["xmlns"] == sfsXmlns);
assert(node.tag == "file-sharing");
final metadata = parseFileMetadataElement(node.firstTag("file")!);
final sources = node.firstTag("sources")!;
final urldata = sources.firstTag("url-data", xmlns: urlDataXmlns);
final url = urldata?.attributes["target"]!;
return StatelessFileSharingData(
metadata: metadata,
url: url
);
}

View File

@ -84,5 +84,21 @@
<xmpp:version>1.1.0</xmpp:version>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0446.html" />
<xmpp:status>partial</xmpp:status>
<xmpp:version>0.1.0</xmpp:version>
<xmpp:note xml:lang="en">Not connected read-only implementation</xmpp:note>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0447.html" />
<xmpp:status>partial</xmpp:status>
<xmpp:version>0.1.2</xmpp:version>
<xmpp:note xml:lang="en">Not connected read-only implementation</xmpp:note>
</xmpp:SupportedXep>
</implements>
</Project>
</rdf:RDF>