From 399d170a784aa6be19f183a4b2cc40620a8f6caa Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Sat, 28 Oct 2006 02:04:55 +0000 Subject: * src/mod_proxy65/: XEP-0065 proxy (thanks to Evgeniy Khramtsov) * src/Makefile.win32: Likewise * src/Makefile.in: Likewise * src/configure.ac: Likewise * src/jlib.hrl: Likewise * src/ejabberd.hrl: Added the ejabberd URL SVN Revision: 666 --- src/mod_proxy65/mod_proxy65_lib.erl | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/mod_proxy65/mod_proxy65_lib.erl (limited to 'src/mod_proxy65/mod_proxy65_lib.erl') diff --git a/src/mod_proxy65/mod_proxy65_lib.erl b/src/mod_proxy65/mod_proxy65_lib.erl new file mode 100644 index 00000000..09ee6b98 --- /dev/null +++ b/src/mod_proxy65/mod_proxy65_lib.erl @@ -0,0 +1,69 @@ +%%%---------------------------------------------------------------------- +%%% File : mod_proxy65_lib.erl +%%% Author : Evgeniy Khramtsov +%%% Purpose : SOCKS5 parsing library. +%%% Created : 12 Oct 2006 by Evgeniy Khramtsov +%%% Id : $Id$ +%%%---------------------------------------------------------------------- + +-module(mod_proxy65_lib). +-author('xram@jabber.ru'). + +-include("mod_proxy65.hrl"). + +-export([ + unpack_init_message/1, + unpack_auth_request/1, + unpack_request/1, + make_init_reply/1, + make_auth_reply/1, + make_reply/0, + make_error_reply/1, + make_error_reply/2 + ]). + +unpack_init_message(<>) + when N > 0, N < 256 -> + {ok, binary_to_list(AuthMethodList)}; + +unpack_init_message(_) -> + error. + +unpack_auth_request(<<1, ULen, User:ULen/binary, + PLen, Pass:PLen/binary>>) when ULen < 256, PLen < 256 -> + {binary_to_list(User), binary_to_list(Pass)}; + +unpack_auth_request(_) -> + error. + +unpack_request(<>) when CMD == ?CMD_CONNECT; + CMD == ?CMD_UDP -> + Command = if + CMD == ?CMD_CONNECT -> connect; + CMD == ?CMD_UDP -> udp + end, + #s5_request{cmd = Command, rsv = RSV, sha1 = binary_to_list(SHA1)}; + +unpack_request(_) -> + error. + +make_init_reply(Method) -> + [?VERSION_5, Method]. + +make_auth_reply(true) -> [1, ?SUCCESS]; +make_auth_reply(false) -> [1, ?ERR_NOT_ALLOWED]. + +%% WARNING: According to SOCKS5 RFC, this reply is _incorrect_, but +%% Psi writes junk to the beginning of the file on correct reply. +%% I'm not sure, but there may be an issue with other clients. +%% Needs more testing. +make_reply() -> + [?VERSION_5, ?SUCCESS, 0, 0, 0, 0]. + +make_error_reply(Request) -> + make_error_reply(Request, ?ERR_NOT_ALLOWED). + +make_error_reply(#s5_request{rsv = RSV, sha1 = SHA1}, Reason) -> + [?VERSION_5, Reason, RSV, ?ATYP_DOMAINNAME, length(SHA1), SHA1, 0,0]. -- cgit v1.2.3