2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.xmpp.stanzas;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
|
|
|
public class IqPacket extends AbstractStanza {
|
|
|
|
|
2015-08-23 15:53:23 +00:00
|
|
|
public enum TYPE {
|
2014-12-30 13:16:25 +00:00
|
|
|
ERROR,
|
|
|
|
SET,
|
|
|
|
RESULT,
|
|
|
|
GET,
|
2015-08-23 15:53:23 +00:00
|
|
|
INVALID,
|
|
|
|
TIMEOUT
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-30 13:16:25 +00:00
|
|
|
public IqPacket(final TYPE type) {
|
2014-10-22 16:38:44 +00:00
|
|
|
super("iq");
|
2014-12-30 13:16:25 +00:00
|
|
|
if (type != TYPE.INVALID) {
|
|
|
|
this.setAttribute("type", type.toString().toLowerCase());
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IqPacket() {
|
|
|
|
super("iq");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Element query() {
|
|
|
|
Element query = findChild("query");
|
|
|
|
if (query == null) {
|
|
|
|
query = addChild("query");
|
|
|
|
}
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
2014-12-21 20:43:58 +00:00
|
|
|
public Element query(final String xmlns) {
|
|
|
|
final Element query = query();
|
2014-10-22 16:38:44 +00:00
|
|
|
query.setAttribute("xmlns", xmlns);
|
|
|
|
return query();
|
|
|
|
}
|
|
|
|
|
2014-12-30 13:16:25 +00:00
|
|
|
public TYPE getType() {
|
2014-12-21 20:43:58 +00:00
|
|
|
final String type = getAttribute("type");
|
2015-07-23 12:02:25 +00:00
|
|
|
if (type == null) {
|
|
|
|
return TYPE.INVALID;
|
|
|
|
}
|
2014-12-21 20:43:58 +00:00
|
|
|
switch (type) {
|
|
|
|
case "error":
|
2014-12-30 13:16:25 +00:00
|
|
|
return TYPE.ERROR;
|
2014-12-21 20:43:58 +00:00
|
|
|
case "result":
|
2014-12-30 13:16:25 +00:00
|
|
|
return TYPE.RESULT;
|
2014-12-21 20:43:58 +00:00
|
|
|
case "set":
|
2014-12-30 13:16:25 +00:00
|
|
|
return TYPE.SET;
|
2014-12-21 20:43:58 +00:00
|
|
|
case "get":
|
2014-12-30 13:16:25 +00:00
|
|
|
return TYPE.GET;
|
2014-12-21 20:43:58 +00:00
|
|
|
default:
|
2014-12-30 13:16:25 +00:00
|
|
|
return TYPE.INVALID;
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-30 13:16:25 +00:00
|
|
|
public IqPacket generateResponse(final TYPE type) {
|
2014-12-21 20:43:58 +00:00
|
|
|
final IqPacket packet = new IqPacket(type);
|
2014-10-22 16:38:44 +00:00
|
|
|
packet.setTo(this.getFrom());
|
|
|
|
packet.setId(this.getId());
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|