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