use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class SimpleSession method sendNotify.
public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
Request notifyRequest = prepareNotifyRequest(dialog);
try {
User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
String presenceContent;
SimplePresence simplePresence = new SimplePresence();
simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
simplePresence.setDmNote(myPresence.getStatus());
if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
else {
simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
if (myPresence.getShow() != null) {
switch(myPresence.getShow()) {
case away:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
case dnd:
simplePresence.setRpid(SimplePresence.Rpid.BUSY);
break;
case xa:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
default:
break;
}
}
}
presenceContent = simplePresence.toXML();
ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
notifyRequest.setContent(presenceContent, contentTypeHeader);
} catch (Exception e) {
Log.debug("Unable to include presence details in the packet.", e);
}
sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class IRCMUCSession method leaveRoom.
@Override
public void leaveRoom() {
try {
getSession().getConnection().sendCommand(new PartCommand(roomname));
} catch (Exception e) {
Log.debug("IRC: Error while trying to part chat room:", e);
}
try {
autoJoin.disable();
} catch (Exception e) {
// Ignore
}
autoJoin = null;
for (String contact : getContacts()) {
Presence p = new Presence();
p.setType(Presence.Type.unavailable);
p.setTo(session.getJID());
p.setFrom(transport.convertIDToJID(roomname, contact));
Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
Element item = elem.addElement("item");
item.addAttribute("affiliation", "none");
item.addAttribute("role", "none");
transport.sendPacket(p);
}
Presence p = new Presence();
p.setType(Presence.Type.unavailable);
p.setTo(session.getJID());
p.setFrom(transport.convertIDToJID(roomname, nickname));
Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
Element item = elem.addElement("item");
item.addAttribute("affiliation", "none");
item.addAttribute("role", "none");
Element status = elem.addElement("status");
status.addAttribute("code", "110");
transport.sendPacket(p);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class BaseMUCTransport method processPacket.
/**
* Handles all incoming presence stanzas.
*
* @param packet The presence packet to be processed.
* @return list of packets that will be sent back to the presence requester.
*/
private List<Packet> processPacket(Presence packet) {
Log.debug("Received presence packet: " + packet.toXML());
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
if (packet.getType() == Presence.Type.error) {
// We don't want to do anything with this. Ignore it.
return reply;
}
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (!session.isLoggedIn()) {
Message m = new Message();
m.setError(Condition.service_unavailable);
m.setTo(from);
m.setFrom(getJID());
m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
reply.add(m);
} else if (to.getNode() == null) {
// Ignore undirected presence.
} else if (to.getResource() != null) {
// Presence to a specific resource.
if (packet.getType() == Presence.Type.unavailable) {
// Handle logout.
try {
MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
mucSession.leaveRoom();
session.getMUCSessionManager().removeSession(to.getNode());
} catch (NotFoundException e) {
// Not found? Well then no problem.
}
} else {
// Handle login.
try {
MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
// Active session.
mucSession.updateStatus(this.getTransport().getPresenceType(packet));
} catch (NotFoundException e) {
// No current session, lets create one.
MUCTransportSession mucSession = createRoom(session, to.getNode(), to.getResource());
session.getMUCSessionManager().storeSession(to.getNode(), mucSession);
mucSession.enterRoom();
}
}
} else {
// Presence to the room itself. Return error as per protocol.
Presence p = new Presence();
p.setError(Condition.jid_malformed);
p.setType(Presence.Type.error);
p.setTo(from);
p.setFrom(to);
reply.add(p);
}
} catch (NotFoundException e) {
Log.debug("Unable to find session.");
Message m = new Message();
m.setError(Condition.service_unavailable);
m.setTo(from);
m.setFrom(getJID());
m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
reply.add(m);
}
return reply;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RegistrationHandler method completeRegistration.
public void completeRegistration(TransportSession session) {
final IQ result = IQ.createResultIQ(session.getRegistrationPacket());
if (!session.getFailureStatus().equals(ConnectionFailureReason.NO_ISSUE)) {
// Ooh there was a connection issue, we're going to report that back!
if (session.getFailureStatus().equals(ConnectionFailureReason.USERNAME_OR_PASSWORD_INCORRECT)) {
result.setError(Condition.not_authorized);
} else if (session.getFailureStatus().equals(ConnectionFailureReason.CAN_NOT_CONNECT)) {
result.setError(Condition.service_unavailable);
} else if (session.getFailureStatus().equals(ConnectionFailureReason.LOCKED_OUT)) {
result.setError(Condition.forbidden);
} else {
result.setError(Condition.undefined_condition);
}
result.setType(IQ.Type.error);
}
parent.sendPacket(result);
session.setRegistrationPacket(null);
// Lets ask them what their presence is, maybe log them in immediately.
final Presence p = new Presence(Presence.Type.probe);
p.setTo(session.getJID());
p.setFrom(parent.getJID());
parent.sendPacket(p);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class TransportBuddy method setPresence.
/**
* Sets the current status.
*
* @param newpresence New presence to set to.
*/
public void setPresence(PresenceType newpresence) {
if (newpresence == null) {
newpresence = PresenceType.unknown;
}
if (newpresence.equals(PresenceType.unavailable)) {
verboseStatus = "";
}
if (!presence.equals(newpresence) && newpresence != PresenceType.unknown) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
if (!verboseStatus.equals("")) {
p.setStatus(verboseStatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
presence = newpresence;
lastActivityTimestamp = new Date().getTime();
}
Aggregations