Software /
code /
prosody
Annotate
tools/xep227toprosody.lua @ 4289:1e68721c02f2
Merge 0.7->0.8
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 02 Jun 2011 15:28:12 +0100 |
parent | 3832:8eff6e82570d |
child | 5091:dbc483d06a07 |
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 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- |
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 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 -- ugly workaround for getting datamanager to work outside of prosody :( |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 prosody = { }; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 prosody.platform = "unknown"; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 if os.getenv("WINDIR") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 prosody.platform = "windows"; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 elseif package.config:sub(1,1) == "/" then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 prosody.platform = "posix"; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 local lxp = require "lxp"; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 local st = require "util.stanza"; |
3831
93ea0f9622a1
tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
39 local xmppstream = require "util.xmppstream"; |
93ea0f9622a1
tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
40 local new_xmpp_handlers = xmppstream.new_sax_handlers; |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 local dm = require "util.datamanager" |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 dm.set_data_path("data"); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 |
3831
93ea0f9622a1
tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
44 local ns_separator = xmppstream.ns_separator; |
93ea0f9622a1
tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
45 local ns_pattern = xmppstream.ns_pattern; |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 |
3832
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
47 local xmlns_xep227 = "http://www.xmpp.org/extensions/xep-0227.html#ns"; |
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
48 |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 ----------------------------------------------------------------------- |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 function store_vcard(username, host, stanza) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 -- create or update vCard for username@host |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 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
|
54 print("["..(err or "success").."] stored vCard: "..username.."@"..host); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 end |
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_password(username, host, password) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 -- create or update account 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, "accounts", {password = password}); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 print("["..(err or "success").."] stored account: "..username.."@"..host.." = "..password); |
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_roster(username, host, roster_items) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 -- 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
|
65 local roster = dm.load(username, host, "roster") or {}; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 -- merge imported roster-items with loaded roster |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 for item_tag in roster_items:childtags() do |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 -- jid for this roster-item |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 local item_jid = item_tag.attr.jid |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 -- validate item stanzas |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 if (item_tag.name == "item") and (item_jid ~= "") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 -- prepare roster item |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 -- TODO: is the subscription attribute optional? |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 local item = {subscription = item_tag.attr.subscription, groups = {}}; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 -- optional: give roster item a real name |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 if item_tag.attr.name then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 item.name = item_tag.attr.name; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 -- optional: iterate over group stanzas inside item stanza |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 for group_tag in item_tag:childtags() do |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 local group_name = group_tag:get_text(); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 if (group_tag.name == "group") and (group_name ~= "") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 item.groups[group_name] = true; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 else |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 print("[error] invalid group stanza: "..group_tag:pretty_print()); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 -- store item in roster |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 roster[item_jid] = item; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 print("[success] roster entry: " ..username.."@"..host.." - "..item_jid); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 else |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 print("[error] invalid roster stanza: " ..item_tag:pretty_print()); |
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 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 -- store merged roster-table |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 local ret, err = dm.store(username, host, "roster", roster); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 print("["..(err or "success").."] stored roster: " ..username.."@"..host); |
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 function store_private(username, host, private_items) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 local private = dm.load(username, host, "private") or {}; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 for ch in private_items:childtags() do |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 --print("private :"..ch:pretty_print()); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 private[ch.name..":"..ch.attr.xmlns] = st.preserialize(ch); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 print("[success] private item: " ..username.."@"..host.." - "..ch.name); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 local ret, err = dm.store(username, host, "private", private); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 print("["..(err or "success").."] stored private: " ..username.."@"..host); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 function store_offline_messages(username, host, offline_messages) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 -- TODO: maybe use list_load(), append and list_store() instead |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 -- of constantly reopening the file with list_append()? |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 for ch in offline_messages:childtags() do |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 --print("message :"..ch:pretty_print()); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 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
|
118 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
|
119 end |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 function store_subscription_request(username, host, presence_stanza) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 local from_bare = presence_stanza.attr.from; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 -- 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
|
127 local roster = dm.load(username, host, "roster") or {}; |
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 local item = roster[from_bare]; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 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
|
131 return; -- already subscribed, do nothing |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 -- add to table of pending subscriptions |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 if not roster.pending then roster.pending = {}; end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 roster.pending[from_bare] = true; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 -- store updated roster-table |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 local ret, err = dm.store(username, host, "roster", roster); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 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
|
141 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 |
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 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 local curr_host = ""; |
2508
fed7f19db0da
xep227toprosody: Fixed some global accesses.
Waqas Hussain <waqas20@gmail.com>
parents:
2507
diff
changeset
|
146 local user_name = ""; |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 |
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 local cb = { |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
150 stream_tag = "user", |
3832
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
151 stream_ns = xmlns_xep227, |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 }; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 function cb.streamopened(session, attr) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 session.notopen = false; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 user_name = attr.name; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 store_password(user_name, curr_host, attr.password); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 function cb.streamclosed(session) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
159 session.notopen = true; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 user_name = ""; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 function cb.handlestanza(session, stanza) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 --print("Parsed stanza "..stanza.name.." xmlns: "..(stanza.attr.xmlns or "")); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 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
|
165 store_vcard(user_name, curr_host, stanza); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 elseif (stanza.name == "query") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 if (stanza.attr.xmlns == "jabber:iq:roster") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 store_roster(user_name, curr_host, stanza); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 elseif (stanza.attr.xmlns == "jabber:iq:private") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 store_private(user_name, curr_host, stanza); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
171 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
172 elseif (stanza.name == "offline-messages") then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
173 store_offline_messages(user_name, curr_host, stanza); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
174 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
|
175 store_subscription_request(user_name, curr_host, stanza); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
176 else |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
177 print("UNHANDLED stanza "..stanza.name.." xmlns: "..(stanza.attr.xmlns or "")); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 |
3831
93ea0f9622a1
tools/xep227toprosody.lua: Convert to use util.xmppstream
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
181 local user_handlers = new_xmpp_handlers({ notopen = true }, cb); |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
183 ----------------------------------------------------------------------- |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
184 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 local lxp_handlers = { |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 --count = 0 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 }; |
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 -- 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
|
190 function lxp_handlers.StartElement(parser, elementname, attributes) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 local curr_ns, name = elementname:match(ns_pattern); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
192 if name == "" then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
193 curr_ns, name = "", curr_ns; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
194 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
195 --io.write("+ ", string.rep(" ", count), name, " (", curr_ns, ")", "\n") |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
196 --count = count + 1; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
197 if curr_host ~= "" then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
198 -- forward to xmlhandlers |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
199 user_handlers:StartElement(elementname, attributes); |
3832
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
200 elseif (curr_ns == xmlns_xep227) and (name == "host") then |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
201 curr_host = attributes["jid"]; -- start of host element |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
202 print("Begin parsing host "..curr_host); |
3832
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
203 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
|
204 io.stderr:write("Unhandled XML element: ", name, "\n"); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
205 os.exit(1); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
206 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
207 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
208 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
209 -- 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
|
210 function lxp_handlers.EndElement(parser, elementname) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
211 local curr_ns, name = elementname:match(ns_pattern); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
212 if name == "" then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
213 curr_ns, name = "", curr_ns; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
214 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
215 --count = count - 1; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
216 --io.write("- ", string.rep(" ", count), name, " (", curr_ns, ")", "\n") |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
217 if curr_host ~= "" then |
3832
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
218 if (curr_ns == xmlns_xep227) and (name == "host") then |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
219 print("End parsing host "..curr_host); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
220 curr_host = "" -- end of host element |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
221 else |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
222 -- forward to xmlhandlers |
2508
fed7f19db0da
xep227toprosody: Fixed some global accesses.
Waqas Hussain <waqas20@gmail.com>
parents:
2507
diff
changeset
|
223 user_handlers:EndElement(elementname); |
2507
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
224 end |
3832
8eff6e82570d
tools/xep227toprosody.lua: Rename ns_xep227 to xmlns_xep227 for consistency with main Prosody code
Matthew Wild <mwild1@gmail.com>
parents:
3831
diff
changeset
|
225 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
|
226 io.stderr:write("Unhandled XML element: ", name, "\n"); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
227 os.exit(1); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
228 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
229 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
230 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
231 function lxp_handlers.CharacterData(parser, string) |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
232 if curr_host ~= "" then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
233 -- forward to xmlhandlers |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
234 user_handlers:CharacterData(string); |
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 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
237 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
238 ----------------------------------------------------------------------- |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
239 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
240 local arg = ...; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
241 local help = "/? -? ? /h -h /help -help --help"; |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
242 if not arg or help:find(arg, 1, true) then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
243 print([[XEP-227 importer for Prosody |
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 Usage: xep227toprosody.lua filename.xml |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
246 |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
247 ]]); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
248 os.exit(1); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
249 end |
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 local file = io.open(arg); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
252 if not file then |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
253 io.stderr:write("Could not open file: ", arg, "\n"); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
254 os.exit(0); |
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 parser = lxp.new(lxp_handlers, ns_separator); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
258 for l in file:lines() do |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
259 parser:parse(l); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
260 end |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
261 parser:parse(); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
262 parser:close(); |
a8ce11633597
xep227toprosody: Initial commit (thanks stefan).
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
263 file:close(); |