socks-handler
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -7,3 +7,3 @@ var socks4, socks5; | ||
exports.handle = function(stream, handlers, callback) { | ||
exports.handle = function(stream, callback) { | ||
return stream.once('data', function(chunk) { | ||
@@ -29,5 +29,3 @@ var handler, version; | ||
}); | ||
return handler.on('error', function(err) { | ||
return typeof callback === "function" ? callback(err) : void 0; | ||
}); | ||
return callback(null, handler); | ||
}); | ||
@@ -34,0 +32,0 @@ }; |
@@ -8,19 +8,15 @@ var COMMAND, REQUEST_STATUS, RSV, VERSION, defaults, name, parsers, through, value, _ref, _ref1, | ||
defaults = require('./defaults'); | ||
_ref = require('./const'), VERSION = _ref.VERSION, COMMAND = _ref.COMMAND, REQUEST_STATUS = _ref.REQUEST_STATUS, RSV = _ref.RSV; | ||
exports.createHandler = function(_handlers) { | ||
var handlers, name, onwrite, request, step, value; | ||
defaults = { | ||
request: function(infos, callback) { | ||
return callback(REQUEST_STATUS.FAILED); | ||
} | ||
}; | ||
exports.createHandler = function() { | ||
var handler, methods, name, request, step, value; | ||
step = 'request'; | ||
handlers = {}; | ||
for (name in defaults) { | ||
value = defaults[name]; | ||
handlers[name] = value; | ||
} | ||
for (name in _handlers) { | ||
value = _handlers[name]; | ||
handlers[name] = value; | ||
} | ||
onwrite = function(chunk) { | ||
methods = {}; | ||
handler = through(function(chunk) { | ||
switch (step) { | ||
@@ -30,3 +26,11 @@ case 'request': | ||
} | ||
}); | ||
handler.set = function(name, value) { | ||
methods[name] = value; | ||
return handler; | ||
}; | ||
for (name in defaults) { | ||
value = defaults[name]; | ||
handler.set(name, value); | ||
} | ||
request = function(data) { | ||
@@ -41,3 +45,3 @@ var e, | ||
} | ||
return handlers.request(request, function(status) { | ||
return methods.request(request, function(status) { | ||
_this.push(new Buffer([RSV, status].concat(__slice.call(request.portBuffer), __slice.call(request.hostBuffer)))); | ||
@@ -52,3 +56,3 @@ if (status !== REQUEST_STATUS.GRANTED) { | ||
}; | ||
return through(onwrite); | ||
return handler; | ||
}; | ||
@@ -55,0 +59,0 @@ |
var ADDRTYPE, AUTH_METHOD, AUTH_STATUS, COMMAND, REQUEST_STATUS, RSV, VERSION, defaults, ip, name, net, parsers, through, value, _ref, _ref1, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, | ||
__slice = [].slice; | ||
@@ -12,20 +13,28 @@ | ||
defaults = require('./defaults'); | ||
_ref = require('./const'), VERSION = _ref.VERSION, AUTH_METHOD = _ref.AUTH_METHOD, COMMAND = _ref.COMMAND, AUTH_STATUS = _ref.AUTH_STATUS, ADDRTYPE = _ref.ADDRTYPE, REQUEST_STATUS = _ref.REQUEST_STATUS, RSV = _ref.RSV; | ||
exports.createHandler = function(_handlers) { | ||
var authMethod, authentication, handlers, handshake, name, onwrite, request, step, value; | ||
defaults = { | ||
handshake: function(_arg, callback) { | ||
var methods, _ref1; | ||
methods = _arg.methods; | ||
if (_ref1 = AUTH_METHOD.NOAUTH, __indexOf.call(methods, _ref1) >= 0) { | ||
return callback(AUTH_METHOD.NOAUTH); | ||
} else { | ||
return callback(AUTH_METHOD.NO_ACCEPTABLE_METHOD); | ||
} | ||
}, | ||
auth: function(infos, callback) { | ||
return callback(AUTH_STATUS.FAILURE); | ||
}, | ||
request: function(infos, callback) { | ||
return callback(REQUEST_STATUS.SERVER_FAILURE); | ||
} | ||
}; | ||
exports.createHandler = function() { | ||
var authMethod, authentication, handler, handshake, methods, name, request, step, value; | ||
step = 'handshake'; | ||
authMethod = -1; | ||
handlers = {}; | ||
for (name in defaults) { | ||
value = defaults[name]; | ||
handlers[name] = value; | ||
} | ||
for (name in _handlers) { | ||
value = _handlers[name]; | ||
handlers[name] = value; | ||
} | ||
onwrite = function(chunk) { | ||
methods = {}; | ||
handler = through(function(chunk) { | ||
switch (step) { | ||
@@ -39,3 +48,11 @@ case 'handshake': | ||
} | ||
}); | ||
handler.set = function(name, value) { | ||
methods[name] = value; | ||
return handler; | ||
}; | ||
for (name in defaults) { | ||
value = defaults[name]; | ||
handler.set(name, value); | ||
} | ||
handshake = function(data) { | ||
@@ -50,3 +67,3 @@ var e, | ||
} | ||
return handlers.handshake(handshake, function(method) { | ||
return methods.handshake(handshake, function(method) { | ||
_this.push(new Buffer([VERSION, method])); | ||
@@ -72,3 +89,3 @@ if (method === AUTH_METHOD.NO_ACCEPTABLE_METHOD) { | ||
} | ||
return handlers.auth(auth, function(status) { | ||
return methods.auth(auth, function(status) { | ||
_this.push(new Buffer([VERSION, status])); | ||
@@ -91,3 +108,3 @@ if (status !== AUTH_STATUS.SUCCESS) { | ||
} | ||
return handlers.request(request, function(status, localPort, localAddress) { | ||
return methods.request(request, function(status, localPort, localAddress) { | ||
var addrType, hostBuffer, portBuffer; | ||
@@ -123,3 +140,3 @@ if (localPort) { | ||
}; | ||
return through(onwrite); | ||
return handler; | ||
}; | ||
@@ -126,0 +143,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Alexandre Kirszenberg <a.kirszenberg@gmail.com>", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "socks", |
13752
11
415