@author Evg_S
| 30 | * @author Evg_S |
| 31 | */ |
| 32 | public class EntityCaps implements JabberBlockListener { |
| 33 | |
| 34 | public final static String NS_CAPS = "http://jabber.org/protocol/caps"; |
| 35 | |
| 36 | /** |
| 37 | * Creates a new instance of EntityCaps |
| 38 | */ |
| 39 | public EntityCaps() { |
| 40 | initCaps(); |
| 41 | } |
| 42 | |
| 43 | public int blockArrived(JabberDataBlock data) { |
| 44 | if (!(data instanceof Iq)) { |
| 45 | return BLOCK_REJECTED; |
| 46 | } |
| 47 | if (!data.getTypeAttribute().equals("get")) { |
| 48 | return BLOCK_REJECTED; |
| 49 | } |
| 50 | |
| 51 | JabberDataBlock query = data.findNamespace("query", "http://jabber.org/protocol/disco#info"); |
| 52 | if (query == null) { |
| 53 | return BLOCK_REJECTED; |
| 54 | } |
| 55 | String node = query.getAttribute("node"); |
| 56 | |
| 57 | if (node != null) { |
| 58 | try { |
| 59 | if (!node.equals(BOMBUS_NAMESPACE + "#" + calcVerHash())) { |
| 60 | return BLOCK_REJECTED; |
| 61 | } |
| 62 | } catch (Exception e) { |
| 63 | e.printStackTrace(); |
| 64 | return BLOCK_REJECTED; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | JabberDataBlock result = new Iq(data.getAttribute("from"), Iq.TYPE_RESULT, data.getAttribute("id")); |
| 69 | result.addChild(query); |
| 70 | |
| 71 | JabberDataBlock identity = query.addChild("identity", null); |
| 72 | identity.setAttribute("category", BOMBUS_ID_CATEGORY); |
| 73 | identity.setAttribute("type", BOMBUS_ID_TYPE); |
| 74 | identity.setAttribute("name", StaticData.getInstance().getVersionInfo().getName()); |
| 75 | |
| 76 | int j = features.size(); |
| 77 | for (int i = 0; i < j; i++) { |
| 78 | query.addChild("feature", null).setAttribute("var", (String) features.elementAt(i)); |
| 79 | } |
| 80 | |
| 81 | StaticData.getInstance().getTheStream().send(result); |
| 82 | |
| 83 | return BLOCK_PROCESSED; |
| 84 | } |
| 85 | public static String ver = null; |
| 86 | |
| 87 | public static String calcVerHash() throws Exception { |
| 88 | if (ver != null) { |
| 89 | return ver; |
nothing calls this directly
no test coverage detected