Search in sources :

Example 6 with XMPPID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.

the class XMPPUserSearchManager method createResultList.

/**
 * Create a result list from ReportedData. Identify dynamically columns and
 * rows and create users adding it to a {@link IResultList}
 *
 * @param data
 *            ReportedData
 * @return {@link IResultList} a list of users
 * @throws
 */
protected IResultList createResultList(ReportedData data) {
    ResultList result = new ResultList();
    Iterator rows = data.getRows();
    while (rows.hasNext()) {
        Row row = (Row) rows.next();
        Iterator jids = row.getValues(JID);
        Iterator names = row.getValues(NAME);
        String jid = null;
        String name = null;
        // XMPP server returns the same length for both
        while (jids.hasNext() && names.hasNext()) {
            try {
                jid = (String) jids.next();
                name = (String) names.next();
                IUser user = new User(new XMPPID(connectNamespace, jid), name);
                result.add(new XMPPResultItem(user));
            } catch (URISyntaxException e) {
                throw new RuntimeException(// $NON-NLS-1$
                "cannot create connect id for client " + jid + " , name = " + name, // $NON-NLS-1$
                e);
            }
        }
    }
    return result;
}
Also used : IResultList(org.eclipse.ecf.presence.search.IResultList) ResultList(org.eclipse.ecf.presence.search.ResultList) User(org.eclipse.ecf.core.user.User) IUser(org.eclipse.ecf.core.user.IUser) Iterator(java.util.Iterator) IUser(org.eclipse.ecf.core.user.IUser) Row(org.jivesoftware.smackx.ReportedData.Row) URISyntaxException(java.net.URISyntaxException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 7 with XMPPID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.

the class ECFConnection method connect.

public synchronized Object connect(ID remote, Object data, int timeout) throws ECFException {
    if (connection != null)
        throw new ECFException("already connected");
    if (timeout > 0)
        SmackConfiguration.setPacketReplyTimeout(timeout);
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
    final XMPPID jabberURI = getXMPPID(remote);
    String username = jabberURI.getNodename();
    String hostname = jabberURI.getHostname();
    String hostnameOverride = null;
    // Check for the URI form of "joe@bloggs.org;talk.google.com", which
    // would at this point would have
    // - username = "joe"
    // - hostname = "blogs.org;talk.google.com"
    // - hostnameOverride = null
    // 
    // We need to turn this into:
    // - username = "joe"
    // - hostname = "bloggs.org"
    // - hostnameOverride = "talk.google.com"
    int semiColonIdx = hostname.lastIndexOf(';');
    if (semiColonIdx != -1) {
        hostnameOverride = hostname.substring(semiColonIdx + 1);
        hostname = hostname.substring(0, semiColonIdx);
    }
    if (google && hostnameOverride == null) {
        hostnameOverride = GOOGLE_TALK_HOST;
    }
    final String serviceName = hostname;
    serverPort = jabberURI.getPort();
    serverResource = jabberURI.getResourceName();
    if (serverResource == null || serverResource.equals(XMPPID.PATH_DELIMITER)) {
        serverResource = getClientIdentifier();
        jabberURI.setResourceName(serverResource);
    }
    try {
        ConnectionConfiguration config;
        if (hostnameOverride != null) {
            config = new ConnectionConfiguration(hostnameOverride, XMPP_DEFAULT_PORT, serviceName);
        } else if (serverPort == -1) {
            config = new ConnectionConfiguration(serviceName);
        } else {
            config = new ConnectionConfiguration(serviceName, serverPort);
        }
        config.setSendPresence(true);
        // authentication; handler should provide keystore password:
        if (callbackHandler instanceof javax.security.auth.callback.CallbackHandler) {
            config.setCallbackHandler((javax.security.auth.callback.CallbackHandler) callbackHandler);
        }
        connection = new XMPPConnection(config);
        connection.connect();
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        if (google || GOOGLE_TALK_HOST.equals(hostnameOverride)) {
            username = username + "@" + serviceName;
        }
        connection.addPacketListener(packetListener, null);
        connection.addConnectionListener(connectionListener);
        // Login
        connection.login(username, (String) data, serverResource);
        waitForBindResult();
    } catch (final XMPPException e) {
        throw new ContainerConnectException("Login attempt failed", e);
    }
    return jid;
}
Also used : CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ECFException(org.eclipse.ecf.core.util.ECFException) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) XMPPException(org.jivesoftware.smack.XMPPException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 8 with XMPPID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.

the class XMPPContainer method isGoogle.

protected boolean isGoogle(ID remoteSpace) {
    if (remoteSpace instanceof XMPPID) {
        final XMPPID theID = (XMPPID) remoteSpace;
        final String host = theID.getHostname();
        if (host == null)
            return false;
        return googleNames.contains(host.toLowerCase());
    }
    return false;
}
Also used : XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 9 with XMPPID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.

the class ECFConnection method sendMessage.

protected void sendMessage(ID receiver, Message aMsg) throws IOException {
    synchronized (this) {
        if (!isConnected())
            throw new IOException("not connected");
        try {
            if (receiver == null)
                throw new IOException("receiver cannot be null for xmpp instant messaging");
            else if (receiver instanceof XMPPID) {
                final XMPPID rcvr = (XMPPID) receiver;
                aMsg.setType(Message.Type.chat);
                final String receiverName = rcvr.getFQName();
                final Chat localChat = connection.getChatManager().createChat(receiverName, new MessageListener() {

                    public void processMessage(Chat chat, Message message) {
                    }
                });
                localChat.sendMessage(aMsg);
            } else if (receiver instanceof XMPPRoomID) {
                final XMPPRoomID roomID = (XMPPRoomID) receiver;
                aMsg.setType(Message.Type.groupchat);
                final String to = roomID.getMucString();
                aMsg.setTo(to);
                connection.sendPacket(aMsg);
            } else
                throw new IOException("receiver must be of type XMPPID or XMPPRoomID");
        } catch (final XMPPException e) {
            final IOException result = new IOException("XMPPException in sendMessage: " + e.getMessage());
            result.setStackTrace(e.getStackTrace());
            throw result;
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) Chat(org.jivesoftware.smack.Chat) MessageListener(org.jivesoftware.smack.MessageListener) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 10 with XMPPID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.

the class XMPPContainer method resetTargetResource.

private void resetTargetResource(ID originalTarget, Object serverData) {
    // Reset resource to that given by server
    if (originalTarget instanceof XMPPID) {
        XMPPID xmppOriginalTarget = (XMPPID) originalTarget;
        if (serverData != null && serverData instanceof String) {
            String jid = (String) serverData;
            String jidResource = trimResourceFromJid(jid);
            if (jidResource != null) {
                xmppOriginalTarget.setResourceName(jidResource);
            }
        }
    }
}
Also used : XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Aggregations

XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)13 Iterator (java.util.Iterator)4 IUser (org.eclipse.ecf.core.user.IUser)3 User (org.eclipse.ecf.core.user.User)3 IRosterEntry (org.eclipse.ecf.presence.roster.IRosterEntry)3 IRosterItem (org.eclipse.ecf.presence.roster.IRosterItem)3 Collection (java.util.Collection)2 RosterEntry (org.jivesoftware.smack.RosterEntry)2 XMPPException (org.jivesoftware.smack.XMPPException)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 CallbackHandler (org.eclipse.ecf.core.security.CallbackHandler)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IPresence (org.eclipse.ecf.presence.IPresence)1 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)1 IRosterGroup (org.eclipse.ecf.presence.roster.IRosterGroup)1