Software /
code /
prosody
Comparison
tools/xep227toprosody.lua @ 5091:dbc483d06a07
tools/xep227toprosody.lua: Update childtags calls, replace some with ipairs
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Aug 2012 18:03:40 +0200 |
parent | 3710:59fbe4536c69 |
child | 5696:9fba74a28e0c |
comparison
equal
deleted
inserted
replaced
5090:61c7c53c06d5 | 5091:dbc483d06a07 |
---|---|
62 | 62 |
63 function store_roster(username, host, roster_items) | 63 function store_roster(username, host, roster_items) |
64 -- fetch current roster-table for username@host if he already has one | 64 -- fetch current roster-table for username@host if he already has one |
65 local roster = dm.load(username, host, "roster") or {}; | 65 local roster = dm.load(username, host, "roster") or {}; |
66 -- merge imported roster-items with loaded roster | 66 -- merge imported roster-items with loaded roster |
67 for item_tag in roster_items:childtags() do | 67 for item_tag in roster_items:childtags("item") do |
68 -- jid for this roster-item | 68 -- jid for this roster-item |
69 local item_jid = item_tag.attr.jid | 69 local item_jid = item_tag.attr.jid |
70 -- validate item stanzas | 70 -- validate item stanzas |
71 if (item_tag.name == "item") and (item_jid ~= "") then | 71 if (item_jid ~= "") then |
72 -- prepare roster item | 72 -- prepare roster item |
73 -- TODO: is the subscription attribute optional? | 73 -- TODO: is the subscription attribute optional? |
74 local item = {subscription = item_tag.attr.subscription, groups = {}}; | 74 local item = {subscription = item_tag.attr.subscription, groups = {}}; |
75 -- optional: give roster item a real name | 75 -- optional: give roster item a real name |
76 if item_tag.attr.name then | 76 if item_tag.attr.name then |
77 item.name = item_tag.attr.name; | 77 item.name = item_tag.attr.name; |
78 end | 78 end |
79 -- optional: iterate over group stanzas inside item stanza | 79 -- optional: iterate over group stanzas inside item stanza |
80 for group_tag in item_tag:childtags() do | 80 for group_tag in item_tag:childtags("group") do |
81 local group_name = group_tag:get_text(); | 81 local group_name = group_tag:get_text(); |
82 if (group_tag.name == "group") and (group_name ~= "") then | 82 if (group_name ~= "") then |
83 item.groups[group_name] = true; | 83 item.groups[group_name] = true; |
84 else | 84 else |
85 print("[error] invalid group stanza: "..group_tag:pretty_print()); | 85 print("[error] invalid group stanza: "..group_tag:pretty_print()); |
86 end | 86 end |
87 end | 87 end |
98 print("["..(err or "success").."] stored roster: " ..username.."@"..host); | 98 print("["..(err or "success").."] stored roster: " ..username.."@"..host); |
99 end | 99 end |
100 | 100 |
101 function store_private(username, host, private_items) | 101 function store_private(username, host, private_items) |
102 local private = dm.load(username, host, "private") or {}; | 102 local private = dm.load(username, host, "private") or {}; |
103 for ch in private_items:childtags() do | 103 for _, ch in ipairs(private_items.tags) do |
104 --print("private :"..ch:pretty_print()); | 104 --print("private :"..ch:pretty_print()); |
105 private[ch.name..":"..ch.attr.xmlns] = st.preserialize(ch); | 105 private[ch.name..":"..ch.attr.xmlns] = st.preserialize(ch); |
106 print("[success] private item: " ..username.."@"..host.." - "..ch.name); | 106 print("[success] private item: " ..username.."@"..host.." - "..ch.name); |
107 end | 107 end |
108 local ret, err = dm.store(username, host, "private", private); | 108 local ret, err = dm.store(username, host, "private", private); |
110 end | 110 end |
111 | 111 |
112 function store_offline_messages(username, host, offline_messages) | 112 function store_offline_messages(username, host, offline_messages) |
113 -- TODO: maybe use list_load(), append and list_store() instead | 113 -- TODO: maybe use list_load(), append and list_store() instead |
114 -- of constantly reopening the file with list_append()? | 114 -- of constantly reopening the file with list_append()? |
115 for ch in offline_messages:childtags() do | 115 for ch in offline_messages:childtags("message", "jabber:client") do |
116 --print("message :"..ch:pretty_print()); | 116 --print("message :"..ch:pretty_print()); |
117 local ret, err = dm.list_append(username, host, "offline", st.preserialize(ch)); | 117 local ret, err = dm.list_append(username, host, "offline", st.preserialize(ch)); |
118 print("["..(err or "success").."] stored offline message: " ..username.."@"..host.." - "..ch.attr.from); | 118 print("["..(err or "success").."] stored offline message: " ..username.."@"..host.." - "..ch.attr.from); |
119 end | 119 end |
120 end | 120 end |