]> granicus.if.org Git - ejabberd/commitdiff
Get rid of jid:to_string/1 and jid:from_string/1
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sun, 26 Feb 2017 07:07:12 +0000 (10:07 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sun, 26 Feb 2017 07:07:12 +0000 (10:07 +0300)
55 files changed:
rebar.config
src/ejabberd_c2s.erl
src/ejabberd_captcha.erl
src/ejabberd_oauth.erl
src/ejabberd_oauth_rest.erl
src/ejabberd_oauth_sql.erl
src/ejabberd_piefxis.erl
src/ejabberd_router.erl
src/ejabberd_router_multicast.erl
src/ejabberd_sm.erl
src/ejabberd_system_monitor.erl
src/ejabberd_web_admin.erl
src/jlib.erl
src/mod_admin_extra.erl
src/mod_client_state.erl
src/mod_configure.erl
src/mod_echo.erl
src/mod_http_api.erl
src/mod_http_upload.erl
src/mod_http_upload_quota.erl
src/mod_irc.erl
src/mod_irc_connection.erl
src/mod_irc_sql.erl
src/mod_mam.erl
src/mod_mam_sql.erl
src/mod_mix.erl
src/mod_muc_admin.erl
src/mod_muc_log.erl
src/mod_muc_mnesia.erl
src/mod_muc_riak.erl
src/mod_muc_room.erl
src/mod_muc_sql.erl
src/mod_multicast.erl
src/mod_offline.erl
src/mod_offline_sql.erl
src/mod_pres_counter.erl
src/mod_privacy.erl
src/mod_privacy_sql.erl
src/mod_proxy65_service.erl
src/mod_proxy65_stream.erl
src/mod_pubsub.erl
src/mod_register.erl
src/mod_roster.erl
src/mod_roster_sql.erl
src/mod_shared_roster.erl
src/mod_shared_roster_mnesia.erl
src/mod_shared_roster_riak.erl
src/mod_shared_roster_sql.erl
src/mod_stream_mgmt.erl
src/mod_vcard.erl
src/node_flat_sql.erl
src/nodetree_virtual.erl
src/prosody2ejabberd.erl
src/xmpp_stream_out.erl
src/xmpp_stream_pkix.erl

index 467857148998637923e00e023af69bec32443127..bc8fc4d05003138ab8aef9676df393beb3e63624 100644 (file)
@@ -24,7 +24,7 @@
         {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.10"}}},
         {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.7"}}},
         {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.21"}}},
-        {xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "1.1.8"}}},
+        {xmpp, ".*", {git, "https://github.com/processone/xmpp", "f5cbd6dc0f3ec786b33a7e708979ed27dfbbb0ec"}},
         {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.9"}}},
         {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.10"}}},
         {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.8"}}},
index 27dbb14d23f1a37457623e7c7c70f957b053c8e1..aca4ac5dc2709108f378f57f0ee0a20d46a383c0 100644 (file)
@@ -262,7 +262,7 @@ process_terminated(#{sockmod := SockMod, socket := Socket, jid := JID} = State,
                   Reason) ->
     Status = format_reason(State, Reason),
     ?INFO_MSG("(~s) Closing c2s session for ~s: ~s",
-             [SockMod:pp(Socket), jid:to_string(JID), Status]),
+             [SockMod:pp(Socket), jid:encode(JID), Status]),
     State1 = case maps:is_key(pres_last, State) of
                 true ->
                     Pres = #presence{type = unavailable,
@@ -402,12 +402,12 @@ bind(R, #{user := U, server := S, access := Access, lang := Lang,
                    State3 = ejabberd_hooks:run_fold(
                               c2s_session_opened, LServer, State2, []),
                    ?INFO_MSG("(~s) Opened c2s session for ~s",
-                             [SockMod:pp(Socket), jid:to_string(JID)]),
+                             [SockMod:pp(Socket), jid:encode(JID)]),
                    {ok, State3};
                deny ->
                    ejabberd_hooks:run(forbidden_session_hook, LServer, [JID]),
                    ?INFO_MSG("(~s) Forbidden c2s session for ~s",
-                             [SockMod:pp(Socket), jid:to_string(JID)]),
+                             [SockMod:pp(Socket), jid:encode(JID)]),
                    Txt = <<"Denied by ACL">>,
                    {error, xmpp:err_not_allowed(Txt, Lang), State}
            end
index 1762457821a0d740190698447f8ad670305570ac..9d0835bf2b371fa7bda26c39144c09d37b400f1d 100644 (file)
@@ -89,12 +89,12 @@ create_captcha(SID, From, To, Lang, Limiter, Args) ->
     case create_image(Limiter) of
       {ok, Type, Key, Image} ->
          Id = <<(randoms:get_string())/binary>>,
-         JID = jid:to_string(From),
+         JID = jid:encode(From),
          CID = <<"sha1+", (p1_sha:sha(Image))/binary, "@bob.xmpp.org">>,
          Data = #bob_data{cid = CID, 'max-age' = 0, type = Type,
                           data = Image},
          Fs = [mk_field(hidden, <<"FORM_TYPE">>, ?NS_CAPTCHA),
-               mk_field(hidden, <<"from">>, jid:to_string(To)),
+               mk_field(hidden, <<"from">>, jid:encode(To)),
                mk_field(hidden, <<"challenge">>, Id),
                mk_field(hidden, <<"sid">>, SID),
                mk_ocr_field(Lang, CID, Type)],
@@ -134,7 +134,7 @@ create_captcha_x(SID, To, Lang, Limiter, #xdata{fields = Fs} = X) ->
                              label = translate:translate(
                                        Lang, <<"CAPTCHA web page">>),
                              values = [Imageurl]},
-                mk_field(hidden, <<"from">>, jid:to_string(To)),
+                mk_field(hidden, <<"from">>, jid:encode(To)),
                 mk_field(hidden, <<"challenge">>, Id),
                 mk_field(hidden, <<"sid">>, SID),
                 mk_ocr_field(Lang, CID, Type)],
index bda38fc07650c3bc9d12d722b963a2beb1fd9db1..cc8af85b52e9f1a43d67cc5fd34e51f28bd3543a 100644 (file)
@@ -108,18 +108,18 @@ get_commands_spec() ->
 
 oauth_issue_token(Jid, TTLSeconds, ScopesString) ->
     Scopes = [list_to_binary(Scope) || Scope <- string:tokens(ScopesString, ";")],
-    case jid:from_string(list_to_binary(Jid)) of
+    try jid:decode(list_to_binary(Jid)) of
         #jid{luser =Username, lserver = Server} ->
             case oauth2:authorize_password({Username, Server},  Scopes, admin_generated) of
                 {ok, {_Ctx,Authorization}} ->
                     {ok, {_AppCtx2, Response}} = oauth2:issue_token(Authorization, [{expiry_time, TTLSeconds}]),
-            {ok, AccessToken} = oauth2_response:access_token(Response),
-            {ok, VerifiedScope} = oauth2_response:scope(Response),
+                   {ok, AccessToken} = oauth2_response:access_token(Response),
+                   {ok, VerifiedScope} = oauth2_response:scope(Response),
                     {AccessToken, VerifiedScope, integer_to_list(TTLSeconds) ++ " seconds"};
-        {error, Error} ->
-            {error, Error}
-            end;
-        error ->
+               {error, Error} ->
+                   {error, Error}
+            end
+    catch _:{bad_jid, _} ->
             {error, "Invalid JID: " ++ Jid}
     end.
 
@@ -127,7 +127,7 @@ oauth_list_tokens() ->
     Tokens = mnesia:dirty_match_object(#oauth_token{_ = '_'}),
     {MegaSecs, Secs, _MiniSecs} = os:timestamp(),
     TS = 1000000 * MegaSecs + Secs,
-    [{Token, jid:to_string(jid:make(U,S)), Scope, integer_to_list(Expires - TS) ++ " seconds"} ||
+    [{Token, jid:encode(jid:make(U,S)), Scope, integer_to_list(Expires - TS) ++ " seconds"} ||
         #oauth_token{token=Token, scope=Scope, us= {U,S},expire=Expires} <- Tokens].
 
 
@@ -479,7 +479,7 @@ process(_Handlers,
     RedirectURI = proplists:get_value(<<"redirect_uri">>, Q, <<"">>),
     SScope = proplists:get_value(<<"scope">>, Q, <<"">>),
     StringJID = proplists:get_value(<<"username">>, Q, <<"">>),
-    #jid{user = Username, server = Server} = jid:from_string(StringJID),
+    #jid{user = Username, server = Server} = jid:decode(StringJID),
     Password = proplists:get_value(<<"password">>, Q, <<"">>),
     State = proplists:get_value(<<"state">>, Q, <<"">>),
     Scope = str:tokens(SScope, <<" ">>),
@@ -542,7 +542,7 @@ process(_Handlers,
       <<"password">> ->
         SScope = proplists:get_value(<<"scope">>, Q, <<"">>),
         StringJID = proplists:get_value(<<"username">>, Q, <<"">>),
-        #jid{user = Username, server = Server} = jid:from_string(StringJID),
+        #jid{user = Username, server = Server} = jid:decode(StringJID),
         Password = proplists:get_value(<<"password">>, Q, <<"">>),
         Scope = str:tokens(SScope, <<" ">>),
         TTL = proplists:get_value(<<"ttl">>, Q, <<"">>),
index ec9ef0d88a2daacebb79e3edb54ad6c70bbbd2f5..b9614eb096d427384b09c4d985abbab5a901d3e2 100644 (file)
@@ -45,7 +45,7 @@ store(R) ->
     Path = path(<<"store">>),
     %% Retry 2 times, with a backoff of 500millisec
     {User, Server} = R#oauth_token.us,
-    SJID = jid:to_string({User, Server, <<"">>}),
+    SJID = jid:encode({User, Server, <<"">>}),
     case rest:with_retry(
            post,
            [?MYNAME, Path, [],
@@ -68,7 +68,7 @@ lookup(Token) ->
                          2, 500) of
         {ok, 200, {Data}} ->
             SJID = proplists:get_value(<<"user">>, Data, <<>>),
-            JID = jid:from_string(SJID),
+            JID = jid:decode(SJID),
             US = {JID#jid.luser, JID#jid.lserver},
             Scope = proplists:get_value(<<"scope">>, Data, []),
             Expire = proplists:get_value(<<"expire">>, Data, 0),
index 4906600f4bf7435913eb8708be9582451d59bb43..10ca49844ff319eb8faf344f0c150d8982405254 100644 (file)
@@ -44,7 +44,7 @@ init() ->
 store(R) ->
     Token = R#oauth_token.token,
     {User, Server} = R#oauth_token.us,
-    SJID = jid:to_string({User, Server, <<"">>}),
+    SJID = jid:encode({User, Server, <<"">>}),
     Scope = str:join(R#oauth_token.scope, <<" ">>),
     Expire = R#oauth_token.expire,
     ?SQL_UPSERT(
@@ -61,7 +61,7 @@ lookup(Token) ->
            ?SQL("select @(jid)s, @(scope)s, @(expire)d"
                 " from oauth_token where token=%(Token)s")) of
         {selected, [{SJID, Scope, Expire}]} ->
-            JID = jid:from_string(SJID),
+            JID = jid:decode(SJID),
             US = {JID#jid.luser, JID#jid.lserver},
             #oauth_token{token = Token,
                          us = US,
index 6ce8a1ae391fadb5c0c97424a2164de851f490a7..d16f826c77a9293732d3e50791f43be9e60c7d88 100644 (file)
@@ -345,15 +345,15 @@ process_el({xmlstreamelement, #xmlel{name = <<"host">>,
                                      attrs = Attrs,
                                      children = Els}}, State) ->
     JIDS = fxml:get_attr_s(<<"jid">>, Attrs),
-    case jid:from_string(JIDS) of
+    try jid:decode(JIDS) of
         #jid{lserver = S} ->
             case ejabberd_router:is_my_host(S) of
                 true ->
                     process_users(Els, State#state{server = S});
                 false ->
                     stop("Unknown host: ~s", [S])
-            end;
-        error ->
+            end
+    catch _:{bad_jid, _} ->
             stop("Invalid 'jid': ~s", [JIDS])
     end;
 process_el({xmlstreamstart, <<"user">>, Attrs}, State = #state{server = S})
index 17b43c15de60cdad481c2d738faa92cb04614ebf..e54abbefab2e6387cb36def8434c34f69594de3d 100644 (file)
@@ -96,7 +96,7 @@ route(#jid{} = From, #jid{} = To, #xmlel{} = El) ->
     catch _:{xmpp_codec, Why} ->
            ?ERROR_MSG("failed to decode xml element ~p when "
                       "routing from ~s to ~s: ~s",
-                      [El, jid:to_string(From), jid:to_string(To),
+                      [El, jid:encode(From), jid:encode(To),
                        xmpp:format_error(Why)])
     end;
 route(#jid{} = From, #jid{} = To, Packet) ->
index ff2862a72c18b848175cd4b04cf6c1889a50be39..39c119fbb531064b06722eb5d073af33f04ee205 100644 (file)
@@ -213,7 +213,7 @@ code_change(_OldVsn, State, _Extra) ->
 do_route(Domain, Destinations, Packet) ->
     ?DEBUG("route multicast:~n~s~nDomain: ~s~nDestinations: ~s~n",
           [xmpp:pp(Packet), Domain,
-           str:join([jid:to_string(To) || To <- Destinations], <<", ">>)]),
+           str:join([jid:encode(To) || To <- Destinations], <<", ">>)]),
     %% Try to find an appropriate multicast service
     case mnesia:dirty_read(route_multicast, Domain) of
 
index 747434405893663796ac5a0435131c78e7bd9c22..1600a2c923b1e0e67450965791bae78e501a14bd 100644 (file)
@@ -501,7 +501,7 @@ do_route(#jid{lresource = <<"">>} = To, Term) ->
              do_route(jid:replace_resource(To, R), Term)
       end, get_user_resources(To#jid.user, To#jid.server));
 do_route(To, Term) ->
-    ?DEBUG("broadcasting ~p to ~s", [Term, jid:to_string(To)]),
+    ?DEBUG("broadcasting ~p to ~s", [Term, jid:encode(To)]),
     {U, S, R} = jid:tolower(To),
     Mod = get_sm_backend(S),
     case online(Mod:get_sessions(U, S, R)) of
index e4c8f4ef72a27ab14c6044ae73a2538d98ffa190..7b2d9d2640487522c50f7fefb0b9d619c0a32a32 100644 (file)
@@ -209,7 +209,7 @@ get_admin_jids() ->
       watchdog_admins,
       fun(JIDs) ->
               [jid:tolower(
-                 jid:from_string(
+                 jid:decode(
                    iolist_to_binary(S))) || S <- JIDs]
       end, []).
 
@@ -341,7 +341,7 @@ process_remote_command(_) -> throw(unknown_command).
 
 opt_type(watchdog_admins) ->
     fun (JIDs) ->
-           [jid:tolower(jid:from_string(iolist_to_binary(S)))
+           [jid:tolower(jid:decode(iolist_to_binary(S)))
             || S <- JIDs]
     end;
 opt_type(watchdog_large_heap) ->
index 968a122bcd990ec83b5bc6e7ea2e7ef05091cce9..0a6f68735008f716beaa75719f221057778de541 100644 (file)
@@ -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
index 227838f273462d8fe6bda20bf1c6b8aff288b7d9..580ad1ffaeff3df5699d343b0754e27468d310fa 100644 (file)
@@ -218,8 +218,8 @@ replace_from_to_attrs(From, To, Attrs) ->
 replace_from_to(From, To,
                #xmlel{name = Name, attrs = Attrs, children = Els}) ->
     NewAttrs =
-       replace_from_to_attrs(jid:to_string(From),
-                             jid:to_string(To), Attrs),
+       replace_from_to_attrs(jid:encode(From),
+                             jid:encode(To), Attrs),
     #xmlel{name = Name, attrs = NewAttrs, children = Els}.
 
 -spec replace_from_attrs(binary(), [attr()]) -> [attr()].
@@ -232,7 +232,7 @@ replace_from_attrs(From, Attrs) ->
 
 replace_from(From,
             #xmlel{name = Name, attrs = Attrs, children = Els}) ->
-    NewAttrs = replace_from_attrs(jid:to_string(From),
+    NewAttrs = replace_from_attrs(jid:encode(From),
                                  Attrs),
     #xmlel{name = Name, attrs = NewAttrs, children = Els}.
 
@@ -261,12 +261,13 @@ split_jid(J) ->
 -spec string_to_jid(binary()) -> jid() | error.
 
 string_to_jid(S) ->
-    jid:from_string(S).
+    try jid:decode(S)
+    catch _:_ -> error end.
 
 -spec jid_to_string(jid() | ljid()) -> binary().
 
 jid_to_string(J) ->
-    jid:to_string(J).
+    jid:encode(J).
 
 -spec is_nodename(binary()) -> boolean().
 
@@ -626,7 +627,7 @@ add_delay_info(El, From, Time, Desc) ->
                       -> xmlel() | error.
 
 create_delay_tag(TimeStamp, FromJID, Desc) when is_tuple(FromJID) ->
-    From = jid:to_string(FromJID),
+    From = jid:encode(FromJID),
     Stamp = now_to_utc_string(TimeStamp, 3),
     Children = case Desc of
                 <<"">> -> [];
index 3130d66c595a59c55b9cf05405a652d7c252a9de..943882967db9aae46afe65a66c02591b4b25e470 100644 (file)
@@ -1009,10 +1009,10 @@ get_presence(U, S) ->
     OnlinePids = [Pid || Pid <- Pids, Pid=/=none],
     case OnlinePids of
        [] ->
-           {jid:to_string({U, S, <<>>}), <<"unavailable">>, <<"">>};
+           {jid:encode({U, S, <<>>}), <<"unavailable">>, <<"">>};
        [SessionPid|_] ->
            {_User, Resource, Show, Status} = get_presence(SessionPid),
-           FullJID = jid:to_string({U, S, Resource}),
+           FullJID = jid:encode({U, S, Resource}),
            {FullJID, Show, Status}
     end.
 
@@ -1238,7 +1238,7 @@ get_roster(User, Server) ->
 make_roster_xmlrpc(Roster) ->
     lists:foldl(
       fun(Item, Res) ->
-             JIDS = jid:to_string(Item#roster.jid),
+             JIDS = jid:encode(Item#roster.jid),
              Nick = Item#roster.name,
              Subs = atom_to_list(Item#roster.subscription),
              Ask = atom_to_list(Item#roster.ask),
@@ -1418,7 +1418,7 @@ btl(B) -> binary_to_list(B).
 
 srg_get_members(Group, Host) ->
     Members = mod_shared_roster:get_group_explicit_users(Host,Group),
-    [jid:to_string(jid:make(MUser, MServer))
+    [jid:encode(jid:make(MUser, MServer))
      || {MUser, MServer} <- Members].
 
 srg_user_add(User, Host, Group, GroupHost) ->
@@ -1437,8 +1437,8 @@ srg_user_del(User, Host, Group, GroupHost) ->
 %% @doc Send a message to a Jabber account.
 %% @spec (Type::binary(), From::binary(), To::binary(), Subject::binary(), Body::binary()) -> ok
 send_message(Type, From, To, Subject, Body) ->
-    FromJID = jid:from_string(From),
-    ToJID = jid:from_string(To),
+    FromJID = jid:decode(From),
+    ToJID = jid:decode(To),
     Packet = build_packet(Type, Subject, Body),
     ejabberd_router:route(xmpp:set_from_to(Packet, FromJID, ToJID)).
 
@@ -1450,8 +1450,8 @@ build_packet(Type, Subject, Body) ->
 send_stanza(FromString, ToString, Stanza) ->
     try
        #xmlel{} = El = fxml_stream:parse_element(Stanza),
-       #jid{} = From = jid:from_string(FromString),
-       #jid{} = To = jid:from_string(ToString),
+       From = jid:decode(FromString),
+       To = jid:decode(ToString),
        Pkt = xmpp:decode(El, ?NS_CLIENT, [ignore_els]),
        ejabberd_router:route(xmpp:set_from_to(Pkt, From, To))
     catch _:{xmpp_codec, Why} ->
@@ -1460,7 +1460,8 @@ send_stanza(FromString, ToString, Stanza) ->
          _:{badmatch, {error, Why}} ->
            io:format("invalid xml: ~p~n", [Why]),
            {error, Why};
-         _:{badmatch, error} ->
+         _:{bad_jid, S} ->
+           io:format("malformed JID: ~s~n", [S]),
            {error, "JID malformed"}
     end.
 
@@ -1619,7 +1620,7 @@ decide_rip_jid({UName, UServer, _UResource}, Match_list) ->
 decide_rip_jid({UName, UServer}, Match_list) ->
     lists:any(
       fun(Match_string) ->
-             MJID = jid:from_string(list_to_binary(Match_string)),
+             MJID = jid:decode(list_to_binary(Match_string)),
              MName = MJID#jid.luser,
              MServer = MJID#jid.lserver,
              Is_server = is_glob_match(UServer, MServer),
index f6d7292b578b9047e658134c7c366c2c02651597..bbce7259cc7b985c9d238bcbd6170b4ce2d37e0b 100644 (file)
@@ -241,7 +241,7 @@ filter_presence({#presence{meta = #{csi_resend := true}}, _} = Acc) ->
 filter_presence({#presence{to = To, type = Type} = Pres,
                 #{csi_state := inactive} = C2SState})
   when Type == available; Type == unavailable ->
-    ?DEBUG("Got availability presence stanza for ~s", [jid:to_string(To)]),
+    ?DEBUG("Got availability presence stanza for ~s", [jid:encode(To)]),
     enqueue_stanza(presence, Pres, C2SState);
 filter_presence(Acc) ->
     Acc.
@@ -261,7 +261,7 @@ filter_chat_states({#message{from = From, to = To} = Msg,
                    Acc;
                _ ->
                ?DEBUG("Got standalone chat state notification for ~s",
-                      [jid:to_string(To)]),
+                      [jid:encode(To)]),
                    enqueue_stanza(chatstate, Msg, C2SState)
            end;
        false ->
@@ -279,7 +279,7 @@ filter_pep({#message{to = To} = Msg,
        undefined ->
            Acc;
        Node ->
-           ?DEBUG("Got PEP notification for ~s", [jid:to_string(To)]),
+           ?DEBUG("Got PEP notification for ~s", [jid:encode(To)]),
            enqueue_stanza({pep, Node}, Msg, C2SState)
     end;
 filter_pep(Acc) ->
@@ -291,7 +291,7 @@ filter_other({Stanza, #{jid := JID} = C2SState} = Acc) when ?is_stanza(Stanza) -
        #{csi_resend := true} ->
            Acc;
        _ ->
-           ?DEBUG("Won't add stanza for ~s to CSI queue", [jid:to_string(JID)]),
+           ?DEBUG("Won't add stanza for ~s to CSI queue", [jid:encode(JID)]),
            From = xmpp:get_from(Stanza),
            C2SState1 = dequeue_sender(From, C2SState),
            {Stanza, C2SState1}
@@ -331,7 +331,7 @@ enqueue_stanza(_Type, Stanza, State) ->
 dequeue_sender(#jid{luser = U, lserver = S},
               #{csi_queue := Q, jid := JID} = C2SState) ->
     ?DEBUG("Flushing packets of ~s@~s from CSI queue of ~s",
-          [U, S, jid:to_string(JID)]),
+          [U, S, jid:encode(JID)]),
     case queue_take({U, S}, Q) of
        {Stanzas, Q1} ->
            C2SState1 = flush_stanzas(C2SState, Stanzas),
@@ -342,7 +342,7 @@ dequeue_sender(#jid{luser = U, lserver = S},
 
 -spec flush_queue(c2s_state()) -> c2s_state().
 flush_queue(#{csi_queue := Q, jid := JID} = C2SState) ->
-    ?DEBUG("Flushing CSI queue of ~s", [jid:to_string(JID)]),
+    ?DEBUG("Flushing CSI queue of ~s", [jid:encode(JID)]),
     C2SState1 = flush_stanzas(C2SState, queue_to_list(Q)),
     C2SState1#{csi_queue => queue_new()}.
 
index 1af8bf6fff715759d712407f8ac7b47df340f799..65ac6a35d7727ca5810218f6ea7ef925a1cc92c2 100644 (file)
@@ -396,7 +396,7 @@ get_permission_level(JID) ->
          allow ->
              PermLev = get_permission_level(From),
              case get_local_items({PermLev, LServer}, LNode,
-                                  jid:to_string(To), Lang)
+                                  jid:encode(To), Lang)
                  of
                {result, Res} -> {result, Res};
                {error, Error} -> {error, Error}
@@ -418,7 +418,7 @@ get_local_items(Acc, From, #jid{lserver = LServer} = To,
            allow ->
                PermLev = get_permission_level(From),
                case get_local_items({PermLev, LServer}, [],
-                                    jid:to_string(To), Lang)
+                                    jid:encode(To), Lang)
                    of
                  {result, Res} -> {result, Items ++ Res};
                  {error, _Error} -> {result, Items}
@@ -1522,7 +1522,7 @@ set_form(From, Host, ?NS_ADMINL(<<"add-user">>), _Lang,
     AccountString = get_value(<<"accountjid">>, XData),
     Password = get_value(<<"password">>, XData),
     Password = get_value(<<"password-verify">>, XData),
-    AccountJID = jid:from_string(AccountString),
+    AccountJID = jid:decode(AccountString),
     User = AccountJID#jid.luser,
     Server = AccountJID#jid.lserver,
     true = lists:member(Server, ?MYHOSTS),
@@ -1536,7 +1536,7 @@ set_form(From, Host, ?NS_ADMINL(<<"delete-user">>),
                                   XData),
     [_ | _] = AccountStringList,
     ASL2 = lists:map(fun (AccountString) ->
-                            JID = jid:from_string(AccountString),
+                            JID = jid:decode(AccountString),
                             User = JID#jid.luser,
                             Server = JID#jid.lserver,
                             true = Server == Host orelse
@@ -1551,7 +1551,7 @@ set_form(From, Host, ?NS_ADMINL(<<"delete-user">>),
 set_form(From, Host, ?NS_ADMINL(<<"end-user-session">>),
         Lang, XData) ->
     AccountString = get_value(<<"accountjid">>, XData),
-    JID = jid:from_string(AccountString),
+    JID = jid:decode(AccountString),
     LUser = JID#jid.luser,
     LServer = JID#jid.lserver,
     true = LServer == Host orelse
@@ -1587,7 +1587,7 @@ set_form(From, Host, ?NS_ADMINL(<<"end-user-session">>),
 set_form(From, Host,
         ?NS_ADMINL(<<"get-user-password">>), Lang, XData) ->
     AccountString = get_value(<<"accountjid">>, XData),
-    JID = jid:from_string(AccountString),
+    JID = jid:decode(AccountString),
     User = JID#jid.luser,
     Server = JID#jid.lserver,
     true = Server == Host orelse
@@ -1605,7 +1605,7 @@ set_form(From, Host,
         ?NS_ADMINL(<<"change-user-password">>), _Lang, XData) ->
     AccountString = get_value(<<"accountjid">>, XData),
     Password = get_value(<<"password">>, XData),
-    JID = jid:from_string(AccountString),
+    JID = jid:decode(AccountString),
     User = JID#jid.luser,
     Server = JID#jid.lserver,
     true = Server == Host orelse
@@ -1616,7 +1616,7 @@ set_form(From, Host,
 set_form(From, Host,
         ?NS_ADMINL(<<"get-user-lastlogin">>), Lang, XData) ->
     AccountString = get_value(<<"accountjid">>, XData),
-    JID = jid:from_string(AccountString),
+    JID = jid:decode(AccountString),
     User = JID#jid.luser,
     Server = JID#jid.lserver,
     true = Server == Host orelse
@@ -1648,7 +1648,7 @@ set_form(From, Host,
 set_form(From, Host, ?NS_ADMINL(<<"user-stats">>), Lang,
         XData) ->
     AccountString = get_value(<<"accountjid">>, XData),
-    JID = jid:from_string(AccountString),
+    JID = jid:decode(AccountString),
     User = JID#jid.luser,
     Server = JID#jid.lserver,
     true = Server == Host orelse
index 7eeb8d4e9745b7332441fb12cd6c88a8fc004869..861b1a0eff85126411380f52af5314a7538f29a7 100644 (file)
@@ -196,7 +196,7 @@ do_client_version(enabled, From, To) ->
         #iq{to = To, from = From2,
             id = ID, type = result, sub_els = [#version{} = V]}} ->
            ?INFO_MSG("Version of the client ~s:~n~s",
-                     [jid:to_string(To), xmpp:pp(V)])
+                     [jid:encode(To), xmpp:pp(V)])
     after 5000 -> % Timeout in miliseconds: 5 seconds
            []
     end.
index c0e2d8421beb05bb1e15796059a50556a43b752b..e3b1edc9cee49a8c3174dcc701ebcb3ae90ede35 100644 (file)
@@ -139,16 +139,16 @@ depends(_Host, _Opts) ->
 extract_auth(#request{auth = HTTPAuth, ip = {IP, _}}) ->
     Info = case HTTPAuth of
             {SJID, Pass} ->
-                case jid:from_string(SJID) of
+                try jid:decode(SJID) of
                       #jid{luser = User, lserver = Server} ->
                         case ejabberd_auth:check_password(User, <<"">>, Server, Pass) of
                               true ->
                                   #{usr => {User, Server, <<"">>}, caller_server => Server};
                               false ->
                                   {error, invalid_auth}
-                        end;
-                    _ ->
-                          {error, invalid_auth}
+                        end
+               catch _:{bad_jid, _} ->
+                       {error, invalid_auth}
                 end;
             {oauth, Token, _} ->
                   case ejabberd_oauth:check_token(Token) of
index 88982839c18593e9d7a109b22befa99873d59cef..a10f059bde834909cc573b2e4a20cb6a10054732 100644 (file)
@@ -542,7 +542,7 @@ process_iq(#iq{type = get, lang = Lang, from = From,
            end;
        deny ->
            ?DEBUG("Denying HTTP upload slot request from ~s",
-                  [jid:to_string(From)]),
+                  [jid:encode(From)]),
            Txt = <<"Denied by ACL">>,
            xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang))
     end;
@@ -559,7 +559,7 @@ create_slot(#state{service_url = undefined, max_size = MaxSize},
                                                      Size > MaxSize ->
     Text = {<<"File larger than ~w bytes">>, [MaxSize]},
     ?INFO_MSG("Rejecting file ~s from ~s (too large: ~B bytes)",
-             [File, jid:to_string(JID), Size]),
+             [File, jid:encode(JID), Size]),
     {error, xmpp:err_not_acceptable(Text, Lang)};
 create_slot(#state{service_url = undefined,
                   jid_in_url = JIDinURL,
@@ -575,7 +575,7 @@ create_slot(#state{service_url = undefined,
            RandStr = make_rand_string(SecretLength),
            FileStr = make_file_string(File),
            ?INFO_MSG("Got HTTP upload slot for ~s (file: ~s)",
-                     [jid:to_string(JID), File]),
+                     [jid:encode(JID), File]),
            {ok, [UserStr, RandStr, FileStr]};
        deny ->
            {error, xmpp:err_service_unavailable()};
@@ -589,7 +589,7 @@ create_slot(#state{service_url = ServiceURL},
     HttpOptions = [{timeout, ?SERVICE_REQUEST_TIMEOUT}],
     SizeStr = integer_to_binary(Size),
     GetRequest = binary_to_list(ServiceURL) ++
-                    "?jid=" ++ ?URL_ENC(jid:to_string({U, S, <<"">>})) ++
+                    "?jid=" ++ ?URL_ENC(jid:encode({U, S, <<"">>})) ++
                     "&name=" ++ ?URL_ENC(File) ++
                     "&size=" ++ ?URL_ENC(SizeStr) ++
                     "&content_type=" ++ ?URL_ENC(ContentType),
@@ -599,33 +599,33 @@ create_slot(#state{service_url = ServiceURL},
                [<<"http", _/binary>> = PutURL,
                 <<"http", _/binary>> = GetURL] ->
                    ?INFO_MSG("Got HTTP upload slot for ~s (file: ~s)",
-                             [jid:to_string(JID), File]),
+                             [jid:encode(JID), File]),
                    {ok, PutURL, GetURL};
                Lines ->
                    ?ERROR_MSG("Can't parse data received for ~s from <~s>: ~p",
-                              [jid:to_string(JID), ServiceURL, Lines]),
+                              [jid:encode(JID), ServiceURL, Lines]),
                    Txt = <<"Failed to parse HTTP response">>,
                    {error, xmpp:err_service_unavailable(Txt, Lang)}
            end;
        {ok, {402, _Body}} ->
            ?INFO_MSG("Got status code 402 for ~s from <~s>",
-                     [jid:to_string(JID), ServiceURL]),
+                     [jid:encode(JID), ServiceURL]),
            {error, xmpp:err_resource_constraint()};
        {ok, {403, _Body}} ->
            ?INFO_MSG("Got status code 403 for ~s from <~s>",
-                     [jid:to_string(JID), ServiceURL]),
+                     [jid:encode(JID), ServiceURL]),
            {error, xmpp:err_not_allowed()};
        {ok, {413, _Body}} ->
            ?INFO_MSG("Got status code 413 for ~s from <~s>",
-                     [jid:to_string(JID), ServiceURL]),
+                     [jid:encode(JID), ServiceURL]),
            {error, xmpp:err_not_acceptable()};
        {ok, {Code, _Body}} ->
            ?ERROR_MSG("Got unexpected status code for ~s from <~s>: ~B",
-                      [jid:to_string(JID), ServiceURL, Code]),
+                      [jid:encode(JID), ServiceURL, Code]),
            {error, xmpp:err_service_unavailable()};
        {error, Reason} ->
            ?ERROR_MSG("Error requesting upload slot for ~s from <~s>: ~p",
-                      [jid:to_string(JID), ServiceURL, Reason]),
+                      [jid:encode(JID), ServiceURL, Reason]),
            {error, xmpp:err_service_unavailable()}
     end.
 
index 1fbaafe3ac65f6f3b34f7f391259e77e050c9a1b..8d79d16d69257d7ed3f53dceb2c5cd9e43bb308e 100644 (file)
@@ -169,24 +169,24 @@ handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size},
     NewSize = case {HardQuota, SoftQuota} of
                  {0, 0} ->
                      ?DEBUG("No quota specified for ~s",
-                            [jid:to_string(JID)]),
+                            [jid:encode(JID)]),
                      undefined;
                  {0, _} ->
                      ?WARNING_MSG("No hard quota specified for ~s",
-                                  [jid:to_string(JID)]),
+                                  [jid:encode(JID)]),
                      enforce_quota(Path, Size, OldSize, SoftQuota, SoftQuota);
                  {_, 0} ->
                      ?WARNING_MSG("No soft quota specified for ~s",
-                                  [jid:to_string(JID)]),
+                                  [jid:encode(JID)]),
                      enforce_quota(Path, Size, OldSize, HardQuota, HardQuota);
                  _ when SoftQuota > HardQuota ->
                      ?WARNING_MSG("Bad quota for ~s (soft: ~p, hard: ~p)",
-                                  [jid:to_string(JID),
+                                  [jid:encode(JID),
                                    SoftQuota, HardQuota]),
                      enforce_quota(Path, Size, OldSize, SoftQuota, SoftQuota);
                  _ ->
                      ?DEBUG("Enforcing quota for ~s",
-                            [jid:to_string(JID)]),
+                            [jid:encode(JID)]),
                      enforce_quota(Path, Size, OldSize, SoftQuota, HardQuota)
              end,
     NewDiskUsage = if is_integer(NewSize) ->
index c7af2834b1f6387f5e24bbbf6c0924758950fee7..091a267970c7da43eb49904e47b85096c0403742 100644 (file)
@@ -688,7 +688,7 @@ adhoc_join(From, To, #adhoc_command{lang = Lang, xdata = X} = Request) ->
                               To#jid.server),
            Reason = translate:translate(Lang, <<"Join the IRC channel here.">>),
            BodyTxt = {<<"Join the IRC channel in this Jabber ID: ~s">>,
-                      [jid:to_string(RoomJID)]},
+                      [jid:encode(RoomJID)]},
            Invite = #message{
                        from = RoomJID, to = From,
                        body = xmpp:mk_text(BodyTxt, Lang),
@@ -934,7 +934,7 @@ data_to_binary(JID, Data) ->
                                         ?ERROR_MSG("failed to convert "
                                                    "parameter ~p for user ~s",
                                                    [Param,
-                                                    jid:to_string(JID)]);
+                                                    jid:encode(JID)]);
                                    true ->
                                         ?ERROR_MSG("failed to convert "
                                                    "parameter ~p",
index 2b2042bf0728bdbee9ede1ca8a4117511254d0b1..46ed8767eaa3aa947dcf315b04eaecfa9845e035 100644 (file)
@@ -971,7 +971,7 @@ process_userinfo(StateData, _Nick, From) ->
     send_text(StateData,
              io_lib:format("NOTICE ~s :\001USERINFO xmpp:~s\001\r\n",
                            [FromUser,
-                            jid:to_string(StateData#state.user)])).
+                            jid:encode(StateData#state.user)])).
 
 process_topic(StateData, Chan, From, String) ->
     [FromUser | _] = str:tokens(From, <<"!">>),
@@ -1162,7 +1162,7 @@ iq_admin(StateData, Channel, From, _To,
            ejabberd_router:route_error(IQ, Error)
     catch E:R ->
            ?ERROR_MSG("failed to process admin query from ~s: ~p",
-                      [jid:to_string(From), {E, {R, erlang:get_stacktrace()}}]),
+                      [jid:encode(From), {E, {R, erlang:get_stacktrace()}}]),
            ejabberd_router:route_error(
              IQ, xmpp:err_internal_server_error())
     end.
index dd419875d74b50a8d1f2d0d6b46d5c5ed0fbbab6..42c075bfe05786786c55610a8f8b148e6925013c 100644 (file)
@@ -42,7 +42,7 @@ init(_Host, _Opts) ->
     ok.
 
 get_data(LServer, Host, From) ->
-    SJID = jid:to_string(jid:tolower(jid:remove_resource(From))),
+    SJID = jid:encode(jid:tolower(jid:remove_resource(From))),
     case catch ejabberd_sql:sql_query(
                  LServer,
                  ?SQL("select @(data)s from irc_custom"
@@ -54,7 +54,7 @@ get_data(LServer, Host, From) ->
     end.
 
 set_data(LServer, Host, From, Data) ->
-    SJID = jid:to_string(jid:tolower(jid:remove_resource(From))),
+    SJID = jid:encode(jid:tolower(jid:remove_resource(From))),
     SData = jlib:term_to_expr(Data),
     F = fun () ->
                 ?SQL_UPSERT_T(
@@ -72,7 +72,7 @@ export(_Server) ->
                             data = Data}) ->
               case str:suffix(Host, IRCHost) of
                   true ->
-                      SJID = jid:to_string(jid:make(U, S)),
+                      SJID = jid:encode(jid:make(U, S)),
                       SData = jlib:term_to_expr(Data),
                       [?SQL("delete from irc_custom"
                             " where jid=%(SJID)s and host=%(IRCHost)s;"),
@@ -86,7 +86,7 @@ export(_Server) ->
 import(_LServer) ->
     [{<<"select jid, host, data from irc_custom;">>,
       fun([SJID, IRCHost, SData]) ->
-              #jid{luser = U, lserver = S} = jid:from_string(SJID),
+              #jid{luser = U, lserver = S} = jid:decode(SJID),
               Data = ejabberd_sql:decode_term(SData),
               #irc_custom{us_host = {{U, S}, IRCHost},
                           data = Data}
index 5cafea5c347242e79eb30651028a1750a9114e7b..47a9c6ce12d13b09ebb2026f41ed5ff4db06d978 100644 (file)
@@ -889,7 +889,7 @@ msg_to_el(#archive_msg{timestamp = TS, packet = El, nick = Nick,
     catch _:{xmpp_codec, Why} ->
            ?ERROR_MSG("Failed to decode raw element ~p from message "
                       "archive of user ~s: ~s",
-                      [El, jid:to_string(JidArchive), xmpp:format_error(Why)]),
+                      [El, jid:encode(JidArchive), xmpp:format_error(Why)]),
            {error, invalid_xml}
     end.
 
index d553c2e640a35f87755656dc5d708675d57dd27f..5379f4e88bfbfac9711085a37e478f432c395ccb 100644 (file)
@@ -53,7 +53,7 @@ remove_user(LUser, LServer) ->
       ?SQL("delete from archive_prefs where username=%(LUser)s")).
 
 remove_room(LServer, LName, LHost) ->
-    LUser = jid:to_string({LName, LHost, <<>>}),
+    LUser = jid:encode({LName, LHost, <<>>}),
     remove_user(LUser, LServer).
 
 delete_old_messages(ServerHost, TimeStamp, Type) ->
@@ -74,12 +74,12 @@ store(Pkt, LServer, {LUser, LHost}, Type, Peer, Nick, _Dir) ->
     ID = integer_to_binary(TSinteger),
     SUser = case Type of
                chat -> LUser;
-               groupchat -> jid:to_string({LUser, LHost, <<>>})
+               groupchat -> jid:encode({LUser, LHost, <<>>})
            end,
-    BarePeer = jid:to_string(
+    BarePeer = jid:encode(
                 jid:tolower(
                   jid:remove_resource(Peer))),
-    LPeer = jid:to_string(
+    LPeer = jid:encode(
              jid:tolower(Peer)),
     XML = fxml:element_to_binary(Pkt),
     Body = fxml:get_subtag_cdata(Pkt, <<"body">>),
@@ -143,7 +143,7 @@ select(LServer, JidRequestor, #jid{luser = LUser} = JidArchive,
        MAMQuery, RSM, MsgType) ->
     User = case MsgType of
               chat -> LUser;
-              {groupchat, _Role, _MUCState} -> jid:to_string(JidArchive)
+              {groupchat, _Role, _MUCState} -> jid:encode(JidArchive)
           end,
     {Query, CountQuery} = make_sql_query(User, LServer, MAMQuery, RSM),
     % TODO from XEP-0313 v0.2: "To conserve resources, a server MAY place a
@@ -228,11 +228,11 @@ make_sql_query(User, LServer, MAMQuery, RSM) ->
     WithClause = case catch jid:tolower(With) of
                     {_, _, <<>>} ->
                         [<<" and bare_peer='">>,
-                         Escape(jid:to_string(With)),
+                         Escape(jid:encode(With)),
                          <<"'">>];
                     {_, _, _} ->
                         [<<" and peer='">>,
-                         Escape(jid:to_string(With)),
+                         Escape(jid:encode(With)),
                          <<"'">>];
                     _ ->
                         []
@@ -314,8 +314,8 @@ make_archive_el(TS, XML, Peer, Kind, Nick, MsgType, JidRequestor, JidArchive) ->
        #xmlel{} = El ->
            try binary_to_integer(TS) of
                TSInt ->
-                   case jid:from_string(Peer) of
-                       #jid{} = PeerJID ->
+                   try jid:decode(Peer) of
+                       PeerJID ->
                            Now = usec_to_now(TSInt),
                            PeerLJID = jid:tolower(PeerJID),
                            T = case Kind of
@@ -330,24 +330,24 @@ make_archive_el(TS, XML, Peer, Kind, Nick, MsgType, JidRequestor, JidArchive) ->
                                           type = T,
                                           nick = Nick,
                                           peer = PeerLJID},
-                             MsgType, JidRequestor, JidArchive);
-                       error ->
+                             MsgType, JidRequestor, JidArchive)
+                   catch _:{bad_jid, _} ->
                            ?ERROR_MSG("Malformed 'peer' field with value "
                                       "'~s' detected for user ~s in table "
                                       "'archive': invalid JID",
-                                      [Peer, jid:to_string(JidArchive)]),
+                                      [Peer, jid:encode(JidArchive)]),
                            {error, invalid_jid}
                    end
            catch _:_ ->
                    ?ERROR_MSG("Malformed 'timestamp' field with value '~s' "
                               "detected for user ~s in table 'archive': "
                               "not an integer",
-                              [TS, jid:to_string(JidArchive)]),
+                              [TS, jid:encode(JidArchive)]),
                    {error, invalid_timestamp}
            end;
        {error, {_, Reason}} ->
            ?ERROR_MSG("Malformed 'xml' field with value '~s' detected "
                       "for user ~s in table 'archive': ~s",
-                      [XML, jid:to_string(JidArchive), Reason]),
+                      [XML, jid:encode(JidArchive), Reason]),
            {error, invalid_xml}
     end.
index edacd7b910ccb7083101a43674ba5ff1412a4657..940e9898fda86a717cfe991c7b3fc8a89f8e80b9 100644 (file)
@@ -261,7 +261,7 @@ publish_participant(From, To) ->
     LFrom = jid:tolower(BareFrom),
     LTo = jid:tolower(jid:remove_resource(To)),
     Participant = #mix_participant{jid = BareFrom},
-    ItemID = p1_sha:sha(jid:to_string(LFrom)),
+    ItemID = p1_sha:sha(jid:encode(LFrom)),
     mod_pubsub:publish_item(
       LTo, To#jid.lserver, ?NS_MIX_NODES_PARTICIPANTS,
       From, ItemID, [xmpp:encode(Participant)]).
@@ -284,7 +284,7 @@ delete_presence(From, To) ->
 
 delete_participant(From, To) ->
     LFrom = jid:tolower(jid:remove_resource(From)),
-    ItemID = p1_sha:sha(jid:to_string(LFrom)),
+    ItemID = p1_sha:sha(jid:encode(LFrom)),
     delete_presence(From, To),
     delete_item(From, To, ?NS_MIX_NODES_PARTICIPANTS, ItemID).
 
index 714e3dd3a9e69013997ba93075111d5461e37452..4b1509fc9bae60531de4b386ff424e92059f6c1f 100644 (file)
@@ -717,7 +717,7 @@ get_room_occupants(Pid) ->
     S = get_room_state(Pid),
     lists:map(
       fun({_LJID, Info}) ->
-             {jid:to_string(Info#user.jid),
+             {jid:encode(Info#user.jid),
               Info#user.nick,
               atom_to_list(Info#user.role)}
       end,
@@ -744,11 +744,11 @@ get_users_to_invite(RoomJid, UsersString) ->
     UsersStrings = binary:split(UsersString, <<":">>, [global]),
     OccupantsTuples = get_room_occupants(RoomJid#jid.luser,
                                         RoomJid#jid.lserver),
-    OccupantsJids = [jid:from_string(JidString)
+    OccupantsJids = [jid:decode(JidString)
                     || {JidString, _Nick, _} <- OccupantsTuples],
     lists:filtermap(
       fun(UserString) ->
-             UserJid = jid:from_string(UserString),
+             UserJid = jid:decode(UserString),
              Val = lists:all(fun(OccupantJid) ->
                                      UserJid#jid.luser /= OccupantJid#jid.luser
                                          orelse UserJid#jid.lserver /= OccupantJid#jid.lserver
@@ -918,7 +918,7 @@ set_room_affiliation(Name, Service, JID, AffiliationString) ->
     case mod_muc:find_online_room(Name, Service) of
        {ok, Pid} ->
            %% Get the PID for the online room so we can get the state of the room
-           {ok, StateData} = gen_fsm:sync_send_all_state_event(Pid, {process_item_change, {jid:from_string(JID), affiliation, Affiliation, <<"">>}, <<"">>}),
+           {ok, StateData} = gen_fsm:sync_send_all_state_event(Pid, {process_item_change, {jid:decode(JID), affiliation, Affiliation, <<"">>}, <<"">>}),
            mod_muc:store_room(StateData#state.server_host, StateData#state.host, StateData#state.room, make_opts(StateData)),
            ok;
        error ->
@@ -933,11 +933,9 @@ subscribe_room(_User, Nick, _Room, _Nodes) when Nick == <<"">> ->
     throw({error, "Nickname must be set"});
 subscribe_room(User, Nick, Room, Nodes) ->
     NodeList = re:split(Nodes, "\\h*,\\h*"),
-    case jid:from_string(Room) of
+    try jid:decode(Room) of
        #jid{luser = Name, lserver = Host} when Name /= <<"">> ->
-           case jid:from_string(User) of
-               error ->
-                   throw({error, "Malformed user JID"});
+           try jid:decode(User) of
                #jid{lresource = <<"">>} ->
                    throw({error, "User's JID should have a resource"});
                UserJID ->
@@ -954,17 +952,19 @@ subscribe_room(User, Nick, Room, Nodes) ->
                        _ ->
                            throw({error, "The room does not exist"})
                    end
+           catch _:{bad_jid, _} ->
+                   throw({error, "Malformed user JID"})
            end;
        _ ->
            throw({error, "Malformed room JID"})
+    catch _:{bad_jid, _} ->
+           throw({error, "Malformed room JID"})
     end.
 
 unsubscribe_room(User, Room) ->
-    case jid:from_string(Room) of
+    try jid:decode(Room) of
        #jid{luser = Name, lserver = Host} when Name /= <<"">> ->
-           case jid:from_string(User) of
-               error ->
-                   throw({error, "Malformed user JID"});
+           try jid:decode(User) of
                UserJID ->
                    case get_room_pid(Name, Host) of
                        Pid when is_pid(Pid) ->
@@ -979,16 +979,20 @@ unsubscribe_room(User, Room) ->
                        _ ->
                            throw({error, "The room does not exist"})
                    end
+           catch _:{bad_jid, _} ->
+                   throw({error, "Malformed user JID"})
            end;
        _ ->
            throw({error, "Malformed room JID"})
+    catch _:{bad_jid, _} ->
+           throw({error, "Malformed room JID"})
     end.
 
 get_subscribers(Name, Host) ->
     case get_room_pid(Name, Host) of
        Pid when is_pid(Pid) ->
            {ok, JIDList} = gen_fsm:sync_send_all_state_event(Pid, get_subscribers),
-           [jid:to_string(jid:remove_resource(J)) || J <- JIDList];
+           [jid:encode(jid:remove_resource(J)) || J <- JIDList];
        _ ->
            throw({error, "The room does not exist"})
     end.
index 13f0efdfe34ff399e2a0e641fcf110751bd8525b..9e040c237b0bf3b93859df04a58bb950c93e06d7 100644 (file)
@@ -278,7 +278,7 @@ build_filename_string(TimeStamp, OutDir, RoomJID,
     {Fd, Fn, Fnrel}.
 
 get_room_name(RoomJID) ->
-    JID = jid:from_string(RoomJID), JID#jid.user.
+    JID = jid:decode(RoomJID), JID#jid.user.
 
 %% calculate day before
 get_timestamp_daydiff(TimeStamp, Daydiff) ->
@@ -998,7 +998,7 @@ get_room_info(RoomJID, Opts) ->
                      {value, {_, SA}} -> SA;
                      false -> <<"">>
                    end,
-    #room{jid = jid:to_string(RoomJID), title = Title,
+    #room{jid = jid:encode(RoomJID), title = Title,
          subject = Subject, subject_author = SubjectAuthor,
          config = Opts}.
 
@@ -1159,7 +1159,7 @@ role_users_to_string(RoleS, Users) ->
     <<RoleS/binary, ": ", UsersString/binary>>.
 
 get_room_occupants(RoomJIDString) ->
-    RoomJID = jid:from_string(RoomJIDString),
+    RoomJID = jid:decode(RoomJIDString),
     RoomName = RoomJID#jid.luser,
     MucService = RoomJID#jid.lserver,
     StateData = get_room_state(RoomName, MucService),
index 881ec758e2b60c3b981f0c3111b7f4ce67855096..f237c564f43b025d14fa6ad21d33ed027cec3ce9 100644 (file)
@@ -279,7 +279,7 @@ import(_LServer, <<"muc_room">>,
                 opts = Opts});
 import(_LServer, <<"muc_registered">>,
        [J, RoomHost, Nick, _TimeStamp]) ->
-    #jid{user = U, server = S} = jid:from_string(J),
+    #jid{user = U, server = S} = jid:decode(J),
     mnesia:dirty_write(
       #muc_registered{us_host = {{U, S}, RoomHost},
                       nick = Nick}).
index 23681e8831bc5f2ec7284a4cdfdd164ce226cacf..0577ef60b40e2e32cbbf1a34be021e9c6c789018 100644 (file)
@@ -178,7 +178,7 @@ import(_LServer, <<"muc_room">>,
       muc_room_schema());
 import(_LServer, <<"muc_registered">>,
        [J, RoomHost, Nick, _TimeStamp]) ->
-    #jid{user = U, server = S} = jid:from_string(J),
+    #jid{user = U, server = S} = jid:decode(J),
     R = #muc_registered{us_host = {{U, S}, RoomHost}, nick = Nick},
     ejabberd_riak:put(R, muc_registered_schema(),
                      [{'2i', [{<<"nick_host">>, {Nick, RoomHost}}]}]).
index 3f3208b68ad65cd4523b7fa29fc84e2cfc68b344..8ab14a92beb22e46f66fe6d7be4b2b62d7bea3a5 100644 (file)
@@ -132,7 +132,7 @@ init([Host, ServerHost, Access, Room, HistorySize,
     State1 = set_opts(DefRoomOpts, State),
     store_room(State1),
     ?INFO_MSG("Created MUC room ~s@~s by ~s",
-             [Room, Host, jid:to_string(Creator)]),
+             [Room, Host, jid:encode(Creator)]),
     add_to_log(room_existence, created, State1),
     add_to_log(room_existence, started, State1),
     {ok, normal_state, State1};
@@ -483,12 +483,12 @@ handle_event({destroy, Reason}, _StateName,
        destroy_room(#muc_destroy{xmlns = ?NS_MUC_OWNER, reason = Reason},
                     StateData),
     ?INFO_MSG("Destroyed MUC room ~s with reason: ~p",
-             [jid:to_string(StateData#state.jid), Reason]),
+             [jid:encode(StateData#state.jid), Reason]),
     add_to_log(room_existence, destroyed, StateData),
     {stop, shutdown, StateData};
 handle_event(destroy, StateName, StateData) ->
     ?INFO_MSG("Destroyed MUC room ~s",
-             [jid:to_string(StateData#state.jid)]),
+             [jid:encode(StateData#state.jid)]),
     handle_event({destroy, undefined}, StateName, StateData);
 handle_event({set_affiliations, Affiliations},
             StateName, StateData) ->
@@ -1056,7 +1056,7 @@ close_room_if_temporary_and_empty(StateData1) ->
       true ->
          ?INFO_MSG("Destroyed MUC room ~s because it's temporary "
                    "and empty",
-                   [jid:to_string(StateData1#state.jid)]),
+                   [jid:encode(StateData1#state.jid)]),
          add_to_log(room_existence, destroyed, StateData1),
          {stop, normal, StateData1};
       _ -> {next_state, normal_state, StateData1}
@@ -1178,7 +1178,7 @@ decide_fate_message(#message{type = error} = Msg,
           true ->
               Reason = str:format("This participant is considered a ghost "
                                   "and is expulsed: ~s",
-                                  [jid:to_string(From)]),
+                                  [jid:encode(From)]),
               {expulse_sender, Reason};
           false -> continue_delivery
         end,
@@ -2575,8 +2575,8 @@ process_admin_items_set(UJID, Items, Lang, StateData) ->
       {result, Res} ->
          ?INFO_MSG("Processing MUC admin query from ~s in "
                    "room ~s:~n ~p",
-                   [jid:to_string(UJID),
-                    jid:to_string(StateData#state.jid), Res]),
+                   [jid:encode(UJID),
+                    jid:encode(StateData#state.jid), Res]),
          case lists:foldl(process_item_change(UJID),
                           StateData, lists:flatten(Res)) of
              {error, _} = Err ->
@@ -2650,7 +2650,7 @@ process_item_change(Item, SD, UJID) ->
        end
     catch E:R ->
            ?ERROR_MSG("failed to set item ~p from ~s: ~p",
-                      [Item, jid:to_string(UJID),
+                      [Item, jid:encode(UJID),
                        {E, {R, erlang:get_stacktrace()}}]),
            {error, xmpp:err_internal_server_error()}
     end.
@@ -2995,7 +2995,7 @@ process_iq_owner(From, #iq{type = set, lang = Lang,
            {error, xmpp:err_forbidden(ErrText, Lang)};
        Destroy /= undefined, Config == undefined, Items == [] ->
            ?INFO_MSG("Destroyed MUC room ~s by the owner ~s",
-                     [jid:to_string(StateData#state.jid), jid:to_string(From)]),
+                     [jid:encode(StateData#state.jid), jid:encode(From)]),
            add_to_log(room_existence, destroyed, StateData),
            destroy_room(Destroy, StateData);
        Config /= undefined, Destroy == undefined, Items == [] ->
@@ -3140,7 +3140,7 @@ get_config(Lang, StateData, From) ->
     MaxUsersRoom = get_max_users(StateData),
     Title = str:format(
              translate:translate(Lang, <<"Configuration of room ~s">>),
-             [jid:to_string(StateData#state.jid)]),
+             [jid:encode(StateData#state.jid)]),
     Fs = [{roomname, Config#config.title},
          {roomdesc, Config#config.description}] ++
        case acl:match_rule(StateData#state.server_host, AccessPersistent, From) of
@@ -3898,8 +3898,8 @@ route_invitation(From, Invitation, Lang, StateData) ->
                translate:translate(
                  Lang,
                  <<"~s invites you to the room ~s">>),
-               [jid:to_string(From),
-                jid:to_string({StateData#state.room, StateData#state.host, <<"">>})]),
+               [jid:encode(From),
+                jid:encode({StateData#state.room, StateData#state.host, <<"">>})]),
              case (StateData#state.config)#config.password_protected of
                  true ->
                      <<", ",
index d242eb9b7a84d53765462cf715c38e10cdeb4aac..df1319ce36f28cc7d29505c980cd41faa1922139 100644 (file)
@@ -82,7 +82,7 @@ forget_room(LServer, Host, Name) ->
     ejabberd_sql:sql_transaction(LServer, F).
 
 can_use_nick(LServer, Host, JID, Nick) ->
-    SJID = jid:to_string(jid:tolower(jid:remove_resource(JID))),
+    SJID = jid:encode(jid:tolower(jid:remove_resource(JID))),
     case catch ejabberd_sql:sql_query(
                  LServer,
                  ?SQL("select @(jid)s from muc_registered "
@@ -110,7 +110,7 @@ get_rooms(LServer, Host) ->
     end.
 
 get_nick(LServer, Host, From) ->
-    SJID = jid:to_string(jid:tolower(jid:remove_resource(From))),
+    SJID = jid:encode(jid:tolower(jid:remove_resource(From))),
     case catch ejabberd_sql:sql_query(
                  LServer,
                  ?SQL("select @(nick)s from muc_registered where"
@@ -120,7 +120,7 @@ get_nick(LServer, Host, From) ->
     end.
 
 set_nick(LServer, Host, From, Nick) ->
-    JID = jid:to_string(jid:tolower(jid:remove_resource(From))),
+    JID = jid:encode(jid:tolower(jid:remove_resource(From))),
     F = fun () ->
                case Nick of
                    <<"">> ->
@@ -215,7 +215,7 @@ export(_Server) ->
                                 nick = Nick}) ->
               case str:suffix(Host, RoomHost) of
                   true ->
-                      SJID = jid:to_string(jid:make(U, S)),
+                      SJID = jid:encode(jid:make(U, S)),
                       [?SQL("delete from muc_registered where"
                             " jid=%(SJID)s and host=%(RoomHost)s;"),
                        ?SQL("insert into muc_registered(jid, host, "
index 48a2b59629bb6cda8b687287860cc4a032f4b009..4f4f966141ef94c6b91223c63e885a5fd61c5915 100644 (file)
@@ -242,7 +242,7 @@ handle_iq(Packet, State) ->
                ejabberd_router:route_error(Packet, Error);
            reply ->
                To = xmpp:get_to(IQ),
-               LServiceS = jid:to_string(To),
+               LServiceS = jid:encode(To),
                case Packet#iq.type of
                    result ->
                        process_iqreply_result(LServiceS, IQ);
@@ -297,7 +297,7 @@ route_trusted(LServiceS, LServerS, FromJID,
     Delivereds = [],
     Dests2 = lists:map(
               fun(D) ->
-                      #dest{jid_string = jid:to_string(D),
+                      #dest{jid_string = jid:encode(D),
                             jid_jid = D, type = bcc,
                             full_xml = #address{type = bcc, jid = D}}
               end, Destinations),
@@ -463,7 +463,7 @@ convert_dest_record(Addrs) ->
       fun(#address{jid = undefined} = Addr) ->
              #dest{jid_string = none, full_xml = Addr};
         (#address{jid = JID, type = Type} = Addr) ->
-             #dest{jid_string = jid:to_string(JID), jid_jid = JID,
+             #dest{jid_string = jid:encode(JID), jid_jid = JID,
                    type = Type, full_xml = Addr}
       end, Addrs).
 
@@ -1120,9 +1120,9 @@ make_reply(internal_server_error, Lang, ErrText) ->
 make_reply(forbidden, Lang, ErrText) ->
     xmpp:err_forbidden(ErrText, Lang).
 
-stj(String) -> jid:from_string(String).
+stj(String) -> jid:decode(String).
 
-jts(String) -> jid:to_string(String).
+jts(String) -> jid:encode(String).
 
 depends(_Host, _Opts) ->
     [].
index 0a11864dbb1fbb9e959bcd9b2656770a41d8dee3..ba304f8219566a791da2c1713edb2349b9fca1cb 100644 (file)
@@ -306,7 +306,7 @@ get_sm_items(_Acc, #jid{luser = U, lserver = S} = JID,
                               Node = integer_to_binary(Seq),
                               #disco_item{jid = BareJID,
                                           node = Node,
-                                          name = jid:to_string(From)}
+                                          name = jid:encode(From)}
                       end, Hdrs)};
 get_sm_items(Acc, _From, _To, _Node, _Lang) ->
     Acc.
@@ -673,7 +673,7 @@ offline_msg_to_route(LServer, #offline_msg{from = From, to = To} = R) ->
            {route, Pkt2}
     catch _:{xmpp_codec, Why} ->
            ?ERROR_MSG("failed to decode packet ~p of user ~s: ~s",
-                      [R#offline_msg.packet, jid:to_string(To),
+                      [R#offline_msg.packet, jid:encode(To),
                        xmpp:format_error(Why)]),
            error
     end.
@@ -693,7 +693,7 @@ read_messages(LUser, LServer) ->
              catch _:{xmpp_codec, Why} ->
                      ?ERROR_MSG("failed to decode packet ~p "
                                 "of user ~s: ~s",
-                                [El, jid:to_string(To),
+                                [El, jid:encode(To),
                                  xmpp:format_error(Why)]),
                      []
              end
@@ -704,8 +704,8 @@ format_user_queue(Hdrs) ->
       fun({Seq, From, To, TS, El}) ->
              ID = integer_to_binary(Seq),
              FPacket = ejabberd_web_admin:pretty_print_xml(El),
-             SFrom = jid:to_string(From),
-             STo = jid:to_string(To),
+             SFrom = jid:encode(From),
+             STo = jid:encode(To),
              Time = case TS of
                         undefined ->
                             Stamp = fxml:get_path_s(El, [{elem, <<"delay">>},
@@ -792,7 +792,7 @@ user_queue_parse_query(LUser, LServer, Query) ->
     end.
 
 us_to_list({User, Server}) ->
-    jid:to_string({User, Server, <<"">>}).
+    jid:encode({User, Server, <<"">>}).
 
 get_queue_length(LUser, LServer) ->
     count_offline_messages(LUser, LServer).
index 6a8d03f337f8aa244e810c6ef35fb2ce783ddcac..a8c587679fdfb2287ad5abc0a8f00c07ed5cf669 100644 (file)
@@ -227,17 +227,17 @@ xml_to_offline_msg(XML) ->
 el_to_offline_msg(El) ->
     To_s = fxml:get_tag_attr_s(<<"to">>, El),
     From_s = fxml:get_tag_attr_s(<<"from">>, El),
-    To = jid:from_string(To_s),
-    From = jid:from_string(From_s),
-    if To == error ->
+    try
+       To = jid:decode(To_s),
+       From = jid:decode(From_s),
+       {ok, #offline_msg{us = {To#jid.luser, To#jid.lserver},
+                         from = From,
+                         to = To,
+                         packet = El}}
+    catch _:{bad_jid, To_s} ->
            ?ERROR_MSG("failed to get 'to' JID from offline XML ~p", [El]),
            {error, bad_jid_to};
-       From == error ->
+         _:{bad_jid, From_s} ->
            ?ERROR_MSG("failed to get 'from' JID from offline XML ~p", [El]),
-           {error, bad_jid_from};
-       true ->
-           {ok, #offline_msg{us = {To#jid.luser, To#jid.lserver},
-                             from = From,
-                             to = To,
-                             packet = El}}
+           {error, bad_jid_from}
     end.
index f70e2d9f0b70a266018c0d6b8ddccb3f6f6024f4..463ac90da9706963fc3c3c2b32ce1de15d90f040 100644 (file)
@@ -105,14 +105,14 @@ update(Server, JID, Dir) ->
                   in ->
                       ?WARNING_MSG("User ~s is being flooded, ignoring received "
                                    "presence subscriptions",
-                                   [jid:to_string(JID)]);
+                                   [jid:encode(JID)]);
                   out ->
                       IP = ejabberd_sm:get_user_ip(JID#jid.luser,
                                                    JID#jid.lserver,
                                                    JID#jid.lresource),
                       ?WARNING_MSG("Flooder detected: ~s, on IP: ~s ignoring "
                                    "sent presence subscriptions~n",
-                                   [jid:to_string(JID),
+                                   [jid:encode(JID),
                                     jlib:ip_to_list(IP)])
                 end,
                 {stop, deny};
index 836dfe66da3776e2834e1feb251e38aa022de9f3..7a34588e509f76c873bc67a368e71809c56ed067 100644 (file)
@@ -236,7 +236,7 @@ encode_list_item(#listitem{action = Action,
 -spec encode_value(listitem_type(), listitem_value()) -> binary().
 encode_value(Type, Val) ->
     case Type of
-       jid -> jid:to_string(Val);
+       jid -> jid:encode(Val);
        group -> Val;
        subscription ->
            case Val of
@@ -252,7 +252,7 @@ encode_value(Type, Val) ->
                          listitem_value().
 decode_value(Type, Value) ->
     case Type of
-       jid -> jid:tolower(jid:from_string(Value));
+       jid -> jid:tolower(jid:decode(Value));
        subscription ->
            case Value of
                <<"from">> -> from;
index 4260fcb5d3393c473e843bc7e65c092138c057c3..615ef7a0dcebc6996eb6aea9153329581cf3a1d1 100644 (file)
@@ -278,10 +278,8 @@ raw_to_item({SType, SValue, SAction, Order, MatchAll,
         {Type, Value} = case SType of
                             <<"n">> -> {none, none};
                             <<"j">> ->
-                                case jid:from_string(SValue) of
-                                    #jid{} = JID ->
-                                        {jid, jid:tolower(JID)}
-                                end;
+                                JID = jid:decode(SValue),
+                               {jid, jid:tolower(JID)};
                             <<"g">> -> {group, SValue};
                             <<"s">> ->
                                 case SValue of
@@ -312,7 +310,7 @@ item_to_raw(#listitem{type = Type, value = Value,
                      match_presence_out = MatchPresenceOut}) ->
     {SType, SValue} = case Type of
                        none -> {<<"n">>, <<"">>};
-                       jid -> {<<"j">>, jid:to_string(Value)};
+                       jid -> {<<"j">>, jid:encode(Value)};
                        group -> {<<"g">>, Value};
                        subscription ->
                            case Value of
index b9a96ca7157d8c56adde5f17e14f0406d73161cf..58aee60cace712a59a7f7a23c7246d669d853e18 100644 (file)
@@ -215,8 +215,8 @@ process_bytestreams(#iq{type = set, lang = Lang, from = InitiatorJID, to = To,
     case acl:match_rule(ServerHost, ACL, InitiatorJID) of
        allow ->
            Node = ejabberd_cluster:get_node_by_id(To#jid.lresource),
-           Target = jid:to_string(jid:tolower(TargetJID)),
-           Initiator = jid:to_string(jid:tolower(InitiatorJID)),
+           Target = jid:encode(jid:tolower(TargetJID)),
+           Initiator = jid:encode(jid:tolower(InitiatorJID)),
            SHA1 = p1_sha:sha(<<SID/binary, Initiator/binary, Target/binary>>),
            Mod = gen_mod:ram_db_mod(global, mod_proxy65),
            MaxConnections = max_connections(ServerHost),
index a04e9e94bb8bebb4012957027dd0bfa1a1f9932b..45ce2f44cc61bd3fbc9489e880e3e89c79ce1bf1 100644 (file)
@@ -121,8 +121,8 @@ activate({P1, J1}, {P2, J2}) ->
       {S1, S2} when is_port(S1), is_port(S2) ->
          P1 ! {activate, P2, S2, J1, J2},
          P2 ! {activate, P1, S1, J1, J2},
-         JID1 = jid:to_string(J1),
-         JID2 = jid:to_string(J2),
+         JID1 = jid:encode(J1),
+         JID2 = jid:encode(J2),
          ?INFO_MSG("(~w:~w) Activated bytestream for ~s "
                    "-> ~s",
                    [P1, P2, JID1, JID2]),
index 970ef52261e9535c0b4a1633b9f46a09172dead8..4ea8400115ce9fa33680acb5a8508d7d7a06a97a 100644 (file)
@@ -1414,7 +1414,7 @@ get_pending_nodes(Host, Owner, Plugins) ->
                               binary()) -> adhoc_command() | {error, stanza_error()}.
 send_pending_auth_events(Host, Node, Owner, Lang) ->
     ?DEBUG("Sending pending auth events for ~s on ~s:~s",
-          [jid:to_string(Owner), Host, Node]),
+          [jid:encode(Owner), Host, Node]),
     Action =
        fun(#pubsub_node{id = Nidx, type = Type}) ->
                case lists:member(<<"get-pending">>, plugin_features(Host, Type)) of
@@ -2819,7 +2819,7 @@ broadcast_publish_item(Host, Node, Nidx, Type, NodeOptions, ItemId, From, Payloa
                                EventItem0;
                            publisher ->
                                EventItem0#ps_item{
-                                 publisher = jid:to_string(From)};
+                                 publisher = jid:encode(From)};
                            none ->
                                EventItem0
                        end,
index 3a435778fcc675cf6900f583557ba19f37eb08c3..5764ad58567a3b087064c32f1e5edbaf849930d4 100644 (file)
@@ -287,7 +287,7 @@ try_set_password(User, Server, Password, #iq{lang = Lang, meta = M} = IQ) ->
          case ejabberd_auth:set_password(User, Server, Password) of
            ok ->
                ?INFO_MSG("~s has changed password from ~s",
-                         [jid:to_string({User, Server, <<"">>}),
+                         [jid:encode({User, Server, <<"">>}),
                           ejabberd_config:may_hide_data(
                             jlib:ip_to_list(maps:get(ip, M, {0,0,0,0})))]),
                xmpp:make_iq_result(IQ);
@@ -405,8 +405,7 @@ send_registration_notifications(Mod, UJID, Source) ->
     case gen_mod:get_module_opt(
            Host, Mod, registration_watchers,
            fun(Ss) ->
-                   [#jid{} = jid:from_string(iolist_to_binary(S))
-                    || S <- Ss]
+                   [jid:decode(iolist_to_binary(S)) || S <- Ss]
            end, []) of
         [] -> ok;
         JIDs when is_list(JIDs) ->
@@ -414,7 +413,7 @@ send_registration_notifications(Mod, UJID, Source) ->
                 (str:format("[~s] The account ~s was registered from "
                                                "IP address ~s on node ~w using ~p.",
                                                [get_time_string(),
-                                                jid:to_string(UJID),
+                                                jid:encode(UJID),
                                                 ip_to_string(Source), node(),
                                                 Mod])),
             lists:foreach(
@@ -643,8 +642,7 @@ mod_opt_type(password_strength) ->
     fun (N) when is_number(N), N >= 0 -> N end;
 mod_opt_type(registration_watchers) ->
     fun (Ss) ->
-           [#jid{} = jid:from_string(iolist_to_binary(S))
-            || S <- Ss]
+           [jid:decode(iolist_to_binary(S)) || S <- Ss]
     end;
 mod_opt_type(welcome_message) ->
     fun (Opts) ->
index c624af56df0df6769e6c807cb1f575379f4737b0..5f499ec747992aa03b98c669ec63a99166b7a215 100644 (file)
@@ -333,7 +333,7 @@ process_iq_get(#iq{to = To, lang = Lang,
           end)
     catch E:R ->
            ?ERROR_MSG("failed to process roster get for ~s: ~p",
-                      [jid:to_string(To), {E, {R, erlang:get_stacktrace()}}]),
+                      [jid:encode(To), {E, {R, erlang:get_stacktrace()}}]),
            Txt = <<"Roster module has failed">>,
            xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
     end.
@@ -1038,10 +1038,10 @@ build_contact_jid_td(RosterJID) ->
     case JIDURI of
       <<>> ->
          ?XAC(<<"td">>, [{<<"class">>, <<"valign">>}],
-              (jid:to_string(RosterJID)));
+              (jid:encode(RosterJID)));
       URI when is_binary(URI) ->
          ?XAE(<<"td">>, [{<<"class">>, <<"valign">>}],
-              [?AC(JIDURI, (jid:to_string(RosterJID)))])
+              [?AC(JIDURI, (jid:encode(RosterJID)))])
     end.
 
 user_roster_parse_query(User, Server, Items, Query) ->
@@ -1049,10 +1049,11 @@ user_roster_parse_query(User, Server, Items, Query) ->
       {value, _} ->
          case lists:keysearch(<<"newjid">>, 1, Query) of
            {value, {_, SJID}} ->
-               case jid:from_string(SJID) of
-                 JID when is_record(JID, jid) ->
-                     user_roster_subscribe_jid(User, Server, JID), ok;
-                 error -> error
+               try jid:decode(SJID) of
+                 JID ->
+                     user_roster_subscribe_jid(User, Server, JID), ok
+               catch _:{bad_jid, _} ->
+                       error
                end;
            false -> error
          end;
@@ -1114,7 +1115,7 @@ user_roster_item_parse_query(User, Server, Items,
     nothing.
 
 us_to_list({User, Server}) ->
-    jid:to_string({User, Server, <<"">>}).
+    jid:encode({User, Server, <<"">>}).
 
 webadmin_user(Acc, _User, _Server, Lang) ->
     Acc ++
@@ -1145,7 +1146,7 @@ import_stop(_LServer, _DBType) ->
     ok.
 
 import(LServer, {sql, _}, _DBType, <<"rostergroups">>, [LUser, SJID, Group]) ->
-    LJID = jid:tolower(jid:from_string(SJID)),
+    LJID = jid:tolower(jid:decode(SJID)),
     ets:insert(rostergroups_tmp, {{LUser, LServer, LJID}, Group}),
     ok;
 import(LServer, {sql, _}, DBType, <<"rosterusers">>, Row) ->
index ba0fd529e13d342faca8381d4041921fcabc0b26..112c13a72dac56964e7065d504b97b93a3cbc989 100644 (file)
@@ -83,7 +83,7 @@ get_roster(LUser, LServer) ->
                          %% Bad JID in database:
                          error -> [];
                          R ->
-                             SJID = jid:to_string(R#roster.jid),
+                             SJID = jid:encode(R#roster.jid),
                              Groups = case dict:find(SJID, GroupsDict) of
                                           {ok, Gs} -> Gs;
                                           error -> []
@@ -97,7 +97,7 @@ get_roster(LUser, LServer) ->
 
 get_roster_by_jid(LUser, LServer, LJID) ->
     {selected, Res} =
-       sql_queries:get_roster_by_jid(LServer, LUser, jid:to_string(LJID)),
+       sql_queries:get_roster_by_jid(LServer, LUser, jid:encode(LJID)),
     case Res of
        [] ->
            #roster{usj = {LUser, LServer, LJID},
@@ -136,7 +136,7 @@ transaction(LServer, F) ->
     ejabberd_sql:sql_transaction(LServer, F).
 
 get_roster_by_jid_with_groups(LUser, LServer, LJID) ->
-    SJID = jid:to_string(LJID),
+    SJID = jid:encode(LJID),
     case sql_queries:get_roster_by_jid(LServer, LUser, SJID) of
        {selected, [I]} ->
             case raw_to_record(LServer, I) of
@@ -162,18 +162,18 @@ remove_user(LUser, LServer) ->
     {atomic, ok}.
 
 update_roster(LUser, LServer, LJID, Item) ->
-    SJID = jid:to_string(LJID),
+    SJID = jid:encode(LJID),
     ItemVals = record_to_row(Item),
     ItemGroups = Item#roster.groups,
     sql_queries:update_roster(LServer, LUser, SJID, ItemVals,
                                ItemGroups).
 
 del_roster(LUser, LServer, LJID) ->
-    SJID = jid:to_string(LJID),
+    SJID = jid:encode(LJID),
     sql_queries:del_roster(LServer, LUser, SJID).
 
 read_subscription_and_groups(LUser, LServer, LJID) ->
-    SJID = jid:to_string(LJID),
+    SJID = jid:encode(LJID),
     case catch sql_queries:get_subscription(LServer, LUser, SJID) of
        {selected, [{SSubscription}]} ->
            Subscription = case SSubscription of
@@ -234,10 +234,7 @@ raw_to_record(LServer,
 raw_to_record(LServer,
              {User, SJID, Nick, SSubscription, SAsk, SAskMessage,
               _SServer, _SSubscribe, _SType}) ->
-    case jid:from_string(SJID) of
-      error ->
-         ?ERROR_MSG("~s", [format_row_error(User, LServer, {jid, SJID})]),
-         error;
+    try jid:decode(SJID) of
       JID ->
          LJID = jid:tolower(JID),
          Subscription = case SSubscription of
@@ -268,13 +265,16 @@ raw_to_record(LServer,
                  us = {User, LServer}, jid = LJID, name = Nick,
                  subscription = Subscription, ask = Ask,
                  askmessage = SAskMessage}
+    catch _:{bad_jid, _} ->
+           ?ERROR_MSG("~s", [format_row_error(User, LServer, {jid, SJID})]),
+           error
     end.
 
 record_to_row(
   #roster{us = {LUser, _LServer},
           jid = JID, name = Name, subscription = Subscription,
           ask = Ask, askmessage = AskMessage}) ->
-    SJID = jid:to_string(jid:tolower(JID)),
+    SJID = jid:encode(jid:tolower(JID)),
     SSubscription = case Subscription of
                      both -> <<"B">>;
                      to -> <<"T">>;
index 5d39833613843febf0633e1cf24b3216778572cf..8a775cb5245679d329d275394252231a08d7a8ca 100644 (file)
@@ -983,15 +983,13 @@ shared_roster_group_parse_query(Host, Group, Query) ->
                                             <<"@all@">> -> USs;
                                             <<"@online@">> -> USs;
                                             _ ->
-                                                case jid:from_string(SJID)
-                                                    of
-                                                  JID
-                                                      when is_record(JID,
-                                                                     jid) ->
+                                                try jid:decode(SJID) of
+                                                    JID ->
                                                       [{JID#jid.luser,
                                                         JID#jid.lserver}
-                                                       | USs];
-                                                  error -> error
+                                                       | USs]
+                                                catch _:{bad_jid, _} ->
+                                                        error
                                                 end
                                           end
                                   end,
@@ -1043,7 +1041,7 @@ get_opt(Opts, Opt, Default) ->
     end.
 
 us_to_list({User, Server}) ->
-    jid:to_string({User, Server, <<"">>}).
+    jid:encode({User, Server, <<"">>}).
 
 split_grouphost(Host, Group) ->
     case str:tokens(Group, <<"@">>) of
index 702e27a090475817367a8cf62910d8f12e4290d9..1e3012794e009e613e3afe918ccd37a9119e539c 100644 (file)
@@ -140,7 +140,7 @@ import(LServer, <<"sr_group">>, [Group, SOpts, _TimeStamp]) ->
                   opts = ejabberd_sql:decode_term(SOpts)},
     mnesia:dirty_write(G);
 import(LServer, <<"sr_user">>, [SJID, Group, _TimeStamp]) ->
-    #jid{luser = U, lserver = S} = jid:from_string(SJID),
+    #jid{luser = U, lserver = S} = jid:decode(SJID),
     User = #sr_user{us = {U, S}, group_host = {Group, LServer}},
     mnesia:dirty_write(User).
 
index 1bf7a142996d53399a67d256244458de010fcc05..441aafd0680d360cb04e9fa60f8258b307d25731 100644 (file)
@@ -142,7 +142,7 @@ import(LServer, <<"sr_group">>, [Group, SOpts, _TimeStamp]) ->
                   opts = ejabberd_sql:decode_term(SOpts)},
     ejabberd_riak:put(G, sr_group_schema(), [{'2i', [{<<"host">>, LServer}]}]);
 import(LServer, <<"sr_user">>, [SJID, Group|_]) ->
-    #jid{luser = U, lserver = S} = jid:from_string(SJID),
+    #jid{luser = U, lserver = S} = jid:decode(SJID),
     User = #sr_user{us = {U, S}, group_host = {Group, LServer}},
     ejabberd_riak:put(User, sr_user_schema(),
                       [{i, {{U, S}, {Group, LServer}}},
index 8a32cc385cc7323fd45470621a8fd4b7d9f6b8ae..6378ea963311d7919fbcb1717a6d51c0fbe4e0de 100644 (file)
@@ -123,7 +123,7 @@ get_group_explicit_users(Host, Group) ->
        {selected, Rs} ->
            lists:map(
              fun({JID}) ->
-                     {U, S, _} = jid:tolower(jid:from_string(JID)),
+                     {U, S, _} = jid:tolower(jid:decode(JID)),
                      {U, S}
              end, Rs);
        _ ->
@@ -198,6 +198,6 @@ import(_, _, _) ->
 %%% Internal functions
 %%%===================================================================
 make_jid_s(U, S) ->
-    jid:to_string(jid:tolower(jid:make(U, S))).
+    jid:encode(jid:tolower(jid:make(U, S))).
 
 make_jid_s({U, S}) -> make_jid_s(U, S).
index 6420c257b0f716f75ba0dcbd394af1a0eb2d6d8e..5b333ede515880ba56c61b0b00c076945c502211 100644 (file)
@@ -229,20 +229,20 @@ c2s_handle_call(State, _Call, _From) ->
 c2s_handle_info(#{mgmt_ack_timer := TRef, jid := JID, mod := Mod} = State,
                {timeout, TRef, ack_timeout}) ->
     ?DEBUG("Timed out waiting for stream management acknowledgement of ~s",
-          [jid:to_string(JID)]),
+          [jid:encode(JID)]),
     State1 = State#{stop_reason => {socket, timeout}},
     State2 = Mod:close(State1, _SendTrailer = false),
     {stop, transition_to_pending(State2)};
 c2s_handle_info(#{mgmt_state := pending, jid := JID, mod := Mod} = State,
                {timeout, _, pending_timeout}) ->
     ?DEBUG("Timed out waiting for resumption of stream for ~s",
-          [jid:to_string(JID)]),
+          [jid:encode(JID)]),
     Mod:stop(State#{mgmt_state => timeout});
 c2s_handle_info(#{jid := JID} = State, {_Ref, {resume, OldState}}) ->
     %% This happens if the resume_session/1 request timed out; the new session
     %% now receives the late response.
     ?DEBUG("Received old session state for ~s after failed resumption",
-          [jid:to_string(JID)]),
+          [jid:encode(JID)]),
     route_unacked_stanzas(OldState#{mgmt_resend => false}),
     State;
 c2s_handle_info(State, _) ->
@@ -257,7 +257,7 @@ c2s_closed(State, _Reason) ->
 
 c2s_terminated(#{mgmt_state := resumed, jid := JID} = State, _Reason) ->
     ?INFO_MSG("Closing former stream of resumed session for ~s",
-             [jid:to_string(JID)]),
+             [jid:encode(JID)]),
     bounce_message_queue(),
     {stop, State};
 c2s_terminated(#{mgmt_state := MgmtState, mgmt_stanzas_in := In, sid := SID,
@@ -328,14 +328,14 @@ handle_enable(#{mgmt_timeout := DefaultTimeout,
              end,
     Res = if Timeout > 0 ->
                  ?INFO_MSG("Stream management with resumption enabled for ~s",
-                           [jid:to_string(JID)]),
+                           [jid:encode(JID)]),
                  #sm_enabled{xmlns = Xmlns,
                              id = make_resume_id(State),
                              resume = true,
                              max = Timeout};
             true ->
                  ?INFO_MSG("Stream management without resumption enabled for ~s",
-                           [jid:to_string(JID)]),
+                           [jid:encode(JID)]),
                  #sm_enabled{xmlns = Xmlns}
          end,
     State1 = State#{mgmt_state => active,
@@ -383,7 +383,7 @@ handle_resume(#{user := User, lserver := LServer, sockmod := SockMod,
            %% csi_flush_queue(State4),
            State5 = ejabberd_hooks:run_fold(c2s_session_resumed, LServer, State4, []),
            ?INFO_MSG("(~s) Resumed session for ~s",
-                     [SockMod:pp(Socket), jid:to_string(JID)]),
+                     [SockMod:pp(Socket), jid:encode(JID)]),
            {ok, State5};
        {error, El, Msg} ->
            ?INFO_MSG("Cannot resume session for ~s@~s: ~s",
@@ -398,7 +398,7 @@ transition_to_pending(#{mgmt_state := active, mod := Mod,
 transition_to_pending(#{mgmt_state := active, jid := JID,
                        lserver := LServer, mgmt_timeout := Timeout} = State) ->
     State1 = cancel_ack_timer(State),
-    ?INFO_MSG("Waiting for resumption of stream for ~s", [jid:to_string(JID)]),
+    ?INFO_MSG("Waiting for resumption of stream for ~s", [jid:encode(JID)]),
     erlang:start_timer(timer:seconds(Timeout), self(), pending_timeout),
     State2 = State1#{mgmt_state => pending},
     ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []);
@@ -409,11 +409,11 @@ transition_to_pending(State) ->
 check_h_attribute(#{mgmt_stanzas_out := NumStanzasOut, jid := JID} = State, H)
   when H > NumStanzasOut ->
     ?DEBUG("~s acknowledged ~B stanzas, but only ~B were sent",
-          [jid:to_string(JID), H, NumStanzasOut]),
+          [jid:encode(JID), H, NumStanzasOut]),
     mgmt_queue_drop(State#{mgmt_stanzas_out => H}, NumStanzasOut);
 check_h_attribute(#{mgmt_stanzas_out := NumStanzasOut, jid := JID} = State, H) ->
     ?DEBUG("~s acknowledged ~B of ~B stanzas",
-          [jid:to_string(JID), H, NumStanzasOut]),
+          [jid:encode(JID), H, NumStanzasOut]),
     mgmt_queue_drop(State, H).
 
 -spec update_num_stanzas_in(state(), xmpp_element()) -> state().
@@ -490,7 +490,7 @@ resend_unacked_stanzas(#{mgmt_state := MgmtState,
        MgmtState == pending orelse
        MgmtState == timeout) andalso QueueLen > 0 ->
     ?DEBUG("Resending ~B unacknowledged stanza(s) to ~s",
-          [QueueLen, jid:to_string(JID)]),
+          [QueueLen, jid:encode(JID)]),
     queue_foldl(
       fun({_, Time, Pkt}, AccState) ->
              NewPkt = add_resent_delay_info(AccState, Pkt, Time),
@@ -522,10 +522,10 @@ route_unacked_stanzas(#{mgmt_state := MgmtState,
                              end
                      end,
     ?DEBUG("Re-routing ~B unacknowledged stanza(s) to ~s",
-          [QueueLen, jid:to_string(JID)]),
+          [QueueLen, jid:encode(JID)]),
     queue_foreach(
       fun({_, _Time, #presence{from = From}}) ->
-             ?DEBUG("Dropping presence stanza from ~s", [jid:to_string(From)]);
+             ?DEBUG("Dropping presence stanza from ~s", [jid:encode(From)]);
         ({_, _Time, #iq{} = El}) ->
              Txt = <<"User session terminated">>,
              ejabberd_router:route_error(
@@ -537,14 +537,14 @@ route_unacked_stanzas(#{mgmt_state := MgmtState,
              %% back to the original sender."  Resending such a stanza could
              %% easily lead to unexpected results as well.
              ?DEBUG("Dropping forwarded message stanza from ~s",
-                    [jid:to_string(From)]);
+                    [jid:encode(From)]);
         ({_, Time, #message{} = Msg}) ->
              case ejabberd_hooks:run_fold(message_is_archived,
                                           LServer, false,
                                           [State, Msg]) of
                  true ->
                      ?DEBUG("Dropping archived message stanza from ~s",
-                            [jid:to_string(xmpp:get_from(Msg))]);
+                            [jid:encode(xmpp:get_from(Msg))]);
                  false when ResendOnTimeout ->
                      NewEl = add_resent_delay_info(State, Msg, Time),
                      ejabberd_router:route(NewEl);
index 0e97f81aec4dd0cb7bb175bcbfbda31672c16b9e..e7677b4bf8ae514117c30129fd3a51b2221331a7 100644 (file)
@@ -393,7 +393,7 @@ mk_field(Var, Val) ->
 -spec mk_search_form(jid(), binary(), binary()) -> search().
 mk_search_form(JID, ServerHost, Lang) ->
     Title = <<(translate:translate(Lang, <<"Search users in ">>))/binary,
-             (jid:to_string(JID))/binary>>,
+             (jid:encode(JID))/binary>>,
     Mod = gen_mod:db_mod(ServerHost, ?MODULE),
     SearchFields = Mod:search_fields(ServerHost),
     Fs = [mk_tfield(Label, Var, Lang) || {Label, Var} <- SearchFields],
@@ -419,7 +419,7 @@ search_result(Lang, JID, ServerHost, XFields) ->
     #xdata{type = result,
           title = <<(translate:translate(Lang,
                                          <<"Search Results for ">>))/binary,
-                    (jid:to_string(JID))/binary>>,
+                    (jid:encode(JID))/binary>>,
           reported = Reported,
           items = lists:map(fun (Item) -> item_to_field(Item) end,
                             search(ServerHost, XFields))}.
index 2df1ffb26defda8cb22529c97adb0c032d2e3fa2..d3294cc685b9cc0b0494dd9eabd714344db8fc82 100644 (file)
@@ -960,7 +960,7 @@ update_subscription(Nidx, JID, Subscription) ->
 
 -spec decode_jid(SJID :: binary()) -> ljid().
 decode_jid(SJID) ->
-    jid:tolower(jid:from_string(SJID)).
+    jid:tolower(jid:decode(SJID)).
 
 -spec decode_affiliation(Arg :: binary()) -> atom().
 decode_affiliation(<<"o">>) -> owner;
@@ -988,11 +988,11 @@ decode_subscriptions(Subscriptions) ->
 
 -spec encode_jid(JID :: ljid()) -> binary().
 encode_jid(JID) ->
-    jid:to_string(JID).
+    jid:encode(JID).
 
 -spec encode_jid_like(JID :: ljid()) -> binary().
 encode_jid_like(JID) ->
-    ejabberd_sql:escape_like_arg_circumflex(jid:to_string(JID)).
+    ejabberd_sql:escape_like_arg_circumflex(jid:encode(JID)).
 
 -spec encode_host(Host :: host()) -> binary().
 encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID);
index d29d9224faefc0ced7cb562d38632c9d2ba7ab84..86876b631cdfdf5255eb937bd079002819b9a200 100644 (file)
@@ -112,13 +112,13 @@ node_record(Host, Node, Nidx) ->
                  options = Module:options()}.
 
 nodeidx({U,S,R}, Node) ->
-    JID = jid:to_string(jid:make(U,S,R)),
+    JID = jid:encode(jid:make(U,S,R)),
     <<JID/binary, ":", Node/binary>>;
 nodeidx(Host, Node) ->
     <<Host/binary, ":", Node/binary>>.
 nodeid(Nidx) ->
     [Head, Node] = binary:split(Nidx, <<":">>),
-    case jid:from_string(Head) of
+    case jid:decode(Head) of
         {jid,<<>>,Host,<<>>,_,_,_} -> {Host, Node};
         {jid,U,S,R,_,_,_} -> {{U,S,R}, Node}
     end.
index 881a5b3e732000306a56c2773ac531da044df20a..5dd0b676608e041a62eaa128324c6e3c5de10c8c 100644 (file)
@@ -172,7 +172,7 @@ convert_data(Host, "vcard", User, [Data]) ->
            ok
     end;
 convert_data(_Host, "config", _User, [Data]) ->
-    RoomJID = jid:from_string(proplists:get_value(<<"jid">>, Data, <<"">>)),
+    RoomJID = jid:decode(proplists:get_value(<<"jid">>, Data, <<"">>)),
     Config = proplists:get_value(<<"_data">>, Data, []),
     RoomCfg = convert_room_config(Data),
     case proplists:get_bool(<<"persistent">>, Config) of
@@ -217,14 +217,14 @@ convert_data(_Host, _Type, _User, _Data) ->
 convert_pending_item(LUser, LServer, LuaList) ->
     lists:flatmap(
       fun({S, true}) ->
-             case jid:from_string(S) of
-                 #jid{} = J ->
+             try jid:decode(S) of
+                 J ->
                      LJID = jid:tolower(J),
                      [#roster{usj = {LUser, LServer, LJID},
                               us = {LUser, LServer},
                               jid = LJID,
-                              ask = in}];
-                 error ->
+                              ask = in}]
+             catch _:{bad_jid, _} ->
                      []
              end;
         (_) ->
@@ -232,8 +232,8 @@ convert_pending_item(LUser, LServer, LuaList) ->
       end, LuaList).
 
 convert_roster_item(LUser, LServer, JIDstring, LuaList) ->
-    case jid:from_string(JIDstring) of
-       #jid{} = JID ->
+    try jid:decode(JIDstring) of
+       JID ->
            LJID = jid:tolower(JID),
            InitR = #roster{usj = {LUser, LServer, LJID},
                            us = {LUser, LServer},
@@ -253,18 +253,18 @@ convert_roster_item(LUser, LServer, JIDstring, LuaList) ->
                     ({<<"name">>, Name}, R) ->
                          R#roster{name = Name}
                  end, InitR, LuaList),
-           [Roster];
-       error ->
+           [Roster]
+    catch _:{bad_jid, _} ->
            []
     end.
 
 convert_room_affiliations(Data) ->
     lists:flatmap(
       fun({J, Aff}) ->
-             case jid:from_string(J) of
+             try jid:decode(J) of
                  #jid{luser = U, lserver = S} ->
-                     [{{U, S, <<>>}, jlib:binary_to_atom(Aff)}];
-                 error ->
+                     [{{U, S, <<>>}, jlib:binary_to_atom(Aff)}]
+             catch _:{bad_jid, _} ->
                      []
              end
       end, proplists:get_value(<<"_affiliations">>, Data, [])).
@@ -278,13 +278,13 @@ convert_room_config(Data) ->
                   [{password_protected, true},
                    {password, Password}]
           end,
-    Subj = case jid:from_string(
+    Subj = try jid:decode(
                  proplists:get_value(
                    <<"subject_from">>, Config, <<"">>)) of
               #jid{lresource = Nick} when Nick /= <<"">> ->
                   [{subject, proplists:get_value(<<"subject">>, Config, <<"">>)},
-                   {subject_author, Nick}];
-              _ ->
+                   {subject_author, Nick}]
+          catch _:{bad_jid, _} ->
                   []
           end,
     Anonymous = case proplists:get_value(<<"whois">>, Config, <<"moderators">>) of
@@ -316,7 +316,7 @@ convert_privacy_item({_, Item}) ->
     {Type, Value} = try case T of
                            none -> {T, none};
                            group -> {T, V};
-                           jid -> {T, jid:tolower(jid:from_string(V))};
+                           jid -> {T, jid:tolower(jid:decode(V))};
                            subscription -> {T, jlib:binary_to_atom(V)}
                        end
                    catch _:_ ->
@@ -333,29 +333,27 @@ convert_privacy_item({_, Item}) ->
              match_presence_out = MatchPresOut}.
 
 el_to_offline_msg(LUser, LServer, #xmlel{attrs = Attrs} = El) ->
-    try xmpp_util:decode_timestamp(
-         fxml:get_attr_s(<<"stamp">>, Attrs)) of
-       {_, _, _} = TS ->
-           Attrs1 = lists:filter(
-                      fun(<<"stamp">>) -> false;
-                         (<<"stamp_legacy">>) -> false;
-                         (_) -> true
-                      end, Attrs),
-           Packet = El#xmlel{attrs = Attrs1},
-           case {jid:from_string(fxml:get_attr_s(<<"from">>, Attrs)),
-                 jid:from_string(fxml:get_attr_s(<<"to">>, Attrs))} of
-               {#jid{} = From, #jid{} = To} ->
-                   [#offline_msg{
-                       us = {LUser, LServer},
-                       timestamp = TS,
-                       expire = never,
-                       from = From,
-                       to = To,
-                       packet = Packet}];
-               _ ->
-                   []
-           end
+    try
+       TS = xmpp_util:decode_timestamp(
+              fxml:get_attr_s(<<"stamp">>, Attrs)),
+       Attrs1 = lists:filter(
+                  fun(<<"stamp">>) -> false;
+                     (<<"stamp_legacy">>) -> false;
+                     (_) -> true
+                  end, Attrs),
+       Packet = El#xmlel{attrs = Attrs1},
+       From = jid:decode(fxml:get_attr_s(<<"from">>, Attrs)),
+       To = jid:decode(fxml:get_attr_s(<<"to">>, Attrs)),
+       [#offline_msg{
+           us = {LUser, LServer},
+           timestamp = TS,
+           expire = never,
+           from = From,
+           to = To,
+           packet = Packet}]
     catch _:{bad_timestamp, _} ->
+           [];
+         _:{bad_jid, _} ->
            []
     end.
 
index 5efc940c218521eb5295ac51df98d67fa342eb3f..67fdf7db93a737f113b76d6c7b6f122a56781492 100644 (file)
@@ -560,7 +560,7 @@ process_sasl_mechanisms(Mechs, #{user := User, server := Server} = State) ->
     case lists:member(<<"EXTERNAL">>, Mechs) of
        true ->
            State1 = State#{stream_state => wait_for_sasl_response},
-           Authzid = jid:to_string(jid:make(User, Server)),
+           Authzid = jid:encode(jid:make(User, Server)),
            send_pkt(State1, #sasl_auth{mechanism = Mech, text = Authzid});
        false ->
            process_sasl_failure(
index 16b7efa42159f3e8659588d16b3739f65483085c..d556510f643915a8185eaa79a0b79cf3d7d0d8bf 100644 (file)
@@ -106,11 +106,13 @@ get_cert_domains(Cert) ->
                             true -> error
                          end,
                      if D /= error ->
-                             case jid:from_string(D) of
+                             try jid:decode(D) of
                                  #jid{luser = <<"">>, lserver = LD,
                                       lresource = <<"">>} ->
                                      [LD];
                                  _ -> []
+                             catch _:{bad_jid, _} ->
+                                     []
                              end;
                         true -> []
                      end;
@@ -131,7 +133,7 @@ get_cert_domains(Cert) ->
                                                           value = XmppAddr}}) ->
                                    case 'XmppAddr':decode('XmppAddr', XmppAddr) of
                                        {ok, D} when is_binary(D) ->
-                                           case jid:from_string(D) of
+                                           try jid:decode(D) of
                                                #jid{luser = <<"">>,
                                                     lserver = LD,
                                                     lresource = <<"">>} ->
@@ -142,16 +144,20 @@ get_cert_domains(Cert) ->
                                                            [PCLD]
                                                    end;
                                                _ -> []
+                                           catch _:{bad_jid, _} ->
+                                                   []
                                            end;
                                        _ -> []
                                    end;
                               ({dNSName, D}) when is_list(D) ->
-                                   case jid:from_string(list_to_binary(D)) of
+                                   try jid:decode(list_to_binary(D)) of
                                        #jid{luser = <<"">>,
                                             lserver = LD,
                                             lresource = <<"">>} ->
                                            [LD];
                                        _ -> []
+                                   catch _:{bad_jid, _} ->
+                                           []
                                    end;
                               (_) -> []
                            end, SANs);