public void setRole(MUCRole.Role newRole) throws NotAllowedException { // Don't allow to change the role to an owner or admin unless the new role is moderator if (MUCRole.Affiliation.owner == affiliation || MUCRole.Affiliation.admin == affiliation) { if (MUCRole.Role.moderator != newRole) { throw new NotAllowedException(); } } // A moderator cannot be kicked from a room if (MUCRole.Role.moderator == role && MUCRole.Role.none == newRole) { throw new NotAllowedException(); } // TODO A moderator MUST NOT be able to revoke voice from a user whose affiliation is at or // TODO above the moderator's level. role = newRole; if (MUCRole.Role.none == role) { presence.setType(Presence.Type.unavailable); presence.setStatus(null); } calculateExtendedInformation(); }
/** * Creates a session with an underlying connection and permission protection. * * @param serverName name of the server. * @param connection The connection we are proxying. * @param streamID unique identifier of this session. */ public LocalClientSession(String serverName, Connection connection, StreamID streamID) { super(serverName, connection, streamID); // Set an unavailable initial presence presence = new Presence(); presence.setType(Presence.Type.unavailable); }
public void process(Presence presence) throws PacketException { try { JID senderJID = presence.getFrom(); JID recipientJID = presence.getTo(); Presence.Type type = presence.getType(); // Reject presence subscription requests sent to the local server itself. if (recipientJID == null || recipientJID.toString().equals(serverName)) { if (type == Presence.Type.subscribe) { Presence reply = new Presence(); reply.setTo(senderJID); reply.setFrom(recipientJID); reply.setType(Presence.Type.unsubscribed); deliverer.deliver(reply); } return; } try { Roster senderRoster = getRoster(senderJID); if (senderRoster != null) { manageSub(recipientJID, true, type, senderRoster); } Roster recipientRoster = getRoster(recipientJID); boolean recipientSubChanged = false; if (recipientRoster != null) { recipientSubChanged = manageSub(senderJID, false, type, recipientRoster); } // Do not forward the packet to the recipient if the presence is of type subscribed // and the recipient user has not changed its subscription state. if (!(type == Presence.Type.subscribed && recipientRoster != null && !recipientSubChanged)) { // If the user is already subscribed to the *local* user's presence then do not // forward the subscription request. Also, do not send an auto-reply on behalf // of the user. This presence stanza is the user's server know that it MUST no // longer send notification of the subscription state change to the user. // See http://tools.ietf.org/html/rfc3921#section-7 and/or OF-38 if (type == Presence.Type.subscribe && recipientRoster != null && !recipientSubChanged) { try { RosterItem.SubType subType = recipientRoster.getRosterItem(senderJID).getSubStatus(); if (subType == RosterItem.SUB_FROM || subType == RosterItem.SUB_BOTH) { return; } } catch (UserNotFoundException e) { // Weird case: Roster item does not exist. Should never happen Log.error( "User does not exist while trying to update roster item. " + "This should never happen (this indicates a programming " + "logic error). Processing stanza: " + presence.toString(), e); } } // Try to obtain a handler for the packet based on the routes. If the handler is // a module, the module will be able to handle the packet. If the handler is a // Session the packet will be routed to the client. If a route cannot be found // then the packet will be delivered based on its recipient and sender. List<JID> jids = routingTable.getRoutes(recipientJID, null); if (!jids.isEmpty()) { for (JID jid : jids) { Presence presenteToSend = presence.createCopy(); // Stamp the presence with the user's bare JID as the 'from' address, // as required by section 8.2.5 of RFC 3921 presenteToSend.setFrom(senderJID.toBareJID()); routingTable.routePacket(jid, presenteToSend, false); } } else { deliverer.deliver(presence.createCopy()); } if (type == Presence.Type.subscribed) { // Send the presence of the local user to the remote user. The remote user // subscribed to the presence of the local user and the local user accepted JID prober = localServer.isLocal(recipientJID) ? new JID(recipientJID.toBareJID()) : recipientJID; presenceManager.probePresence(prober, senderJID); PresenceEventDispatcher.subscribedToPresence(recipientJID, senderJID); } } if (type == Presence.Type.unsubscribed) { // Send unavailable presence from all of the local user's available resources // to the remote user presenceManager.sendUnavailableFromSessions(recipientJID, senderJID); PresenceEventDispatcher.unsubscribedToPresence(senderJID, recipientJID); } } catch (SharedGroupException e) { Presence result = presence.createCopy(); JID sender = result.getFrom(); result.setFrom(presence.getTo()); result.setTo(sender); result.setError(PacketError.Condition.not_acceptable); deliverer.deliver(result); } } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } }
protected void handleSnacResponse(SnacResponseEvent e) { super.handleSnacResponse(e); Log.debug("OSCAR bos snac response received: " + e); SnacCommand cmd = e.getSnacCommand(); if (cmd instanceof LocRightsCmd) { request(new SetInfoCmd(new InfoData("oscargateway", null, MY_CAPS, null))); request(new MyInfoRequest()); } else if (cmd instanceof ParamInfoCmd) { ParamInfoCmd pic = (ParamInfoCmd) cmd; ParamInfo info = pic.getParamInfo(); request( new SetParamInfoCmd( new ParamInfo( 0, info.getFlags() | ParamInfo.FLAG_TYPING_NOTIFICATION, 8000, info.getMaxSenderWarning(), info.getMaxReceiverWarning(), 0))); } else if (cmd instanceof ServiceRedirect) { ServiceRedirect sr = (ServiceRedirect) cmd; oscarSession.connectToService(sr.getSnacFamily(), sr.getRedirectHost(), sr.getCookie()); } else if (cmd instanceof SsiDataCmd) { SsiDataCmd sdc = (SsiDataCmd) cmd; List<SsiItem> items = sdc.getItems(); for (SsiItem item : items) { SsiItemObj obj = itemFactory.getItemObj(item); if (obj instanceof BuddyItem) { Log.debug("AIM got buddy item " + obj); oscarSession.gotBuddy((BuddyItem) obj); } else if (obj instanceof GroupItem) { Log.debug("AIM got group item " + obj); oscarSession.gotGroup((GroupItem) obj); } } if (sdc.getLastModDate() != 0) { request(new ActivateSsiCmd()); clientReady(); Presence p = new Presence(); p.setTo(oscarSession.getJID()); p.setFrom(oscarSession.getTransport().getJID()); oscarSession.getTransport().sendPacket(p); oscarSession.setLoginStatus(TransportLoginStatus.LOGGED_IN); oscarSession.gotCompleteSSI(); } } else if (cmd instanceof OfflineMsgIcqCmd) { OfflineMsgIcqCmd omic = (OfflineMsgIcqCmd) cmd; String sn = String.valueOf(omic.getFromUIN()); // String msg = "Offline message sent at "+new // Date(omic.getDate().getTime()).toString()+"\n"+OscarTools.stripHtml(omic.getContents()).trim(); String msg = "Offline message received:\n" + StringUtils.unescapeFromXML(OscarTools.stripHtml(omic.getContents()).trim()); EncodedStringInfo encmsg = MinimalEncoder.encodeMinimally(msg); InstantMessage imsg = new InstantMessage( encmsg.getImEncoding().getCharsetCode(), ByteBlock.wrap(encmsg.getData())); oscarSession .getTransport() .sendMessage( oscarSession.getJIDWithHighestPriority(), oscarSession.getTransport().convertIDToJID(sn), imsg.getMessage()); } else if (cmd instanceof OfflineMsgDoneCmd) { request(new OfflineMsgIcqAckCmd(oscarSession.getUIN(), (int) oscarSession.nextIcqId())); } else if (cmd instanceof MetaShortInfoCmd) { // MetaShortInfoCmd msic = (MetaShortInfoCmd)cmd; // Log.debug("RECEIVED META SHORT INFO: "+msic); // oscarSession.updateRosterNickname(String.valueOf(msic.getUIN()), // msic.getNickname()); } else if (cmd instanceof BuddyAddedYouCmd) { BuddyAddedYouCmd bay = (BuddyAddedYouCmd) cmd; Presence p = new Presence(); p.setType(Presence.Type.subscribe); p.setTo(oscarSession.getJID()); p.setFrom(oscarSession.getTransport().convertIDToJID(bay.getUin())); oscarSession.getTransport().sendPacket(p); } else if (cmd instanceof BuddyAuthRequest) { BuddyAuthRequest bar = (BuddyAuthRequest) cmd; Presence p = new Presence(); p.setType(Presence.Type.subscribe); p.setTo(oscarSession.getJID()); p.setFrom(oscarSession.getTransport().convertIDToJID(bar.getScreenname())); oscarSession.getTransport().sendPacket(p); } else if (cmd instanceof AuthReplyCmd) { AuthReplyCmd ar = (AuthReplyCmd) cmd; if (ar.isAccepted()) { Presence p = new Presence(); p.setType(Presence.Type.subscribed); p.setTo(oscarSession.getJID()); p.setFrom(oscarSession.getTransport().convertIDToJID(ar.getSender())); oscarSession.getTransport().sendPacket(p); } else { Presence p = new Presence(); p.setType(Presence.Type.unsubscribed); p.setTo(oscarSession.getJID()); p.setFrom(oscarSession.getTransport().convertIDToJID(ar.getSender())); oscarSession.getTransport().sendPacket(p); } } else if (cmd instanceof AuthFutureCmd) { AuthFutureCmd af = (AuthFutureCmd) cmd; Presence p = new Presence(); p.setType(Presence.Type.subscribe); p.setTo(oscarSession.getJID()); p.setFrom(oscarSession.getTransport().convertIDToJID(af.getUin())); oscarSession.getTransport().sendPacket(p); } }