25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

o Change the usage of #state.lang somewhat.

o  Fix value of DefaultLang: it doesn't contain the whole serialized
attribute.
o  Use exmpp_jid:make_bare_jid/2 more.

I started to work on the second half of the module and discovered
several annoying things:
o  JID are represented in two forms: the #jid record and the
{N, D, R} tuple.
o  Sometimes, #xmlelement may contain non-#xml* tuples in their
children. This is the case for some <presence/> stanzas. Their
children are used to pass random data.
I'm less and less convicted that ejabberd_c2s can be fully converted
without starting to work on other modules.

SVN Revision: 1370
This commit is contained in:
Jean-Sébastien Pédron 2008-06-20 14:54:59 +00:00
parent 06eea52ad8
commit 2a43998444
2 changed files with 29 additions and 29 deletions

View File

@ -8,6 +8,10 @@
FSM state function are updated. But other functions are not for now. FSM state function are updated. But other functions are not for now.
Users are able to connect to ejabberd but some features may not work. Users are able to connect to ejabberd but some features may not work.
* src/ejabberd_c2s.erl: Change the usage of #state.lang somewhat.
Fix value of DefaultLang: it doesn't contain the whole serialized
attribute. Use exmpp_jid:make_bare_jid/2 more.
2008-06-19 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-06-19 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/ejabberd_receiver.erl: Replace the use of xml_stream by * src/ejabberd_receiver.erl: Replace the use of xml_stream by

View File

