Comparison

plugins/mod_pubsub/pubsub.lib.lua @ 8337:dc4ea43ac463

mod_pubsub: Add support for Create and Configure
author Kim Alvefur <zash@zash.se>
date Wed, 18 Oct 2017 09:08:16 +0200
parent 8336:587305c0ff85
child 8338:30d8157391e9
comparison
equal deleted inserted replaced
8336:587305c0ff85 8337:dc4ea43ac463
120 end 120 end
121 121
122 function handlers.set_create(origin, stanza, create, service) 122 function handlers.set_create(origin, stanza, create, service)
123 local node = create.attr.node; 123 local node = create.attr.node;
124 local ok, ret, reply; 124 local ok, ret, reply;
125 local config;
126 local configure = stanza.tags[1]:get_child("configure");
127 if configure then
128 local config_form = config:get_child("x", "jabber:x:data");
129 if not config_form then
130 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform"));
131 return true;
132 end
133 local form_data, err = node_config_form:data(config_form);
134 if not form_data then
135 origin.send(st.error_reply(stanza, "modify", "bad-request", err));
136 return true;
137 end
138 config = {
139 ["max_items"] = tonumber(form_data["pubsub#max_items"]);
140 ["persist_items"] = form_data["pubsub#persist_items"];
141 };
142 end
125 if node then 143 if node then
126 ok, ret = service:create(node, stanza.attr.from); 144 ok, ret = service:create(node, stanza.attr.from, config);
127 if ok then 145 if ok then
128 reply = st.reply(stanza); 146 reply = st.reply(stanza);
129 else 147 else
130 reply = pubsub_error_reply(stanza, ret); 148 reply = pubsub_error_reply(stanza, ret);
131 end 149 end
132 else 150 else
133 repeat 151 repeat
134 node = uuid_generate(); 152 node = uuid_generate();
135 ok, ret = service:create(node, stanza.attr.from); 153 ok, ret = service:create(node, stanza.attr.from, config);
136 until ok or ret ~= "conflict"; 154 until ok or ret ~= "conflict";
137 if ok then 155 if ok then
138 reply = st.reply(stanza) 156 reply = st.reply(stanza)
139 :tag("pubsub", { xmlns = xmlns_pubsub }) 157 :tag("pubsub", { xmlns = xmlns_pubsub })
140 :tag("create", { node = node }); 158 :tag("create", { node = node });