diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-02-26 10:07:12 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-02-26 10:07:12 +0300 |
commit | c1439ddd5bff82292919774c224a2bf3c8f63258 (patch) | |
tree | cc80ebe280ac56fcdfa9656f8f03a1938f53bdeb /src/ejabberd_web_admin.erl | |
parent | Don't pass empty resource to jid:make() (diff) |
Get rid of jid:to_string/1 and jid:from_string/1
Diffstat (limited to 'src/ejabberd_web_admin.erl')
-rw-r--r-- | src/ejabberd_web_admin.erl | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/ejabberd_web_admin.erl b/src/ejabberd_web_admin.erl index 968a122b..0a6f6873 100644 --- a/src/ejabberd_web_admin.erl +++ b/src/ejabberd_web_admin.erl @@ -257,15 +257,16 @@ get_auth_admin(Auth, HostHTTP, RPath, Method) -> case Auth of {SJID, Pass} -> {HostOfRule, AccessRule} = get_acl_rule(RPath, Method), - case jid:from_string(SJID) of - error -> {unauthorized, <<"badformed-jid">>}; - #jid{user = <<"">>, server = User} -> - get_auth_account(HostOfRule, AccessRule, User, HostHTTP, - Pass); - #jid{user = User, server = Server} -> - get_auth_account(HostOfRule, AccessRule, User, Server, - Pass) - end; + try jid:decode(SJID) of + #jid{user = <<"">>, server = User} -> + get_auth_account(HostOfRule, AccessRule, User, HostHTTP, + Pass); + #jid{user = User, server = Server} -> + get_auth_account(HostOfRule, AccessRule, User, Server, + Pass) + catch _:{bad_jid, _} -> + {unauthorized, <<"badformed-jid">>} + end; undefined -> {unauthorized, <<"no-auth-provided">>} end. @@ -1213,7 +1214,7 @@ string_to_spec(<<"server_regexp">>, Val) -> {server_regexp, Val}; string_to_spec(<<"node_regexp">>, Val) -> #jid{luser = U, lserver = S, resource = <<"">>} = - jid:from_string(Val), + jid:decode(Val), {node_regexp, U, S}; string_to_spec(<<"user_glob">>, Val) -> string_to_spec2(user_glob, Val); @@ -1221,7 +1222,7 @@ string_to_spec(<<"server_glob">>, Val) -> {server_glob, Val}; string_to_spec(<<"node_glob">>, Val) -> #jid{luser = U, lserver = S, resource = <<"">>} = - jid:from_string(Val), + jid:decode(Val), {node_glob, U, S}; string_to_spec(<<"all">>, _) -> all; string_to_spec(<<"raw">>, Val) -> @@ -1231,7 +1232,7 @@ string_to_spec(<<"raw">>, Val) -> string_to_spec2(ACLName, Val) -> #jid{luser = U, lserver = S, resource = <<"">>} = - jid:from_string(Val), + jid:decode(Val), case U of <<"">> -> {ACLName, S}; _ -> {ACLName, {U, S}} @@ -1447,16 +1448,17 @@ list_users_parse_query(Query, Host) -> lists:keysearch(<<"newusername">>, 1, Query), {value, {_, Password}} = lists:keysearch(<<"newuserpassword">>, 1, Query), - case jid:from_string(<<Username/binary, "@", + try jid:decode(<<Username/binary, "@", Host/binary>>) of - error -> error; #jid{user = User, server = Server} -> case ejabberd_auth:try_register(User, Server, Password) of {error, _Reason} -> error; _ -> ok end + catch _:{bad_jid, _} -> + error end; false -> nothing end. @@ -1547,10 +1549,10 @@ get_lastactivity_menuitem_list(Server) -> end. us_to_list({User, Server}) -> - jid:to_string({User, Server, <<"">>}). + jid:encode({User, Server, <<"">>}). su_to_list({Server, User}) -> - jid:to_string({User, Server, <<"">>}). + jid:encode({User, Server, <<"">>}). %%%================================== %%%% get_stats |