2005-11-22 Alexey Shchepin <alexey@sevcom.net>
+ * src/web/ejabberd_web_admin.erl: Fixed encoding of user names in
+ URLs
+
+ * src/web/ejabberd_http.erl: Added url_encode function from yaws
+
* src/ejabberd_c2s.erl: Send stream error when connection is
replaced (thanks to Maxim Ryazanov)
%% External exports
-export([start/2,
start_link/2,
- receive_headers/1]).
+ receive_headers/1,
+ url_encode/1]).
-include("ejabberd.hrl").
-include("jlib.hrl").
[].
+url_encode([H|T]) ->
+ if
+ H >= $a, $z >= H ->
+ [H|url_encode(T)];
+ H >= $A, $Z >= H ->
+ [H|url_encode(T)];
+ H >= $0, $9 >= H ->
+ [H|url_encode(T)];
+ H == $_; H == $.; H == $-; H == $/; H == $: -> % FIXME: more..
+ [H|url_encode(T)];
+ true ->
+ case integer_to_hex(H) of
+ [X, Y] ->
+ [$%, X, Y | url_encode(T)];
+ [X] ->
+ [$%, $0, X | url_encode(T)]
+ end
+ end;
+
+url_encode([]) ->
+ [].
+
+integer_to_hex(I) ->
+ case catch erlang:integer_to_list(I, 16) of
+ {'EXIT', _} ->
+ old_integer_to_hex(I);
+ Int ->
+ Int
+ end.
+
+
+old_integer_to_hex(I) when I<10 ->
+ integer_to_list(I);
+old_integer_to_hex(I) when I<16 ->
+ [I-10+$A];
+old_integer_to_hex(I) when I>=16 ->
+ N = trunc(I/16),
+ old_integer_to_hex(N) ++ old_integer_to_hex(I rem 16).
+
+
% The following code is mostly taken from yaws_ssl.erl
parse_request(State, Data) ->
?T("Online")
end,
?XE("tr",
- [?XE("td", [?AC(URLFunc({user, Prefix, User, Server}),
- us_to_list(US))]),
+ [?XE("td",
+ [?AC(URLFunc({user, Prefix,
+ ejabberd_http:url_encode(User),
+ Server}),
+ us_to_list(US))]),
?XE("td", FQueueLen),
?XC("td", FLast)])
end, Users)
SUsers = lists:usort(Users),
lists:flatmap(
fun({S, U} = SU) ->
- [?AC("../user/" ++ U ++ "/", su_to_list(SU)), ?BR]
+ [?AC("../user/" ++ ejabberd_http:url_encode(U) ++ "/",
+ su_to_list(SU)),
+ ?BR]
end, SUsers).
user_info(User, Server, Query, Lang) ->