Mercurial > prosody-modules
comparison mod_pubsub_post/mod_pubsub_post.lua @ 3018:727a8beeb5c3
mod_pubsub_post: Add an option for what to use as pubsub 'actor'
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 20 May 2018 03:03:59 +0200 |
| parents | 8e48c0b233e0 |
| children | af73963cf1dd |
comparison
equal
deleted
inserted
replaced
| 3017:8e48c0b233e0 | 3018:727a8beeb5c3 |
|---|---|
| 65 else | 65 else |
| 66 return publish_payload(node, actor, "current", xmlpayload); | 66 return publish_payload(node, actor, "current", xmlpayload); |
| 67 end | 67 end |
| 68 end | 68 end |
| 69 | 69 |
| 70 local actor_source = module:get_option_string("pubsub_post_actor", "superuser"); | |
| 71 | |
| 70 function handle_POST(event, path) | 72 function handle_POST(event, path) |
| 71 local request = event.request; | 73 local request = event.request; |
| 72 module:log("debug", "Handling POST: \n%s\n", tostring(request.body)); | 74 module:log("debug", "Handling POST: \n%s\n", tostring(request.body)); |
| 73 | 75 |
| 74 local content_type = request.headers.content_type or "application/octet-stream"; | 76 local content_type = request.headers.content_type or "application/octet-stream"; |
| 75 local actor = true; | 77 local actor = true; |
| 78 | |
| 79 if actor_source == "request.ip" then | |
| 80 actor = request.ip or request.conn:ip(); | |
| 81 elseif actor_source ~= "superuser" then | |
| 82 module:log("error", "pubsub_post_actor set to unsupported value %q", actor_source); | |
| 83 return 500; | |
| 84 end | |
| 76 | 85 |
| 77 if content_type == "application/xml" or content_type:sub(-4) == "+xml" then | 86 if content_type == "application/xml" or content_type:sub(-4) == "+xml" then |
| 78 return handle_xml(path, actor, request.body); | 87 return handle_xml(path, actor, request.body); |
| 79 elseif content_type == "application/json" or content_type:sub(-5) == "+json" then | 88 elseif content_type == "application/json" or content_type:sub(-5) == "+json" then |
| 80 return handle_json(path, actor, request.body); | 89 return handle_json(path, actor, request.body); |
