mod_pubsub_post/mod_pubsub_post.lua
changeset 3019 338b7c808ecc
parent 3018 72dbc9b66de8
child 3020 3f4e2340bfdc
equal deleted inserted replaced
3018:72dbc9b66de8 3019:338b7c808ecc
    24 		return error_mapping[err] or 500;
    24 		return error_mapping[err] or 500;
    25 	end
    25 	end
    26 	return 202;
    26 	return 202;
    27 end
    27 end
    28 
    28 
       
    29 local function publish_atom(node, feed)
       
    30 	for entry in feed:childtags("entry") do
       
    31 		local item_id = entry:get_child_text("id");
       
    32 		if not item_id then
       
    33 			item_id = uuid_generate();
       
    34 			entry:tag("id"):text(item_id):up();
       
    35 		end
       
    36 		if not entry:get_child_text("published") then
       
    37 			entry:tag("published"):text(timestamp_generate()):up();
       
    38 		end
       
    39 		local resp = publish_payload(node, item_id, entry);
       
    40 		if resp ~= 202 then return resp; end
       
    41 	end
       
    42 	return 202;
       
    43 end
       
    44 
    29 local function handle_xml(node, payload)
    45 local function handle_xml(node, payload)
    30 	local xmlpayload, err = xml.parse(payload);
    46 	local xmlpayload, err = xml.parse(payload);
    31 	if not xmlpayload then
    47 	if not xmlpayload then
    32 		module:log("debug", "XML parse error: %s\n%q", err, payload);
    48 		module:log("debug", "XML parse error: %s\n%q", err, payload);
    33 		return { status_code = 400, body = tostring(err) };
    49 		return { status_code = 400, body = tostring(err) };
    34 	end
    50 	end
    35 	return publish_payload(node, "current", xmlpayload);
    51 	if xmlpayload.attr.xmlns == "http://www.w3.org/2005/Atom" and xmlpayload.name == "feed" then
       
    52 		return publish_atom(node, xmlpayload);
       
    53 	else
       
    54 		return publish_payload(node, "current", xmlpayload);
       
    55 	end
    36 end
    56 end
    37 
    57 
    38 function handle_POST(event, path)
    58 function handle_POST(event, path)
    39 	local request = event.request;
    59 	local request = event.request;
    40 	module:log("debug", "Handling POST: \n%s\n", tostring(request.body));
    60 	module:log("debug", "Handling POST: \n%s\n", tostring(request.body));