mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 14:47:12 -04:00
handler/SocketIORouter: use jshint
This commit is contained in:
parent
9c126674b3
commit
e7b2a2b3b9
1 changed files with 19 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* This is the Socket.IO Router. It routes the Messages between the
|
* This is the Socket.IO Router. It routes the Messages between the
|
||||||
* components of the Server. The components are at the moment: pad and timeslider
|
* components of the Server. The components are at the moment: pad and timeslider
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ var securityManager = require("../db/SecurityManager");
|
||||||
* Saves all components
|
* Saves all components
|
||||||
* key is the component name
|
* key is the component name
|
||||||
* value is the component module
|
* value is the component module
|
||||||
*/
|
*/
|
||||||
var components = {};
|
var components = {};
|
||||||
|
|
||||||
var socket;
|
var socket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a component
|
* adds a component
|
||||||
*/
|
*/
|
||||||
|
@ -40,10 +40,10 @@ exports.addComponent = function(moduleName, module)
|
||||||
{
|
{
|
||||||
//save the component
|
//save the component
|
||||||
components[moduleName] = module;
|
components[moduleName] = module;
|
||||||
|
|
||||||
//give the module the socket
|
//give the module the socket
|
||||||
module.setSocketIO(socket);
|
module.setSocketIO(socket);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the socket.io and adds event functions for routing
|
* sets the socket.io and adds event functions for routing
|
||||||
|
@ -52,31 +52,31 @@ exports.setSocketIO = function(_socket)
|
||||||
{
|
{
|
||||||
//save this socket internaly
|
//save this socket internaly
|
||||||
socket = _socket;
|
socket = _socket;
|
||||||
|
|
||||||
socket.sockets.on('connection', function(client)
|
socket.sockets.on('connection', function(client)
|
||||||
{
|
{
|
||||||
var clientAuthorized = false;
|
var clientAuthorized = false;
|
||||||
|
|
||||||
//wrap the original send function to log the messages
|
//wrap the original send function to log the messages
|
||||||
client._send = client.send;
|
client._send = client.send;
|
||||||
client.send = function(message)
|
client.send = function(message)
|
||||||
{
|
{
|
||||||
messageLogger.info("to " + client.id + ": " + stringifyWithoutPassword(message));
|
messageLogger.info("to " + client.id + ": " + stringifyWithoutPassword(message));
|
||||||
client._send(message);
|
client._send(message);
|
||||||
}
|
};
|
||||||
|
|
||||||
//tell all components about this connect
|
//tell all components about this connect
|
||||||
for(var i in components)
|
for(var i in components)
|
||||||
{
|
{
|
||||||
components[i].handleConnect(client);
|
components[i].handleConnect(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
//try to handle the message of this client
|
//try to handle the message of this client
|
||||||
function handleMessage(message)
|
function handleMessage(message)
|
||||||
{
|
{
|
||||||
if(message.component && components[message.component])
|
if(message.component && components[message.component])
|
||||||
{
|
{
|
||||||
//check if component is registered in the components array
|
//check if component is registered in the components array
|
||||||
if(components[message.component])
|
if(components[message.component])
|
||||||
{
|
{
|
||||||
messageLogger.info("from " + client.id + ": " + stringifyWithoutPassword(message));
|
messageLogger.info("from " + client.id + ": " + stringifyWithoutPassword(message));
|
||||||
|
@ -87,8 +87,8 @@ exports.setSocketIO = function(_socket)
|
||||||
{
|
{
|
||||||
messageLogger.error("Can't route the message:" + stringifyWithoutPassword(message));
|
messageLogger.error("Can't route the message:" + stringifyWithoutPassword(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on('message', function(message)
|
client.on('message', function(message)
|
||||||
{
|
{
|
||||||
if(message.protocolVersion && message.protocolVersion != 2)
|
if(message.protocolVersion && message.protocolVersion != 2)
|
||||||
|
@ -111,7 +111,7 @@ exports.setSocketIO = function(_socket)
|
||||||
securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, function(err, statusObject)
|
securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, function(err, statusObject)
|
||||||
{
|
{
|
||||||
ERR(err);
|
ERR(err);
|
||||||
|
|
||||||
//access was granted, mark the client as authorized and handle the message
|
//access was granted, mark the client as authorized and handle the message
|
||||||
if(statusObject.accessStatus == "grant")
|
if(statusObject.accessStatus == "grant")
|
||||||
{
|
{
|
||||||
|
@ -143,21 +143,21 @@ exports.setSocketIO = function(_socket)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
//returns a stringified representation of a message, removes the password
|
//returns a stringified representation of a message, removes the password
|
||||||
//this ensures there are no passwords in the log
|
//this ensures there are no passwords in the log
|
||||||
function stringifyWithoutPassword(message)
|
function stringifyWithoutPassword(message)
|
||||||
{
|
{
|
||||||
var newMessage = {};
|
var newMessage = {};
|
||||||
|
|
||||||
for(var i in message)
|
for(var i in message)
|
||||||
{
|
{
|
||||||
if(i == "password" && message[i] != null)
|
if(i == "password" && message[i])
|
||||||
newMessage["password"] = "xxx";
|
newMessage.password = "xxx";
|
||||||
else
|
else
|
||||||
newMessage[i]=message[i];
|
newMessage[i]=message[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(newMessage);
|
return JSON.stringify(newMessage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue