use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method handleDiscoInfo.
/**
* Handle service discovery info request.
*
* @param packet An IQ packet in the disco info namespace.
* @return A list of IQ packets to be returned to the user.
*/
private List<Packet> handleDiscoInfo(IQ packet) {
// TODO: why return a list? we're sure to return always exactly one result.
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
IQ result = IQ.createResultIQ(packet);
if (packet.getTo().getNode() == null) {
// Requested info from transport itself.
if (from.getNode() == null || RegistrationManager.getInstance().isRegistered(from, this.transportType) || permissionManager.hasAccess(from)) {
Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO));
response.addElement("identity").addAttribute("category", "gateway").addAttribute("type", this.transportType.discoIdentity()).addAttribute("name", this.description);
response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO);
response.addElement("feature").addAttribute("var", NameSpace.DISCO_ITEMS);
response.addElement("feature").addAttribute("var", NameSpace.IQ_GATEWAY);
response.addElement("feature").addAttribute("var", NameSpace.IQ_REGISTER);
response.addElement("feature").addAttribute("var", NameSpace.IQ_VERSION);
response.addElement("feature").addAttribute("var", NameSpace.IQ_LAST);
response.addElement("feature").addAttribute("var", NameSpace.VCARD_TEMP);
if (RegistrationManager.getInstance().isRegistered(from, this.transportType)) {
response.addElement("feature").addAttribute("var", NameSpace.IQ_REGISTERED);
}
result.setChildElement(response);
} else {
result.setError(Condition.forbidden);
}
} else {
// Requested info from a gateway user.
final TransportSession<B> session;
try {
session = sessionManager.getSession(packet.getFrom());
if ((from.getNode() == null || permissionManager.hasAccess(from)) && session != null) {
final Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO));
response.addElement("identity").addAttribute("category", "client").addAttribute("type", "pc");
response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO);
for (final SupportedFeature feature : session.supportedFeatures) {
response.addElement("feature").addAttribute("var", feature.getVar());
}
result.setChildElement(response);
} else {
result.setError(Condition.forbidden);
}
} catch (NotFoundException ex) {
result.setError(Condition.item_not_found);
}
}
reply.add(result);
return reply;
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method handleVCardTemp.
/**
* Handle vcard request.
*
* @param packet An IQ packet in the vcard-temp namespace.
* @return A list of IQ packets to be returned to the user.
*/
private List<Packet> handleVCardTemp(IQ packet) {
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
if (packet.getType() == IQ.Type.get) {
IQ result = IQ.createResultIQ(packet);
if (from.getNode() != null) {
try {
TransportSession<B> session = sessionManager.getSession(from);
Element vcard = session.getBuddyManager().getBuddy(to).getVCard();
result.setChildElement(vcard);
} catch (NotFoundException e) {
Log.debug("Contact not found while retrieving vcard for: " + from);
result.setError(Condition.item_not_found);
}
} else {
result.setError(Condition.feature_not_implemented);
}
reply.add(result);
} else if (packet.getType() == IQ.Type.set) {
IQ result = IQ.createResultIQ(packet);
result.setError(Condition.forbidden);
reply.add(result);
}
return reply;
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method cleanUpRoster.
/**
* Cleans a roster of entries related to this transport.
*
* This function will run through the roster of the specified user and clean up any
* entries that share the domain of this transport. Depending on the removeNonPersistent
* option, it will either leave or keep the non-persistent 'contact' entries.
*
* @param jid JID of the user whose roster we want to clean up.
* @param leaveDomain If set, we do not touch the roster item associated with the domain itself.
* @param removeNonPersistent If set, we will also remove non-persistent items.
* @throws UserNotFoundException if the user is not found.
*/
public void cleanUpRoster(JID jid, Boolean leaveDomain, Boolean removeNonPersistent) throws UserNotFoundException {
try {
Roster roster = rosterManager.getRoster(jid.getNode());
// Lets lock down the roster from update notifications if there's an active session.
try {
TransportSession<B> session = sessionManager.getSession(jid.getNode());
session.lockRoster();
} catch (NotFoundException e) {
// No active session? Then no problem.
}
for (RosterItem ri : roster.getRosterItems()) {
if (ri.getJid().getDomain().equals(this.jid.getDomain())) {
if (ri.isShared()) {
// Is a shared item we can't really touch.
continue;
}
if (!removeNonPersistent && ri.getID() == 0) {
// Is a non-persistent roster item.
continue;
}
if (leaveDomain && ri.getJid().getNode() == null) {
// The actual transport domain item.
continue;
}
try {
Log.debug("Cleaning up roster entry " + ri.getJid().toString());
roster.deleteRosterItem(ri.getJid(), false);
} catch (Exception e) {
Log.debug("Error removing roster item: " + ri.toString(), e);
}
}
}
// All done, lets unlock the roster.
try {
TransportSession<B> session = sessionManager.getSession(jid.getNode());
session.unlockRoster();
} catch (NotFoundException e) {
// No active session? Then no problem.
}
} catch (UserNotFoundException e) {
throw new UserNotFoundException("Unable to find roster.");
}
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method sendOfflineMessage.
/**
* Sends an offline message through the component manager.
*
* @param to Who the message is for.
* @param from Who the message is from.
* @param msg Message to be send.
* @param type Type of message to be sent.
* @param time Time when the message was originally sent.
* @param reason Reason for offline message (can be null)
*/
public void sendOfflineMessage(JID to, JID from, String msg, Message.Type type, Date time, String reason) {
Message m = new Message();
m.setType(type);
m.setFrom(from);
m.setTo(to);
m.setBody(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(msg));
if (msg.length() == 0) {
Log.debug("Dropping empty message packet.");
return;
}
Element delay = m.addChildElement("delay", NameSpace.DELAY);
// delay.addAttribute("from", from.toBareJID());
delay.addAttribute("stamp", UTC_FORMAT.format(time));
if (reason != null) {
delay.addCDATA(reason);
}
Element offline = m.addChildElement("offline", NameSpace.OFFLINE);
offline.addElement("item").addAttribute("node", UTC_FORMAT.format(time));
Element x = m.addChildElement("x", NameSpace.X_DELAY);
// x.addAttribute("from", from.toBareJID());
x.addAttribute("stamp", UTC_FORMAT.format(time));
if (reason != null) {
x.addCDATA(reason);
}
try {
TransportSession session = sessionManager.getSession(to);
if (session.getDetachTimestamp() != 0) {
// This is a detached session then, so lets store the packet instead of delivering.
session.storePendingPacket(m);
return;
}
} catch (NotFoundException e) {
// No session? That's "fine", allow it through, it's probably something from the transport itself.
}
sendPacket(m);
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BasicFlapConnection method handleSnacPacket.
@Override
protected void handleSnacPacket(SnacPacketEvent e) {
Log.debug("OSCAR snac packet received: " + e);
SnacCommand cmd = e.getSnacCommand();
if (cmd instanceof ServerReadyCmd) {
ServerReadyCmd src = (ServerReadyCmd) cmd;
setSnacFamilies(src.getSnacFamilies());
Collection<SnacFamilyInfo> familyInfos = SnacFamilyInfoFactory.getDefaultFamilyInfos(src.getSnacFamilies());
setSnacFamilyInfos(familyInfos);
getMainSession().registerSnacFamilies(this);
request(new ClientVersionsCmd(familyInfos));
request(new RateInfoRequest());
} else if (cmd instanceof RecvImIcbm) {
RecvImIcbm icbm = (RecvImIcbm) cmd;
String sn = icbm.getSenderInfo().getScreenname();
InstantMessage message = icbm.getMessage();
String msg = StringUtils.convertFromHtml(message.getMessage());
getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(sn), msg);
} else if (cmd instanceof OldIcbm) {
OldIcbm oicbm = (OldIcbm) cmd;
if (oicbm.getMessageType() == OldIcbm.MTYPE_PLAIN) {
String uin = String.valueOf(oicbm.getSender());
String msg = StringUtils.convertFromHtml(oicbm.getReason());
Log.debug("Got ICBM message " + uin + " with " + msg + "\n" + oicbm);
// InstantMessage message = oicbm.getMessage();
// Log.debug("Got ICBM message "+uin+" with "+message+"\n"+oicbm);
// String msg = StringUtils.unescapeFromXML(OscarTools.stripHtml(message.getMessage()));
getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(uin), msg);
}
} else if (cmd instanceof WarningNotification) {
WarningNotification wn = (WarningNotification) cmd;
MiniUserInfo warner = wn.getWarner();
if (warner == null) {
getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.warninganon", "kraken", Arrays.asList(wn.getNewLevel().toString())), Message.Type.headline);
} else {
Log.debug("*** " + warner.getScreenname() + " warned you up to " + wn.getNewLevel() + "%");
getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.warningdirect", "kraken", Arrays.asList(warner.getScreenname(), wn.getNewLevel().toString())), Message.Type.headline);
}
} else if (cmd instanceof ExtraInfoAck) {
ExtraInfoAck eia = (ExtraInfoAck) cmd;
List<ExtraInfoBlock> extraInfo = eia.getExtraInfos();
if (extraInfo != null) {
for (ExtraInfoBlock i : extraInfo) {
ExtraInfoData data = i.getExtraData();
final byte[] pendingAvatar = getMainSession().getSsiHierarchy().getPendingAvatarData();
if (JiveGlobals.getBooleanProperty("plugin.gateway." + getMainSession().getTransport().getType() + ".avatars", true) && (data.getFlags() & ExtraInfoData.FLAG_UPLOAD_ICON) != 0 && pendingAvatar != null) {
Log.debug("OSCAR: Server has indicated that it wants our icon.");
request(new UploadIconCmd(ByteBlock.wrap(pendingAvatar)), new SnacRequestAdapter() {
@Override
public void handleResponse(SnacResponseEvent e) {
SnacCommand cmd = e.getSnacCommand();
if (cmd instanceof UploadIconAck && pendingAvatar != null) {
UploadIconAck iconAck = (UploadIconAck) cmd;
if (iconAck.getCode() == UploadIconAck.CODE_DEFAULT || iconAck.getCode() == UploadIconAck.CODE_SUCCESS) {
ExtraInfoBlock iconInfo = iconAck.getIconInfo();
if (iconInfo == null) {
Log.debug("OSCAR: Got icon ack with no iconInfo: " + iconAck);
}
Log.debug("OSCAR: Successfully set icon.");
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(pendingAvatar);
getMainSession().getAvatar().setLegacyIdentifier(org.jivesoftware.util.StringUtils.encodeHex(md.digest()));
} catch (NoSuchAlgorithmException ee) {
Log.error("No algorithm found for MD5!", ee);
}
} else if (iconAck.getCode() == UploadIconAck.CODE_BAD_FORMAT) {
Log.debug("OSCAR: Uploaded icon was not in an unaccepted format.");
} else if (iconAck.getCode() == UploadIconAck.CODE_TOO_LARGE) {
Log.debug("OSCAR: Uploaded icon was too large to be accepted.");
} else {
Log.debug("OSCAR: Got unknown code from UploadIconAck: " + iconAck.getCode());
}
} else if (cmd instanceof SnacError) {
Log.debug("Got SnacError while setting icon: " + cmd);
}
// Clear the pending binary data from Krakens memory.
getMainSession().getSsiHierarchy().clearPendingAvatar();
}
});
}
}
}
} else if (cmd instanceof BuddyStatusCmd) {
BuddyStatusCmd bsc = (BuddyStatusCmd) cmd;
FullUserInfo info = bsc.getUserInfo();
PresenceType pType = PresenceType.available;
String vStatus = "";
if (info.getAwayStatus()) {
pType = PresenceType.away;
}
if ((info.getFlags() & FullUserInfo.MASK_WIRELESS) != 0) {
pType = PresenceType.xa;
vStatus = "Mobile: ";
}
if (getMainSession().getTransport().getType().equals(TransportType.icq) && info.getScreenname().matches("/^\\d+$/")) {
pType = ((OSCARTransport) getMainSession().getTransport()).convertICQStatusToXMPP(info.getIcqStatus());
}
List<ExtraInfoBlock> extraInfo = info.getExtraInfoBlocks();
if (extraInfo != null) {
for (ExtraInfoBlock i : extraInfo) {
ExtraInfoData data = i.getExtraData();
if (i.getType() == ExtraInfoBlock.TYPE_AVAILMSG) {
ByteBlock msgBlock = data.getData();
int len = BinaryTools.getUShort(msgBlock, 0);
if (len >= 0) {
byte[] msgBytes = msgBlock.subBlock(2, len).toByteArray();
String msg;
try {
msg = new String(msgBytes, "UTF-8");
} catch (UnsupportedEncodingException e1) {
continue;
}
if (msg.length() > 0) {
vStatus = vStatus + msg;
}
}
} else if (i.getType() == ExtraInfoBlock.TYPE_ICONHASH && JiveGlobals.getBooleanProperty("plugin.gateway." + getMainSession().getTransport().getType() + ".avatars", true)) {
try {
OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(info.getScreenname()));
Avatar curAvatar = oscarBuddy.getAvatar();
if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(org.jivesoftware.util.StringUtils.encodeHex(i.getExtraData().getData().toByteArray()))) {
IconRequest req = new IconRequest(info.getScreenname(), i.getExtraData());
request(req, new SnacRequestAdapter() {
@Override
public void handleResponse(SnacResponseEvent e) {
SnacCommand cmd = e.getSnacCommand();
if (cmd instanceof IconDataCmd) {
IconDataCmd idc = (IconDataCmd) cmd;
if (idc.getIconData().getLength() > 0 && idc.getIconData().getLength() != 90) {
Log.debug("Got icon data: " + idc);
if (getMainSession().getBuddyManager().isActivated()) {
try {
OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(idc.getScreenname()));
oscarBuddy.setAvatar(new Avatar(getMainSession().getTransport().convertIDToJID(idc.getScreenname()), org.jivesoftware.util.StringUtils.encodeHex(idc.getIconInfo().getExtraData().getData().toByteArray()), idc.getIconData().toByteArray()));
} catch (NotFoundException ee) {
// Apparently we don't care about this contact.
} catch (IllegalArgumentException ee) {
Log.debug("OSCAR: Got null avatar, ignoring.");
}
}
}
}
}
@Override
public void handleTimeout(SnacRequestTimeoutEvent e) {
Log.debug("Time out while waiting for icon data.");
}
});
}
} catch (NotFoundException ee) {
// Apparently we don't care about this contact.
}
}
}
}
if (getMainSession().getBuddyManager().isActivated()) {
try {
OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(info.getScreenname()));
oscarBuddy.setPresenceAndStatus(pType, vStatus);
} catch (NotFoundException ee) {
// Apparently we don't care about this contact.
Log.debug("OSCAR: Received presense notification for contact we don't care about: " + info.getScreenname());
}
} else {
getMainSession().getBuddyManager().storePendingStatus(getMainSession().getTransport().convertIDToJID(info.getScreenname()), pType, vStatus);
}
} else if (cmd instanceof BuddyOfflineCmd) {
BuddyOfflineCmd boc = (BuddyOfflineCmd) cmd;
if (getMainSession().getBuddyManager().isActivated()) {
try {
OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(boc.getScreenname()));
oscarBuddy.setPresence(PresenceType.unavailable);
} catch (NotFoundException ee) {
// Apparently we don't care about this contact.
}
} else {
getMainSession().getBuddyManager().storePendingStatus(getMainSession().getTransport().convertIDToJID(boc.getScreenname()), PresenceType.unavailable, null);
}
} else if (cmd instanceof TypingCmd) {
TypingCmd tc = (TypingCmd) cmd;
String sn = tc.getScreenname();
final ChatStateEventSource chatStateEventSource = getMainSession().getTransport().getChatStateEventSource();
final JID receiver = getMainSession().getJID();
final JID sender = getMainSession().getTransport().convertIDToJID(sn);
if (tc.getTypingState() == TypingCmd.STATE_TYPING) {
chatStateEventSource.isComposing(sender, receiver);
} else if (tc.getTypingState() == TypingCmd.STATE_PAUSED) {
chatStateEventSource.sendIsPaused(sender, receiver);
} else if (tc.getTypingState() == TypingCmd.STATE_NO_TEXT) {
chatStateEventSource.isInactive(sender, receiver);
}
}
}
Aggregations