aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/componentmanager.lua2
-rw-r--r--core/rostermanager.lua6
-rw-r--r--core/s2smanager.lua9
-rw-r--r--core/stanza_router.lua16
-rw-r--r--util/logger.lua17
-rw-r--r--util/stanza.lua48
-rw-r--r--util/termcolours.lua33
7 files changed, 107 insertions, 24 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua
index 38718882..254abfe4 100644
--- a/core/componentmanager.lua
+++ b/core/componentmanager.lua
@@ -25,7 +25,7 @@ function register_component(host, component)
if not hosts[host] then
-- TODO check for host well-formedness
components[host] = component;
- hosts[host] = {type = "component", host = host, connected = true};
+ hosts[host] = {type = "component", host = host, connected = true, s2sout = {} };
log("debug", "component added: "..host);
else
log("error", "Attempt to set component for existing host: "..host);
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index 504d9961..a08f989d 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -1,8 +1,6 @@
-local mainlog = log;
-local function log(type, message)
- mainlog(type, "rostermanager", message);
-end
+
+local log = require "util.logger".init("rostermanager");
local setmetatable = setmetatable;
local format = string.format;
diff --git a/core/s2smanager.lua b/core/s2smanager.lua
index 3f286d0e..bec1c29b 100644
--- a/core/s2smanager.lua
+++ b/core/s2smanager.lua
@@ -24,13 +24,10 @@ local md5_hash = require "util.hashes".md5;
local dialback_secret = "This is very secret!!! Ha!";
-local srvmap = { ["gmail.com"] = "talk.google.com", ["identi.ca"] = "longlance.controlezvous.ca", ["cdr.se"] = "jabber.cdr.se" };
+local srvmap = { ["gmail.com"] = "talk.google.com", ["identi.ca"] = "hampton.controlezvous.ca", ["cdr.se"] = "jabber.cdr.se" };
module "s2smanager"
-function connect_host(from_host, to_host)
-end
-
function send_to_host(from_host, to_host, data)
local host = hosts[from_host].s2sout[to_host];
if host then
@@ -67,10 +64,6 @@ function send_to_host(from_host, to_host, data)
end
end
-function disconnect_host(host)
-
-end
-
local open_sessions = 0;
function new_incoming(conn)
diff --git a/core/stanza_router.lua b/core/stanza_router.lua
index 6c117c25..c1819651 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -32,7 +32,7 @@ local jid_split = require "util.jid".split;
local print = print;
function core_process_stanza(origin, stanza)
- log("debug", "Received["..origin.type.."]: "..tostring(st.reply(st.reply(stanza))))
+ log("debug", "Received[%s]: %s", origin.type, stanza:pretty_top_tag())
if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling.
-- TODO verify validity of stanza (as well as JID validity)
@@ -174,16 +174,22 @@ function core_handle_stanza(origin, stanza)
stanza.attr.to = nil; -- reset it
else
log("warn", "Unhandled c2s presence: %s", tostring(stanza));
- origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+ if stanza.attr.type ~= "error" then
+ origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+ end
end
else
log("warn", "Unhandled c2s stanza: %s", tostring(stanza));
- origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+ if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
+ origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+ end
end -- TODO handle other stanzas
else
log("warn", "Unhandled origin: %s", origin.type);
- -- s2s stanzas can get here
- (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+ if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
+ -- s2s stanzas can get here
+ (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+ end
end
end
diff --git a/util/logger.lua b/util/logger.lua
index fd5d3d80..f93cafc1 100644
--- a/util/logger.lua
+++ b/util/logger.lua
@@ -3,8 +3,21 @@ local format = string.format;
local print = print;
local debug = debug;
local tostring = tostring;
+
+local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
+local do_pretty_printing = not os.getenv("WINDIR");
+
module "logger"
+local logstyles = {};
+
+--TODO: This should be done in config, but we don't have proper config yet
+if do_pretty_printing then
+ logstyles["info"] = getstyle("bold");
+ logstyles["warn"] = getstyle("bold", "yellow");
+ logstyles["error"] = getstyle("bold", "red");
+end
+
function init(name)
--name = nil; -- While this line is not commented, will automatically fill in file/line number info
return function (level, message, ...)
@@ -13,9 +26,9 @@ function init(name)
level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
end
if ... then
- print(name, level, format(message, ...));
+ print(name, getstring(logstyles[level], level), format(message, ...));
else
- print(name, level, message);
+ print(name, getstring(logstyles[level], level), message);
end
end
end
diff --git a/util/stanza.lua b/util/stanza.lua
index cfa33c5b..5a6ba8c5 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -10,8 +10,11 @@ local next = next;
local print = print;
local unpack = unpack;
local s_gsub = string.gsub;
+local os = os;
+
+local do_pretty_printing = not os.getenv("WINDIR");
+local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
-local debug = debug;
local log = require "util.logger".init("stanza");
module "stanza"
@@ -157,9 +160,6 @@ function deserialize(stanza)
end
stanza.tags = tags;
end
- if not stanza.last_add then
- stanza.last_add = {};
- end
end
return stanza;
@@ -195,4 +195,44 @@ function presence(attr)
return stanza("presence", attr);
end
+if do_pretty_printing then
+ local style_attrk = getstyle("yellow");
+ local style_attrv = getstyle("red");
+ local style_tagname = getstyle("red");
+ local style_punc = getstyle("magenta");
+
+ local attr_format = " "..getstring(style_attrk, "%s")..getstring(style_punc, "=")..getstring(style_attrv, "'%s'");
+ local top_tag_format = getstring(style_punc, "<")..getstring(style_tagname, "%s").."%s"..getstring(style_punc, ">");
+ --local tag_format = getstring(style_punc, "<")..getstring(style_tagname, "%s").."%s"..getstring(style_punc, ">").."%s"..getstring(style_punc, "</")..getstring(style_tagname, "%s")..getstring(style_punc, ">");
+ local tag_format = top_tag_format.."%s"..getstring(style_punc, "</")..getstring(style_tagname, "%s")..getstring(style_punc, ">");
+ function stanza_mt.pretty_print(t)
+ local children_text = "";
+ for n, child in ipairs(t) do
+ if type(child) == "string" then
+ children_text = children_text .. xml_escape(child);
+ else
+ children_text = children_text .. child:pretty_print();
+ end
+ end
+
+ local attr_string = "";
+ if t.attr then
+ for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(attr_format, k, tostring(v)); end end
+ end
+ return s_format(tag_format, t.name, attr_string, children_text, t.name);
+ end
+
+ function stanza_mt.pretty_top_tag(t)
+ local attr_string = "";
+ if t.attr then
+ for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(attr_format, k, tostring(v)); end end
+ end
+ return s_format(top_tag_format, t.name, attr_string);
+ end
+else
+ -- Sorry, fresh out of colours for you guys ;)
+ stanza_mt.pretty_print = stanza_mt.__tostring;
+ stanza_mt.pretty_top_tag = stanza_mt.top_tag;
+end
+
return _M;
diff --git a/util/termcolours.lua b/util/termcolours.lua
new file mode 100644
index 00000000..5cf5b555
--- /dev/null
+++ b/util/termcolours.lua
@@ -0,0 +1,33 @@
+local t_concat, t_insert = table.concat, table.insert;
+local char, format = string.char, string.format;
+local ipairs = ipairs;
+module "termcolours"
+
+local stylemap = {
+ reset = 0; bright = 1, dim = 2, underscore = 4, blink = 5, reverse = 7, hidden = 8;
+ black = 30; red = 31; green = 32; yellow = 33; blue = 34; magenta = 35; cyan = 36; white = 37;
+ ["black background"] = 40; ["red background"] = 41; ["green background"] = 42; ["yellow background"] = 43; ["blue background"] = 44; ["magenta background"] = 45; ["cyan background"] = 46; ["white background"] = 47;
+ bold = 1, dark = 2, underline = 4, underlined = 4, normal = 0;
+ }
+
+local fmt_string = char(0x1B).."[%sm%s"..char(0x1B).."[0m";
+function getstring(style, text)
+ if style then
+ return format(fmt_string, style, text);
+ else
+ return text;
+ end
+end
+
+function getstyle(...)
+ local styles, result = { ... }, {};
+ for i, style in ipairs(styles) do
+ style = stylemap[style];
+ if style then
+ t_insert(result, style);
+ end
+ end
+ return t_concat(result, ";");
+end
+
+return _M;