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

Conversation

robby2016
Copy link
Contributor

This simple enhancement allows admins to list private rooms as well using the existing "list" request.
To make this fully backwards compatible, if no "admin_key" is provided the list gets returned like before (without the private rooms).

The same solution could be applied to other plugins like the audiobrige too.

@januscla
Copy link

Thanks for your contribution, @robby2016! Please make sure you sign our CLA, as it's a required step before we can merge this.

@lminiero
Copy link
Member

Thanks for the contribution! Makes sense, and to apply it to other plugins as well. That said, please use tabs, not spaces: if your editor supports it, the repo has an .editorconfig file with a few rules.

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

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

Besides the spaces/tabs thing, I added a few additional notes.

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(room->is_private) {
/* only if admin_key isset */
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.

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).

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.

@robby2016
Copy link
Contributor Author

Thank you very much for the great feedback. Of course! You're absolutely right, the check should happen outside of the loop. Hope this second version is better.

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fixes! I just added a few nitpicking notes, but it should be fine to merge once those are addressed 👍

/* Skip private room if no valid admin_key was provided */
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.

Looks like you added an extra tab for the lines above?

janus_mutex_unlock(&rooms_mutex);
goto prepare_response;
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

Please put theelse on the same line as the closing bracket (only code style, sorry for the bother).

if(admin_key != NULL) {
json_t *admin_key_json = json_object_get(root, "admin_key");
/* Verify admin_key if it was provided */
if(admin_key_json != NULL && strlen(json_string_value(admin_key_json)) > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This should also have a check on json_is_string(admin_key_json), as there's no guarantee admin_key is a string in the JSON (it's not part of the objects we use for validation in "list", since list requires no arguments).

@robby2016
Copy link
Contributor Author

Not a problem at all and sorry for the styles issues.

@lminiero
Copy link
Member

No problem, we don't really have these rules written anywhere... I probably should do that!
Thanks again, merging 👍

@lminiero lminiero merged commit adb77a1 into meetecho:master May 20, 2020
lminiero added a commit that referenced this pull request May 20, 2020
@lminiero
Copy link
Member

FYI, I just added the same changes to other plugins with private resources as well.

@robby2016
Copy link
Contributor Author

Awesome! Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants