else {
if(registration == null)
db.sendInsert(null,"goim_component_registrations","subdomain,jid,username,password",getSubdomain(),iq.getFrom().toBareJID(),username,"");
else
db.sendUpdate(null,"goim_component_registrations","username=?,password=?",new Object[]{username,""},"id=?",registration.get("id"));
Presence presence = new Presence(Presence.Type.subscribe);
presence.setTo(iq.getFrom());
presence.setFrom(componentJID);
manager.sendPacket(this,presence);
}
}
} else
result = null;
if(result != null)
manager.sendPacket(this,result);
}
}
} else if(packet instanceof Presence) {
Presence presence = (Presence)packet;
if(presence.getTo().equals(componentJID)) {
Kernel.debug(this,"Presence packet to: " + packet.getTo().toString() + " .. type: " + presence.getType(),3);
if(presence.getType() == null || presence.getType() == Presence.Type.probe) { // available
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
manager.sendPacket(this,reply);
} else if(presence.getType() == Presence.Type.subscribe) {
Presence reply = new Presence(Presence.Type.subscribed);
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
manager.sendPacket(this,reply);
}
} else {
if(presence.getType() == Presence.Type.subscribe) {
Presence reply = new Presence(Presence.Type.subscribed);
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
manager.sendPacket(this,reply);
addSubscription(presence.getFrom().toBareJID(),presence.getTo().getNode());
} else if(presence.getType() == null || presence.getType() == Presence.Type.probe) { // available
// Kernel.debug(this,"Available presence packet to: " +
// presence.getTo().toString(),2);
if(presence.getType() == Presence.Type.probe) {
Presence reply = new Presence(Presence.Type.unavailable);
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
manager.sendPacket(this,reply);
}
addSubscription(presence.getFrom().toBareJID(),presence.getTo().getNode());
}
}
} else if(packet instanceof Message) {
Message message = (Message)packet;
if(message.getBody().startsWith("show")) {
Message reply = new Message();
reply.setTo(message.getFrom());
reply.setFrom(message.getTo());
reply.setType(message.getType());
reply.setThread(message.getThread());
StringBuffer subs = new StringBuffer("Your Subscriptions:\n");
for(String lfsusername : subscriptions.keySet()) {
List<String> jids = subscriptions.get(lfsusername.toLowerCase());
if(jids == null) continue;
if(jids.contains(message.getFrom().toBareJID()))
subs.append("- ").append(lfsusername).append("\n");
}
reply.setBody(subs.toString());
manager.sendPacket(this,reply);
}
} else
Kernel.debug(this,"Received packet: " + packet.getClass().toString() + " " + packet.toXML(),2);
}