use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class BOSConnection method handleSnacResponse.
@Override
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, getMainSession().getCapabilities(), 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;
getMainSession().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) {
BuddyItem bi = (BuddyItem) obj;
Log.debug("OSCAR: got buddy item " + bi);
getMainSession().getSsiHierarchy().gotBuddy(bi);
} else if (obj instanceof GroupItem) {
GroupItem gi = (GroupItem) obj;
Log.debug("OSCAR: got group item " + gi);
getMainSession().getSsiHierarchy().gotGroup(gi);
} else if (obj instanceof IconItem) {
IconItem ii = (IconItem) obj;
Log.debug("OSCAR: got icon item " + ii);
getMainSession().getSsiHierarchy().gotIconItem(ii);
} else if (obj instanceof VisibilityItem) {
VisibilityItem vi = (VisibilityItem) obj;
Log.debug("OSCAR: got visibility item " + vi);
getMainSession().getSsiHierarchy().gotVisibilityItem(vi);
} else {
Log.debug("OSCAR: got item we're not handling " + obj);
}
}
if (sdc.getLastModDate() != 0) {
request(new ActivateSsiCmd());
clientReady();
getMainSession().setLoginStatus(TransportLoginStatus.LOGGED_IN);
getMainSession().gotCompleteSSI();
}
} else if (cmd instanceof OfflineMsgIcqCmd) {
OfflineMsgIcqCmd omic = (OfflineMsgIcqCmd) cmd;
String sn = String.valueOf(omic.getFromUIN());
Date whenSent = omic.getDate();
ByteBlock block = omic.getIcqData();
final int len = LEBinaryTools.getUShort(block, 12) - 1;
String msg = OscarTools.getString(block.subBlock(14, len), null);
msg = StringUtils.unescapeFromXML(OscarTools.stripHtml(msg));
// TODO: Translate offline message note
getMainSession().getTransport().sendOfflineMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(sn), msg, whenSent, "Offline Message");
} else if (cmd instanceof OfflineMsgDoneCmd) {
request(new OfflineMsgIcqAckCmd(getMainSession().getUIN(), (int) getMainSession().nextIcqId()));
} else if (cmd instanceof MetaShortInfoCmd) {
// MetaShortInfoCmd msic = (MetaShortInfoCmd)cmd;
// Log.debug("RECEIVED META SHORT INFO: "+msic);
// getMainSession().updateRosterNickname(String.valueOf(msic.getUIN()), msic.getNickname());
} else if (cmd instanceof AuthReplyCmd) {
AuthReplyCmd ar = (AuthReplyCmd) cmd;
if (ar.isAccepted()) {
Presence p = new Presence();
p.setType(Presence.Type.subscribed);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
getMainSession().getTransport().sendPacket(p);
} else {
Presence p = new Presence();
p.setType(Presence.Type.unsubscribed);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
getMainSession().getTransport().sendPacket(p);
}
} else if (cmd instanceof AuthFutureCmd) {
AuthFutureCmd af = (AuthFutureCmd) cmd;
Presence p = new Presence();
p.setType(Presence.Type.subscribe);
p.setTo(getMainSession().getJID());
p.setFrom(getMainSession().getTransport().convertIDToJID(af.getUin()));
getMainSession().getTransport().sendPacket(p);
} else if (cmd instanceof SnacError) {
SnacError se = (SnacError) cmd;
if (se.getErrorCode() == SnacError.CODE_REFUSED_BY_CLIENT) {
getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.msgrefused", "kraken"));
}
//TODO: Tons more errors that can be caught. Gotta catch 'em all! =) (please don't sue me Nintendo)
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RegistrationHandler method handleDeregister.
/**
* Processes an IQ-register request that is expressing the wish to
* deregister from a gateway.
*
* @param packet the IQ-register stanza.
*/
private void handleDeregister(final IQ packet) {
final IQ result = IQ.createResultIQ(packet);
if (packet.getChildElement().elements().size() != 1) {
Log.debug("Cannot process this stanza - exactly one" + " childelement of <remove> expected:" + packet.toXML());
final IQ error = IQ.createResultIQ(packet);
error.setError(Condition.bad_request);
parent.sendPacket(error);
return;
}
final JID from = packet.getFrom();
final JID to = packet.getTo();
// Tell the end user the transport went byebye.
final Presence unavailable = new Presence(Presence.Type.unavailable);
unavailable.setTo(from);
unavailable.setFrom(to);
this.parent.sendPacket(unavailable);
try {
deleteRegistration(from);
} catch (UserNotFoundException e) {
Log.debug("Error cleaning up contact list of: " + from);
result.setError(Condition.registration_required);
}
parent.sendPacket(result);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class TransportBuddy method sendOfflinePresenceIfAvailable.
/**
* Sends an offline presence for a contact only if it is currently online.
*
* In case you are wondering why, this is useful when a resource goes offline and we want to indicate all contacts are offline.
*
* @param to JID to send presence updates to.
*/
public void sendOfflinePresenceIfAvailable(JID to) {
if (!presence.equals(PresenceType.unavailable)) {
Presence p = new Presence();
p.setType(Presence.Type.unavailable);
p.setTo(to);
p.setFrom(jid);
getManager().sendPacket(p);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class TransportBuddy method setAvatar.
/**
* Sets the current avatar for this contact.
*
* @param avatar Avatar instance to associate with this contact.
*/
public void setAvatar(Avatar avatar) {
boolean triggerUpdate = false;
if ((avatar != null && this.avatar == null) || (avatar == null && this.avatar != null) || (avatar != null && !this.avatar.getXmppHash().equals(avatar.getXmppHash()))) {
triggerUpdate = true;
}
this.avatar = avatar;
this.avatarSet = true;
if (triggerUpdate) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!verboseStatus.equals("")) {
p.setStatus(verboseStatus);
}
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
if (avatar != null) {
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class TransportBuddy method setVerboseStatus.
/**
* Sets the current verbose status.
*
* @param newstatus New verbose status.
*/
public void setVerboseStatus(String newstatus) {
if (newstatus == null) {
newstatus = "";
}
if (!verboseStatus.equals(newstatus)) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!newstatus.equals("")) {
p.setStatus(newstatus);
}
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);
}
verboseStatus = newstatus;
lastActivityTimestamp = new Date().getTime();
lastActivityEvent = verboseStatus;
}
Aggregations