aboutsummaryrefslogtreecommitdiff
path: root/src/mod_proxy65/mod_proxy65_service.erl
diff options
context:
space:
mode:
authorJérôme Sautret <jerome.sautret@process-one.net>2007-06-27 10:01:39 +0000
committerJérôme Sautret <jerome.sautret@process-one.net>2007-06-27 10:01:39 +0000
commit9cd3a6db0742d7923a545bdc043fba5c0393ba33 (patch)
treeddbeeb737332340ff1c01dbf7dcc617b72e4d8a5 /src/mod_proxy65/mod_proxy65_service.erl
parent* src/mod_muc/mod_muc_room.erl: Include <body/> in MUC invitations (diff)
Unsafe working version of http file transfer
SVN Revision: 798
Diffstat (limited to 'src/mod_proxy65/mod_proxy65_service.erl')
-rw-r--r--src/mod_proxy65/mod_proxy65_service.erl81
1 files changed, 70 insertions, 11 deletions
diff --git a/src/mod_proxy65/mod_proxy65_service.erl b/src/mod_proxy65/mod_proxy65_service.erl
index f9f3bf12d..c590f22f7 100644
--- a/src/mod_proxy65/mod_proxy65_service.erl
+++ b/src/mod_proxy65/mod_proxy65_service.erl
@@ -23,6 +23,7 @@
%% API.
-export([start_link/2]).
+-include("mod_proxy65.hrl").
-include("../ejabberd.hrl").
-include("../jlib.hrl").
@@ -34,6 +35,8 @@
name,
stream_addr,
port,
+ http_port,
+ http_base_path,
acl
}).
@@ -84,12 +87,14 @@ handle_info(_Info, State) ->
%%%------------------------
%% disco#info request
-process_iq(_, #iq{type = get, xmlns = ?NS_DISCO_INFO, lang = Lang} = IQ, #state{name=Name}) ->
+process_iq(_, #iq{type = get, xmlns = ?NS_DISCO_INFO} = IQ, #state{name=Name, http_port=HTTP_Port}) ->
+ io:format("~p~n", [IQ]),
IQ#iq{type = result, sub_el =
- [{xmlelement, "query", [{"xmlns", ?NS_DISCO_INFO}], iq_disco_info(Lang, Name)}]};
+ [{xmlelement, "query", [{"xmlns", ?NS_DISCO_INFO}], iq_disco_info(Name, HTTP_Port)}]};
%% disco#items request
process_iq(_, #iq{type = get, xmlns = ?NS_DISCO_ITEMS} = IQ, _) ->
+ io:format("~p~n", [IQ]),
IQ#iq{type = result, sub_el =
[{xmlelement, "query", [{"xmlns", ?NS_DISCO_ITEMS}], []}]};
@@ -101,6 +106,7 @@ process_iq(_, #iq{type = get, xmlns = ?NS_VCARD, lang = Lang} = IQ, _) ->
%% bytestreams info request
process_iq(JID, #iq{type = get, sub_el = SubEl, xmlns = ?NS_BYTESTREAMS} = IQ,
#state{acl = ACL, stream_addr = StreamAddr, serverhost = ServerHost}) ->
+ io:format("~p~n", [IQ]),
case acl:match_rule(ServerHost, ACL, JID) of
allow ->
StreamHostEl = [{xmlelement, "streamhost", StreamAddr, []}],
@@ -110,9 +116,39 @@ process_iq(JID, #iq{type = get, sub_el = SubEl, xmlns = ?NS_BYTESTREAMS} = IQ,
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}
end;
+
+%% bytestream target fake connection (for later http connection)
+process_iq(TargetJID, #iq{type = set, sub_el = SubEl, xmlns = ?NS_HTTP_BYTESTREAMS} = IQ,
+ #state{acl = _ACL, myhost = MyHost,
+ http_port=HTTP_Port, http_base_path=HTTP_Base_Path}) ->
+ % XXX TODO: acl
+ SID = xml:get_tag_attr_s("sid", SubEl),
+ case catch jlib:string_to_jid(xml:get_tag_attr_s("jid", SubEl)) of
+ InitiatorJID when is_record(InitiatorJID, jid), SID /= "",
+ length(SID) =< 128, TargetJID /= InitiatorJID ->
+ Target = jlib:jid_to_string(jlib:jid_tolower(TargetJID)),
+ Initiator = jlib:jid_to_string(jlib:jid_tolower(InitiatorJID)),
+ SHA1 = sha:sha(SID ++ Initiator ++ Target),
+ URL = "http://" ++ MyHost ++ ":"++HTTP_Port++ HTTP_Base_Path,
+ case catch mod_proxy65_sm:register_stream(SHA1, TargetJID, URL, MyHost, self()) of
+ {atomic, ok} ->
+ IQ#iq{type = result, sub_el =
+ [{xmlelement, "connected",
+ [{"xmlns", ?NS_HTTP_BYTESTREAMS}, {"jid", MyHost}], []}]};
+ _Reason ->
+ ?ERROR_MSG("process IQ set ~p:~n~p~n", [?NS_HTTP_BYTESTREAMS, _Reason]),
+ IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
+ end;
+ _Reason ->
+ ?ERROR_MSG("process IQ set ~p:~n~p~n", [?NS_HTTP_BYTESTREAMS, _Reason]),
+ IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}
+ end;
+
+
%% bytestream activation request
process_iq(InitiatorJID, #iq{type = set, sub_el = SubEl, xmlns = ?NS_BYTESTREAMS} = IQ,
- #state{acl = ACL, serverhost = ServerHost}) ->
+ #state{acl = ACL, serverhost = ServerHost, myhost = MyHost,
+ http_port=HTTP_Port, http_base_path=HTTP_Base_Path}) ->
case acl:match_rule(ServerHost, ACL, InitiatorJID) of
allow ->
ActivateEl = xml:get_path_s(SubEl, [{elem, "activate"}]),
@@ -123,9 +159,21 @@ process_iq(InitiatorJID, #iq{type = set, sub_el = SubEl, xmlns = ?NS_BYTESTREAMS
Target = jlib:jid_to_string(jlib:jid_tolower(TargetJID)),
Initiator = jlib:jid_to_string(jlib:jid_tolower(InitiatorJID)),
SHA1 = sha:sha(SID ++ Initiator ++ Target),
- case mod_proxy65_sm:activate_stream(SHA1, InitiatorJID, TargetJID, ServerHost) of
+ {Module, Activated} =
+ case xml:get_path_s(SubEl, [{elem, "x"}]) of
+ {xmlelement, "x", [{"xmlns", ?NS_HTTP_BYTESTREAMS}], _} ->
+ {mod_proxy65_http,
+ [{xmlelement, "activated",
+ [{"xmlns", ?NS_HTTP_BYTESTREAMS},
+ {"url", "http://" ++ MyHost ++ ":"++HTTP_Port++
+ HTTP_Base_Path ++ ?DEFAULT_HTTP_UPLOAD_PATH}], []}]};
+ _ ->
+ {mod_proxy65_sm, []}
+ end,
+ case mod_proxy65_sm:activate_stream(SHA1, InitiatorJID, TargetJID,
+ ServerHost, Module) of
ok ->
- IQ#iq{type = result, sub_el = []};
+ IQ#iq{type = result, sub_el = Activated};
false ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]};
limit ->
@@ -135,7 +183,8 @@ process_iq(InitiatorJID, #iq{type = set, sub_el = SubEl, xmlns = ?NS_BYTESTREAMS
_ ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
end;
- _ ->
+ _Reason ->
+ ?ERROR_MSG("process IQ set ~p:~n~p~n", [?NS_BYTESTREAMS, _Reason]),
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}
end;
deny ->
@@ -155,15 +204,21 @@ process_iq(_, _, _) ->
%%%-------------------------
-define(FEATURE(Feat), {xmlelement,"feature",[{"var", Feat}],[]}).
-iq_disco_info(Lang, Name) ->
+iq_disco_info(Name, HTTP_Port) ->
+ HTTP_Bytestreams = case HTTP_Port of
+ "0" ->
+ [];
+ _ ->
+ [?FEATURE(?NS_HTTP_BYTESTREAMS)]
+ end,
[{xmlelement, "identity",
[{"category", "proxy"},
{"type", "bytestreams"},
- {"name", translate:translate(Lang, Name)}], []},
+ {"name", Name}], []},
?FEATURE(?NS_DISCO_INFO),
?FEATURE(?NS_DISCO_ITEMS),
?FEATURE(?NS_VCARD),
- ?FEATURE(?NS_BYTESTREAMS)].
+ ?FEATURE(?NS_BYTESTREAMS)] ++ HTTP_Bytestreams.
iq_vcard(Lang) ->
[{xmlelement, "FN", [],
@@ -177,6 +232,8 @@ iq_vcard(Lang) ->
parse_options(ServerHost, Opts) ->
MyHost = gen_mod:get_opt(host, Opts, "proxy." ++ ServerHost),
Port = gen_mod:get_opt(port, Opts, 7777),
+ HTTP_Port = integer_to_list(gen_mod:get_opt(http_port, Opts, 0)),
+ HTTP_Base_Path = gen_mod:get_opt(http_base_path, Opts, ?DEFAULT_HTTP_BASE_PATH),
ACL = gen_mod:get_opt(access, Opts, all),
Name = gen_mod:get_opt(name, Opts, "SOCKS5 Bytestreams"),
IP = case gen_mod:get_opt(ip, Opts, none) of
@@ -189,7 +246,9 @@ parse_options(ServerHost, Opts) ->
serverhost = ServerHost,
name = Name,
port = Port,
- stream_addr = StreamAddr,
+ http_port = HTTP_Port,
+ http_base_path = HTTP_Base_Path,
+ stream_addr = StreamAddr,
acl = ACL}}.
%% Return the IP of the proxy host, or if not found, the ip of the xmpp domain
@@ -201,4 +260,4 @@ get_proxy_or_domainip(ServerHost, MyHost) ->
{ok, Addr} -> Addr;
{error, _} -> {127,0,0,1}
end
- end. \ No newline at end of file
+ end.