@ -142,7 +142,6 @@
-define(NS_AUTH, "jabber:iq:auth"). -define(NS_AUTH, "jabber:iq:auth").
-define(NS_FEATURE_COMPRESS, "http://jabber.org/features/compress"). -define(NS_FEATURE_COMPRESS, "http://jabber.org/features/compress").
-define(NS_PRIVACY, "jabber:iq:privacy"). -define(NS_PRIVACY, "jabber:iq:privacy").
-define(NS_VCARD, "vcard-temp").
-define(STREAM_ERROR(Condition), -define(STREAM_ERROR(Condition),
exmpp_xml:xmlel_to_xmlelement(exmpp_stream:error(Condition), exmpp_xml:xmlel_to_xmlelement(exmpp_stream:error(Condition),
@ -273,9 +272,9 @@ get_subscribed_and_online(FsmRef) ->
wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) -> wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
DefaultLang = case ?MYLANG of DefaultLang = case ?MYLANG of
undefined -> undefined ->
" xml:lang='en'"; "en";
DL -> DL ->
" xml:lang='" ++ DL ++ "'" DL
end, end,
Header = exmpp_stream:opening_reply(Opening, Header = exmpp_stream:opening_reply(Opening,
StateData#state.streamid), StateData#state.streamid),
@ -287,8 +286,9 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
case lists:member(Server, ?MYHOSTS) of case lists:member(Server, ?MYHOSTS) of
true -> true ->
Lang = exmpp_stream:get_lang(Opening), Lang = exmpp_stream:get_lang(Opening),
% OLD FORMAT: JID with empty strings.
change_shaper(StateData, change_shaper(StateData,
exmpp_jid:make_jid("", Server, "")), exmpp_jid:make_bare_jid(undefined, Server)),
case exmpp_stream:get_version(Opening) of case exmpp_stream:get_version(Opening) of
{1, 0} -> {1, 0} ->
send_element(StateData, Header1), send_element(StateData, Header1),
@ -375,7 +375,7 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
send_element(StateData, send_element(StateData,
exmpp_xml:append_child(Header1, exmpp_xml:append_child(Header1,
exmpp_stream:error('policy-violation', exmpp_stream:error('policy-violation',
Lang, "Use of STARTTLS required"))), "en", "Use of STARTTLS required"))),
{stop, normal, StateData}; {stop, normal, StateData};
true -> true ->
send_element(StateData, Header1), send_element(StateData, Header1),
@ -437,7 +437,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
fsm_next_state(wait_for_auth, StateData); fsm_next_state(wait_for_auth, StateData);
{auth, _ID, set, {_U, _P, _D, ""}} -> {auth, _ID, set, {_U, _P, _D, ""}} ->
Err = exmpp_stanza:error('not-acceptable', Err = exmpp_stanza:error('not-acceptable',
{StateData#state.lang, "No resource provided"}), {"en", "No resource provided"}),
send_element(StateData, exmpp_iq:error(El, Err)), send_element(StateData, exmpp_iq:error(El, Err)),
fsm_next_state(wait_for_auth, StateData); fsm_next_state(wait_for_auth, StateData);
{auth, _ID, set, {U, P, D, R}} -> {auth, _ID, set, {U, P, D, R}} ->
@ -468,7 +468,8 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
StateData#state.server, StateData#state.server,
{[], []}, {[], []},
[U, StateData#state.server]), [U, StateData#state.server]),
LJID = {JID#jid.lnode, JID#jid.ldomain, ""}, LJID = {JID#jid.lnode, JID#jid.ldomain,
undefined},
Fs1 = [LJID | Fs], Fs1 = [LJID | Fs],
Ts1 = [LJID | Ts], Ts1 = [LJID | Ts],
PrivList = ejabberd_hooks:run_fold( PrivList = ejabberd_hooks:run_fold(
@ -633,9 +634,8 @@ wait_for_feature_request({xmlstreamelement, #xmlel{ns = NS, name = Name} = El},
_ -> _ ->
if if
(SockMod == gen_tcp) and TLSRequired -> (SockMod == gen_tcp) and TLSRequired ->
Lang = StateData#state.lang,
send_element(StateData, exmpp_stream:error( send_element(StateData, exmpp_stream:error(
'policy-violation', Lang, "Use of STARTTLS required")), 'policy-violation', "en", "Use of STARTTLS required")),
send_element(StateData, exmpp_stream:closing()), send_element(StateData, exmpp_stream:closing()),
{stop, normal, StateData}; {stop, normal, StateData};
true -> true ->
@ -742,7 +742,7 @@ wait_for_bind({xmlstreamelement, El}, StateData) ->
Err = exmpp_server_binding:error(El, 'bad-request'), Err = exmpp_server_binding:error(El, 'bad-request'),
send_element(StateData, Err), send_element(StateData, Err),
fsm_next_state(wait_for_bind, StateData); fsm_next_state(wait_for_bind, StateData);
throw:Exception -> throw:_Exception ->
fsm_next_state(wait_for_bind, StateData) fsm_next_state(wait_for_bind, StateData)
end; end;
@ -789,7 +789,7 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
StateData#state.server, StateData#state.server,
{[], []}, {[], []},
[U, StateData#state.server]), [U, StateData#state.server]),
LJID = {JID#jid.lnode, JID#jid.ldomain, ""}, LJID = {JID#jid.lnode, JID#jid.ldomain, undefined},
Fs1 = [LJID | Fs], Fs1 = [LJID | Fs],
Ts1 = [LJID | Ts], Ts1 = [LJID | Ts],
PrivList = PrivList =
@ -805,6 +805,8 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
pres_t = ?SETS:from_list(Ts1), pres_t = ?SETS:from_list(Ts1),
privacy_list = PrivList}); privacy_list = PrivList});
_ -> _ ->
% OLD FORMAT: Jid may use 'undefined' instead of empty
% strings.
ejabberd_hooks:run(forbidden_session_hook, ejabberd_hooks:run(forbidden_session_hook,
StateData#state.server, [JID]), StateData#state.server, [JID]),
?INFO_MSG("(~w) Forbidden session for ~s", ?INFO_MSG("(~w) Forbidden session for ~s",
@ -843,15 +845,15 @@ session_established({xmlstreamelement, El}, StateData) ->
FromJID = StateData#state.jid, FromJID = StateData#state.jid,
To = exmpp_stanza:get_recipient(El), To = exmpp_stanza:get_recipient(El),
ToJID = case To of ToJID = case To of
"" -> undefined ->
exmpp_jid:make_jid(User, Server, ""); exmpp_jid:make_bare_jid(User, Server);
_ -> _ ->
exmpp_jid:string_to_jid(To) exmpp_jid:string_to_jid(To)
end, end,
NewEl = case exmpp_stanza:get_lang(El) of NewEl = case exmpp_stanza:get_lang(El) of
"" -> undefined ->
case StateData#state.lang of case StateData#state.lang of
"" -> El; undefined -> El;
Lang -> Lang ->
exmpp_stanza:set_lang(El, Lang) exmpp_stanza:set_lang(El, Lang)
end; end;
@ -889,17 +891,12 @@ session_established({xmlstreamelement, El}, StateData) ->
StateData) StateData)
end; end;
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'iq'} -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'iq'} ->
IQ_Content = case exmpp_iq:get_type(El) of case exmpp_iq:get_payload(El) of
'get' -> exmpp_iq:get_request(El); #xmlel{ns = ?NS_PRIVACY} ->
'set' -> exmpp_iq:get_request(El);
'result' -> exmpp_iq:get_result(El);
'error' -> exmpp_stanza:get_error(El)
end,
case IQ_Content of
#xmlel{ns = ?NS_PRIVACY} = IQ ->
% XXX OLD FORMAT: IQ was #iq. % XXX OLD FORMAT: IQ was #iq.
IQ_Record = exmpp_iq:make_iq_record(El),
process_privacy_iq( process_privacy_iq(
FromJID, ToJID, IQ, StateData); FromJID, ToJID, IQ_Record, StateData);
_ -> _ ->
% XXX OLD FORMAT: NewElOld. % XXX OLD FORMAT: NewElOld.
NewElOld = exmpp_xml:xmlel_to_xmlelement(NewEl, NewElOld = exmpp_xml:xmlel_to_xmlelement(NewEl,
@ -1018,6 +1015,7 @@ handle_sync_event({get_presence}, _From, StateName, StateData) ->
fsm_reply(Reply, StateName, StateData); fsm_reply(Reply, StateName, StateData);
handle_sync_event(get_subscribed_and_online, _From, StateName, StateData) -> handle_sync_event(get_subscribed_and_online, _From, StateName, StateData) ->
% XXX OLD FORMAT: This function needs update. User has the form {N, D, R}.
Subscribed = StateData#state.pres_f, Subscribed = StateData#state.pres_f,
Online = StateData#state.pres_available, Online = StateData#state.pres_available,
Pred = fun(User, _Caps) -> Pred = fun(User, _Caps) ->
@ -1042,15 +1040,13 @@ code_change(_OldVsn, StateName, StateData, _Extra) ->
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_info({send_text, Text}, StateName, StateData) -> handle_info({send_text, Text}, StateName, StateData) ->
% XXX OLD FORMAT: This clause should be removed.
send_text(StateData, Text), send_text(StateData, Text),
ejabberd_hooks:run(c2s_loop_debug, [Text]), ejabberd_hooks:run(c2s_loop_debug, [Text]),
fsm_next_state(StateName, StateData); fsm_next_state(StateName, StateData);
handle_info(replaced, _StateName, StateData) -> handle_info(replaced, _StateName, StateData) ->
Lang = StateData#state.lang, send_element(StateData, exmpp_stream:error('conflict')),
send_text(StateData, send_element(StateData, exmpp_stream:closing()),
xml:element_to_string(
?SERRT_CONFLICT(Lang, "Replaced by new connection"))
++ ?STREAM_TRAILER),
{stop, normal, StateData#state{authenticated = replaced}}; {stop, normal, StateData#state{authenticated = replaced}};
handle_info({route, From, To, Packet}, StateName, StateData) -> handle_info({route, From, To, Packet}, StateName, StateData) ->
{xmlelement, Name, Attrs, Els} = Packet, {xmlelement, Name, Attrs, Els} = Packet,