Annotate

tools/xep227toprosody.lua @ 10270:c2b9ff42db03

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 21 Sep 2019 16:50:29 +0200
parent 6870:d5b416070f70
child 11680:a3d3fb9d0d43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env lua
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 -- Prosody IM
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2009 Matthew Wild
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 -- Copyright (C) 2008-2009 Waqas Hussain
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 -- Copyright (C) 2010 Stefan Gehn
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5696
diff changeset
6 --
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 -- This project is MIT/X11 licensed. Please see the
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 -- COPYING file in the source package for more information.
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 --
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 -- FIXME: XEP-0227 supports XInclude but luaexpat does not
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 --
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 -- XEP-227 elements and their current level of support:
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 -- Hosts : supported
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 -- Users : supported
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 -- Rosters : supported, needs testing
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 -- Offline Messages : supported, needs testing
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 -- Private XML Storage : supported, needs testing
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 -- vCards : supported, needs testing
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 -- Privacy Lists: UNSUPPORTED
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 -- http://xmpp.org/extensions/xep-0227.html#privacy-lists
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 -- mod_privacy uses dm.load(username, host, "privacy"); and stores stanzas 1:1
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 -- Incoming Subscription Requests : supported
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 package.path = package.path..";../?.lua";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 package.cpath = package.cpath..";../?.so"; -- needed for util.pposix used in datamanager
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27
5696
9fba74a28e0c package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 5091
diff changeset
28 local my_name = arg[0];
9fba74a28e0c package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 5091
diff changeset
29 if my_name:match("[/\\]") then
9fba74a28e0c package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 5091
diff changeset
30 package.path = package.path..";"..my_name:gsub("[^/\\]+$", "../?.lua");
9fba74a28e0c package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 5091
diff changeset
31 package.cpath = package.cpath..";"..my_name:gsub("[^/\\]+$", "../?.so");
9fba74a28e0c package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 5091
diff changeset
32 end
9fba74a28e0c package{,c}path fixes for migration tools
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 5091
diff changeset
33
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 -- ugly workaround for getting datamanager to work outside of prosody :(
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 prosody = { };
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 prosody.platform = "unknown";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 if os.getenv("WINDIR") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 prosody.platform = "windows";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 elseif package.config:sub(1,1) == "/" then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 prosody.platform = "posix";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 local lxp = require "lxp";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 local st = require "util.stanza";
3709
db1c1ddc79e8 tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents: 3540
diff changeset
45 local xmppstream = require "util.xmppstream";
db1c1ddc79e8 tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents: 3540
diff changeset
46 local new_xmpp_handlers = xmppstream.new_sax_handlers;
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 local dm = require "util.datamanager"
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 dm.set_data_path("data");
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49
3709
db1c1ddc79e8 tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents: 3540
diff changeset
50 local ns_separator = xmppstream.ns_separator;
db1c1ddc79e8 tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents: 3540
diff changeset
51 local ns_pattern = xmppstream.ns_pattern;
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52
3710
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
53 local xmlns_xep227 = "http://www.xmpp.org/extensions/xep-0227.html#ns";
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
54
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 -----------------------------------------------------------------------
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 function store_vcard(username, host, stanza)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 -- create or update vCard for username@host
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 local ret, err = dm.store(username, host, "vcard", st.preserialize(stanza));
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 print("["..(err or "success").."] stored vCard: "..username.."@"..host);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 function store_password(username, host, password)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 -- create or update account for username@host
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 local ret, err = dm.store(username, host, "accounts", {password = password});
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 print("["..(err or "success").."] stored account: "..username.."@"..host.." = "..password);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 function store_roster(username, host, roster_items)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 -- fetch current roster-table for username@host if he already has one
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 local roster = dm.load(username, host, "roster") or {};
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 -- merge imported roster-items with loaded roster
5091
dbc483d06a07 tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
Kim Alvefur <zash@zash.se>
parents: 3710
diff changeset
73 for item_tag in roster_items:childtags("item") do
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 -- jid for this roster-item
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 local item_jid = item_tag.attr.jid
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 -- validate item stanzas
5091
dbc483d06a07 tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
Kim Alvefur <zash@zash.se>
parents: 3710
diff changeset
77 if (item_jid ~= "") then
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 -- prepare roster item
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 -- TODO: is the subscription attribute optional?
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 local item = {subscription = item_tag.attr.subscription, groups = {}};
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 -- optional: give roster item a real name
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 if item_tag.attr.name then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 item.name = item_tag.attr.name;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85 -- optional: iterate over group stanzas inside item stanza
5091
dbc483d06a07 tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
Kim Alvefur <zash@zash.se>
parents: 3710
diff changeset
86 for group_tag in item_tag:childtags("group") do
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 local group_name = group_tag:get_text();
5091
dbc483d06a07 tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
Kim Alvefur <zash@zash.se>
parents: 3710
diff changeset
88 if (group_name ~= "") then
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 item.groups[group_name] = true;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 else
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 print("[error] invalid group stanza: "..group_tag:pretty_print());
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 -- store item in roster
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95 roster[item_jid] = item;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96 print("[success] roster entry: " ..username.."@"..host.." - "..item_jid);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97 else
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 print("[error] invalid roster stanza: " ..item_tag:pretty_print());
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 -- store merged roster-table
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 local ret, err = dm.store(username, host, "roster", roster);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 print("["..(err or "success").."] stored roster: " ..username.."@"..host);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 function store_private(username, host, private_items)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 local private = dm.load(username, host, "private") or {};
5091
dbc483d06a07 tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
Kim Alvefur <zash@zash.se>
parents: 3710
diff changeset
109 for _, ch in ipairs(private_items.tags) do
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 --print("private :"..ch:pretty_print());
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 private[ch.name..":"..ch.attr.xmlns] = st.preserialize(ch);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 print("[success] private item: " ..username.."@"..host.." - "..ch.name);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 local ret, err = dm.store(username, host, "private", private);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115 print("["..(err or "success").."] stored private: " ..username.."@"..host);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
116 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 function store_offline_messages(username, host, offline_messages)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
119 -- TODO: maybe use list_load(), append and list_store() instead
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 -- of constantly reopening the file with list_append()?
5091
dbc483d06a07 tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
Kim Alvefur <zash@zash.se>
parents: 3710
diff changeset
121 for ch in offline_messages:childtags("message", "jabber:client") do
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122 --print("message :"..ch:pretty_print());
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 local ret, err = dm.list_append(username, host, "offline", st.preserialize(ch));
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 print("["..(err or "success").."] stored offline message: " ..username.."@"..host.." - "..ch.attr.from);
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2508
diff changeset
125 end
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
129 function store_subscription_request(username, host, presence_stanza)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
130 local from_bare = presence_stanza.attr.from;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 -- fetch current roster-table for username@host if he already has one
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
133 local roster = dm.load(username, host, "roster") or {};
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
134
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 local item = roster[from_bare];
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 if item and (item.subscription == "from" or item.subscription == "both") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
137 return; -- already subscribed, do nothing
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 -- add to table of pending subscriptions
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 if not roster.pending then roster.pending = {}; end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 roster.pending[from_bare] = true;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 -- store updated roster-table
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 local ret, err = dm.store(username, host, "roster", roster);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146 print("["..(err or "success").."] stored subscription request: " ..username.."@"..host.." - "..from_bare);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
149 -----------------------------------------------------------------------
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
150
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151 local curr_host = "";
2508
fed7f19db0da xep227toprosody: Fixed some global accesses.
Waqas Hussain <waqas20@gmail.com>
parents: 2507
diff changeset
152 local user_name = "";
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
153
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
154
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
155 local cb = {
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
156 stream_tag = "user",
3710
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
157 stream_ns = xmlns_xep227,
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158 };
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159 function cb.streamopened(session, attr)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
160 session.notopen = false;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
161 user_name = attr.name;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
162 store_password(user_name, curr_host, attr.password);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
163 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
164 function cb.streamclosed(session)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
165 session.notopen = true;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
166 user_name = "";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
167 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
168 function cb.handlestanza(session, stanza)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
169 --print("Parsed stanza "..stanza.name.." xmlns: "..(stanza.attr.xmlns or ""));
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
170 if (stanza.name == "vCard") and (stanza.attr.xmlns == "vcard-temp") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
171 store_vcard(user_name, curr_host, stanza);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
172 elseif (stanza.name == "query") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
173 if (stanza.attr.xmlns == "jabber:iq:roster") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
174 store_roster(user_name, curr_host, stanza);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
175 elseif (stanza.attr.xmlns == "jabber:iq:private") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
176 store_private(user_name, curr_host, stanza);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
177 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
178 elseif (stanza.name == "offline-messages") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
179 store_offline_messages(user_name, curr_host, stanza);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
180 elseif (stanza.name == "presence") and (stanza.attr.xmlns == "jabber:client") then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
181 store_subscription_request(user_name, curr_host, stanza);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
182 else
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
183 print("UNHANDLED stanza "..stanza.name.." xmlns: "..(stanza.attr.xmlns or ""));
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
184 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
185 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
186
3709
db1c1ddc79e8 tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents: 3540
diff changeset
187 local user_handlers = new_xmpp_handlers({ notopen = true }, cb);
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
188
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
189 -----------------------------------------------------------------------
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
190
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
191 local lxp_handlers = {
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
192 --count = 0
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
193 };
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
194
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
195 -- TODO: error handling for invalid opening elements if curr_host is empty
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
196 function lxp_handlers.StartElement(parser, elementname, attributes)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
197 local curr_ns, name = elementname:match(ns_pattern);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
198 if name == "" then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
199 curr_ns, name = "", curr_ns;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
200 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
201 --io.write("+ ", string.rep(" ", count), name, " (", curr_ns, ")", "\n")
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
202 --count = count + 1;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
203 if curr_host ~= "" then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
204 -- forward to xmlhandlers
6869
5ce783c37024 xep227toprosody: Pass parser to callbacks (needed since addition of stanza size limits)
Kim Alvefur <zash@zash.se>
parents: 5696
diff changeset
205 user_handlers.StartElement(parser, elementname, attributes);
3710
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
206 elseif (curr_ns == xmlns_xep227) and (name == "host") then
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
207 curr_host = attributes["jid"]; -- start of host element
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
208 print("Begin parsing host "..curr_host);
3710
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
209 elseif (curr_ns ~= xmlns_xep227) or (name ~= "server-data") then
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
210 io.stderr:write("Unhandled XML element: ", name, "\n");
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
211 os.exit(1);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
212 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
213 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
214
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
215 -- TODO: error handling for invalid closing elements if host is empty
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
216 function lxp_handlers.EndElement(parser, elementname)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
217 local curr_ns, name = elementname:match(ns_pattern);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
218 if name == "" then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
219 curr_ns, name = "", curr_ns;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
220 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
221 --count = count - 1;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
222 --io.write("- ", string.rep(" ", count), name, " (", curr_ns, ")", "\n")
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
223 if curr_host ~= "" then
3710
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
224 if (curr_ns == xmlns_xep227) and (name == "host") then
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
225 print("End parsing host "..curr_host);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
226 curr_host = "" -- end of host element
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
227 else
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
228 -- forward to xmlhandlers
6869
5ce783c37024 xep227toprosody: Pass parser to callbacks (needed since addition of stanza size limits)
Kim Alvefur <zash@zash.se>
parents: 5696
diff changeset
229 user_handlers.EndElement(parser, elementname);
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
230 end
3710
59fbe4536c69 tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents: 3709
diff changeset
231 elseif (curr_ns ~= xmlns_xep227) or (name ~= "server-data") then
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
232 io.stderr:write("Unhandled XML element: ", name, "\n");
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
233 os.exit(1);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
234 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
235 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
236
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
237 function lxp_handlers.CharacterData(parser, string)
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
238 if curr_host ~= "" then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
239 -- forward to xmlhandlers
6869
5ce783c37024 xep227toprosody: Pass parser to callbacks (needed since addition of stanza size limits)
Kim Alvefur <zash@zash.se>
parents: 5696
diff changeset
240 user_handlers.CharacterData(parser, string);
2507
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
241 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
242 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
243
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
244 -----------------------------------------------------------------------
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
245
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
246 local arg = ...;
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
247 local help = "/? -? ? /h -h /help -help --help";
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
248 if not arg or help:find(arg, 1, true) then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
249 print([[XEP-227 importer for Prosody
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
250
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
251 Usage: xep227toprosody.lua filename.xml
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
252
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
253 ]]);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
254 os.exit(1);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
255 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
256
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
257 local file = io.open(arg);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
258 if not file then
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
259 io.stderr:write("Could not open file: ", arg, "\n");
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
260 os.exit(0);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
261 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
262
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
263 local parser = lxp.new(lxp_handlers, ns_separator);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
264 for l in file:lines() do
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
265 parser:parse(l);
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
266 end
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
267 parser:parse();
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
268 parser:close();
a8ce11633597 xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
269 file:close();