|
1 using Gee, Lm; |
|
2 |
|
3 class ModuleIq : Module { |
|
4 const string NS_IQ_VERSION = "jabber:iq:version"; |
|
5 public static delegate void Callback(string id, MessageNode request, MessageNode response); |
|
6 protected HashMap<string, Callback> callbacks; |
|
7 public ModuleIq(Config cfg, Connection conn) { |
|
8 base(cfg, conn); |
|
9 var iq_handler = new Lm.MessageHandler((handler, connection, message) => { |
|
10 var node = message.node; |
|
11 |
|
12 var query = node.get_child("query"); |
|
13 if (query == null) return Lm.HandlerResult.ALLOW_MORE_HANDLERS; |
|
14 |
|
15 var from = node.get_attribute("from"); |
|
16 var id = node.get_attribute("id"); |
|
17 |
|
18 var response = new Lm.Message(from, Lm.MessageType.IQ); |
|
19 response.node.set_attribute("type","result"); |
|
20 if (id!=null) |
|
21 response.node.set_attribute("id",id); |
|
22 var rquery = response.node.add_child("query",null); |
|
23 |
|
24 switch (query.get_attribute("xmlns")) { |
|
25 case NS_IQ_VERSION: |
|
26 rquery.set_attribute("xmlns", NS_IQ_VERSION); |
|
27 rquery.add_child("name", "iswydt"); |
|
28 rquery.add_child("version", IswydtVersion); |
|
29 stderr.printf("RQ: %s\n",rquery.to_string()); |
|
30 stderr.printf("RS: %s\n",response.node.to_string()); |
|
31 this.conn.cn.send(response); |
|
32 return Lm.HandlerResult.REMOVE_MESSAGE; |
|
33 } |
|
34 return Lm.HandlerResult.ALLOW_MORE_HANDLERS; |
|
35 }, null); |
|
36 conn.cn.register_message_handler(iq_handler, Lm.MessageType.IQ, Lm.HandlerPriority.NORMAL); |
|
37 } |
|
38 public override string name() { |
|
39 return "iq"; |
|
40 } |
|
41 } |