diff --git a/resources/prosody-plugins/mod_av_moderation_component.lua b/resources/prosody-plugins/mod_av_moderation_component.lua index 8a657097c25d..efa61a4da716 100644 --- a/resources/prosody-plugins/mod_av_moderation_component.lua +++ b/resources/prosody-plugins/mod_av_moderation_component.lua @@ -5,7 +5,7 @@ local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite; local room_jid_match_rewrite = util.room_jid_match_rewrite; local process_host_module = util.process_host_module; local array = require "util.array"; -local json = require 'util.json'; +local json = require 'cjson.safe'; local st = require 'util.stanza'; local muc_component_host = module:get_option_string('muc_component'); @@ -49,7 +49,12 @@ function notify_occupants_enable(jid, enable, room, actorJid, mediaType) body_json.room = internal_room_jid_match_rewrite(room.jid); body_json.actor = actorJid; body_json.mediaType = mediaType; - local body_json_str = json.encode(body_json); + local body_json_str, error = json.encode(body_json); + + if not body_json_str then + module:log('error', 'error encoding json room:%s error:%s', room.jid, error); + return; + end if jid then send_json_message(jid, body_json_str) @@ -75,12 +80,23 @@ function notify_whitelist_change(jid, moderators, room, mediaType, removed) body_json.removed = true; end body_json.mediaType = mediaType; - local moderators_body_json_str = json.encode(body_json); + local moderators_body_json_str, error = json.encode(body_json); + + if not moderators_body_json_str then + module:log('error', 'error encoding moderator json room:%s error:%s', room.jid, error); + return; + end + body_json.whitelists = nil; if not removed then body_json.approved = true; -- we want to send to participants only that they were approved to unmute end - local participant_body_json_str = json.encode(body_json); + local participant_body_json_str, error = json.encode(body_json); + + if not participant_body_json_str then + module:log('error', 'error encoding participant json room:%s error:%s', room.jid, error); + return; + end for _, occupant in room:each_occupant() do if moderators and occupant.role == 'moderator' then @@ -110,7 +126,13 @@ function notify_jid_approved(jid, from, room, mediaType) body_json.mediaType = mediaType; body_json.from = from; - send_json_message(jid, json.encode(body_json)); + local json_message, error = json.encode(body_json); + if not json_message then + module:log('error', 'skip sending json message to:%s error:%s', jid, error); + return; + end + + send_json_message(jid, json_message); end -- receives messages from clients to the component sending A/V moderation enable/disable commands or adding diff --git a/resources/prosody-plugins/mod_conference_duration_component.lua b/resources/prosody-plugins/mod_conference_duration_component.lua index bf26587d3cd3..d643dc23c74c 100644 --- a/resources/prosody-plugins/mod_conference_duration_component.lua +++ b/resources/prosody-plugins/mod_conference_duration_component.lua @@ -1,7 +1,7 @@ -- DEPRECATED and will be removed, giving time for mobile clients to update local st = require "util.stanza"; local socket = require "socket"; -local json = require "util.json"; +local json = require 'cjson.safe'; local it = require "util.iterators"; local process_host_module = module:require "util".process_host_module; diff --git a/resources/prosody-plugins/mod_jibri_session.lua b/resources/prosody-plugins/mod_jibri_session.lua new file mode 100644 index 000000000000..5fb0f585005f --- /dev/null +++ b/resources/prosody-plugins/mod_jibri_session.lua @@ -0,0 +1,69 @@ +local json = require 'cjson'; + +local util = module:require 'util'; +local room_jid_match_rewrite = util.room_jid_match_rewrite; +local get_room_from_jid = util.get_room_from_jid; + +-- This needs to be attached to the main virtual host and the virtual host where jicofo is connected and authenticated. +-- The first pass is the iq coming from the client where we get the creator and attach it to the app_data. +-- The second pass is jicofo approving that and inviting jibri where we attach the session_id information to app_data +local function attachJibriSessionId(event) +local stanza = event.stanza; + if stanza.name == "iq" then + local jibri = stanza:get_child('jibri', 'http://jitsi.org/protocol/jibri'); + if jibri then + if jibri.attr.action == 'start' then + + local update_app_data = false; + local app_data = jibri.attr.app_data; + if app_data then + app_data = json.decode(app_data); + else + app_data = {}; + end + if app_data.file_recording_metadata == nil then + app_data.file_recording_metadata = {}; + end + + if jibri.attr.room then + local jibri_room = jibri.attr.room; + jibri_room = room_jid_match_rewrite(jibri_room) + local room = get_room_from_jid(jibri_room); + if room then + local conference_details = {}; + conference_details["session_id"] = room._data.meetingId; + app_data.file_recording_metadata.conference_details = conference_details; + update_app_data = true; + end + else + -- no room is because the iq received by the initiator in the room + local session = event.origin; + -- if a token is provided, add data to app_data + if session ~= nil then + local initiator = {}; + + if session.jitsi_meet_context_user ~= nil then + initiator.id = session.jitsi_meet_context_user.id; + end + if session.jitsi_meet_context_group ~= nil then + initiator.group = session.jitsi_meet_context_group; + end + + app_data.file_recording_metadata.initiator = initiator + update_app_data = true; + end + + end + + if update_app_data then + app_data = json.encode(app_data); + jibri.attr.app_data = app_data; + jibri:up() + stanza:up() + end + end + end + end +end + +module:hook('pre-iq/full', attachJibriSessionId); diff --git a/resources/prosody-plugins/mod_muc_breakout_rooms.lua b/resources/prosody-plugins/mod_muc_breakout_rooms.lua index d255dc7d2a1f..c3d2850e4fc0 100644 --- a/resources/prosody-plugins/mod_muc_breakout_rooms.lua +++ b/resources/prosody-plugins/mod_muc_breakout_rooms.lua @@ -29,7 +29,7 @@ end local jid_node = require 'util.jid'.node; local jid_host = require 'util.jid'.host; local jid_split = require 'util.jid'.split; -local json = require 'util.json'; +local json = require 'cjson.safe'; local st = require 'util.stanza'; local uuid_gen = require 'util.uuid'.generate; @@ -166,13 +166,18 @@ function broadcast_breakout_rooms(room_jid) end end - local json_msg = json.encode({ + local json_msg, error = json.encode({ type = BREAKOUT_ROOMS_IDENTITY_TYPE, event = JSON_TYPE_UPDATE_BREAKOUT_ROOMS, roomCounter = main_room._data.breakout_rooms_counter, rooms = rooms }); + if not json_msg then + module:log('error', 'not broadcasting breakout room information room:%s error:%s', main_room_jid, error); + return; + end + for _, occupant in main_room:each_occupant() do if jid_node(occupant.jid) ~= 'focus' then send_json_msg(occupant.jid, json_msg) @@ -329,12 +334,16 @@ function on_message(event) local participant_jid = message.attr.participantJid; local target_room_jid = message.attr.roomJid; - local json_msg = json.encode({ + local json_msg, error = json.encode({ type = BREAKOUT_ROOMS_IDENTITY_TYPE, event = JSON_TYPE_MOVE_TO_ROOM_REQUEST, roomJid = target_room_jid }); + if not json_msg then + module:log('error', 'skip sending request room:%s error:%s', room.jid, error); + end + send_json_msg(participant_jid, json_msg) return true; end diff --git a/resources/prosody-plugins/mod_muc_census.lua b/resources/prosody-plugins/mod_muc_census.lua index 2b26d02be25f..88f66a9657a6 100644 --- a/resources/prosody-plugins/mod_muc_census.lua +++ b/resources/prosody-plugins/mod_muc_census.lua @@ -19,7 +19,7 @@ -- network filters local jid = require "util.jid"; -local json = require "util.json"; +local json = require 'cjson.safe'; local iterators = require "util.iterators"; local util = module:require "util"; local is_healthcheck_room = util.is_healthcheck_room; diff --git a/resources/prosody-plugins/mod_muc_jigasi_invite.lua b/resources/prosody-plugins/mod_muc_jigasi_invite.lua index 3a761fadb4d9..0920c71b96f1 100644 --- a/resources/prosody-plugins/mod_muc_jigasi_invite.lua +++ b/resources/prosody-plugins/mod_muc_jigasi_invite.lua @@ -6,7 +6,7 @@ local jid_split = require "util.jid".split; local hashes = require "util.hashes"; local random = require "util.random"; local st = require("util.stanza"); -local json = require "util.json"; +local json = require 'cjson.safe'; local util = module:require "util"; local async_handler_wrapper = util.async_handler_wrapper; local process_host_module = util.process_host_module; @@ -133,7 +133,12 @@ local function handle_jigasi_invite(event) module:log("warn", "Wrong content type: %s or missing payload", request.headers.content_type); return { status_code = 400; } end - local payload = json.decode(request.body); + local payload, error = json.decode(request.body); + + if not payload then + module:log('error', 'Cannot decode json error:%s', error); + return { status_code = 400; } + end local conference = payload["conference"]; local phone_no = payload["phoneNo"]; diff --git a/resources/prosody-plugins/mod_muc_kick_jigasi.lua b/resources/prosody-plugins/mod_muc_kick_jigasi.lua index 9a5ab7acc44d..00b54f6d74db 100644 --- a/resources/prosody-plugins/mod_muc_kick_jigasi.lua +++ b/resources/prosody-plugins/mod_muc_kick_jigasi.lua @@ -8,7 +8,7 @@ local starts_with = util.starts_with; local formdecode = require "util.http".formdecode; local urlencode = require "util.http".urlencode; local jid = require "util.jid"; -local json = require "util.json"; +local json = require 'cjson.safe'; local muc_domain_prefix = module:get_option_string("muc_mapper_domain_prefix", "conference"); @@ -107,9 +107,9 @@ function handle_kick_participant (event) return { status_code = 400; } end - local params = json.decode(request.body); + local params, error = json.decode(request.body); if not params then - module:log("warn", "Missing params"); + module:log("warn", "Missing params error:%s", error); return { status_code = 400; } end diff --git a/resources/prosody-plugins/mod_muc_lobby_rooms.lua b/resources/prosody-plugins/mod_muc_lobby_rooms.lua index b8b0899ed2e7..92d95e1aa78c 100644 --- a/resources/prosody-plugins/mod_muc_lobby_rooms.lua +++ b/resources/prosody-plugins/mod_muc_lobby_rooms.lua @@ -30,7 +30,7 @@ local jid_bare = require 'util.jid'.bare; local jid_prep = require "util.jid".prep; local jid_resource = require "util.jid".resource; local resourceprep = require "util.encodings".stringprep.resourceprep; -local json = require 'util.json'; +local json = require 'cjson.safe'; local filters = require 'util.filters'; local st = require 'util.stanza'; local muc_util = module:require "muc/util"; @@ -80,10 +80,17 @@ function broadcast_json_msg(room, from, json_msg) local occupant = room:get_occupant_by_real_jid(from); if occupant then + local json_msg_str, error = json.encode(json_msg); + + if not json_msg_str then + module:log('error', 'Error broadcasting message room:%s', room.jid, error); + return; + end + room:broadcast_message( st.message({ type = 'groupchat', from = occupant.nick }) :tag('json-message', {xmlns='http://jitsi.org/jitmeet'}) - :text(json.encode(json_msg)):up()); + :text(json_msg_str):up()); end end diff --git a/resources/prosody-plugins/mod_muc_password_check.lua b/resources/prosody-plugins/mod_muc_password_check.lua index 5f948a8e7a6a..7a3c5409e848 100644 --- a/resources/prosody-plugins/mod_muc_password_check.lua +++ b/resources/prosody-plugins/mod_muc_password_check.lua @@ -2,7 +2,7 @@ local inspect = require "inspect"; local formdecode = require "util.http".formdecode; local urlencode = require "util.http".urlencode; local jid = require "util.jid"; -local json = require "util.json"; +local json = require 'cjson.safe'; local util = module:require "util"; local async_handler_wrapper = util.async_handler_wrapper; local starts_with = util.starts_with; @@ -106,9 +106,9 @@ function handle_validate_room_password (event) return { status_code = 400; } end - local params = json.decode(request.body); + local params, error = json.decode(request.body); if not params then - module:log("warn", "Missing params"); + module:log("warn", "Missing params error:%s", error); return { status_code = 400; } end @@ -125,9 +125,15 @@ function handle_validate_room_password (event) return { status_code = error_code; } end + local json_msg_str, error_encode = json.encode({ valid = (room:get_password() == passcode) }); + if not json_msg_str then + module:log('error', 'Cannot encode json room:%s error:%s', room.jid, error_encode); + return { status_code = 400; }; + end + local PUT_response = { headers = { content_type = "application/json"; }; - body = json.encode({ valid = (room:get_password() == passcode) }) + body = json_msg_str; }; -- module:log("debug","Sending response for room password validate: %s", inspect(PUT_response)); @@ -150,11 +156,17 @@ function handle_get_room_password (event) room_details["passcodeProtected"] = room:get_password() ~= nil; room_details["lobbyEnabled"] = room._data ~= nil and room._data.lobbyroom ~= nil; + local json_msg_str, error = json.encode(room_details); + if not json_msg_str then + module:log('error', 'Cannot encode json room:%s error:%s', room.jid, error); + return { status_code = 400; }; + end + local GET_response = { headers = { content_type = "application/json"; }; - body = json.encode(room_details); + body = json_msg_str; }; -- module:log("debug","Sending response for room password: %s", inspect(GET_response)); diff --git a/resources/prosody-plugins/mod_muc_size.lua b/resources/prosody-plugins/mod_muc_size.lua index 7143e77c6d69..757d5cd47df0 100644 --- a/resources/prosody-plugins/mod_muc_size.lua +++ b/resources/prosody-plugins/mod_muc_size.lua @@ -4,7 +4,7 @@ local jid = require "util.jid"; local it = require "util.iterators"; -local json = require "util.json"; +local json = require 'cjson.safe'; local iterators = require "util.iterators"; local array = require"util.array"; diff --git a/resources/prosody-plugins/mod_polls.lua b/resources/prosody-plugins/mod_polls.lua index 6b68688aca9f..5494a6f95d94 100644 --- a/resources/prosody-plugins/mod_polls.lua +++ b/resources/prosody-plugins/mod_polls.lua @@ -2,7 +2,7 @@ -- by keeping track of the state of polls in each room, and sending -- that state to new participants when they join. -local json = require("util.json"); +local json = require 'cjson.safe'; local st = require("util.stanza"); local jid = require "util.jid"; local util = module:require("util"); @@ -22,8 +22,11 @@ local function get_poll_message(stanza) if json_data == nil then return nil; end - local data = json.decode(json_data); + local data, error = json.decode(json_data); if not data or (data.type ~= "new-poll" and data.type ~= "answer-poll") then + if error then + module:log('error', 'Error decoding data error:%s', error); + end return nil; end return data; @@ -192,12 +195,17 @@ module:hook("muc-occupant-joined", function(event) }; end + local json_msg_str, error = json.encode(data); + if not json_msg_str then + module:log('error', 'Error encoding data room:%s error:%s', room.jid, error); + end + local stanza = st.message({ from = room.jid, to = event.occupant.jid }) :tag("json-message", { xmlns = "http://jitsi.org/jitmeet" }) - :text(json.encode(data)) + :text(json_msg_str) :up(); room:route_stanza(stanza); end); diff --git a/resources/prosody-plugins/mod_reservations.lua b/resources/prosody-plugins/mod_reservations.lua index bc6229bb46e9..62db02da6086 100644 --- a/resources/prosody-plugins/mod_reservations.lua +++ b/resources/prosody-plugins/mod_reservations.lua @@ -72,7 +72,7 @@ local jid = require 'util.jid'; local http = require "net.http"; -local json = require "util.json"; +local json = require 'cjson.safe'; local st = require "util.stanza"; local timer = require 'util.timer'; local datetime = require 'util.datetime'; @@ -396,10 +396,10 @@ end -- Ref: https://github.com/jitsi/jicofo/blob/master/doc/reservation.md -- @return nil if invalid, or table with payload parsed from JSON response function RoomReservation:parse_conference_response(response_body) - local data = json.decode(response_body); + local data, error = json.decode(response_body); if data == nil then -- invalid JSON payload - module:log("error", "Invalid JSON response from API - %s", response_body); + module:log("error", "Invalid JSON response from API - %s error:%s", response_body, error); return; end diff --git a/resources/prosody-plugins/mod_room_metadata_component.lua b/resources/prosody-plugins/mod_room_metadata_component.lua index 0d101c0ec7df..2403496231e6 100644 --- a/resources/prosody-plugins/mod_room_metadata_component.lua +++ b/resources/prosody-plugins/mod_room_metadata_component.lua @@ -12,7 +12,7 @@ -- breakout_rooms_component = "breakout.jitmeet.example.com" local jid_node = require 'util.jid'.node; -local json = require 'util.json'; +local json = require 'cjson.safe'; local st = require 'util.stanza'; local util = module:require 'util'; @@ -39,10 +39,16 @@ module:log("info", "Starting room metadata for %s", muc_component_host); -- Utility functions function getMetadataJSON(room) - return json.encode({ + local res, error = json.encode({ type = COMPONENT_IDENTITY_TYPE, metadata = room.jitsiMetadata or {} }); + + if not res then + module:log('error', 'Error encoding data room:%s', room.jid, error); + end + + return res; end -- Putting the information on the config form / disco-info allows us to save @@ -124,9 +130,9 @@ function on_message(event) return false; end - local jsonData = json.decode(messageText); + local jsonData, error = json.decode(messageText); if jsonData == nil then -- invalid JSON - module:log("error", "Invalid JSON message: %s", messageText); + module:log("error", "Invalid JSON message: %s error:%s", messageText, error); return false; end diff --git a/resources/prosody-plugins/mod_speakerstats_component.lua b/resources/prosody-plugins/mod_speakerstats_component.lua index 0d4b040a3d3d..3487b17fd6c8 100644 --- a/resources/prosody-plugins/mod_speakerstats_component.lua +++ b/resources/prosody-plugins/mod_speakerstats_component.lua @@ -6,7 +6,7 @@ local process_host_module = util.process_host_module; local jid_resource = require "util.jid".resource; local st = require "util.stanza"; local socket = require "socket"; -local json = require "util.json"; +local json = require 'cjson.safe'; local um_is_admin = require "core.usermanager".is_admin; local jid_split = require 'util.jid'.split; @@ -264,13 +264,19 @@ function occupant_joined(event) body_json.type = 'speakerstats'; body_json.users = users_json; - local stanza = st.message({ - from = module.host; - to = occupant.jid; }) - :tag("json-message", {xmlns='http://jitsi.org/jitmeet'}) - :text(json.encode(body_json)):up(); + local json_msg_str, error = json.encode(body_json); - room:route_stanza(stanza); + if json_msg_str then + local stanza = st.message({ + from = module.host; + to = occupant.jid; }) + :tag("json-message", {xmlns='http://jitsi.org/jitmeet'}) + :text(json_msg_str):up(); + + room:route_stanza(stanza); + else + module:log('error', 'Error encoding room:%s error:%s', room.jid, error); + end end end diff --git a/resources/prosody-plugins/mod_turncredentials_http.lua b/resources/prosody-plugins/mod_turncredentials_http.lua index 81b301b0df9d..1aaef2ec45d8 100644 --- a/resources/prosody-plugins/mod_turncredentials_http.lua +++ b/resources/prosody-plugins/mod_turncredentials_http.lua @@ -5,7 +5,7 @@ local ext_services = module:depends("external_services"); local get_services = ext_services.get_services; local async_handler_wrapper = module:require "util".async_handler_wrapper; -local json = require "util.json"; +local json = require 'cjson.safe'; --- Handles request for retrieving turn credentials -- @param event the http event, holds the request query diff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.lua index 85a08c600a29..5136261011b1 100644 --- a/resources/prosody-plugins/mod_visitors_component.lua +++ b/resources/prosody-plugins/mod_visitors_component.lua @@ -14,7 +14,7 @@ local is_sip_jibri_join = util.is_sip_jibri_join; local process_host_module = util.process_host_module; local new_id = require 'util.id'.medium; local um_is_admin = require 'core.usermanager'.is_admin; -local json = require 'util.json'; +local json = require 'cjson.safe'; local inspect = require 'inspect'; local MUC_NS = 'http://jabber.org/protocol/muc'; @@ -127,7 +127,13 @@ local function request_promotion_received(room, from_jid, from_vnode, nick, time body_json.on = false; end - local msg_to_send = json.encode(body_json); + local msg_to_send, error = json.encode(body_json); + + if not msg_to_send then + module:log('error', 'Error encoding msg room:%s error:%s', room.jid, error) + return true; + end + if visitors_promotion_requests[room.jid] then visitors_promotion_requests[room.jid][from_jid] = { msg = msg_to_send; @@ -386,9 +392,12 @@ process_host_module(muc_domain_prefix..'.'..muc_domain_base, function(host_modul if json_data == nil then return; end - local data = json.decode(json_data); + local data, error = json.decode(json_data); if not data or data.type ~= 'visitors' or (data.action ~= "promotion-response" and data.action ~= "demote-request") then + if error then + module:log('error', 'Error decoding error:%s', error); + end return; end