25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Removed unneeded use of length function + Remove trailing spaces

SVN Revision: 2610
This commit is contained in:
Mickaël Rémond 2009-09-21 15:10:50 +00:00
parent d6f63ceec5
commit 325660a547

View File

@ -48,7 +48,7 @@
-define(SETS, gb_sets). -define(SETS, gb_sets).
-record(state, {socket, encoding, port, password, -record(state, {socket, encoding, port, password,
queue, user, host, server, nick, queue, user, host, server, nick,
channels = dict:new(), channels = dict:new(),
nickchannel, nickchannel,
@ -83,7 +83,7 @@ start_link(From, Host, Server, Username, Encoding, Port, Password) ->
%% Returns: {ok, StateName, StateData} | %% Returns: {ok, StateName, StateData} |
%% {ok, StateName, StateData, Timeout} | %% {ok, StateName, StateData, Timeout} |
%% ignore | %% ignore |
%% {stop, StopReason} %% {stop, StopReason}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
init([From, Host, Server, Username, Encoding, Port, Password]) -> init([From, Host, Server, Username, Encoding, Port, Password]) ->
gen_fsm:send_event(self(), init), gen_fsm:send_event(self(), init),
@ -100,7 +100,7 @@ init([From, Host, Server, Username, Encoding, Port, Password]) ->
%% Func: StateName/2 %% Func: StateName/2
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
open_socket(init, StateData) -> open_socket(init, StateData) ->
Addr = StateData#state.server, Addr = StateData#state.server,
@ -109,8 +109,8 @@ open_socket(init, StateData) ->
case gen_tcp:connect(Addr, Port, [binary, {packet, 0}]) of case gen_tcp:connect(Addr, Port, [binary, {packet, 0}]) of
{ok, Socket} -> {ok, Socket} ->
NewStateData = StateData#state{socket = Socket}, NewStateData = StateData#state{socket = Socket},
if if
StateData#state.password /= "" -> StateData#state.password /= "" ->
send_text(NewStateData, send_text(NewStateData,
io_lib:format("PASS ~s\r\n", [StateData#state.password])); io_lib:format("PASS ~s\r\n", [StateData#state.password]));
true -> true true -> true
@ -159,7 +159,7 @@ stream_established(closed, StateData) ->
%% {reply, Reply, NextStateName, NextStateData} | %% {reply, Reply, NextStateName, NextStateData} |
%% {reply, Reply, NextStateName, NextStateData, Timeout} | %% {reply, Reply, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
%state_name(Event, From, StateData) -> %state_name(Event, From, StateData) ->
% Reply = ok, % Reply = ok,
@ -169,7 +169,7 @@ stream_established(closed, StateData) ->
%% Func: handle_event/3 %% Func: handle_event/3
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_event(_Event, StateName, StateData) -> handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}. {next_state, StateName, StateData}.
@ -181,7 +181,7 @@ handle_event(_Event, StateName, StateData) ->
%% {reply, Reply, NextStateName, NextStateData} | %% {reply, Reply, NextStateName, NextStateData} |
%% {reply, Reply, NextStateName, NextStateData, Timeout} | %% {reply, Reply, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_sync_event(_Event, _From, StateName, StateData) -> handle_sync_event(_Event, _From, StateName, StateData) ->
Reply = ok, Reply = ok,
@ -203,7 +203,7 @@ code_change(_OldVsn, StateName, StateData, _Extra) ->
%% Func: handle_info/3 %% Func: handle_info/3
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_info({route_chan, Channel, Resource, handle_info({route_chan, Channel, Resource,
{xmlelement, "presence", Attrs, _Els}}, {xmlelement, "presence", Attrs, _Els}},
@ -249,11 +249,9 @@ handle_info({route_chan, Channel, Resource,
NewStateData == stop -> NewStateData == stop ->
{stop, normal, StateData}; {stop, normal, StateData};
true -> true ->
case length(dict:fetch_keys(NewStateData#state.channels)) of case dict:fetch_keys(NewStateData#state.channels) of
0 -> [] -> {stop, normal, NewStateData};
{stop, normal, NewStateData}; _ -> {next_state, StateName, NewStateData}
_ ->
{next_state, StateName, NewStateData}
end end
end; end;
@ -787,7 +785,7 @@ process_channel_topic_who(StateData, Chan, String) ->
Msg1 = case Words of Msg1 = case Words of
[_, "333", _, _Chan, Whoset , Timeset] -> [_, "333", _, _Chan, Whoset , Timeset] ->
case string:to_integer(Timeset) of case string:to_integer(Timeset) of
{Unixtimeset, _Rest} -> {Unixtimeset, _Rest} ->
"Topic for #" ++ Chan ++ " set by " ++ Whoset ++ "Topic for #" ++ Chan ++ " set by " ++ Whoset ++
" at " ++ unixtime2string(Unixtimeset); " at " ++ unixtime2string(Unixtimeset);
_-> _->
@ -1007,7 +1005,7 @@ process_topic(StateData, Chan, From, String) ->
process_part(StateData, Chan, From, String) -> process_part(StateData, Chan, From, String) ->
[FromUser | FromIdent] = string:tokens(From, "!"), [FromUser | FromIdent] = string:tokens(From, "!"),
{ok, Msg, _} = regexp:sub(String, ".*PART[^:]*:", ""), {ok, Msg, _} = regexp:sub(String, ".*PART[^:]*:", ""),
Msg1 = filter_message(Msg), Msg1 = filter_message(Msg),
ejabberd_router:route( ejabberd_router:route(
jlib:make_jid(lists:concat([Chan, "%", StateData#state.server]), jlib:make_jid(lists:concat([Chan, "%", StateData#state.server]),
@ -1035,7 +1033,7 @@ process_part(StateData, Chan, From, String) ->
process_quit(StateData, From, String) -> process_quit(StateData, From, String) ->
[FromUser | FromIdent] = string:tokens(From, "!"), [FromUser | FromIdent] = string:tokens(From, "!"),
{ok, Msg, _} = regexp:sub(String, ".*QUIT[^:]*:", ""), {ok, Msg, _} = regexp:sub(String, ".*QUIT[^:]*:", ""),
Msg1 = filter_message(Msg), Msg1 = filter_message(Msg),
%%NewChans = %%NewChans =
@ -1301,7 +1299,7 @@ unixtime2string(Unixtime) ->
Secs = Unixtime + calendar:datetime_to_gregorian_seconds( Secs = Unixtime + calendar:datetime_to_gregorian_seconds(
{{1970, 1, 1}, {0,0,0}}), {{1970, 1, 1}, {0,0,0}}),
case calendar:universal_time_to_local_time( case calendar:universal_time_to_local_time(
calendar:gregorian_seconds_to_datetime(Secs)) of calendar:gregorian_seconds_to_datetime(Secs)) of
{{Year, Month, Day}, {Hour, Minute, Second}} -> {{Year, Month, Day}, {Hour, Minute, Second}} ->
lists:flatten( lists:flatten(
io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w",
@ -1319,4 +1317,3 @@ toupper([C | Cs]) ->
end; end;
toupper([]) -> toupper([]) ->
[]. [].