use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.
the class MamManager method ensureMamQueryResultMatchesThisManager.
private void ensureMamQueryResultMatchesThisManager(MamQueryResult mamQueryResult) {
EntityFullJid localAddress = connection().getUser();
EntityBareJid localBareAddress = null;
if (localAddress != null) {
localBareAddress = localAddress.asEntityBareJid();
}
boolean isLocalUserArchive = archiveAddress == null || archiveAddress.equals(localBareAddress);
Jid finIqFrom = mamQueryResult.mamFin.getFrom();
if (finIqFrom != null) {
if (finIqFrom.equals(archiveAddress) || (isLocalUserArchive && finIqFrom.equals(localBareAddress))) {
return;
}
throw new IllegalArgumentException("The given MamQueryResult is from the MAM archive '" + finIqFrom + "' whereas this MamManager is responsible for '" + archiveAddress + '\'');
} else if (!isLocalUserArchive) {
throw new IllegalArgumentException("The given MamQueryResult is from the local entity (user) MAM archive, whereas this MamManager is responsible for '" + archiveAddress + '\'');
}
}
use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.
the class BindIQProvider method parse.
@Override
public Bind parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
String name;
Bind bind = null;
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
name = parser.getName();
switch(name) {
case "resource":
String resourceString = parser.nextText();
bind = Bind.newSet(Resourcepart.from(resourceString));
break;
case "jid":
EntityFullJid fullJid = JidCreate.entityFullFrom(parser.nextText());
bind = Bind.newResult(fullJid);
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return bind;
}
use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.
the class AbstractXMPPConnection method toString.
@Override
public final String toString() {
EntityFullJid localEndpoint = getUser();
String localEndpointString = localEndpoint == null ? "not-authenticated" : localEndpoint.toString();
return getClass().getSimpleName() + '[' + localEndpointString + "] (" + getConnectionCounter() + ')';
}
use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.
the class MultipleRecipientManager method reply.
/**
* Sends a reply to a previously received stanza that was sent to multiple recipients. Before
* attempting to send the reply message some checks are performed. If any of those checks
* fails, then an XMPPException is going to be thrown with the specific error detail.
*
* @param connection the connection to use to send the reply.
* @param original the previously received stanza that was sent to multiple recipients.
* @param reply the new message to send as a reply.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws InterruptedException if the calling thread was interrupted.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws FeatureNotSupportedException if a requested feature is not supported by the remote entity.
* @throws NoResponseException if there was no response from the remote entity.
*/
public static void reply(XMPPConnection connection, Message original, Message reply) throws XMPPErrorException, InterruptedException, NotConnectedException, NoResponseException, FeatureNotSupportedException {
MultipleRecipientInfo info = getMultipleRecipientInfo(original);
if (info == null) {
throw new IllegalArgumentException("Original message does not contain multiple recipient info");
}
if (info.shouldNotReply()) {
throw new IllegalArgumentException("Original message should not be replied");
}
if (info.getReplyRoom() != null) {
throw new IllegalArgumentException("Reply should be sent through a room");
}
// Any <thread/> element from the initial message MUST be copied into the reply.
if (original.getThread() != null) {
reply.asBuilder().setThread(original.getThread()).build();
}
MultipleAddresses.Address replyAddress = info.getReplyAddress();
if (replyAddress != null && replyAddress.getJid() != null) {
// Send reply to the reply_to address
reply.setTo(replyAddress.getJid());
connection.sendStanza(reply);
} else {
// Send reply to multiple recipients
List<Jid> to = new ArrayList<>(info.getTOAddresses().size());
List<Jid> cc = new ArrayList<>(info.getCCAddresses().size());
for (MultipleAddresses.Address jid : info.getTOAddresses()) {
to.add(jid.getJid());
}
for (MultipleAddresses.Address jid : info.getCCAddresses()) {
cc.add(jid.getJid());
}
// Add original sender as a 'to' address (if not already present)
if (!to.contains(original.getFrom()) && !cc.contains(original.getFrom())) {
to.add(original.getFrom());
}
// Remove the sender from the TO/CC list (try with bare JID too)
EntityFullJid from = connection.getUser();
if (!to.remove(from) && !cc.remove(from)) {
EntityBareJid bareJID = from.asEntityBareJid();
to.remove(bareJID);
cc.remove(bareJID);
}
send(connection, reply, to, cc, null, null, null, false);
}
}
use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.
the class Socks5BytestreamManager method getLocalStreamHost.
/**
* Returns the stream host information of the local SOCKS5 proxy containing the IP address and
* the port. The returned list may be empty if the local SOCKS5 proxy is not running.
*
* @return the stream host information of the local SOCKS5 proxy
*/
public List<StreamHost> getLocalStreamHost() {
// Ensure that the local SOCKS5 proxy is running (if enabled).
Socks5Proxy.getSocks5Proxy();
List<StreamHost> streamHosts = new ArrayList<>();
XMPPConnection connection = connection();
EntityFullJid myJid = connection.getUser();
for (Socks5Proxy socks5Server : Socks5Proxy.getRunningProxies()) {
List<InetAddress> addresses = socks5Server.getLocalAddresses();
if (addresses.isEmpty()) {
continue;
}
final int port = socks5Server.getPort();
for (InetAddress address : addresses) {
// Prevent loopback addresses from appearing as streamhost
if (address.isLoopbackAddress()) {
continue;
}
streamHosts.add(new StreamHost(myJid, address, port));
}
}
return streamHosts;
}
Aggregations