Skip to content

Commit

Permalink
Fix null references (#853)
Browse files Browse the repository at this point in the history
* fix: Add a null check when accessing chatRoom.

* ref: Simplify code.

* fix: Mark getChatRoom as nullable.

* fix: Add thread safe null checks around jingleSession.

* fix: Fix more nullable references.
  • Loading branch information
bgrozev authored Dec 17, 2021
1 parent cf515cf commit 04c1143
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface JitsiMeetConference
* Returns <tt>ChatRoom2</tt> instance for the MUC this instance is
* currently in or <tt>null</tt> if it isn't in any.
*/
ChatRoom getChatRoom();
@Nullable ChatRoom getChatRoom();

default JibriRecorder getJibriRecorder()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ private void joinTheRoom()
{
logger.info("Joining " + roomName);

chatRoom = getClientXmppProvider().findOrCreateRoom(roomName);
ChatRoom chatRoom = getClientXmppProvider().findOrCreateRoom(roomName);
this.chatRoom = chatRoom;
chatRoom.addListener(chatRoomListener);

AuthenticationAuthority authenticationAuthority = jicofoServices.getAuthenticationAuthority();
Expand All @@ -465,6 +466,7 @@ else if (ConferenceConfig.config.enableAutoOwner())
JigasiConfig.config.xmppConnectionName()
),
this,
chatRoom,
jicofoServices.getXmppServices().getJigasiDetector(),
logger);

