-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add MUC room config extension SPI and disco query passthrough #3420
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
Open
romanbsd
wants to merge
1
commit into
igniterealtime:main
Choose a base branch
from
romanbsd:muc-room-config-extension-spi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoomConfigExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright (C) 2026 Ignite Realtime Foundation. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.jivesoftware.openfire.muc; | ||
|
|
||
| import org.xmpp.forms.DataForm; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Allows plugins to contribute additional fields to MUC room configuration forms and room disco#info. | ||
| */ | ||
| public interface MUCRoomConfigExtension { | ||
|
|
||
| /** | ||
| * Adds extension-specific fields to the room owner configuration form. | ||
| * | ||
| * @param form the configuration form being built. | ||
| * @param room the room being configured. | ||
| */ | ||
| default void contributeConfigForm(DataForm form, MUCRoom room) { | ||
| } | ||
|
|
||
| /** | ||
| * Populates extension-specific fields in the configuration form with current room values. | ||
| * | ||
| * @param form the configuration form being populated. | ||
| * @param room the room being configured. | ||
| */ | ||
| default void populateConfigForm(DataForm form, MUCRoom room) { | ||
| } | ||
|
|
||
| /** | ||
| * Processes extension-specific fields from a submitted configuration form. | ||
| * | ||
| * @param completedForm the submitted configuration form. | ||
| * @param room the room being configured. | ||
| */ | ||
| default void processConfigSubmit(DataForm completedForm, MUCRoom room) { | ||
| } | ||
|
|
||
| /** | ||
| * Contributes extension-specific disco#info features for a room. Invoked while building the room's | ||
| * disco#info feature list. | ||
| * | ||
| * @param features mutable collection of disco features to augment. | ||
| * @param room the room being described. | ||
| */ | ||
| default void contributeRoomDiscoFeatures(Collection<String> features, MUCRoom room) { | ||
| } | ||
|
|
||
| /** | ||
| * Contributes extension-specific disco#info extended data forms for a room. Invoked while building the | ||
| * room's extended disco#info (XEP-0128) forms; the set already contains the room's {@code muc#roominfo} | ||
| * form, which an extension may augment or supplement with additional forms. | ||
| * | ||
| * @param forms mutable set of extended data forms to augment. | ||
| * @param room the room being described. | ||
| */ | ||
| default void contributeRoomDiscoForms(Set<DataForm> forms, MUCRoom room) { | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoomConfigExtensionManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Copyright (C) 2026 Ignite Realtime Foundation. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.jivesoftware.openfire.muc; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.xmpp.forms.DataForm; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Set; | ||
| import java.util.concurrent.CopyOnWriteArrayList; | ||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * Registry for {@link MUCRoomConfigExtension} implementations contributed by plugins. | ||
| */ | ||
| public final class MUCRoomConfigExtensionManager { | ||
|
|
||
| private static final Logger Log = LoggerFactory.getLogger(MUCRoomConfigExtensionManager.class); | ||
|
|
||
| private static final MUCRoomConfigExtensionManager INSTANCE = new MUCRoomConfigExtensionManager(); | ||
|
|
||
| private final CopyOnWriteArrayList<MUCRoomConfigExtension> extensions = new CopyOnWriteArrayList<>(); | ||
|
|
||
| private MUCRoomConfigExtensionManager() { | ||
| } | ||
|
|
||
| public static MUCRoomConfigExtensionManager getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| public void register(MUCRoomConfigExtension extension) { | ||
| if (extension != null) { | ||
| extensions.addIfAbsent(extension); | ||
| } | ||
| } | ||
|
|
||
| public void unregister(MUCRoomConfigExtension extension) { | ||
| extensions.remove(extension); | ||
| } | ||
|
|
||
| public void contributeConfigForm(DataForm form, MUCRoom room) { | ||
| forEachExtension("contributing to the config form", room, extension -> extension.contributeConfigForm(form, room)); | ||
| } | ||
|
|
||
| public void populateConfigForm(DataForm form, MUCRoom room) { | ||
| forEachExtension("populating the config form", room, extension -> extension.populateConfigForm(form, room)); | ||
| } | ||
|
|
||
| public void processConfigSubmit(DataForm completedForm, MUCRoom room) { | ||
| forEachExtension("processing the config submission", room, extension -> extension.processConfigSubmit(completedForm, room)); | ||
| } | ||
|
|
||
| public void contributeRoomDiscoFeatures(Collection<String> features, MUCRoom room) { | ||
| forEachExtension("contributing disco#info features", room, extension -> extension.contributeRoomDiscoFeatures(features, room)); | ||
| } | ||
|
|
||
| public void contributeRoomDiscoForms(Set<DataForm> forms, MUCRoom room) { | ||
| forEachExtension("contributing disco#info forms", room, extension -> extension.contributeRoomDiscoForms(forms, room)); | ||
| } | ||
|
|
||
| /** | ||
| * Applies an operation to every registered extension, isolating failures: an exception thrown by one | ||
| * (third-party) extension is logged and does not prevent the remaining extensions from running, nor | ||
| * does it break the room configuration / disco handling that invoked this manager. | ||
| */ | ||
| private void forEachExtension(final String action, final MUCRoom room, final Consumer<MUCRoomConfigExtension> operation) { | ||
| for (final MUCRoomConfigExtension extension : extensions) { | ||
| try { | ||
| operation.accept(extension); | ||
| } catch (final RuntimeException e) { | ||
| Log.warn("MUC room config extension {} threw an exception while {} for room {}", | ||
| extension, action, room == null ? null : room.getName(), e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...server/src/test/java/org/jivesoftware/openfire/muc/MUCRoomConfigExtensionManagerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * Copyright (C) 2026 Ignite Realtime Foundation. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.jivesoftware.openfire.muc; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.xmpp.forms.DataForm; | ||
| import org.xmpp.forms.FormField; | ||
|
|
||
| import java.util.HashSet; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| class MUCRoomConfigExtensionManagerTest { | ||
|
|
||
| private DataForm processedForm; | ||
| private MUCRoom processedRoom; | ||
|
|
||
| @AfterEach | ||
| void cleanup() { | ||
| MUCRoomConfigExtensionManager.getInstance().unregister(testExtension); | ||
| MUCRoomConfigExtensionManager.getInstance().unregister(throwingExtension); | ||
| } | ||
|
|
||
| private final MUCRoomConfigExtension throwingExtension = new MUCRoomConfigExtension() { | ||
| @Override | ||
| public void contributeConfigForm(final DataForm form, final MUCRoom room) { | ||
| throw new RuntimeException("boom"); | ||
| } | ||
| }; | ||
|
|
||
| private final MUCRoomConfigExtension testExtension = new MUCRoomConfigExtension() { | ||
| @Override | ||
| public void contributeConfigForm(final DataForm form, final MUCRoom room) { | ||
| form.addField("test#field", "Test", FormField.Type.text_single); | ||
| } | ||
|
|
||
| @Override | ||
| public void populateConfigForm(final DataForm form, final MUCRoom room) { | ||
| form.getField("test#field").addValue("value"); | ||
| } | ||
|
|
||
| @Override | ||
| public void processConfigSubmit(final DataForm completedForm, final MUCRoom room) { | ||
| processedForm = completedForm; | ||
| processedRoom = room; | ||
| } | ||
|
|
||
| @Override | ||
| public void contributeRoomDiscoFeatures(final java.util.Collection<String> features, final MUCRoom room) { | ||
| features.add("urn:xmpp:test:0"); | ||
| } | ||
|
|
||
| @Override | ||
| public void contributeRoomDiscoForms(final java.util.Set<DataForm> forms, final MUCRoom room) { | ||
| final DataForm form = new DataForm(DataForm.Type.result); | ||
| form.addField("FORM_TYPE", null, FormField.Type.hidden).addValue("urn:xmpp:test:0"); | ||
| forms.add(form); | ||
| } | ||
| }; | ||
|
|
||
| @Test | ||
| void registeredExtensionContributesConfigForm() { | ||
| MUCRoomConfigExtensionManager.getInstance().register(testExtension); | ||
| final DataForm form = new DataForm(DataForm.Type.form); | ||
| final MUCRoom room = mock(MUCRoom.class); | ||
| MUCRoomConfigExtensionManager.getInstance().contributeConfigForm(form, room); | ||
| assertNotNull(form.getField("test#field")); | ||
|
|
||
| MUCRoomConfigExtensionManager.getInstance().populateConfigForm(form, room); | ||
| assertEquals("value", form.getField("test#field").getFirstValue()); | ||
|
|
||
| MUCRoomConfigExtensionManager.getInstance().processConfigSubmit(form, room); | ||
| assertSame(form, processedForm); | ||
| assertSame(room, processedRoom); | ||
| } | ||
|
|
||
| @Test | ||
| void registeredExtensionContributesDisco() { | ||
| MUCRoomConfigExtensionManager.getInstance().register(testExtension); | ||
| final var room = mock(MUCRoom.class); | ||
| final var features = new HashSet<String>(); | ||
| final var forms = new HashSet<DataForm>(); | ||
| MUCRoomConfigExtensionManager.getInstance().contributeRoomDiscoFeatures(features, room); | ||
| MUCRoomConfigExtensionManager.getInstance().contributeRoomDiscoForms(forms, room); | ||
| assertTrue(features.contains("urn:xmpp:test:0")); | ||
| // Assert the specific form this extension contributed, rather than mere non-emptiness, so the test | ||
| // does not depend on what else may be registered on the process-wide singleton. | ||
| assertTrue(forms.stream().anyMatch(f -> { | ||
| final FormField formType = f.getField("FORM_TYPE"); | ||
| return formType != null && "urn:xmpp:test:0".equals(formType.getFirstValue()); | ||
| })); | ||
| } | ||
|
|
||
| @Test | ||
| void throwingExtensionIsIsolated() { | ||
| // A throwing extension must neither propagate nor prevent other extensions from running. | ||
| MUCRoomConfigExtensionManager.getInstance().register(throwingExtension); | ||
| MUCRoomConfigExtensionManager.getInstance().register(testExtension); | ||
| final DataForm form = new DataForm(DataForm.Type.form); | ||
| final MUCRoom room = mock(MUCRoom.class); | ||
| assertDoesNotThrow(() -> MUCRoomConfigExtensionManager.getInstance().contributeConfigForm(form, room)); | ||
| assertNotNull(form.getField("test#field")); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.