clix/export.lua

changeset 50
e5cdd8e93e05
child 53
bfc53225a38f
equal deleted inserted replaced
49:64e637041347 50:e5cdd8e93e05
1 short_opts.i = "interactive";
2 local split_jid = require "util.jid".split;
3 local timer = require "util.timer";
4
5 local xmlns_pie = "urn:xmpp:pie:0";
6 local xmlns_nodes = {
7 { "query", "jabber:iq:roster" },
8 { "query", "jabber:iq:privacy" },
9 { "vCard", "vcard-temp" },
10 }
11 local xmlns_private = "jabber:iq:private";
12 local xmlns_private_nodes = {
13 { "storage", "storage:bookmarks" },
14 }
15
16 local function on_connect(conn)
17 local export = verse.stanza("server-data", { xmlns = xmlns_pie })
18 :tag("host", { jid = conn.host })
19 :tag("user", { name = conn.username, password = conn.password });
20 local out = 0;
21
22 for i = 1,#xmlns_nodes do
23 out = out + 1;
24 local node = xmlns_nodes[i];
25 print(("requesting %s*%s"):format(node[2], node[1]));
26 conn:send_iq(verse.iq{type="get"}
27 :tag(node[1], { xmlns = node[2] })
28 , function(stanza)
29 print(("got %s*%s"):format(node[2], node[1]));
30 local query = stanza:get_child(node[1], node[2]);
31 if query then
32 export:add_child(query):up();
33 end
34 out = out - 1;
35 end);
36 end
37
38 for i = 1,#xmlns_private_nodes do
39 out = out + 1;
40 local node = xmlns_private_nodes[i];
41 print(("requesting private node %s*%s"):format(node[2], node[1]));
42 conn:send_iq(verse.iq{type="get"}
43 :tag("query", { xmlns = xmlns_private })
44 :tag(node[1], { xmlns = node[2] })
45 , function(stanza)
46 print(("got private %s*%s"):format(node[2], node[1]));
47 local query = stanza:get_child("query", xmlns_private);
48 if query then
49 export:add_child(query):up();
50 end
51 out = out - 1;
52 end);
53 end
54
55 timer.add_task(1, function ()
56 if out > 0 then
57 return 1
58 end
59 print("<?xml version='1.0' encoding='UTF-8'?>");
60 print(export);
61 conn:close();
62 end)
63 end
64
65 return function (opts, arg)
66 if opts.short_help then
67 print("Export your account");
68 return;
69 end
70 if opts.help then
71 return 0;
72 end
73 clix_connect(opts, on_connect);
74 end
75

mercurial