Changeset

4131:81636fa77cab

Merge 0.8->trunk
author Waqas Hussain <waqas20@gmail.com>
date Sat, 29 Jan 2011 04:54:08 +0500 (2011-01-28)
parents 4126:5044698a9d90 (current diff) 4130:c3508071af47 (diff)
children 4133:71b38dca22c3
files core/s2smanager.lua
diffstat 4 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/core/s2smanager.lua	Fri Jan 21 14:02:56 2011 +0000
+++ b/core/s2smanager.lua	Sat Jan 29 04:54:08 2011 +0500
@@ -76,7 +76,8 @@
 				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
--- a/core/stanza_router.lua	Fri Jan 21 14:02:56 2011 +0000
+++ b/core/stanza_router.lua	Sat Jan 29 04:54:08 2011 +0500
@@ -40,6 +40,7 @@
 	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 @@
 	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
--- a/plugins/mod_ping.lua	Fri Jan 21 14:02:56 2011 +0000
+++ b/plugins/mod_ping.lua	Sat Jan 29 04:54:08 2011 +0500
@@ -22,8 +22,10 @@
 
 -- 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
 
--- a/util-src/windows.c	Fri Jan 21 14:02:56 2011 +0000
+++ b/util-src/windows.c	Sat Jan 29 04:54:08 2011 +0500
@@ -38,15 +38,16 @@
 		}
 		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 @@
 	
 	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 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[] =