UserStatus getConnectionStatus(JID jid) { InteropSession s = mSessions.get(jid.toBareJID()); if (s != null) { UserStatus u = new UserStatus(); u.username = s.getUsername(); u.password = s.getPassword(); u.state = s.getState(); u.nextConnectAttemptTime = s.getNextConnectTime(); return u; } else { Map<String, String> registration = null; try { registration = Interop.getDataProvider().getIMGatewayRegistration(jid, mName); } catch (IOException e) { warn( "Caught exception trying to fetch Gateway Registration from provider for " + jid.toBareJID() + " svc " + mName.toString(), e); } if (registration != null) { UserStatus u = new UserStatus(); u.username = registration.get(InteropRegistrationProvider.USERNAME); u.password = registration.get(InteropRegistrationProvider.PASSWORD); u.state = InteropSession.State.INTENTIONALLY_OFFLINE; return u; } else { return null; } } }
/** * @param jid * @throws ComponentException * @throws UserNotFoundException */ void disconnectUser(JID jid) throws ComponentException, UserNotFoundException { try { Interop.getDataProvider().removeIMGatewayRegistration(jid, mName); } catch (IOException e) { throw new ComponentException(e); } InteropSession s = mSessions.remove(jid.toBareJID()); if (s != null) { s.shutdown(); } removeAllSubscriptions(jid, getServiceJID(jid).getDomain()); }
protected List<Packet> processPresence(Presence pres) { JID from = pres.getFrom(); synchronized (mSessions) { InteropSession s = getSession(from.toBareJID()); if (s != null) return s.processPresence(pres); else { // is it being sent to the service? If so, then check // to see if we have a registration we need to load if (pres.getTo().getNode() == null) { try { Map<String, String> registration = Interop.getDataProvider().getIMGatewayRegistration(from, mName); if (registration != null) { String username = registration.get(InteropRegistrationProvider.USERNAME); String password = registration.get(InteropRegistrationProvider.PASSWORD); s = mFact.createSession(this, new JID(from.toBareJID()), username, password); mSessions.put(from.toBareJID(), s); return s.processPresence(pres); } } catch (IOException e) { warn( "Caught exception trying to fetch Gateway Registration from provider for " + from.toBareJID() + " svc " + mName.toString(), e); } } } } debug("Unknown session: sending unavailable reply"); Presence p = new Presence(Presence.Type.unavailable); p.setFrom(pres.getTo()); p.setTo(pres.getFrom()); List<Packet> toRet = new ArrayList<Packet>(1); toRet.add(p); return toRet; }
void connectUser( JID jid, String name, String password, String transportName, String transportBuddyGroup) throws ComponentException, UserNotFoundException { synchronized (mSessions) { InteropSession s = mSessions.get(jid.toBareJID()); if (s != null) { disconnectUser(jid); } // add the SERVICE user (two-way sub) addOrUpdateRosterSubscription( jid, getServiceJID(jid), transportName, transportBuddyGroup, RosterItem.SUB_BOTH, RosterItem.ASK_NONE, RosterItem.RECV_NONE); HashMap<String, String> data = new HashMap<String, String>(); data.put(InteropRegistrationProvider.USERNAME, name); data.put(InteropRegistrationProvider.PASSWORD, password); try { Interop.getDataProvider().putIMGatewayRegistration(jid, mName, data); } catch (IOException ex) { throw new ComponentException(ex); } mSessions.put( jid.toBareJID(), mFact.createSession(this, new JID(jid.toBareJID()), name, password)); } // send a probe to the user's jid -- if the user is online, then we'll // get a presence packet which will trigger a logon Presence p = new Presence(Presence.Type.probe); p.setTo(new JID(jid.toBareJID())); p.setFrom(getServiceJID(jid)); send(p); }