Skip to content

Commit

Permalink
Re-work ad-hoc command (XEP-0050) implementation
Browse files Browse the repository at this point in the history
Fixes SMACK-933.
  • Loading branch information
Flowdalic committed Dec 6, 2023
1 parent dac06b0 commit 7f48269
Show file tree
Hide file tree
Showing 21 changed files with 2,041 additions and 1,217 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright © 2017-2020 Florian Schmaus, 2016-2017 Fernando Ramirez
* Copyright © 2017-2023 Florian Schmaus, 2016-2017 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,8 +44,8 @@
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;

import org.jivesoftware.smackx.commands.AdHocCommand;
import org.jivesoftware.smackx.commands.AdHocCommandManager;
import org.jivesoftware.smackx.commands.RemoteCommand;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
Expand Down Expand Up @@ -233,7 +233,7 @@ private MamManager(XMPPConnection connection, Jid archiveAddress) {
super(connection);
this.archiveAddress = archiveAddress;
serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection);
adHocCommandManager = AdHocCommandManager.getInstance(connection);
}

/**
Expand Down Expand Up @@ -759,7 +759,7 @@ public boolean isAdvancedConfigurationSupported() throws InterruptedException, X
return false;
}

public RemoteCommand getAdvancedConfigurationCommand() throws InterruptedException, XMPPException, SmackException {
public AdHocCommand getAdvancedConfigurationCommand() throws InterruptedException, XMPPException, SmackException {
DiscoverItems discoverItems = adHocCommandManager.discoverCommands(archiveAddress);
for (DiscoverItems.Item item : discoverItems.getItems()) {
if (item.getNode().equals(ADVANCED_CONFIG_NODE))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2020 Florian Schmaus
* Copyright 2016-2023 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -27,8 +27,9 @@
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;

import org.jivesoftware.smackx.commands.AdHocCommand;
import org.jivesoftware.smackx.commands.AdHocCommandManager;
import org.jivesoftware.smackx.commands.RemoteCommand;
import org.jivesoftware.smackx.commands.AdHocCommandResult;
import org.jivesoftware.smackx.xdata.form.FillableForm;

import org.jxmpp.jid.EntityBareJid;
Expand Down Expand Up @@ -56,37 +57,38 @@ public static synchronized ServiceAdministrationManager getInstanceFor(XMPPConne
public ServiceAdministrationManager(XMPPConnection connection) {
super(connection);

adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection);
adHocCommandManager = AdHocCommandManager.getInstance(connection);
}

public RemoteCommand addUser() {
public AdHocCommand addUser() {
return addUser(connection().getXMPPServiceDomain());
}

public RemoteCommand addUser(Jid service) {
public AdHocCommand addUser(Jid service) {
return adHocCommandManager.getRemoteCommand(service, COMMAND_NODE_HASHSIGN + "add-user");
}

public void addUser(final EntityBareJid userJid, final String password)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
RemoteCommand command = addUser();
command.execute();
AdHocCommand command = addUser();

FillableForm answerForm = new FillableForm(command.getForm());
AdHocCommandResult.StatusExecuting commandExecutingResult = command.execute().asExecutingOrThrow();

FillableForm answerForm = commandExecutingResult.getFillableForm();

answerForm.setAnswer("accountjid", userJid);
answerForm.setAnswer("password", password);
answerForm.setAnswer("password-verify", password);

command.execute(answerForm);
assert command.isCompleted();
AdHocCommandResult result = command.execute(answerForm);
assert result.isCompleted();
}

public RemoteCommand deleteUser() {
public AdHocCommand deleteUser() {
return deleteUser(connection().getXMPPServiceDomain());
}

public RemoteCommand deleteUser(Jid service) {
public AdHocCommand deleteUser(Jid service) {
return adHocCommandManager.getRemoteCommand(service, COMMAND_NODE_HASHSIGN + "delete-user");
}

Expand All @@ -98,14 +100,14 @@ public void deleteUser(EntityBareJid userJidToDelete)

public void deleteUser(Set<EntityBareJid> jidsToDelete)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
RemoteCommand command = deleteUser();
command.execute();
AdHocCommand command = deleteUser();
AdHocCommandResult.StatusExecuting commandExecutingResult = command.execute().asExecutingOrThrow();

FillableForm answerForm = new FillableForm(command.getForm());
FillableForm answerForm = commandExecutingResult.getFillableForm();

answerForm.setAnswer("accountjids", jidsToDelete);

command.execute(answerForm);
assert command.isCompleted();
AdHocCommandResult result = command.execute(answerForm);
assert result.isCompleted();
}
}
Loading

0 comments on commit 7f48269

Please sign in to comment.