Merge with 0.5
[prosody.git] / plugins / mod_version.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 local st = require "util.stanza";
10
11 module:add_feature("jabber:iq:version");
12
13 local version = "the best operating system ever!";
14
15 if not module:get_option("hide_os_type") then
16         if os.getenv("WINDIR") then
17                 version = "Windows";
18         else
19                 local uname = io.popen("uname");
20                 if uname then
21                         version = uname:read("*a");
22                 else
23                         version = "an OS";
24                 end
25         end
26 end
27
28 version = version:match("^%s*(.-)%s*$") or version;
29
30 local query = st.stanza("query", {xmlns = "jabber:iq:version"})
31         :tag("name"):text("Prosody"):up()
32         :tag("version"):text(prosody.version):up()
33         :tag("os"):text(version);
34
35 module:hook("iq/host/jabber:iq:version:query", function(event)
36         local stanza = event.stanza;
37         if stanza.attr.type == "get" and stanza.attr.to == module.host then
38                 event.origin.send(st.reply(stanza):add_child(query));
39                 return true;
40         end
41 end);