# HG changeset patch # User Marco Cirillo # Date 1316556314 0 # Node ID ac4a6cc5776c67f4240f94f657af97aa62232280 # Parent 967757965dbd2c326d463e249795390371a1aad6 mod_stanza_counter: cleanup, corrections. (prosody starts, web stats work) diff -r 967757965dbd -r ac4a6cc5776c mod_stanza_counter/mod_stanza_counter.lua --- a/mod_stanza_counter/mod_stanza_counter.lua Tue Sep 20 21:21:06 2011 +0000 +++ b/mod_stanza_counter/mod_stanza_counter.lua Tue Sep 20 22:05:14 2011 +0000 @@ -6,41 +6,13 @@ module.host = "*" -- Needs to be global for stats web wise. -local ports = module:get_option_array("stanza_counter_ports" or {{ port = 5280; base = "stanza-counter" }}) +local ports = module:get_option_array("stanza_counter_ports" or {{ port = 5280 }}) -- http handlers -local r_200 = "\n -\n -\n -Prosody's Stanza Counter\n -\n -\n -\n -\n -

Incoming and Outgoing stanzas divided per type

\n -

Incoming IQs: %d
\n -Outgoing IQs: %d
\n -Incoming Messages: %d
\n -Outgoing Messages: %d
\n -Incoming Presences: %d
\n -Outgoing Presences: %d

\n -\n -\n -\n" +local r_200 = "\n\n\nProsody's Stanza Counter\n\n\n\n\n

Incoming and Outgoing stanzas divided per type

\n

Incoming IQs: %d
\nOutgoing IQs: %d
\nIncoming Messages: %d
\nOutgoing Messages: %d
\nIncoming Presences: %d
\nOutgoing Presences: %d

\n\n\n\n" -local r_405 = "\n -\n -\n -Prosody's Stanza Counter - Error\n -\n -\n -\n -\n -

Bad Method ... I only support GET.

\n -\n -\n -\n" +local r_405 = "\n\n\nProsody's Stanza Counter - Error\n\n\n\n\n

Bad Method ... I only support GET.

\n\n\n\n" local function res(code, r, h) local response = { @@ -53,7 +25,7 @@ end local function req(method, body, request) - if method = "GET" then + if method == "GET" then local forge_res = r_200:format(prosody.stanza_counter.iq["incoming"], prosody.stanza_counter.iq["outgoing"], prosody.stanza_counter.message["incoming"], @@ -78,7 +50,7 @@ -- init http interface local function init_web() - httpserver.new_from_config(ports, req) + httpserver.new_from_config(ports, req, { base = "stanza-counter" }) end -- Setup on server start @@ -91,7 +63,7 @@ return function(self) local origin, stanza = self.origin, self.stanza if not prosody.stanza_counter then init_counter() end - if check + if check then if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil; else prosody.stanza_counter.iq["outgoing"] = prosody.stanza_counter.iq["outgoing"] + 1 @@ -102,11 +74,11 @@ end end -local function message_callback(check) +local function mes_callback(check) return function(self) local origin, stanza = self.origin, self.stanza if not prosody.stanza_counter then init_counter() end - if check + if check then if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil; else prosody.stanza_counter.message["outgoing"] = prosody.stanza_counter.message["outgoing"] + 1 @@ -117,11 +89,11 @@ end end -local function presence_callback(check) +local function pre_callback(check) return function(self) local origin, stanza = self.origin, self.stanza if not prosody.stanza_counter then init_counter() end - if check + if check then if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil; else prosody.stanza_counter.presence["outgoing"] = prosody.stanza_counter.presence["outgoing"] + 1