@ -11,7 +11,7 @@ if not have_async then
return ;
end
local wrap_async_run = module : require " util " . wrap_async_run ;
local async_handler_wrapper = module : require " util " . async_handler_wrapper ;
-- Options
local poltergeist_component
@ -175,7 +175,7 @@ module:hook(
-- @return GET response, containing a json with response details
function handle_create_poltergeist ( event )
if ( not event.request . url.query ) then
return 400 ;
return { status_code = 400 ; } ;
end
local params = parse ( event.request . url.query ) ;
@ -189,7 +189,7 @@ function handle_create_poltergeist (event)
local session = { } ;
if not verify_token ( params [ " token " ] , room_name , group , session ) then
return 403 ;
return { status_code = 403 ; } ;
end
-- If the provided room conference doesn't exist then we
@ -197,7 +197,7 @@ function handle_create_poltergeist (event)
local room = get_room ( room_name , group ) ;
if ( not room ) then
log ( " error " , " no room found %s " , room_name ) ;
return 404 ;
return { status_code = 404 ; } ;
end
-- If the poltergiest is already in the conference then it will
@ -210,7 +210,7 @@ function handle_create_poltergeist (event)
username ,
room_name
) ;
return 202 ;
return { status_code = 202 ; } ;
end
local context = {
@ -228,7 +228,7 @@ function handle_create_poltergeist (event)
end
poltergeist.add_to_muc ( room , user_id , name , avatar , context , status , resources )
return 200 ;
return { status_code = 200 ; } ;
end
--- Handles request for updating poltergeists status
@ -236,7 +236,7 @@ end
-- @return GET response, containing a json with response details
function handle_update_poltergeist ( event )
if ( not event.request . url.query ) then
return 400 ;
return { status_code = 400 ; } ;
end
local params = parse ( event.request . url.query ) ;
@ -252,18 +252,18 @@ function handle_update_poltergeist (event)
end
if not verify_token ( params [ " token " ] , room_name , group , { } ) then
return 403 ;
return { status_code = 403 ; } ;
end
local room = get_room ( room_name , group ) ;
if ( not room ) then
log ( " error " , " no room found %s " , room_name ) ;
return 404 ;
return { status_code = 404 ; } ;
end
local username = poltergeist.get_username ( room , user_id ) ;
if ( not username ) then
return 404 ;
return { status_code = 404 ; } ;
end
local call_details = {
@ -273,11 +273,11 @@ function handle_update_poltergeist (event)
local nick = poltergeist.create_nick ( username ) ;
if ( not poltergeist.occupies ( room , nick ) ) then
return 404 ;
return { status_code = 404 ; } ;
end
poltergeist.update ( room , nick , status , call_details ) ;
return 200 ;
return { status_code = 200 ; } ;
end
--- Handles remove poltergeists
@ -285,7 +285,7 @@ end
-- @return GET response, containing a json with response details
function handle_remove_poltergeist ( event )
if ( not event.request . url.query ) then
return 400 ;
return { status_code = 400 ; } ;
end
local params = parse ( event.request . url.query ) ;
@ -294,27 +294,27 @@ function handle_remove_poltergeist (event)
local group = params [ " group " ] ;
if not verify_token ( params [ " token " ] , room_name , group , { } ) then
return 403 ;
return { status_code = 403 ; } ;
end
local room = get_room ( room_name , group ) ;
if ( not room ) then
log ( " error " , " no room found %s " , room_name ) ;
return 404 ;
return { status_code = 404 ; } ;
end
local username = poltergeist.get_username ( room , user_id ) ;
if ( not username ) then
return 404 ;
return { status_code = 404 ; } ;
end
local nick = poltergeist.create_nick ( username ) ;
if ( not poltergeist.occupies ( room , nick ) ) then
return 404 ;
return { status_code = 404 ; } ;
end
poltergeist.remove ( room , nick , false ) ;
return 200 ;
return { status_code = 200 ; } ;
end
log ( " info " , " Loading poltergeist service " ) ;
@ -323,8 +323,8 @@ module:provides("http", {
default_path = " / " ;
name = " poltergeist " ;
route = {
[ " GET /poltergeist/create " ] = function ( event ) return wrap_async_run ( event , handle_create_poltergeist ) end ;
[ " GET /poltergeist/update " ] = function ( event ) return wrap_async_run ( event , handle_update_poltergeist ) end ;
[ " GET /poltergeist/remove " ] = function ( event ) return wrap_async_run ( event , handle_remove_poltergeist ) end ;
[ " GET /poltergeist/create " ] = function ( event ) return async_handler_wrapper ( event , handle_create_poltergeist ) end ;
[ " GET /poltergeist/update " ] = function ( event ) return async_handler_wrapper ( event , handle_update_poltergeist ) end ;
[ " GET /poltergeist/remove " ] = function ( event ) return async_handler_wrapper ( event , handle_remove_poltergeist ) end ;
} ;
} ) ;