mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Bosh compliance: honor xmpp:version (thanks to Stefan Strigler)
SVN Revision: 2275
This commit is contained in:
parent
01dc4611b9
commit
5048b6bdaf
@ -3,12 +3,12 @@
|
||||
%%% Author : Stefan Strigler <steve@zeank.in-berlin.de>
|
||||
%%% Purpose : HTTP Binding support (JEP-0124)
|
||||
%%% Created : 21 Sep 2005 by Stefan Strigler <steve@zeank.in-berlin.de>
|
||||
%%% Id : $Id: ejabberd_http_bind.erl 156 2007-06-25 09:22:57Z cromain $
|
||||
%%% Id : $Id: ejabberd_http_bind.erl 239 2007-08-03 10:54:00Z sstrigler $
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
-module(ejabberd_http_bind).
|
||||
-author('steve@zeank.in-berlin.de').
|
||||
-vsn('$Rev: 156 $').
|
||||
-vsn('$Rev: 239 $').
|
||||
|
||||
-behaviour(gen_fsm).
|
||||
|
||||
@ -64,6 +64,8 @@
|
||||
-define(FSMOPTS, []).
|
||||
-endif.
|
||||
|
||||
-define(BOSH_VERSION, "1.6").
|
||||
|
||||
-define(MAX_REQUESTS, 2). % number of simultaneous requests
|
||||
-define(MIN_POLLING, "2"). % don't poll faster than that or we will
|
||||
% shoot you
|
||||
@ -119,7 +121,8 @@ process_request(Data) ->
|
||||
"condition='improper-addressing' "
|
||||
"xmlns='http://jabber.org/protocol/httpbind'/>"};
|
||||
true ->
|
||||
Sid = if
|
||||
Sid =
|
||||
if
|
||||
(ParsedSid == "") ->
|
||||
%% create new session
|
||||
NewSid = sha:sha(term_to_binary({now(), make_ref()})),
|
||||
@ -152,11 +155,12 @@ process_request(Data) ->
|
||||
CHold
|
||||
end
|
||||
end,
|
||||
XmppVersion = xml:get_attr_s("xmpp:version", Attrs),
|
||||
mnesia:transaction(
|
||||
fun() ->
|
||||
mnesia:write(#http_bind{id = NewSid,
|
||||
pid = Pid,
|
||||
to = XmppDomain,
|
||||
to = {XmppDomain, XmppVersion},
|
||||
wait = Wait,
|
||||
hold = Hold})
|
||||
end),
|
||||
@ -189,7 +193,7 @@ process_request(Data) ->
|
||||
end,
|
||||
ParsedSid
|
||||
end,
|
||||
%% ?DEBUG("~n InPacket: ~s ~n", [InPacket]),
|
||||
%% ?DEBUG("~n InPacket: ~s ~n", [InPacket]),
|
||||
case http_put(Sid, Rid, Key, NewKey, Hold, InPacket, StreamStart) of
|
||||
{error, not_exists} ->
|
||||
?DEBUG("no session associated with sid: ~p", [Sid]),
|
||||
@ -278,6 +282,16 @@ prepare_response(Sid,ParsedSid,Rid,Wait,Hold,Attrs) ->
|
||||
"condition='host-unknown' "
|
||||
"xmlns='http://jabber.org/protocol/httpbind'/>"};
|
||||
true ->
|
||||
BOSH_attribs =
|
||||
[{"authid", AuthID},
|
||||
{"xmlns:xmpp", "urn:xmpp:xbosh"},
|
||||
{"xmlns:stream","http://etherx.jabber.org/streams"}] ++
|
||||
case OutEls of
|
||||
[] ->
|
||||
[];
|
||||
_ ->
|
||||
[{"xmpp:version", "1.0"}]
|
||||
end,
|
||||
{200, ?HEADER,
|
||||
xml:element_to_string(
|
||||
{xmlelement,"body",
|
||||
@ -289,8 +303,10 @@ prepare_response(Sid,ParsedSid,Rid,Wait,Hold,Attrs) ->
|
||||
{"inactivity",
|
||||
integer_to_list(trunc(?MAX_INACTIVITY/1000))},
|
||||
{"polling", ?MIN_POLLING},
|
||||
{"authid", AuthID}
|
||||
],OutEls})}
|
||||
{"ver", ?BOSH_VERSION},
|
||||
{"from", To},
|
||||
{"secure", "true"} %% we're always being secure
|
||||
] ++ BOSH_attribs,OutEls})}
|
||||
end
|
||||
end
|
||||
end.
|
||||
@ -480,7 +496,7 @@ handle_sync_event(stop, _From, _StateName, StateData) ->
|
||||
Reply = ok,
|
||||
{stop, normal, Reply, StateData};
|
||||
|
||||
handle_sync_event({http_put, Rid, Key, NewKey, Hold, Packet, StartTo},
|
||||
handle_sync_event({http_put, Rid, Key, NewKey, Hold, Packet, StreamTo},
|
||||
_From, StateName, StateData) ->
|
||||
%% check if Rid valid
|
||||
RidAllow = case Rid of
|
||||
@ -602,14 +618,17 @@ handle_sync_event({http_put, Rid, Key, NewKey, Hold, Packet, StartTo},
|
||||
}};
|
||||
{Receiver, _Tag} ->
|
||||
SendPacket =
|
||||
if
|
||||
StartTo /= "" ->
|
||||
["<stream:stream to='",
|
||||
StartTo,
|
||||
"' xmlns='jabber:client' "
|
||||
%%"version='1.0' "
|
||||
case StreamTo of
|
||||
{To, ""} ->
|
||||
["<stream:stream to='", To, "' "
|
||||
"xmlns='jabber:client' "
|
||||
"xmlns:stream='http://etherx.jabber.org/streams'>"] ++ Packet;
|
||||
true ->
|
||||
{To, Version} ->
|
||||
["<stream:stream to='", To, "' "
|
||||
"xmlns='jabber:client' "
|
||||
"version='", Version, "' "
|
||||
"xmlns:stream='http://etherx.jabber.org/streams'>"] ++ Packet;
|
||||
_ ->
|
||||
Packet
|
||||
end,
|
||||
?DEBUG("really sending now: ~s", [SendPacket]),
|
||||
@ -732,12 +751,12 @@ http_put(Sid, Rid, Key, NewKey, Hold, Packet, Restart) ->
|
||||
[] ->
|
||||
?DEBUG("not found",[]),
|
||||
{error, not_exists};
|
||||
[#http_bind{pid = FsmRef,to=To}] ->
|
||||
[#http_bind{pid = FsmRef,to=StreamTo}] ->
|
||||
case Restart of
|
||||
true ->
|
||||
?DEBUG("restart requested for ~s", [To]),
|
||||
gen_fsm:sync_send_all_state_event(
|
||||
FsmRef, {http_put, Rid, Key, NewKey, Hold, Packet, To});
|
||||
FsmRef, {http_put, Rid, Key, NewKey, Hold, Packet, StreamTo});
|
||||
_ ->
|
||||
gen_fsm:sync_send_all_state_event(
|
||||
FsmRef, {http_put, Rid, Key, NewKey, Hold, Packet, ""})
|
||||
|
Loading…
Reference in New Issue
Block a user