From 215af9f1975a7d5b9f91b635fa4a82170c4f26bd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 26 Jan 2011 13:23:39 +0000 Subject: s2smanager: Change 'Connection failed' error message text to 'Server-to-server connection failed' (thanks Paul) --- core/s2smanager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 1d038433..04ea459d 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -75,7 +75,8 @@ local function bounce_sendq(session, reason) reply:tag("error", {type = "cancel"}) :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); if reason then - reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):text("Connection failed: "..reason):up(); + reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}) + :text("Server-to-server connection failed: "..reason):up(); end core_process_stanza(dummy, reply); end -- cgit v1.2.3 From 30be4fa5853c460d6d83d4b55d2d753fe35015bd Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Jan 2011 04:40:43 +0500 Subject: windows.c: Return nil,err from functions instead of throwing errors. --- util-src/windows.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/util-src/windows.c b/util-src/windows.c index e1e07608..121cc471 100644 --- a/util-src/windows.c +++ b/util-src/windows.c @@ -38,15 +38,16 @@ static int Lget_nameservers(lua_State *L) { } return 1; } else { - luaL_error(L, "DnsQueryConfig returned %d", status); - return 0; // unreachable, but prevents a compiler warning + lua_pushnil(L); + lua_pushfstring(L, "DnsQueryConfig returned %d", status); + return 2; } } -static void lassert(lua_State *L, BOOL test, char* string) { - if (!test) { - luaL_error(L, "%s: %d", string, GetLastError()); - } +static int lerror(lua_State *L, char* string) { + lua_pushnil(L); + lua_pushfstring(L, "%s: %d", string, GetLastError()); + return 2; } static int Lget_consolecolor(lua_State *L) { @@ -55,9 +56,9 @@ static int Lget_consolecolor(lua_State *L) { CONSOLE_SCREEN_BUFFER_INFO info; - lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle"); - lassert(L, GetConsoleScreenBufferInfo(console, &info), "GetConsoleScreenBufferInfo"); - lassert(L, ReadConsoleOutputAttribute(console, &color, sizeof(WORD), info.dwCursorPosition, &read_len), "ReadConsoleOutputAttribute"); + if (console == INVALID_HANDLE_VALUE) return lerror(L, "GetStdHandle"); + if (!GetConsoleScreenBufferInfo(console, &info)) return lerror(L, "GetConsoleScreenBufferInfo"); + if (!ReadConsoleOutputAttribute(console, &color, sizeof(WORD), info.dwCursorPosition, &read_len)) return lerror(L, "ReadConsoleOutputAttribute"); lua_pushnumber(L, color); return 1; @@ -65,9 +66,10 @@ static int Lget_consolecolor(lua_State *L) { static int Lset_consolecolor(lua_State *L) { int color = luaL_checkint(L, 1); HWND console = GetStdHandle(STD_OUTPUT_HANDLE); - lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle"); - lassert(L, SetConsoleTextAttribute(console, color), "SetConsoleTextAttribute"); - return 0; + if (console == INVALID_HANDLE_VALUE) return lerror(L, "GetStdHandle"); + if (!SetConsoleTextAttribute(console, color)) return lerror(L, "SetConsoleTextAttribute"); + lua_pushboolean(L, 1); + return 1; } static const luaL_Reg Reg[] = -- cgit v1.2.3 From bd95b3ba7be4490956e242753869d969f08504c6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Jan 2011 04:42:05 +0500 Subject: mod_ping: Use util.datetime to generate timestamp in ad-hoc command response (instead of the current use of os.date, which doesn't take timezone into account). --- plugins/mod_ping.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mod_ping.lua b/plugins/mod_ping.lua index c0ba6189..0bfcac66 100644 --- a/plugins/mod_ping.lua +++ b/plugins/mod_ping.lua @@ -22,8 +22,10 @@ module:hook("iq/host/urn:xmpp:ping:ping", ping_handler); -- Ad-hoc command +local datetime = require "util.datetime".datetime; + function ping_command_handler (self, data, state) - local now = os.date("%Y-%m-%dT%X"); + local now = datetime(); return { info = "Pong\n"..now, status = "completed" }; end -- cgit v1.2.3 From 4e486d4ba9300c553a7a8fce15037141d48a77f5 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Jan 2011 04:42:56 +0500 Subject: stanza_router: Return a error on invalid IQ type. --- core/stanza_router.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 97d328a1..406ad2f0 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -40,6 +40,7 @@ local function handle_unhandled_stanza(host, origin, stanza) end end +local iq_types = { set=true, get=true, result=true, error=true }; function core_process_stanza(origin, stanza) (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag()) @@ -47,8 +48,8 @@ function core_process_stanza(origin, stanza) if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log if stanza.name == "iq" then if not stanza.attr.id then stanza.attr.id = ""; end -- COMPAT Jabiru doesn't send the id attribute on roster requests - if (stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1) then - origin.send(st.error_reply(stanza, "modify", "bad-request")); + if not iq_types[stanza.attr.type] or ((stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1)) then + origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid IQ type or incorrect number of children")); return; end end -- cgit v1.2.3