Expand Down Expand Up @@ -827,9 +829,9 @@ private void terminateParticipant(

synchronized (participantLock)
{
if (participant.isSessionEstablished())
JingleSession jingleSession = participant.getJingleSession();
if (jingleSession != null)
{
JingleSession jingleSession = participant.getJingleSession();

jingle.terminateSession(jingleSession, reason, message, sendSessionTerminate);

Expand Down Expand Up @@ -1720,6 +1722,7 @@ public void onInviteFailed(ParticipantInviteRunnable channelAllocator)
* {@inheritDoc}
*/
@Override
@Nullable
public ChatRoom getChatRoom()
{
return chatRoom;
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/org/jitsi/jicofo/conference/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,6 @@ public ConferenceSourceMap getSources()
return conference == null ? new ConferenceSourceMap() : conference.getSourcesForParticipant(this);
}

/**
* @return {@code true} if the Jingle session with this participant has
* been established.
*/
public boolean isSessionEstablished()
{
return jingleSession != null;
}

/**
* Add a set of remote sources, which are to be signaled to the remote side. The sources may be signaled
* immediately, or queued to be signaled later.
Expand All @@ -440,7 +431,8 @@ public void addRemoteSources(ConferenceSourceMap sources)
sources = sources.copy().stripByMediaType(getSupportedMediaTypes());
}

if (!isSessionEstablished())
JingleSession jingleSession = getJingleSession();
if (jingleSession == null)
{
logger.debug("No Jingle session yet, queueing source-add.");
remoteSourcesQueue.sourceAdd(sources);
Expand All @@ -467,7 +459,7 @@ public void addRemoteSources(ConferenceSourceMap sources)
}
jingle.sendAddSourceIQ(
sources,
getJingleSession(),
jingleSession,
ConferenceConfig.config.getUseJsonEncodedSources() && supportsJsonEncodedSources());
}
}
Expand Down Expand Up @@ -527,7 +519,8 @@ public void removeRemoteSources(ConferenceSourceMap sources)
sources = sources.copy().stripByMediaType(getSupportedMediaTypes());
}

if (!isSessionEstablished())
JingleSession jingleSession = getJingleSession();
if (jingleSession == null)
{
logger.debug("No Jingle session yet, queueing source-remove.");
remoteSourcesQueue.sourceRemove(sources);
Expand All @@ -554,7 +547,7 @@ public void removeRemoteSources(ConferenceSourceMap sources)
}
jingle.sendRemoveSourceIQ(
sources,
getJingleSession(),
jingleSession,
ConferenceConfig.config.getUseJsonEncodedSources() && supportsJsonEncodedSources());
}
}
Expand All @@ -571,9 +564,10 @@ public void sendQueuedRemoteSources()
return;
}

if (!isSessionEstablished())
JingleSession jingleSession = getJingleSession();
if (jingleSession == null)
{
logger.warn("Can not singal remote sources, Jingle session not established.");
logger.warn("Can not signal remote sources, Jingle session not established.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class TranscriberManager
*/
public TranscriberManager(@NotNull XmppProvider xmppProvider,
@NotNull JitsiMeetConferenceImpl conference,
@NotNull ChatRoom chatRoom,
JigasiDetector jigasiDetector,
@NotNull Logger parentLogger)
{
Expand All @@ -101,7 +102,7 @@ public TranscriberManager(@NotNull XmppProvider xmppProvider,
this.connection = xmppProvider.getXmppConnection();

this.conference = conference;
this.chatRoom = conference.getChatRoom();
this.chatRoom = chatRoom;
chatRoom.addListener(chatRoomListener);
this.jigasiDetector = jigasiDetector;
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/kotlin/org/jitsi/jicofo/xmpp/AvModerationHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ class AvModerationHandler(
if (incomingJson["type"] == "av_moderation") {
val conferenceJid = JidCreate.entityBareFrom(incomingJson["room"]?.toString())

val conference = conferenceStore.getConference(conferenceJid) ?: return@execute Unit.also {
logger.warn("Not processing message for not existing conference conferenceJid=$conferenceJid")
}
val conference = conferenceStore.getConference(conferenceJid)
?: throw IllegalStateException("Conference $conferenceJid does not exist.")
val chatRoom = conference.chatRoom
?: throw IllegalStateException("Conference has no associated chatRoom.")

val enabled = incomingJson["enabled"] as Boolean?

if (enabled != null) {
val mediaType = MediaType.parseString(incomingJson["mediaType"] as String)
val oldEnabledValue = conference.chatRoom.isAvModerationEnabled(mediaType)
conference.chatRoom.setAvModerationEnabled(mediaType, enabled)
val oldEnabledValue = chatRoom.isAvModerationEnabled(mediaType)
chatRoom.setAvModerationEnabled(mediaType, enabled)
if (oldEnabledValue != enabled && enabled) {
logger.info(
"Moderation had been enabled for conferenceJid=$conferenceJid, by=${
Expand All @@ -88,14 +89,13 @@ class AvModerationHandler(
conference.muteAllParticipants(mediaType)
}
} else {
val lists = incomingJson["whitelists"]?.let { parseAsMapOfStringToListOfString(it) }
if (lists != null) {
conference.chatRoom.updateAvModerationWhitelists(lists)
incomingJson["whitelists"]?.let {
chatRoom.updateAvModerationWhitelists(parseAsMapOfStringToListOfString(it))
}
}
}
} catch (e: Exception) {
logger.warn("Cannot parse json for av_moderation coming from ${stanza.from}", e)
logger.warn("Failed to process av_moderation request from ${stanza.from}", e)
}
}
}
Expand Down
23 changes: 7 additions & 16 deletions src/main/kotlin/org/jitsi/jicofo/xmpp/ConferenceIqHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ class ConferenceIqHandler(
* which should be returned to the user
*/
private fun processExtensions(query: ConferenceIq, response: ConferenceIq?, roomExists: Boolean): IQ? {
val peerJid = query.from
var identity: String? = null
val room = query.room
val isBreakoutRoom = breakoutAddress != null && room.domain == breakoutAddress

Expand All @@ -120,27 +118,20 @@ class ConferenceIqHandler(
val authErrorOrResponse = authAuthority.processAuthentication(query, response)

// Checks if authentication module wants to cancel further
// processing and eventually returns it's response
// processing and eventually returns its response
if (authErrorOrResponse != null) {
return authErrorOrResponse
}
// Only authenticated users are allowed to create new rooms
if (!roomExists) {
// If a breakout room exists and all members had left the main room, skip
// If an associated breakout room exists and all members have left the main room, skip
// authentication for the main room so users can go back to it.
var breakoutRoomExists: Boolean = false
for (conference in focusManager.getConferences()) {
if (conference.chatRoom.isBreakoutRoom && room.toString() == conference.chatRoom.mainRoom) {
breakoutRoomExists = true
break
}
val breakoutRoomExists = focusManager.conferences.any { conference ->
conference.chatRoom?.let { it.isBreakoutRoom && room.toString() == it.mainRoom } ?: false
}
if (!breakoutRoomExists) {
identity = authAuthority.getUserIdentity(peerJid)
if (identity == null) {
// Error not authorized
return ErrorFactory.createNotAuthorizedError(query, "not authorized user domain")
}
if (!breakoutRoomExists && authAuthority.getUserIdentity(query.from) == null) {
// Error not authorized
return ErrorFactory.createNotAuthorizedError(query, "not authorized user domain")
}
}
}
Expand Down

0 comments on commit 04c1143

Please sign in to comment.