Software /
code /
verse
Comparison
plugins/jingle_ft.lua @ 379:d80d27234e38
plugins.jingle_ft: Update to version 0.16
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 01 May 2015 21:46:24 +0200 |
parent | 250:a5ac643a7fd6 |
child | 380:0891b4e27766 |
comparison
equal
deleted
inserted
replaced
368:154c2f04d73b | 379:d80d27234e38 |
---|---|
1 local verse = require "verse"; | 1 local verse = require "verse"; |
2 local ltn12 = require "ltn12"; | 2 local ltn12 = require "ltn12"; |
3 | 3 |
4 local dirsep = package.config:sub(1,1); | 4 local dirsep = package.config:sub(1,1); |
5 | 5 |
6 local xmlns_jingle_ft = "urn:xmpp:jingle:apps:file-transfer:1"; | 6 local xmlns_jingle_ft = "urn:xmpp:jingle:apps:file-transfer:4"; |
7 local xmlns_si_file_transfer = "http://jabber.org/protocol/si/profile/file-transfer"; | |
8 | 7 |
9 function verse.plugins.jingle_ft(stream) | 8 function verse.plugins.jingle_ft(stream) |
10 stream:hook("ready", function () | 9 stream:hook("ready", function () |
11 stream:add_disco_feature(xmlns_jingle_ft); | 10 stream:add_disco_feature(xmlns_jingle_ft); |
12 end, 10); | 11 end, 10); |
24 return description; | 23 return description; |
25 end | 24 end |
26 | 25 |
27 local ft_mt = { __index = ft_content }; | 26 local ft_mt = { __index = ft_content }; |
28 stream:hook("jingle/content/"..xmlns_jingle_ft, function (jingle, description_tag) | 27 stream:hook("jingle/content/"..xmlns_jingle_ft, function (jingle, description_tag) |
29 local file_tag = description_tag:get_child("offer"):get_child("file", xmlns_si_file_transfer); | 28 local file_tag = description_tag:get_child("file"); |
30 local file = { | 29 local file = { |
31 name = file_tag.attr.name; | 30 name = file_tag:get_child_text("name"); |
32 size = tonumber(file_tag.attr.size); | 31 size = tonumber(file_tag:get_child_text("size")); |
32 desc = file_tag:get_child_text("desc"); | |
33 date = file_tag:get_child_text("date"); | |
33 }; | 34 }; |
34 | 35 |
35 return setmetatable({ jingle = jingle, file = file }, ft_mt); | 36 return setmetatable({ jingle = jingle, file = file }, ft_mt); |
36 end); | 37 end); |
37 | 38 |
40 local date; | 41 local date; |
41 if file_info.timestamp then | 42 if file_info.timestamp then |
42 date = os.date("!%Y-%m-%dT%H:%M:%SZ", file_info.timestamp); | 43 date = os.date("!%Y-%m-%dT%H:%M:%SZ", file_info.timestamp); |
43 end | 44 end |
44 return verse.stanza("description", { xmlns = xmlns_jingle_ft }) | 45 return verse.stanza("description", { xmlns = xmlns_jingle_ft }) |
45 :tag("offer") | 46 :tag("file") |
46 :tag("file", { xmlns = xmlns_si_file_transfer, | 47 :tag("name"):text(file_info.filename):up() |
47 name = file_info.filename, -- Mandatory | 48 :tag("size"):text(tostring(file_info.size)):up() |
48 size = file_info.size, -- Mandatory | 49 :tag("date"):text(date):up() |
49 date = date, | 50 :tag("desc"):text(file_info.description):up() |
50 hash = file_info.hash, | 51 :up(); |
51 }) | |
52 :tag("desc"):text(file_info.description or ""); | |
53 end); | 52 end); |
54 | 53 |
55 function stream:send_file(to, filename) | 54 function stream:send_file(to, filename) |
56 local file, err = io.open(filename); | 55 local file, err = io.open(filename); |
57 if not file then return file, err; end | 56 if not file then return file, err; end |