Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List private rooms if valid admin_key was provided. #2161

Merged
merged 3 commits into from
May 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -3551,12 +3551,33 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
if(!room)
continue;
janus_refcount_increase(&room->ref);
if(room->is_private) {
/* Skip private room */
JANUS_LOG(LOG_VERB, "Skipping private room '%s'\n", room->room_name);
janus_refcount_decrease(&room->ref);
continue;
}
if(room->is_private) {
/* only if admin_key isset */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments should start with a capital letter (code style).

if(admin_key != NULL) {
json_t *admin_key_json = json_object_get(root, "admin_key");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you're checking this property any time you hit a private room. I'd just to it once, before iterating on the rooms at all, and this way you know when you need it if a valid key was provided (and return an error right away if it's wrong, rather than adding a goto). You can refer to other methods that use it for that.

/* verify admin_key was provided */
if(admin_key_json != NULL && strlen(json_string_value(admin_key_json)) > 0) {
JANUS_CHECK_SECRET(admin_key, root, "admin_key", error_code, error_cause,
JANUS_VIDEOROOM_ERROR_MISSING_ELEMENT, JANUS_VIDEOROOM_ERROR_INVALID_ELEMENT, JANUS_VIDEOROOM_ERROR_UNAUTHORIZED);
if(error_code != 0) {
JANUS_LOG(LOG_VERB, "No room list, wrong admin_key provided\n");
goto end_loop;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above: this can be done without the loop (the way it's done currently leaks memory, by the way).

}
}
else {
/* Skip private room */
JANUS_LOG(LOG_VERB, "Skipping private room '%s'\n", room->room_name);
janus_refcount_decrease(&room->ref);
continue;
}
}
else {
/* Skip private room */
JANUS_LOG(LOG_VERB, "Skipping private room '%s'\n", room->room_name);
janus_refcount_decrease(&room->ref);
continue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-checking the admin_key you also simplify this duplicate error management.

}
if(!g_atomic_int_get(&room->destroyed)) {
json_t *rl = json_object();
json_object_set_new(rl, "room", string_ids ? json_string(room->room_id_str) : json_integer(room->room_id));
Expand Down Expand Up @@ -3596,6 +3617,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
}
janus_refcount_decrease(&room->ref);
}
end_loop:
janus_mutex_unlock(&rooms_mutex);
response = json_object();
json_object_set_new(response, "videoroom", json_string("success"));
Expand Down