Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat: Move to use cjson everywhere.
damenchoa76f9d548b2c
diff --git a/resources/prosody-plugins/mod_av_moderation_component.lua b/resources/prosody-plugins/mod_av_moderation_component.luaindex 8a657097c2..efa61a4da7 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;+ endif jid thensend_json_message(jid, body_json_str)@@ -75,12 +80,23 @@ function notify_whitelist_change(jid, moderators, room, mediaType, removed)body_json.removed = true;endbody_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 thenbody_json.approved = true; -- we want to send to participants only that they were approved to unmuteend- 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;+ endfor _, occupant in room:each_occupant() doif 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 addingdiff --git a/resources/prosody-plugins/mod_conference_duration_component.lua b/resources/prosody-plugins/mod_conference_duration_component.luaindex bf26587d3c..d643dc23c7 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 updatelocal 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_muc_breakout_rooms.lua b/resources/prosody-plugins/mod_muc_breakout_rooms.luaindex d255dc7d2a..c3d2850e4f 100644--- a/resources/prosody-plugins/mod_muc_breakout_rooms.lua+++ b/resources/prosody-plugins/mod_muc_breakout_rooms.lua@@ -29,7 +29,7 @@ endlocal 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)endend- 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() doif jid_node(occupant.jid) ~= 'focus' thensend_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;enddiff --git a/resources/prosody-plugins/mod_muc_census.lua b/resources/prosody-plugins/mod_muc_census.luaindex 2b26d02be2..88f66a9657 100644--- a/resources/prosody-plugins/mod_muc_census.lua+++ b/resources/prosody-plugins/mod_muc_census.lua@@ -19,7 +19,7 @@-- network filterslocal 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.luaindex 3a761fadb4..0920c71b96 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; }+ endlocal 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.luaindex 9a5ab7acc4..00b54f6d74 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; }enddiff --git a/resources/prosody-plugins/mod_muc_lobby_rooms.lua b/resources/prosody-plugins/mod_muc_lobby_rooms.luaindex b8b0899ed2..92d95e1aa7 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());endenddiff --git a/resources/prosody-plugins/mod_muc_password_check.lua b/resources/prosody-plugins/mod_muc_password_check.luaindex 5f948a8e7a..7a3c5409e8 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.luaindex 7143e77c6d..757d5cd47d 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.luaindex 6b68688aca..5494a6f95d 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 thenreturn 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);+ endreturn nil;endreturn 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.luaindex bc6229bb46..62db02da60 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 responsefunction 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;enddiff --git a/resources/prosody-plugins/mod_room_metadata_component.lua b/resources/prosody-plugins/mod_room_metadata_component.luaindex 0d101c0ec7..2403496231 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 functionsfunction 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;enddiff --git a/resources/prosody-plugins/mod_speakerstats_component.lua b/resources/prosody-plugins/mod_speakerstats_component.luaindex 0d4b040a3d..3487b17fd6 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);+ endendenddiff --git a/resources/prosody-plugins/mod_turncredentials_http.lua b/resources/prosody-plugins/mod_turncredentials_http.luaindex 81b301b0df..1aaef2ec45 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 querydiff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.luaindex 85a08c600a..5136261011 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, timebody_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] thenvisitors_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_modulif json_data == nil thenreturn;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);+ endreturn;end