diff --git a/ChangeLog b/ChangeLog index 3a76aaaef..c40f7c383 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,43 @@ binary() version of LUser and LServer. (convert_to_exmpp2/2): User and server are stored as binary(). + * src/adhoc.erl, src/ejabberd_c2s.erl, src/ejabberd_s2s.erl, + src/ejabberd_s2s_in.erl, src/ejabberd_s2s_out.erl, + src/ejabberd_service.erl, src/ejabberd_sm.erl, + src/ejabberd_system_monitor.erl, src/jd2ejd.erl, src/jlib.erl, + src/mod_adhoc.erl, src/mod_announce.erl, src/mod_caps.erl, + src/mod_configure.erl, src/mod_configure2.erl, src/mod_disco.erl, + src/mod_irc/mod_irc.erl, src/mod_irc/mod_irc_connection.erl, + src/mod_last.erl, src/mod_last_odbc.erl, src/mod_muc/mod_muc.erl, + src/mod_muc/mod_muc_log.erl, src/mod_muc/mod_muc_room.erl, + src/mod_offline.erl, src/mod_offline_odbc.erl, src/mod_privacy.erl, + src/mod_privacy_odbc.erl, src/mod_proxy65/mod_proxy65_service.erl, + src/mod_pubsub/mod_pubsub.erl, src/mod_register.erl, + src/mod_roster.erl, src/mod_roster_odbc.erl, src/mod_service_log.erl, + src/mod_shared_roster.erl, src/mod_stats.erl, src/mod_vcard.erl, + src/mod_vcard_ldap.erl, src/mod_vcard_odbc.erl, + src/web/ejabberd_http_poll.erl, src/web/ejabberd_web.erl, + src/web/ejabberd_web_admin.erl: Now that #jid{} isn't part of the API + of Exmppp anymore, replace remaining direct usages by calls to + exmpp_jid. Replace exmpp_jid:make_bare_jid() by exmpp_jid:make_jid(). + Replace exmpp_jid:*_to_jid/1 by exmpp_jid:parse_jid/1. Instead + creating #xmlattr directly, use the new ?XMLATTR macro; it'll take + care of the anything-to-binary() conversion. + + * src/adhoc.erl, src/mod_caps.erl (read_caps/2), src/mod_offline.erl + (find_x_expire/2), src/mod_offline_odbc.erl, src/jd2ejd.erl, + src/mod_muc/mod_muc.erl, src/mod_irc/mod_irc_connection.erl, + src/mod_privacy_odbc.erl, src/mod_privacy.erl, src/jlib.erl, + src/mod_pubsub/mod_pubsub.erl, src/mod_stats.erl: Fix some bugs by + getting attributes as list() instead of binary(). + + * src/mod_muc/mod_muc.erl (terminate/2): Fix a bug where + binary_to_list/1 was called on a list(). + + * src/ejabberd_s2s_in.erl (is_packet_key/1): Fix a bug where recipient + and sender were used as binary() instead of list(), which is required + by the rest of the S2S code. + 2009-01-19 Pablo Polvorin * src/cyrsasl_digest.erl: Typo (prolists -> proplists). diff --git a/src/adhoc.erl b/src/adhoc.erl index d2720e685..df2104980 100644 --- a/src/adhoc.erl +++ b/src/adhoc.erl @@ -43,9 +43,9 @@ parse_request(#iq{type = Type, ns = NS, payload = SubEl, lang = Lang}) -> case {Type, NS} of {set, ?NS_ADHOC} -> ?DEBUG("entering parse_request...", []), - Node = exmpp_xml:get_attribute(SubEl, 'node', ""), - SessionID = exmpp_xml:get_attribute(SubEl, 'sessionid', ""), - Action = exmpp_xml:get_attribute(SubEl, 'action', ""), + Node = exmpp_xml:get_attribute_as_list(SubEl, 'node', ""), + SessionID = exmpp_xml:get_attribute_as_list(SubEl, 'sessionid', ""), + Action = exmpp_xml:get_attribute_as_list(SubEl, 'action', ""), XData = find_xdata_el(SubEl), AllEls = exmpp_xml:get_child_elements(SubEl), if XData -> @@ -113,7 +113,7 @@ produce_response(#adhoc_response{lang = _Lang, "" -> ActionsElAttrs = []; _ -> - ActionsElAttrs = [#xmlattr{name = 'execute', value = list_to_binary(DefaultAction)}] + ActionsElAttrs = [?XMLATTR('execute', DefaultAction)] end, ActionsEls = [#xmlel{ns = ?NS_ADHOC, name = 'actions', attrs = ActionsElAttrs, children = @@ -121,11 +121,11 @@ produce_response(#adhoc_response{lang = _Lang, end, NotesEls = lists:map(fun({Type, Text}) -> #xmlel{ns = ?NS_ADHOC, name = 'note', attrs = - [#xmlattr{name = 'type', value = list_to_binary(Type)}], + [?XMLATTR('type', Type)], children = [#xmlcdata{cdata = list_to_binary(Text)}]} end, Notes), #xmlel{ns = ?NS_ADHOC, name = 'command', attrs = - [#xmlattr{name = 'sessionid', value = list_to_binary(SessionID)}, - #xmlattr{name = 'node', value = list_to_binary(Node)}, - #xmlattr{name = 'status', value = list_to_binary(atom_to_list(Status))}], children = + [?XMLATTR('sessionid', SessionID), + ?XMLATTR('node', Node), + ?XMLATTR('status', Status)], children = ActionsEls ++ NotesEls ++ Elements}. diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index b0a722733..f0bebca5f 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -241,7 +241,7 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) -> true -> Lang = exmpp_stream:get_lang(Opening), change_shaper(StateData, - exmpp_jid:make_bare_jid(Server)), + exmpp_jid:make_jid(Server)), case exmpp_stream:get_version(Opening) of {1, 0} -> send_element(StateData, Header), @@ -398,7 +398,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) -> {auth, _ID, set, {U, P, D, R}} -> try JID = exmpp_jid:make_jid(U, StateData#state.server, R), - UBinary = exmpp_jid:lnode(JID), + UBinary = exmpp_jid:lnode(JID), case acl:match_rule(ServerString, StateData#state.access, JID) of allow -> @@ -506,7 +506,7 @@ wait_for_feature_request({xmlstreamelement, #xmlel{ns = NS, name = Name} = El}, {?NS_SASL, 'auth'} when not ((SockMod == gen_tcp) and TLSRequired) -> {auth, Mech, ClientIn} = exmpp_server_sasl:next_step(El), case cyrsasl:server_start(StateData#state.sasl_state, - Mech, + binary_to_list(Mech), ClientIn) of {ok, Props} -> (StateData#state.sockmod):reset_stream( @@ -833,7 +833,7 @@ session_established2(El, StateData) -> undefined -> exmpp_jid:jid_to_bare_jid(StateData#state.jid); _ -> - exmpp_jid:binary_to_jid(To) + exmpp_jid:parse_jid(To) end, NewEl = case exmpp_stanza:get_lang(El) of undefined -> @@ -1848,7 +1848,7 @@ process_unauthenticated_stanza(StateData, El) when ?IS_IQ(El) -> ResIQ = exmpp_iq:error_without_original(El, 'service-unavailable'), Res1 = exmpp_stanza:set_sender(ResIQ, - exmpp_jid:make_bare_jid(StateData#state.server)), + exmpp_jid:make_jid(StateData#state.server)), Res2 = exmpp_stanza:remove_recipient(Res1), send_element(StateData, Res2); _ -> diff --git a/src/ejabberd_s2s.erl b/src/ejabberd_s2s.erl index a3a89c1ca..139e0f8c9 100644 --- a/src/ejabberd_s2s.erl +++ b/src/ejabberd_s2s.erl @@ -406,14 +406,14 @@ new_connection(MyServer, Server, From, FromTo, max_s2s_connections_number({From, To}) -> case acl:match_rule( - From, max_s2s_connections, exmpp_jid:make_bare_jid(To)) of + From, max_s2s_connections, exmpp_jid:make_jid(To)) of Max when is_integer(Max) -> Max; _ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER end. max_s2s_connections_number_per_node({From, To}) -> case acl:match_rule( - From, max_s2s_connections_per_node, exmpp_jid:make_bare_jid(To)) of + From, max_s2s_connections_per_node, exmpp_jid:make_jid(To)) of Max when is_integer(Max) -> Max; _ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE end. diff --git a/src/ejabberd_s2s_in.erl b/src/ejabberd_s2s_in.erl index 63088437a..b2bd7fd8e 100644 --- a/src/ejabberd_s2s_in.erl +++ b/src/ejabberd_s2s_in.erl @@ -346,7 +346,7 @@ stream_established({xmlstreamelement, El}, StateData) -> Conns = ?DICT:store({LFrom, LTo}, wait_for_verification, StateData#state.connections), change_shaper(StateData, LTo, - exmpp_jid:make_bare_jid(LFrom)), + exmpp_jid:make_jid(LFrom)), {next_state, stream_established, StateData#state{connections = Conns, @@ -371,7 +371,7 @@ stream_established({xmlstreamelement, El}, StateData) -> error; F -> try - exmpp_jid:binary_to_jid(F) + exmpp_jid:parse_jid(F) catch _Exception1 -> error end @@ -381,7 +381,7 @@ stream_established({xmlstreamelement, El}, StateData) -> error; T -> try - exmpp_jid:binary_to_jid(T) + exmpp_jid:parse_jid(T) catch _Exception2 -> error end @@ -580,15 +580,15 @@ cancel_timer(Timer) -> is_key_packet(#xmlel{ns = ?NS_DIALBACK, name = 'result', attrs = Attrs} = El) -> {key, - exmpp_stanza:get_recipient_from_attrs(Attrs), - exmpp_stanza:get_sender_from_attrs(Attrs), + binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)), + binary_to_list(exmpp_stanza:get_sender_from_attrs(Attrs)), exmpp_stanza:get_id_from_attrs(Attrs), exmpp_xml:get_cdata_as_list(El)}; is_key_packet(#xmlel{ns = ?NS_DIALBACK, name = 'verify', attrs = Attrs} = El) -> {verify, - exmpp_stanza:get_recipient_from_attrs(Attrs), - exmpp_stanza:get_sender_from_attrs(Attrs), + binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)), + binary_to_list(exmpp_stanza:get_sender_from_attrs(Attrs)), exmpp_stanza:get_id_from_attrs(Attrs), exmpp_xml:get_cdata_as_list(El)}; is_key_packet(_) -> @@ -612,7 +612,7 @@ get_cert_domains(Cert) -> end, if D /= error -> - JID = exmpp_jid:list_to_jid(D), + JID = exmpp_jid:parse_jid(D), case {exmpp_jid:lnode_as_list(JID), exmpp_jid:ldomain_as_list(JID), exmpp_jid:lresource_as_list(JID)} of @@ -648,7 +648,7 @@ get_cert_domains(Cert) -> case 'XmppAddr':decode( 'XmppAddr', XmppAddr) of {ok, D} when is_binary(D) -> - JID2 = exmpp_jid:list_to_jid(binary_to_list(D)), + JID2 = exmpp_jid:parse_jid(binary_to_list(D)), case {exmpp_jid:lnode_as_list(JID2), exmpp_jid:ldomain_as_list(JID2), exmpp_jid:lresource_as_list(JID2)} of @@ -666,7 +666,7 @@ get_cert_domains(Cert) -> [] end; ({dNSName, D}) when is_list(D) -> - JID3 = exmpp_jid:list_to_jid(D), + JID3 = exmpp_jid:parse_jid(D), case {exmpp_jid:lnode_as_list(JID3), exmpp_jid:ldomain_as_list(JID3), exmpp_jid:lresource_as_list(JID3)} of diff --git a/src/ejabberd_s2s_out.erl b/src/ejabberd_s2s_out.erl index 0d8c56176..8833309e5 100644 --- a/src/ejabberd_s2s_out.erl +++ b/src/ejabberd_s2s_out.erl @@ -819,8 +819,8 @@ bounce_element(El, Condition) -> <<"result">> -> ok; _ -> Err = exmpp_stanza:reply_with_error(El, Condition), - From = exmpp_jid:binary_to_jid(exmpp_stanza:get_sender(El)), - To = exmpp_jid:binary_to_jid(exmpp_stanza:get_recipient(El)), + From = exmpp_jid:parse_jid(exmpp_stanza:get_sender(El)), + To = exmpp_jid:parse_jid(exmpp_stanza:get_recipient(El)), % No namespace conversion (:server <-> :client) is done. % This is handled by C2S and S2S send_element functions. ejabberd_router:route(To, From, Err) diff --git a/src/ejabberd_service.erl b/src/ejabberd_service.erl index 2ff624ae2..41a78e0a7 100644 --- a/src/ejabberd_service.erl +++ b/src/ejabberd_service.erl @@ -227,10 +227,10 @@ stream_established({xmlstreamelement, El}, StateData) -> %% when accept packets from any address. %% In this case, the component can send packet of %% behalf of the server users. - false -> exmpp_jid:binary_to_jid(From); + false -> exmpp_jid:parse_jid(From); %% The default is the standard behaviour in XEP-0114 _ -> - FromJID1 = exmpp_jid:binary_to_jid(From), + FromJID1 = exmpp_jid:parse_jid(From), Server = exmpp_jid:ldomain_as_list(FromJID1), case lists:member(Server, StateData#state.hosts) of true -> FromJID1; diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 646f15999..1cdaf92bd 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -142,7 +142,7 @@ bounce_offline_message(From, To, Packet) -> disconnect_removed_user(User, Server) -> ejabberd_sm:route(exmpp_jid:make_jid(), - exmpp_jid:make_bare_jid(User, + exmpp_jid:make_jid(User, Server), #xmlel{name = 'broadcast', children = [{exit, "User removed"}]}). diff --git a/src/ejabberd_system_monitor.erl b/src/ejabberd_system_monitor.erl index 2a5418329..f4e8c3774 100644 --- a/src/ejabberd_system_monitor.erl +++ b/src/ejabberd_system_monitor.erl @@ -174,7 +174,7 @@ process_large_heap(Pid, Info) -> lists:foreach( fun(S) -> try - JID = exmpp_jid:list_to_jid(S), + JID = exmpp_jid:parse_jid(S), send_message(From, JID, Body) catch _ -> @@ -196,7 +196,7 @@ get_admin_jids() -> lists:flatmap( fun(S) -> try - JID = exmpp_jid:list_to_jid(S), + JID = exmpp_jid:parse_jid(S), [{exmpp_jid:lnode(JID), exmpp_jid:ldomain(JID), exmpp_jid:lresource(JID)}] diff --git a/src/jd2ejd.erl b/src/jd2ejd.erl index 86a6df3d6..4ee7577f4 100644 --- a/src/jd2ejd.erl +++ b/src/jd2ejd.erl @@ -115,7 +115,7 @@ process_xdb(_User, _Server, _El) -> xdb_data(_User, _Server, #xmlcdata{}) -> ok; xdb_data(User, Server, #xmlel{ns = NS} = El) -> - From = exmpp_jid:make_bare_jid(User, Server), + From = exmpp_jid:make_jid(User, Server), LServer = exmpp_stringprep:nameprep(Server), case NS of ?NS_LEGACY_AUTH -> @@ -132,7 +132,7 @@ xdb_data(User, Server, #xmlel{ns = NS} = El) -> end, ok; ?NS_LAST_ACTIVITY -> - TimeStamp = exmpp_xml:get_attribute(El, 'last', ""), + TimeStamp = exmpp_xml:get_attribute_as_list(El, 'last', ""), Status = exmpp_xml:get_cdata(El), case lists:member(mod_last_odbc, gen_mod:loaded_modules(LServer)) of @@ -156,12 +156,12 @@ xdb_data(User, Server, #xmlel{ns = NS} = El) -> true -> catch mod_vcard_odbc:process_sm_iq( From, - exmpp_jid:make_bare_jid(Server), + exmpp_jid:make_jid(Server), #iq{kind = request, type = set, ns = ?NS_VCARD, payload = El, iq_ns = ?NS_JABBER_CLIENT}); false -> catch mod_vcard:process_sm_iq( From, - exmpp_jid:make_bare_jid(Server), + exmpp_jid:make_jid(Server), #iq{kind = request, type = set, ns = ?NS_VCARD, payload = El, iq_ns = ?NS_JABBER_CLIENT}) end, ok; @@ -169,11 +169,11 @@ xdb_data(User, Server, #xmlel{ns = NS} = El) -> process_offline(Server, From, El), ok; XMLNS -> - case exmpp_xml:get_attribute(El, "j_private_flag", "") of + case exmpp_xml:get_attribute_as_list(El, "j_private_flag", "") of "1" -> catch mod_private:process_sm_iq( From, - exmpp_jid:make_bare_jid(Server), + exmpp_jid:make_jid(Server), #iq{kind = request, type = set, ns = ?NS_PRIVATE, iq_ns = ?NS_JABBER_CLIENT, payload = #xmlel{name = 'query', children = @@ -192,10 +192,10 @@ process_offline(Server, To, #xmlel{children = Els}) -> FromS = exmpp_stanza:get_sender(El), From = case FromS of undefined -> - exmpp_jid:make_bare_jid(Server); + exmpp_jid:make_jid(Server); _ -> try - exmpp_jid:list_to_jid(FromS) + exmpp_jid:parse_jid(FromS) catch _ -> error diff --git a/src/jlib.erl b/src/jlib.erl index 06bee3377..aba42c935 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -51,7 +51,7 @@ parse_xdata_submit(#xmlel{attrs = Attrs, children = Els}) -> - case exmpp_xml:get_attribute_from_list(Attrs, 'type', "") of + case exmpp_xml:get_attribute_from_list_as_list(Attrs, 'type', "") of "submit" -> lists:reverse(parse_xdata_fields(Els, [])); _ -> @@ -62,7 +62,7 @@ parse_xdata_fields([], Res) -> Res; parse_xdata_fields([#xmlel{name = 'field', attrs = Attrs, children = SubEls} | Els], Res) -> - case exmpp_xml:get_attribute_from_list(Attrs, 'var', "") of + case exmpp_xml:get_attribute_from_list_as_list(Attrs, 'var', "") of "" -> parse_xdata_fields(Els, Res); Var -> @@ -132,7 +132,7 @@ rsm_encode_first(undefined, undefined, Arr) -> rsm_encode_first(First, undefined, Arr) -> [#xmlel{ns = ?NS_RSM, name = 'first', children = [#xmlcdata{cdata = list_to_binary(First)}]}|Arr]; rsm_encode_first(First, Index, Arr) -> - [#xmlel{ns = ?NS_RSM, name = 'first', attrs = [#xmlattr{name = 'index', value = i2b(Index)}], children = [#xmlcdata{cdata = list_to_binary(First)}]}|Arr]. + [#xmlel{ns = ?NS_RSM, name = 'first', attrs = [?XMLATTR('index', Index)], children = [#xmlcdata{cdata = list_to_binary(First)}]}|Arr]. rsm_encode_last(undefined, Arr) -> Arr; rsm_encode_last(Last, Arr) -> diff --git a/src/mod_adhoc.erl b/src/mod_adhoc.erl index a53d8339e..19dfcd9d8 100644 --- a/src/mod_adhoc.erl +++ b/src/mod_adhoc.erl @@ -95,10 +95,9 @@ get_local_commands(Acc, _From, To, <<>>, Lang) -> end, Nodes = [#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = Server}, - #xmlattr{name = 'node', value = list_to_binary(?NS_ADHOC_s)}, - #xmlattr{name = 'name', - value = list_to_binary(translate:translate(Lang, "Commands"))}] + [?XMLATTR('jid', Server), + ?XMLATTR('node', ?NS_ADHOC_s), + ?XMLATTR('name', translate:translate(Lang, "Commands"))] }], {result, Items ++ Nodes} end; @@ -127,9 +126,9 @@ get_sm_commands(Acc, _From, To, <<>>, Lang) -> end, Nodes = [#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(To)}, - #xmlattr{name = 'node', value = list_to_binary(?NS_ADHOC_s)}, - #xmlattr{name = 'name', value = list_to_binary(translate:translate(Lang, "Commands"))}] + [?XMLATTR('jid', exmpp_jid:jid_to_binary(To)), + ?XMLATTR('node', ?NS_ADHOC_s), + ?XMLATTR('name', translate:translate(Lang, "Commands"))] }], {result, Items ++ Nodes} end; @@ -145,15 +144,15 @@ get_sm_commands(Acc, _From, _To, _Node, _Lang) -> %% On disco info request to the ad-hoc node, return automation/command-list. get_local_identity(Acc, _From, _To, ?NS_ADHOC_b, Lang) -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = <<"automation">>}, - #xmlattr{name = 'type', value = <<"command-list">>}, - #xmlattr{name = 'name', value = list_to_binary(translate:translate(Lang, "Commands"))}]} | Acc]; + [?XMLATTR('category', <<"automation">>), + ?XMLATTR('type', <<"command-list">>), + ?XMLATTR('name', translate:translate(Lang, "Commands"))]} | Acc]; get_local_identity(Acc, _From, _To, <<"ping">>, Lang) -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = <<"automation">>}, - #xmlattr{name = 'type', value = <<"command-node">>}, - #xmlattr{name = 'name', value = list_to_binary(translate:translate(Lang, "Ping"))}]} | Acc]; + [?XMLATTR('category', <<"automation">>), + ?XMLATTR('type', <<"command-node">>), + ?XMLATTR('name', translate:translate(Lang, "Ping"))]} | Acc]; get_local_identity(Acc, _From, _To, _Node, _Lang) -> Acc. @@ -163,9 +162,9 @@ get_local_identity(Acc, _From, _To, _Node, _Lang) -> %% On disco info request to the ad-hoc node, return automation/command-list. get_sm_identity(Acc, _From, _To, ?NS_ADHOC_s, Lang) -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = <<"automation">>}, - #xmlattr{name = 'type', value = <<"command-list">>}, - #xmlattr{name = 'name', value = list_to_binary(translate:translate(Lang, "Commands"))}]} | Acc]; + [?XMLATTR('category', <<"automation">>), + ?XMLATTR('type', <<"command-list">>), + ?XMLATTR('name', translate:translate(Lang, "Commands"))]} | Acc]; get_sm_identity(Acc, _From, _To, _Node, _Lang) -> Acc. @@ -245,9 +244,9 @@ ping_item(Acc, _From, To, Lang) -> [] end, Nodes = [#xmlel{ns = ?NS_DISCO_INFO, name = 'item', attrs = - [#xmlattr{name = 'jid', value = Server}, - #xmlattr{name = 'node', value = <<"ping">>}, - #xmlattr{name = 'name', value = list_to_binary(translate:translate(Lang, "Ping"))}]}], + [?XMLATTR('jid', Server), + ?XMLATTR('node', <<"ping">>), + ?XMLATTR('name', translate:translate(Lang, "Ping"))]}], {result, Items ++ Nodes}. diff --git a/src/mod_announce.erl b/src/mod_announce.erl index 6285fe623..5a419fef2 100644 --- a/src/mod_announce.erl +++ b/src/mod_announce.erl @@ -179,9 +179,9 @@ announce(From, To, Packet) -> %% Announcing via ad-hoc commands -define(INFO_COMMAND(Lang, Node), [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = <<"automation">>}, - #xmlattr{name = 'type', value = <<"command-node">>}, - #xmlattr{name = 'name', value = list_to_binary(get_title(Lang, Node))}]}]). + [?XMLATTR('category', <<"automation">>), + ?XMLATTR('type', <<"command-node">>), + ?XMLATTR('name', get_title(Lang, Node))]}]). disco_identity(Acc, _From, _To, Node, Lang) -> LNode = tokenize(binary_to_list(Node)), @@ -277,9 +277,9 @@ disco_features(Acc, From, To, Node, _Lang) -> -define(NODE_TO_ITEM(Lang, Server, Node), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = Server}, - #xmlattr{name = 'node', value = Node}, - #xmlattr{name = 'name', value = list_to_binary(get_title(Lang, Node))}]}). + [?XMLATTR('jid', Server), + ?XMLATTR('node', Node), + ?XMLATTR('name', get_title(Lang, Node))]}). -define(ITEMS_RESULT(Allow, Items), case Allow of @@ -488,8 +488,8 @@ announce_commands(From, To, _ -> [?VVALUE(Val)] end). -define(TVFIELD(Type, Var, Val), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'var', value = Var}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('var', Var)], children = ?VVALUEL(Val)}). -define(HFIELD(), ?TVFIELD(<<"hidden">>, <<"FORM_TYPE">>, list_to_binary(?NS_ADMIN_s))). @@ -502,28 +502,28 @@ generate_adhoc_form(Lang, Node, ServerHost) -> {[], []} end, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = <<"form">>}], children = + [?XMLATTR('type', <<"form">>)], children = [?HFIELD(), #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(get_title(Lang, Node))}]}] ++ if (LNode == ?NS_ADMINL("delete-motd")) or (LNode == ?NS_ADMINL("delete-motd-allhosts")) -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"confirm">>}, - #xmlattr{name = 'type', value = <<"boolean">>}, - #xmlattr{name = 'label', value = list_to_binary(translate:translate(Lang, "Really delete message of the day?"))}], children = + [?XMLATTR('var', <<"confirm">>), + ?XMLATTR('type', <<"boolean">>), + ?XMLATTR('label', translate:translate(Lang, "Really delete message of the day?"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"true">>}]}]}]; true -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"subject">>}, - #xmlattr{name = 'type', value = <<"text-single">>}, - #xmlattr{name = 'label', value = list_to_binary(translate:translate(Lang, "Subject"))}], children = + [?XMLATTR('var', <<"subject">>), + ?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', translate:translate(Lang, "Subject"))], children = ?VVALUEL(list_to_binary(OldSubject))}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"body">>}, - #xmlattr{name = 'type', value = <<"text-multi">>}, - #xmlattr{name = 'label', value = list_to_binary(translate:translate(Lang, "Message body"))}], children = + [?XMLATTR('var', <<"body">>), + ?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', translate:translate(Lang, "Message body"))], children = ?VVALUEL(list_to_binary(OldBody))}] end}. @@ -569,7 +569,7 @@ handle_adhoc_form(From, To, node = Node, sessionid = SessionID, status = completed}, - Packet = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', attrs = [#xmlattr{name = 'type', value = <<"normal">>}], children = + Packet = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', attrs = [?XMLATTR('type', <<"normal">>)], children = if Subject /= [] -> [#xmlel{ns = ?NS_JABBER_CLIENT, name = 'subject', children = [#xmlcdata{cdata = list_to_binary(Subject)}]}]; diff --git a/src/mod_caps.erl b/src/mod_caps.erl index f98b2fcd6..c7483a121 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -74,9 +74,9 @@ read_caps(Els) -> read_caps(Els, nothing). read_caps([#xmlel{ns = ?NS_CAPS, name = 'c'} = El | Tail], _Result) -> - Node = exmpp_xml:get_attribute(El, 'node', ""), - Version = exmpp_xml:get_attribute(El, 'ver', ""), - Exts = string:tokens(exmpp_xml:get_attribute(El, 'ext', ""), " "), + Node = exmpp_xml:get_attribute_as_list(El, 'node', ""), + Version = exmpp_xml:get_attribute_as_list(El, 'ver', ""), + Exts = string:tokens(exmpp_xml:get_attribute_as_list(El, 'ext', ""), " "), read_caps(Tail, #caps{node = Node, version = Version, exts = Exts}); read_caps([#xmlel{ns = ?NS_MUC_USER, name = 'x'} | _Tail], _Result) -> nothing; @@ -263,7 +263,7 @@ handle_cast({note_caps, From, Stanza = exmpp_iq:get(?NS_JABBER_CLIENT, Query, ID), ejabberd_local:register_iq_response_handler (list_to_binary(Host), ID, ?MODULE, handle_disco_response), - ejabberd_router:route(exmpp_jid:make_bare_jid(Host), + ejabberd_router:route(exmpp_jid:make_jid(Host), From, Stanza), timer:send_after(?CAPS_QUERY_TIMEOUT, self(), {disco_timeout, ID}), ?DICT:store(ID, {Node, SubNode}, Dict) @@ -281,7 +281,7 @@ handle_cast({disco_response, From, _To, #iq{id = ID, type = Type, payload = Payl {ok, {Node, SubNode}} -> Features = lists:flatmap(fun(#xmlel{name = 'feature'} = F) -> - [exmpp_xml:get_attribute(F, 'var', "")]; + [exmpp_xml:get_attribute_as_list(F, 'var', "")]; (_) -> [] end, Els), diff --git a/src/mod_configure.erl b/src/mod_configure.erl index a382a0920..490e60858 100644 --- a/src/mod_configure.erl +++ b/src/mod_configure.erl @@ -91,24 +91,24 @@ stop(Host) -> -define(INFO_IDENTITY(Category, Type, Name, Lang), [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = Category}, - #xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'name', value = ?T(Lang, Name)}]}]). + [?XMLATTR('category', Category), + ?XMLATTR('type', Type), + ?XMLATTR('name', ?T(Lang, Name))]}]). -define(INFO_COMMAND(Name, Lang), ?INFO_IDENTITY(<<"automation">>, <<"command-node">>, Name, Lang)). -define(NODEJID(To, Name, Node), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(To)}, - #xmlattr{name = 'name', value = ?T(Lang, Name)}, - #xmlattr{name = 'node', value = Node}]}). + [?XMLATTR('jid', exmpp_jid:jid_to_binary(To)), + ?XMLATTR('name', ?T(Lang, Name)), + ?XMLATTR('node', Node)]}). -define(NODE(Name, Node), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = Server}, - #xmlattr{name = 'name', value = ?T(Lang, Name)}, - #xmlattr{name = 'node', value = Node}]}). + [?XMLATTR('jid', Server), + ?XMLATTR('name', ?T(Lang, Name)), + ?XMLATTR('node', Node)]}). -define(NS_ADMINX(Sub), <>). -define(NS_ADMINL(Sub), ["http:","jabber.org","protocol","admin", Sub]). @@ -263,9 +263,9 @@ adhoc_sm_items(Acc, From, To, Lang) -> empty -> [] end, Nodes = [#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_binary(To)}, - #xmlattr{name = 'name', value = ?T(Lang, "Configuration")}, - #xmlattr{name = 'node', value = <<"config">>}]}], + [?XMLATTR('jid', exmpp_jid:jid_to_binary(To)), + ?XMLATTR('name', ?T(Lang, "Configuration")), + ?XMLATTR('node', <<"config">>)]}], {result, Items ++ Nodes}; _ -> Acc @@ -302,11 +302,11 @@ get_user_resources(BareJID) -> exmpp_jid:ldomain(BareJID)), lists:map(fun(R) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', - value = exmpp_jid:jid_to_binary( - exmpp_jid:bare_jid_to_jid(BareJID, R))}, - #xmlattr{name = 'name', - value = exmpp_jid:lnode(BareJID)}]} + [?XMLATTR('jid', + exmpp_jid:jid_to_binary( + exmpp_jid:bare_jid_to_jid(BareJID, R))), + ?XMLATTR('name', + exmpp_jid:lnode(BareJID))]} end, lists:sort(Rs)). %%%----------------------------------------------------------------------- @@ -325,7 +325,7 @@ adhoc_local_items(Acc, From, To, Lang) -> Lang), Nodes1 = lists:filter( fun(N) -> - Nd = exmpp_xml:get_attribute(N, 'node', ""), + Nd = exmpp_xml:get_attribute_as_list(N, 'node', ""), F = get_local_features([], From, To, Nd, Lang), case F of {result, [?NS_ADHOC_s]} -> @@ -356,8 +356,8 @@ recursively_get_local_items(PermLev, LServer, Node, Server, Lang) -> Nodes = lists:flatten( lists:map( fun(N) -> - S = exmpp_xml:get_attribute(N, 'jid', ""), - Nd = exmpp_xml:get_attribute(N, 'node', ""), + S = exmpp_xml:get_attribute_as_list(N, 'jid', ""), + Nd = exmpp_xml:get_attribute_as_list(N, 'node', ""), if (S /= Server) or (Nd == "") -> []; true -> @@ -530,8 +530,8 @@ get_local_items({_, Host}, ["all users", [$@ | Diap]], _Server, _Lang) -> Sub = lists:sublist(SUsers, N1, N2 - N1 + 1), lists:map(fun({S, U}) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(U, S)}, - #xmlattr{name = 'name', value = exmpp_jid:jid_to_binary(U, S)}]} + [?XMLATTR('jid', exmpp_jid:jid_to_binary(U, S)), + ?XMLATTR('name', exmpp_jid:jid_to_binary(U, S))]} end, Sub) end of {'EXIT', _Reason} -> @@ -623,8 +623,8 @@ get_online_vh_users(Host) -> SURs = lists:sort([{S, U, R} || {U, S, R} <- USRs]), lists:map(fun({S, U, R}) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_binary(U, S, R)}, - #xmlattr{name = 'name', value = exmpp_jid:jid_to_binary(U, S)}]} + [?XMLATTR('jid', exmpp_jid:jid_to_binary(U, S, R)), + ?XMLATTR('name', exmpp_jid:jid_to_binary(U, S))]} end, SURs) end. @@ -638,8 +638,8 @@ get_all_vh_users(Host) -> N when N =< 100 -> lists:map(fun({S, U}) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(U, S)}, - #xmlattr{name = 'name', value = exmpp_jid:jid_to_binary(U, S)}]} + [?XMLATTR('jid', exmpp_jid:jid_to_binary(U, S)), + ?XMLATTR('name', exmpp_jid:jid_to_binary(U, S))]} end, SUsers); N -> NParts = trunc(math:sqrt(N * 0.618)) + 1, @@ -658,9 +658,9 @@ get_all_vh_users(Host) -> <<(list_to_binary(FU))/binary, "@", (list_to_binary(FS))/binary, " -- ", (list_to_binary(LU))/binary, "@", (list_to_binary(LS))/binary>>, #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = list_to_binary(Host)}, - #xmlattr{name = 'node', value = <<"all users/", Node/binary>>}, - #xmlattr{name = 'name', value = Name}]} + [?XMLATTR('jid', Host), + ?XMLATTR('node', <<"all users/", Node/binary>>), + ?XMLATTR('name', Name)]} end, lists:seq(1, N, M)) end end. @@ -676,12 +676,10 @@ get_outgoing_s2s(Host, Lang) -> lists:map( fun(T) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = list_to_binary(Host)}, - #xmlattr{name = 'node', value = <<"outgoing s2s/", (list_to_binary(T))/binary>>}, - #xmlattr{name = 'name', value = - list_to_binary( - io_lib:format( - ?T(Lang, "To ~s"), [T]))}]} + [?XMLATTR('jid', Host), + ?XMLATTR('node', <<"outgoing s2s/", (list_to_binary(T))/binary>>), + ?XMLATTR('name', + io_lib:format(?T(Lang, "To ~s"), [T]))]} end, lists:usort(TConns)) end. @@ -693,12 +691,10 @@ get_outgoing_s2s(Host, Lang, To) -> lists:map( fun({F, _T}) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = list_to_binary(Host)}, - #xmlattr{name = 'node', value = <<"outgoing s2s/", (list_to_binary(To))/binary, "/", (list_to_binary(F))/binary>>}, - #xmlattr{name = 'name', value = - list_to_binary( - io_lib:format( - ?T(Lang, "From ~s"), [F]))}]} + [?XMLATTR('jid', Host), + ?XMLATTR('node', <<"outgoing s2s/", (list_to_binary(To))/binary, "/", (list_to_binary(F))/binary>>), + ?XMLATTR('name', + io_lib:format(?T(Lang, "From ~s"), [F]))]} end, lists:keysort(1, lists:filter(fun(E) -> element(2, E) == To end, Connections))) @@ -714,9 +710,9 @@ get_running_nodes(Server, _Lang) -> fun(N) -> S = list_to_binary(atom_to_list(N)), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = list_to_binary(Server)}, - #xmlattr{name = 'node', value = <<"running nodes/", (list_to_binary(S))/binary>>}, - #xmlattr{name = 'name', value = S}]} + [?XMLATTR('jid', Server), + ?XMLATTR('node', <<"running nodes/", (list_to_binary(S))/binary>>), + ?XMLATTR('name', S)]} end, lists:sort(DBNodes)) end. @@ -731,9 +727,9 @@ get_stopped_nodes(_Lang) -> fun(N) -> S = list_to_binary(atom_to_list(N)), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = list_to_binary(?MYNAME)}, - #xmlattr{name = 'node', value = <<"stopped nodes/", S/binary>>}, - #xmlattr{name = 'name', value = S}]} + [?XMLATTR('jid', ?MYNAME), + ?XMLATTR('node', <<"stopped nodes/", S/binary>>), + ?XMLATTR('name', S)]} end, lists:sort(DBNodes)) end. @@ -832,46 +828,46 @@ adhoc_local_commands(From, To, -define(TVFIELD(Type, Var, Val), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'var', value = Var}], + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}). -define(HFIELD(), ?TVFIELD(<<"hidden">>, <<"FORM_TYPE">>, list_to_binary(?NS_ADMIN_s))). -define(TLFIELD(Type, Label, Var), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = ?T(Lang, Label)}, - #xmlattr{name = 'var', value = Var}]}). + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', ?T(Lang, Label)), + ?XMLATTR('var', Var)]}). -define(XFIELD(Type, Label, Var, Val), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = ?T(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', ?T(Lang, Label)), + ?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}). -define(XMFIELD(Type, Label, Var, Vals), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = ?T(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', ?T(Lang, Label)), + ?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Val)}]} || Val <- Vals]}). -define(TABLEFIELD(Table, Val), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = <<"list-single">>}, - #xmlattr{name = 'label', value = list_to_binary(atom_to_list(Table))}, - #xmlattr{name = 'var', value = list_to_binary(atom_to_list(Table))}], + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"list-single">>), + ?XMLATTR('label', Table), + ?XMLATTR('var', Table)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(atom_to_list(Val))}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [#xmlattr{name = 'label', value = - ?T(Lang, "RAM copy")}], + #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label', + ?T(Lang, "RAM copy"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"ram_copies">>}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [#xmlattr{name = 'label', value = + #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label', ?T(Lang, - "RAM and disc copy")}], + "RAM and disc copy"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"disc_copies">>}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [#xmlattr{name = 'label', value = + #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label', ?T(Lang, - "Disc only copy")}], + "Disc only copy"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"disc_only_copies">>}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [#xmlattr{name = 'label', value = - ?T(Lang, "Remote copy")}], + #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = [?XMLATTR('label', + ?T(Lang, "Remote copy"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"unknown">>}]}]} ]}). @@ -1031,7 +1027,7 @@ get_form(_Host, ["running nodes", _ENode, "restart"], Lang) -> Make_option = fun(LabelNum, LabelUnit, Value)-> #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = - [#xmlattr{name = 'label', value = <<(list_to_binary(LabelNum))/binary, (?T(Lang, LabelUnit))/binary>>}], children = + [?XMLATTR('label', LabelNum ++ ?T(Lang, LabelUnit))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Value)}]}]} end, {result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children = @@ -1039,9 +1035,9 @@ get_form(_Host, ["running nodes", _ENode, "restart"], Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Restart Service"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"list-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Time delay")}, - #xmlattr{name = 'var', value = <<"delay">>}], children = + [?XMLATTR('type', <<"list-single">>), + ?XMLATTR('label', ?T(Lang, "Time delay")), + ?XMLATTR('var', <<"delay">>)], children = [Make_option("", "immediately", "1"), Make_option("15 ", "seconds", "15"), Make_option("30 ", "seconds", "30"), @@ -1057,23 +1053,23 @@ get_form(_Host, ["running nodes", _ENode, "restart"], Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'required'} ]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"fixed">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Send announcement to all online users on all hosts")}]}, + [?XMLATTR('type', <<"fixed">>), + ?XMLATTR('label', ?T(Lang, "Send announcement to all online users on all hosts"))]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"subject">>}, - #xmlattr{name = 'type', value = <<"text-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Subject")}]}, + [?XMLATTR('var', <<"subject">>), + ?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', ?T(Lang, "Subject"))]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"announcement">>}, - #xmlattr{name = 'type', value = <<"text-multi">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Message body")}]} + [?XMLATTR('var', <<"announcement">>), + ?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', ?T(Lang, "Message body"))]} ]}]}; get_form(_Host, ["running nodes", _ENode, "shutdown"], Lang) -> Make_option = fun(LabelNum, LabelUnit, Value)-> #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = - [#xmlattr{name = 'label', value = <<(list_to_binary(LabelNum))/binary, (?T(Lang, LabelUnit))/binary>>}], children = + [?XMLATTR('label', LabelNum ++ ?T(Lang, LabelUnit))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Value)}]}]} end, {result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children = @@ -1081,9 +1077,9 @@ get_form(_Host, ["running nodes", _ENode, "shutdown"], Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Shut Down Service"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"list-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Time delay")}, - #xmlattr{name = 'var', value = <<"delay">>}], children = + [?XMLATTR('type', <<"list-single">>), + ?XMLATTR('label', ?T(Lang, "Time delay")), + ?XMLATTR('var', <<"delay">>)], children = [Make_option("", "immediately", "1"), Make_option("15 ", "seconds", "15"), Make_option("30 ", "seconds", "30"), @@ -1099,16 +1095,16 @@ get_form(_Host, ["running nodes", _ENode, "shutdown"], Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'required'} ]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"fixed">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Send announcement to all online users on all hosts")}]}, + [?XMLATTR('type', <<"fixed">>), + ?XMLATTR('label', ?T(Lang, "Send announcement to all online users on all hosts"))]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"subject">>}, - #xmlattr{name = 'type', value = <<"text-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Subject")}]}, + [?XMLATTR('var', <<"subject">>), + ?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', ?T(Lang, "Subject"))]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = <<"announcement">>}, - #xmlattr{name = 'type', value = <<"text-multi">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Message body")}]} + [?XMLATTR('var', <<"announcement">>), + ?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', ?T(Lang, "Message body"))]} ]}]}; get_form(Host, ["config", "acls"], Lang) -> @@ -1118,11 +1114,11 @@ get_form(Host, ["config", "acls"], Lang) -> [#xmlcdata{cdata = list_to_binary(?T( Lang, "Access Control List Configuration"))}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = <<"text-multi">>}, - #xmlattr{name = 'label', value = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', ?T( - Lang, "Access control lists")}, - #xmlattr{name = 'var', value = <<"acls">>}], + Lang, "Access control lists")), + ?XMLATTR('var', <<"acls">>)], children = lists:map(fun(S) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(S)}]} end, @@ -1146,11 +1142,11 @@ get_form(Host, ["config", "access"], Lang) -> [#xmlcdata{cdata = list_to_binary(?T( Lang, "Access Configuration"))}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =[#xmlattr{name = 'type', value = <<"text-multi">>}, - #xmlattr{name = 'label', value = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =[?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', ?T( - Lang, "Access rules")}, - #xmlattr{name = 'var', value = <<"access">>}], + Lang, "Access rules")), + ?XMLATTR('var', <<"access">>)], children = lists:map(fun(S) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =[#xmlcdata{cdata = list_to_binary(S)}]} end, @@ -1173,19 +1169,19 @@ get_form(_Host, ?NS_ADMINL("add-user"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Add User"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Jabber ID")}, - #xmlattr{name = 'var', value = <<"accountjid">>}], children = + [?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjid">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"text-private">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Password")}, - #xmlattr{name = 'var', value = <<"password">>}], children = + [?XMLATTR('type', <<"text-private">>), + ?XMLATTR('label', ?T(Lang, "Password")), + ?XMLATTR('var', <<"password">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"text-private">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Password Verification")}, - #xmlattr{name = 'var', value = <<"password-verify">>}], children = + [?XMLATTR('type', <<"text-private">>), + ?XMLATTR('label', ?T(Lang, "Password Verification")), + ?XMLATTR('var', <<"password-verify">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1195,9 +1191,9 @@ get_form(_Host, ?NS_ADMINL("delete-user"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Delete User"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-multi">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Jabber ID")}, - #xmlattr{name = 'var', value = <<"accountjids">>}], children = + [?XMLATTR('type', <<"jid-multi">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjids">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1207,9 +1203,9 @@ get_form(_Host, ?NS_ADMINL("end-user-session"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "End User Session"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-single">>}, - #xmlattr{name = 'label', value = list_to_binary(?T(Lang, "Jabber ID"))}, - #xmlattr{name = 'var', value = <<"accountjid">>}], children = + [?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjid">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1219,9 +1215,9 @@ get_form(_Host, ?NS_ADMINL("get-user-password"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Password"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Jabber ID")}, - #xmlattr{name = 'var', value = <<"accountjid">>}], children = + [?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjid">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1231,14 +1227,14 @@ get_form(_Host, ?NS_ADMINL("change-user-password"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Password"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Jabber ID")}, - #xmlattr{name = 'var', value = <<"accountjid">>}], children = + [?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjid">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"text-private">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Password")}, - #xmlattr{name = 'var', value = <<"password">>}], children = + [?XMLATTR('type', <<"text-private">>), + ?XMLATTR('label', ?T(Lang, "Password")), + ?XMLATTR('var', <<"password">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1248,9 +1244,9 @@ get_form(_Host, ?NS_ADMINL("get-user-lastlogin"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Last Login Time"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Jabber ID")}, - #xmlattr{name = 'var', value = <<"accountjid">>}], children = + [?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjid">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1260,9 +1256,9 @@ get_form(_Host, ?NS_ADMINL("user-stats"), Lang) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(?T(Lang, "Get User Statistics"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"jid-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Jabber ID")}, - #xmlattr{name = 'var', value = <<"accountjid">>}], children = + [?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', ?T(Lang, "Jabber ID")), + ?XMLATTR('var', <<"accountjid">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'required'}]} ]}]}; @@ -1272,9 +1268,9 @@ get_form(Host, ?NS_ADMINL("get-registered-users-num"), Lang) -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children = [?HFIELD(), #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"text-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Number of registered users")}, - #xmlattr{name = 'var', value = <<"registeredusersnum">>}], children = + [?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', ?T(Lang, "Number of registered users")), + ?XMLATTR('var', <<"registeredusersnum">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Num)}]}] }]}]}; @@ -1284,9 +1280,9 @@ get_form(Host, ?NS_ADMINL("get-online-users-num"), Lang) -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', children = [?HFIELD(), #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"text-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Number of online users")}, - #xmlattr{name = 'var', value = <<"onlineusersnum">>}], children = + [?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', ?T(Lang, "Number of online users")), + ?XMLATTR('var', <<"onlineusersnum">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Num)}]}] }]}]}; @@ -1566,7 +1562,7 @@ set_form(From, Host, ?NS_ADMINL("add-user"), _Lang, XData) -> AccountString = get_value("accountjid", XData), Password = get_value("password", XData), Password = get_value("password-verify", XData), - AccountJID = exmpp_jid:list_to_jid(AccountString), + AccountJID = exmpp_jid:parse_jid(AccountString), User = exmpp_jid:lnode_as_list(AccountJID), Server = exmpp_jid:ldomain_as_list(AccountJID), true = lists:member(Server, ?MYHOSTS), @@ -1592,7 +1588,7 @@ set_form(From, Host, ?NS_ADMINL("delete-user"), _Lang, XData) -> set_form(From, Host, ?NS_ADMINL("end-user-session"), _Lang, XData) -> AccountString = get_value("accountjid", XData), - JID = exmpp_jid:list_to_jid(AccountString), + JID = exmpp_jid:parse_jid(AccountString), LUser = [_|_] = exmpp_jid:lnode_as_list(JID), LServer = exmpp_jid:ldomain_as_list(JID), true = (LServer == Host) orelse (get_permission_level(From) == global), @@ -1611,7 +1607,7 @@ set_form(From, Host, ?NS_ADMINL("end-user-session"), _Lang, XData) -> set_form(From, Host, ?NS_ADMINL("get-user-password"), Lang, XData) -> AccountString = get_value("accountjid", XData), - JID = exmpp_jid:list_to_jid(AccountString), + JID = exmpp_jid:parse_jid(AccountString), User = [_|_] = exmpp_jid:lnode_as_list(JID), Server = exmpp_jid:ldomain_as_list(JID), true = (Server == Host) orelse (get_permission_level(From) == global), @@ -1626,7 +1622,7 @@ set_form(From, Host, ?NS_ADMINL("get-user-password"), Lang, XData) -> set_form(From, Host, ?NS_ADMINL("change-user-password"), _Lang, XData) -> AccountString = get_value("accountjid", XData), Password = get_value("password", XData), - JID = exmpp_jid:list_to_jid(AccountString), + JID = exmpp_jid:parse_jid(AccountString), User = [_|_] = exmpp_jid:lnode_as_list(JID), Server = exmpp_jid:ldomain_as_list(JID), true = (Server == Host) orelse (get_permission_level(From) == global), @@ -1636,7 +1632,7 @@ set_form(From, Host, ?NS_ADMINL("change-user-password"), _Lang, XData) -> set_form(From, Host, ?NS_ADMINL("get-user-lastlogin"), Lang, XData) -> AccountString = get_value("accountjid", XData), - JID = exmpp_jid:list_to_jid(AccountString), + JID = exmpp_jid:parse_jid(AccountString), User = [_|_] = exmpp_jid:lnode_as_list(JID), Server = exmpp_jid:ldomain_as_list(JID), true = (Server == Host) orelse (get_permission_level(From) == global), @@ -1666,7 +1662,7 @@ set_form(From, Host, ?NS_ADMINL("get-user-lastlogin"), Lang, XData) -> _ -> ?T(Lang, "Online") end, - {result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [#xmlattr{name = 'type', value = <<"result">>}], children = + {result, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"result">>)], children = [?HFIELD(), ?XFIELD(<<"jid-single">>, "Jabber ID", <<"accountjid">>, list_to_binary(AccountString)), ?XFIELD(<<"text-single">>, "Last login", <<"lastlogin">>, list_to_binary(FLast)) @@ -1674,7 +1670,7 @@ set_form(From, Host, ?NS_ADMINL("get-user-lastlogin"), Lang, XData) -> set_form(From, Host, ?NS_ADMINL("user-stats"), Lang, XData) -> AccountString = get_value("accountjid", XData), - JID = exmpp_jid:list_to_jid(AccountString), + JID = exmpp_jid:parse_jid(AccountString), User = [_|_] = exmpp_jid:lnode_as_list(JID), Server = exmpp_jid:ldomain_as_list(JID), true = (Server == Host) orelse (get_permission_level(From) == global), @@ -1726,12 +1722,12 @@ stop_node(From, Host, ENode, Action, XData) -> Delay = list_to_integer(get_value("delay", XData)), Subject = case get_value("subject", XData) of [] -> []; - S -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'var', value = <<"subject">>}], children = + S -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"subject">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(S)}]}]}] end, Announcement = case get_values("announcement", XData) of [] -> []; - As -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'var', value = <<"body">>}], children = + As -> [#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"body">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Line)}]} || Line <- As] }] end, case Subject ++ Announcement of @@ -1741,10 +1737,10 @@ stop_node(From, Host, ENode, Action, XData) -> node = binary_to_list(?NS_ADMINX(<<"announce-allhosts">>)), action = "complete", xdata = #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = <<"submit">>}], children = + [?XMLATTR('type', <<"submit">>)], children = SubEls}, others= [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = <<"submit">>}], children = + [?XMLATTR('type', <<"submit">>)], children = SubEls}] }, To = exmpp_jid:make_jid(Host), @@ -1826,15 +1822,15 @@ get_sm_form(User, Server, "config", Lang) -> list_to_binary(?T( Lang, "Administration of ") ++ User)}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'type', value = <<"list-single">>}, - #xmlattr{name = 'label', value = ?T(Lang, "Action on user")}, - #xmlattr{name = 'var', value = <<"action">>}], children = + [?XMLATTR('type', <<"list-single">>), + ?XMLATTR('label', ?T(Lang, "Action on user")), + ?XMLATTR('var', <<"action">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"edit">>}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = - [#xmlattr{name = 'label', value = ?T(Lang, "Edit Properties")}], children = + [?XMLATTR('label', ?T(Lang, "Edit Properties"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"edit">>}]}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'option', attrs = - [#xmlattr{name = 'label', value = ?T(Lang, "Remove User")}], children = + [?XMLATTR('label', ?T(Lang, "Remove User"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"remove">>}]}]} ]}, ?XFIELD(<<"text-private">>, "Password", <<"password">>, diff --git a/src/mod_configure2.erl b/src/mod_configure2.erl index 26fed15fa..33c698ab9 100644 --- a/src/mod_configure2.erl +++ b/src/mod_configure2.erl @@ -45,8 +45,8 @@ start(Host, Opts) -> gen_iq_handler:add_iq_handler(ejabberd_local, list_to_binary(Host), ?NS_ECONFIGURE, ?MODULE, process_local_iq, IQDisc), % Add nss/names/attrs used by this module to the known lists of Exmpp. - exmpp_xml:add_autoload_known_nss([?NS_ECONFIGURE]), - exmpp_xml:add_autoload_known_names([ + exmpp_xml:add_known_nss(xmpp, [?NS_ECONFIGURE]), + exmpp_xml:add_known_elems(xmpp, [ 'access', 'acls', 'body', @@ -57,7 +57,7 @@ start(Host, Opts) -> 'subject', 'welcome-message' ]), - exmpp_xml:add_autoload_known_attrs([ + exmpp_xml:add_known_attrs(xmpp, [ 'online-users', 'outgoing-s2s-servers', 'registered-users', @@ -124,19 +124,16 @@ process_local_iq(From, To, #iq{type = Type, payload = Request} = IQ_Rec) -> process_get(#xmlel{ns = ?NS_ECONFIGURE, name = 'info'}) -> S2SConns = ejabberd_s2s:dirty_get_connections(), TConns = lists:usort([element(2, C) || C <- S2SConns]), - Attrs = [#xmlattr{name = 'registered-users', value = - list_to_binary(integer_to_list(mnesia:table_info(passwd, size)))}, - #xmlattr{name = 'online-users', value = - list_to_binary(integer_to_list(mnesia:table_info(presence, size)))}, - #xmlattr{name = 'running-nodes', value = - list_to_binary(integer_to_list(length(mnesia:system_info(running_db_nodes))))}, - #xmlattr{name = 'stopped-nodes', value = - list_to_binary(integer_to_list( - length(lists:usort(mnesia:system_info(db_nodes) ++ - mnesia:system_info(extra_db_nodes)) -- - mnesia:system_info(running_db_nodes))))}, - #xmlattr{name = 'outgoing-s2s-servers', value = - list_to_binary(integer_to_list(length(TConns)))}], + Attrs = [?XMLATTR('registered-users', mnesia:table_info(passwd, size)), + ?XMLATTR('online-users', mnesia:table_info(presence, size)), + ?XMLATTR('running-nodes', + length(mnesia:system_info(running_db_nodes))), + ?XMLATTR('stopped-nodes', + length(lists:usort(mnesia:system_info(db_nodes) ++ + mnesia:system_info(extra_db_nodes)) -- + mnesia:system_info(running_db_nodes))), + ?XMLATTR('outgoing-s2s-servers', + length(TConns))], {result, #xmlel{ns = ?NS_ECONFIGURE, name = 'info', attrs = Attrs}}; process_get(#xmlel{ns = ?NS_ECONFIGURE, name = 'welcome-message', attrs = Attrs}) -> {Subj, Body} = case ejabberd_config:get_local_option(welcome_message) of diff --git a/src/mod_disco.erl b/src/mod_disco.erl index 00b90c697..345a56ff7 100644 --- a/src/mod_disco.erl +++ b/src/mod_disco.erl @@ -139,7 +139,7 @@ process_local_iq_items(From, To, #iq{type = get, payload = SubEl, {result, Items} -> ANode = case Node of <<>> -> []; - _ -> [#xmlattr{name = 'node', value = Node}] + _ -> [?XMLATTR('node', Node)] end, Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query', attrs = ANode, children = Items}, @@ -165,7 +165,7 @@ process_local_iq_info(From, To, #iq{type = get, payload = SubEl, {result, Features} -> ANode = case Node of <<>> -> []; - _ -> [#xmlattr{name = 'node', value = Node}] + _ -> [?XMLATTR('node', Node)] end, Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query', attrs = ANode, @@ -180,9 +180,9 @@ process_local_iq_info(_From, _To, #iq{type = set} = IQ_Rec) -> get_local_identity(Acc, _From, _To, <<>>, _Lang) -> Acc ++ [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [ - #xmlattr{name = 'category', value = <<"server">>}, - #xmlattr{name = 'type', value = <<"im">>}, - #xmlattr{name = 'name', value = <<"ejabberd">>} + ?XMLATTR('category', <<"server">>), + ?XMLATTR('type', <<"im">>), + ?XMLATTR('name', <<"ejabberd">>) ]}]; get_local_identity(Acc, _From, _To, _Node, _Lang) -> @@ -214,7 +214,7 @@ feature_to_xml({{Feature, _Host}}) -> feature_to_xml(Feature) when is_binary(Feature) -> #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', value = Feature} + ?XMLATTR('var', Feature) ]}; feature_to_xml(Feature) when is_list(Feature) -> @@ -226,7 +226,7 @@ domain_to_xml({Domain}) -> domain_to_xml(Domain); domain_to_xml(Domain) when is_binary(Domain)-> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [ - #xmlattr{name = 'jid', value = Domain} + ?XMLATTR('jid', Domain) ]}; domain_to_xml(Domain) when is_list(Domain) -> domain_to_xml(list_to_binary(Domain)). @@ -280,7 +280,7 @@ process_sm_iq_items(From, To, #iq{type = get, payload = SubEl, {result, Items} -> ANode = case Node of <<>> -> []; - _ -> [#xmlattr{name = 'node', value = Node}] + _ -> [?XMLATTR('node', Node)] end, Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query', attrs = ANode, children = Items}, @@ -294,7 +294,7 @@ process_sm_iq_items(From, To, #iq{type = set, payload = SubEl} = IQ_Rec) -> LFrom = exmpp_jid:lnode_as_list(From), LServer = exmpp_jid:ldomain_as_list(From), Self = (LTo == LFrom) andalso (ToServer == LServer), - Node = exmpp_xml:get_attribute(SubEl, 'node', ""), + Node = exmpp_xml:get_attribute_as_list(SubEl, 'node', ""), if Self, Node /= [] -> %% Here, we treat disco publish attempts to your own JID. @@ -358,7 +358,7 @@ process_sm_iq_info(From, To, #iq{type = get, payload = SubEl, {result, Features} -> ANode = case Node of <<>> -> []; - _ -> [#xmlattr{name = 'node', value = Node}] + _ -> [?XMLATTR('node', Node)] end, Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query', attrs = ANode, @@ -396,9 +396,9 @@ get_user_resources(JID) -> exmpp_jid:ldomain(JID)), lists:map(fun(R) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [ - #xmlattr{name = 'jid', value = - exmpp_jid:jid_to_binary(exmpp_jid:bare_jid_to_jid(JID, R))}, - #xmlattr{name = 'name', value = exmpp_jid:lnode(JID)} + ?XMLATTR('jid', + exmpp_jid:jid_to_binary(exmpp_jid:bare_jid_to_jid(JID, R))), + ?XMLATTR('name', exmpp_jid:lnode(JID)) ]} end, lists:sort(Rs)). @@ -421,10 +421,10 @@ process_disco_publish(User, Node, Items) -> F = fun() -> lists:foreach( fun(#xmlel{} = Item) -> - Action = exmpp_xml:get_attribute(Item, 'action', ""), - Jid = exmpp_xml:get_attribute(Item, 'jid', ""), - PNode = exmpp_xml:get_attribute(Item, 'node', ""), - Name = exmpp_xml:get_attribute(Item, 'name', ""), + Action = exmpp_xml:get_attribute_as_list(Item, 'action', ""), + Jid = exmpp_xml:get_attribute_as_list(Item, 'jid', ""), + PNode = exmpp_xml:get_attribute_as_list(Item, 'node', ""), + Name = exmpp_xml:get_attribute_as_list(Item, 'name', ""), ?INFO_MSG("Disco publish: ~p ~p ~p ~p ~p ~p~n", [User, Action, Node, Jid, PNode, Name]), @@ -488,18 +488,18 @@ retrieve_disco_publish(User, Node) -> name = Name, node = PNode}) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - lists:append([[#xmlattr{name = 'jid', value = list_to_binary(Jid)}], + lists:append([[?XMLATTR('jid', Jid)], case Name of "" -> []; _ -> - [#xmlattr{name = 'name', value = list_to_binary(Name)}] + [?XMLATTR('name', Name)] end, case PNode of "" -> []; _ -> - [#xmlattr{name = 'node', value = list_to_binary(PNode)}] + [?XMLATTR('node', PNode)] end])} end, Items)} end. diff --git a/src/mod_irc/mod_irc.erl b/src/mod_irc/mod_irc.erl index bcc61a4b8..eb4d5fa7f 100644 --- a/src/mod_irc/mod_irc.erl +++ b/src/mod_irc/mod_irc.erl @@ -303,17 +303,17 @@ closed_connection(Host, From, Server) -> iq_disco(Lang) -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = <<"conference">>}, - #xmlattr{name = 'type', value = <<"irc">>}, - #xmlattr{name = 'name', value = list_to_binary(translate:translate(Lang, "IRC Transport"))}]}, + [?XMLATTR('category', <<"conference">>), + ?XMLATTR('type', <<"irc">>), + ?XMLATTR('name', translate:translate(Lang, "IRC Transport"))]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', value = list_to_binary(?NS_DISCO_INFO_s)}]}, + [?XMLATTR('var', ?NS_DISCO_INFO_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', value = list_to_binary(?NS_MUC_s)}]}, + [?XMLATTR('var', ?NS_MUC_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', value = list_to_binary(?NS_INBAND_REGISTER_s)}]}, + [?XMLATTR('var', ?NS_INBAND_REGISTER_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', value = list_to_binary(?NS_VCARD_s)}]}]. + [?XMLATTR('var', ?NS_VCARD_s)]}]. iq_get_vcard(Lang) -> [#xmlel{ns = ?NS_VCARD, name = 'FN', children = @@ -354,7 +354,7 @@ process_irc_register(Host, From, _To, DefEnc, #iq{type = get, ns = XMLNS, lang = Lang, payload = SubEl} = IQ_Rec) -> Node = - string:tokens(exmpp_xml:get_attribute(SubEl, 'node', ""), "/"), + string:tokens(exmpp_xml:get_attribute_as_list(SubEl, 'node', ""), "/"), case get_form(Host, From, Node, Lang ,DefEnc) of {result, Res} -> Result = #xmlel{ns = XMLNS, name = 'query', children = Res}, @@ -381,7 +381,7 @@ process_irc_register(Host, From, _To, _DefEnc, exmpp_iq:error(IQ_Rec, 'bad-request'); _ -> Node = string:tokens( - exmpp_xml:get_attribute(SubEl, "node", ""), + exmpp_xml:get_attribute_as_list(SubEl, "node", ""), "/"), case set_form( Host, From, Node, Lang, XData) of @@ -439,13 +439,13 @@ get_form(Host, From, [], Lang, DefEnc) -> Lang, "Enter username and encodings you wish to use for " "connecting to IRC servers"))}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = <<"text-single">>}, - #xmlattr{name = 'label', value = - list_to_binary(translate:translate( - Lang, "IRC Username"))}, - #xmlattr{name = 'var', value = <<"username">>}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', + translate:translate( + Lang, "IRC Username")), + ?XMLATTR('var', <<"username">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Username)}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = <<"fixed">>}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"fixed">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary( lists:flatten( @@ -457,7 +457,7 @@ get_form(Host, From, [], Lang, DefEnc) -> "in format '{\"irc server\", \"encoding\"}'. " "By default this service use \"~s\" encoding."), [DefEnc])))}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = <<"fixed">>}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"fixed">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary( translate:translate( @@ -465,10 +465,10 @@ get_form(Host, From, [], Lang, DefEnc) -> "Example: [{\"irc.lucky.net\", \"koi8-r\"}, " "{\"vendetta.fef.net\", \"iso8859-1\"}]." ))}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = <<"text-multi">>}, - #xmlattr{name = 'label', value = - list_to_binary(translate:translate(Lang, "Encodings"))}, - #xmlattr{name = 'var', value = <<"encodings">>}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', + translate:translate(Lang, "Encodings")), + ?XMLATTR('var', <<"encodings">>)], children = lists:map( fun(S) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(S)}]} diff --git a/src/mod_irc/mod_irc_connection.erl b/src/mod_irc/mod_irc_connection.erl index 7fcb8c651..c7d07113e 100644 --- a/src/mod_irc/mod_irc_connection.erl +++ b/src/mod_irc/mod_irc_connection.erl @@ -590,8 +590,8 @@ terminate(_Reason, _StateName, StateData) -> lists:concat([Chan, "%", StateData#state.server]), StateData#state.host, StateData#state.nick), StateData#state.user, - #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [#xmlattr{name = 'type', value = <<"error">>}], children = - [#xmlel{ns = ?NS_JABBER_CLIENT, name = 'error', attrs = [#xmlattr{name = 'code', value = <<"502">>}], children = + #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [?XMLATTR('type', <<"error">>)], children = + [#xmlel{ns = ?NS_JABBER_CLIENT, name = 'error', attrs = [?XMLATTR('code', <<"502">>)], children = [#xmlcdata{cdata = <<"Server Connect Failed">>}]}]}) end, dict:fetch_keys(StateData#state.channels)), case StateData#state.socket of @@ -629,11 +629,11 @@ bounce_messages(Reason) -> ok; _ -> Error = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'error', - attrs = [#xmlattr{name = 'code', value = <<"502">>}], + attrs = [?XMLATTR('code', <<"502">>)], children = [#xmlcdata{cdata = Reason}]}, Err = exmpp_stanza:reply_with_error(El, Error), - From = exmpp_jid:binary_to_jid(exmpp_stanza:get_sender(El)), - To = exmpp_jid:binary_to_jid(exmpp_stanza:get_recipient(El)), + From = exmpp_jid:parse_jid(exmpp_stanza:get_sender(El)), + To = exmpp_jid:parse_jid(exmpp_stanza:get_recipient(El)), ejabberd_router:route(To, From, Err) end, bounce_messages(Reason) @@ -692,8 +692,8 @@ process_channel_list_user(StateData, Chan, User) -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = Affiliation}, - #xmlattr{name = 'role', value = Role}]}]}]}), + [?XMLATTR('affiliation', Affiliation), + ?XMLATTR('role', Role)]}]}]}), case catch dict:update(Chan, fun(Ps) -> ?SETS:add_element(User2, Ps) @@ -893,11 +893,11 @@ process_part(StateData, Chan, From, String) -> exmpp_jid:make_jid(lists:concat([Chan, "%", StateData#state.server]), StateData#state.host, FromUser), StateData#state.user, - #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [#xmlattr{name = 'type', value = <<"unavailable">>}], children = + #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [?XMLATTR('type', <<"unavailable">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = <<"member">>}, - #xmlattr{name = 'role', value = <<"none">>}]}]}, + [?XMLATTR('affiliation', <<"member">>), + ?XMLATTR('role', <<"none">>)]}]}, #xmlel{ns = ?NS_MUC_USER, name = 'status', children = [#xmlcdata{cdata = list_to_binary(Msg1 ++ " (" ++ FromIdent ++ ")")}]}] }), @@ -927,11 +927,11 @@ process_quit(StateData, From, String) -> lists:concat([Chan, "%", StateData#state.server]), StateData#state.host, FromUser), StateData#state.user, - #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [#xmlattr{name = 'type', value = <<"unavailable">>}], children = + #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [?XMLATTR('type', <<"unavailable">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = <<"member">>}, - #xmlattr{name = 'role', value = <<"none">>}]}]}, + [?XMLATTR('affiliation', <<"member">>), + ?XMLATTR('role', <<"none">>)]}]}, #xmlel{ns = ?NS_MUC_USER, name = 'status', children = [#xmlcdata{cdata = list_to_binary(Msg1 ++ " (" ++ FromIdent ++ ")")}]} ]}), @@ -953,8 +953,8 @@ process_join(StateData, Channel, From, _String) -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = <<"member">>}, - #xmlattr{name = 'role', value = <<"participant">>}]}]}, + [?XMLATTR('affiliation', <<"member">>), + ?XMLATTR('role', <<"participant">>)]}]}, #xmlel{ns = ?NS_MUC_USER, name = 'status', children = [#xmlcdata{cdata = list_to_binary(FromIdent)}]}]}), @@ -979,8 +979,8 @@ process_mode_o(StateData, Chan, _From, Nick, Affiliation, Role) -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = list_to_binary(Affiliation)}, - #xmlattr{name = 'role', value = list_to_binary(Role)}]}]}]}). + [?XMLATTR('affiliation', Affiliation), + ?XMLATTR('role', Role)]}]}]}). process_kick(StateData, Chan, From, Nick, String) -> Msg = lists:last(string:tokens(String, ":")), @@ -994,12 +994,12 @@ process_kick(StateData, Chan, From, Nick, String) -> exmpp_jid:make_jid(lists:concat([Chan, "%", StateData#state.server]), StateData#state.host, Nick), StateData#state.user, - #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [#xmlattr{name = 'type', value = <<"unavailable">>}], children = + #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [?XMLATTR('type', <<"unavailable">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = <<"none">>}, - #xmlattr{name = 'role', value = <<"none">>}]}, - #xmlel{ns = ?NS_MUC_USER, name = 'status', attrs = [#xmlattr{name = 'code', value = <<"307">>}]} + [?XMLATTR('affiliation', <<"none">>), + ?XMLATTR('role', <<"none">>)]}, + #xmlel{ns = ?NS_MUC_USER, name = 'status', attrs = [?XMLATTR('code', <<"307">>)]} ]}]}). process_nick(StateData, From, NewNick) -> @@ -1015,13 +1015,13 @@ process_nick(StateData, From, NewNick) -> lists:concat([Chan, "%", StateData#state.server]), StateData#state.host, FromUser), StateData#state.user, - #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [#xmlattr{name = 'type', value = <<"unavailable">>}], children = + #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [?XMLATTR('type', <<"unavailable">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = <<"member">>}, - #xmlattr{name = 'role', value = <<"participant">>}, - #xmlattr{name = 'nick', value = list_to_binary(Nick)}]}, - #xmlel{ns = ?NS_MUC_USER, name = 'status', attrs = [#xmlattr{name = 'code', value = <<"303">>}]} + [?XMLATTR('affiliation', <<"member">>), + ?XMLATTR('role', <<"participant">>), + ?XMLATTR('nick', Nick)]}, + #xmlel{ns = ?NS_MUC_USER, name = 'status', attrs = [?XMLATTR('code', <<"303">>)]} ]}]}), ejabberd_router:route( exmpp_jid:make_jid( @@ -1031,8 +1031,8 @@ process_nick(StateData, From, NewNick) -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = - [#xmlattr{name = 'affiliation', value = <<"member">>}, - #xmlattr{name = 'role', value = <<"participant">>}]} + [?XMLATTR('affiliation', <<"member">>), + ?XMLATTR('role', <<"participant">>)]} ]}]}), ?SETS:add_element(Nick, remove_element(FromUser, Ps)); @@ -1051,8 +1051,8 @@ process_error(StateData, String) -> lists:concat([Chan, "%", StateData#state.server]), StateData#state.host, StateData#state.nick), StateData#state.user, - #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [#xmlattr{name = 'type', value = <<"error">>}], children = - [#xmlel{ns = ?NS_JABBER_CLIENT, name = 'error', attrs = [#xmlattr{name = 'code', value = <<"502">>}], children = + #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', attrs = [?XMLATTR('type', <<"error">>)], children = + [#xmlel{ns = ?NS_JABBER_CLIENT, name = 'error', attrs = [?XMLATTR('code', <<"502">>)], children = [#xmlcdata{cdata = list_to_binary(String)}]}]}) end, dict:fetch_keys(StateData#state.channels)). @@ -1098,9 +1098,9 @@ process_iq_admin(StateData, Channel, set, SubEl) -> false -> {error, 'bad-request'}; ItemEl -> - Nick = exmpp_xml:get_attribute(ItemEl, 'nick', ""), - Affiliation = exmpp_xml:get_attribute(ItemEl, 'affiliation', ""), - Role = exmpp_xml:get_attribute(ItemEl, 'role', ""), + Nick = exmpp_xml:get_attribute_as_list(ItemEl, 'nick', ""), + Affiliation = exmpp_xml:get_attribute_as_list(ItemEl, 'affiliation', ""), + Role = exmpp_xml:get_attribute_as_list(ItemEl, 'role', ""), Reason = exmpp_xml:get_path(ItemEl, [{element, 'reason'}, cdata_as_list]), process_admin(StateData, Channel, Nick, Affiliation, Role, Reason) end; diff --git a/src/mod_last.erl b/src/mod_last.erl index e8d14cb6f..321ef8327 100644 --- a/src/mod_last.erl +++ b/src/mod_last.erl @@ -78,7 +78,7 @@ stop(Host) -> process_local_iq(_From, _To, #iq{type = get} = IQ_Rec) -> Sec = get_node_uptime(), Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', attrs = - [#xmlattr{name = 'seconds', value = list_to_binary(integer_to_list(Sec))}]}, + [?XMLATTR('seconds', Sec)]}, exmpp_iq:result(IQ_Rec, Response); process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) -> exmpp_iq:error(IQ_Rec, 'not-allowed'). @@ -142,7 +142,7 @@ get_last(IQ_Rec, LUser, LServer) -> TimeStamp2 = now_to_seconds(now()), Sec = TimeStamp2 - TimeStamp, Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', - attrs = [#xmlattr{name = 'seconds', value = list_to_binary(integer_to_list(Sec))}], + attrs = [?XMLATTR('seconds', Sec)], children = [#xmlcdata{cdata = Status}]}, exmpp_iq:result(IQ_Rec, Response) end. diff --git a/src/mod_last_odbc.erl b/src/mod_last_odbc.erl index 97b72a682..961a20329 100644 --- a/src/mod_last_odbc.erl +++ b/src/mod_last_odbc.erl @@ -71,7 +71,7 @@ stop(Host) -> process_local_iq(_From, _To, #iq{type = get} = IQ_Rec) -> Sec = get_node_uptime(), Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', attrs = - [#xmlattr{name = 'seconds', value = list_to_binary(integer_to_list(Sec))}]}, + [?XMLATTR('seconds', Sec)]}, exmpp_iq:result(IQ_Rec, Response); process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) -> exmpp_iq:error(IQ_Rec, 'not-allowed'). @@ -137,7 +137,7 @@ get_last(IQ_Rec, LUser, LServer) -> TimeStamp2 = now_to_seconds(now()), Sec = TimeStamp2 - TimeStamp, Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', - attrs = [#xmlattr{name = 'seconds', value = list_to_binary(integer_to_list(Sec))}], + attrs = [?XMLATTR('seconds', Sec)], children = [#xmlcdata{cdata = list_to_binary(Status)}]}, exmpp_iq:result(IQ_Rec, Response); _ -> diff --git a/src/mod_muc/mod_muc.erl b/src/mod_muc/mod_muc.erl index 5970bbce1..62c292d52 100644 --- a/src/mod_muc/mod_muc.erl +++ b/src/mod_muc/mod_muc.erl @@ -265,7 +265,7 @@ handle_info(_Info, State) -> %% The return value is ignored. %%-------------------------------------------------------------------- terminate(_Reason, State) -> - ejabberd_router:unregister_route(State#state.host), + ejabberd_router:unregister_route(binary_to_list(State#state.host)), ok. %%-------------------------------------------------------------------- @@ -378,7 +378,7 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper, ok end; 'message' -> - case exmpp_xml:get_attribute(Packet,type, "chat") of + case exmpp_xml:get_attribute_as_list(Packet,type, "chat") of "error" -> ok; _ -> @@ -496,30 +496,30 @@ register_room(Host, Room, Pid) when is_binary(Host), is_binary(Room) -> iq_disco_info(Lang) -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', - attrs = [#xmlattr{name = 'category', - value = "conference"}, - #xmlattr{name = 'type', - value = "text"}, - #xmlattr{name = 'name', - value = translate:translate(Lang, "Chatrooms")}]}, + attrs = [?XMLATTR('category', + <<"conference">>), + ?XMLATTR('type', + <<"text">>), + ?XMLATTR('name', + translate:translate(Lang, "Chatrooms"))]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', - value = ?NS_DISCO_INFO_s}]}, + [?XMLATTR('var', + ?NS_DISCO_INFO_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', - value = ?NS_DISCO_ITEMS_s}]}, + [?XMLATTR('var', + ?NS_DISCO_ITEMS_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', - value = ?NS_MUC_s}]}, + [?XMLATTR('var', + ?NS_MUC_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', - value = ?NS_INBAND_REGISTER_s}]}, + [?XMLATTR('var', + ?NS_INBAND_REGISTER_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', - value = ?NS_RSM_s}]}, + [?XMLATTR('var', + ?NS_RSM_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = - [#xmlattr{name = 'var', - value = ?NS_VCARD_s}]}]. + [?XMLATTR('var', + ?NS_VCARD_s)]}]. iq_disco_items(Host, From, Lang, none) when is_binary(Host) -> @@ -530,11 +530,11 @@ iq_disco_items(Host, From, Lang, none) when is_binary(Host) -> flush(), {true, #xmlel{name = 'item', - attrs = [#xmlattr{name = 'jid', - value = exmpp_jid:jid_to_binary(Name, - Host)}, - #xmlattr{name = 'name', - value = Desc}]}}; + attrs = [?XMLATTR('jid', + exmpp_jid:jid_to_binary(Name, + Host)), + ?XMLATTR('name', + Desc)]}}; _ -> false end @@ -615,10 +615,10 @@ flush() -> -define(XFIELD(Type, Label, Var, Val), #xmlel{name = "field", - attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', - value = translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], + attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', + translate:translate(Lang, Label)), + ?XMLATTR('var', Var)], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = Val}]}]}). diff --git a/src/mod_muc/mod_muc_log.erl b/src/mod_muc/mod_muc_log.erl index 080fb4874..ae8c89645 100644 --- a/src/mod_muc/mod_muc_log.erl +++ b/src/mod_muc/mod_muc_log.erl @@ -271,7 +271,7 @@ build_filename_string(TimeStamp, OutDir, RoomJID, DirType, DirName, FileFormat) {Fd, Fn, Fnrel}. get_room_name(RoomJID) -> - JID = exmpp_jid:list_to_jid(RoomJID), + JID = exmpp_jid:parse_jid(RoomJID), exmpp_jid:node_as_list(JID). %% calculate day before diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index e05fc53ce..95400ed78 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -554,7 +554,7 @@ normal_state(_Event, StateData) -> %%---------------------------------------------------------------------- handle_event({service_message, Msg}, _StateName, StateData) -> MessagePkt = #xmlel{name = 'message', - attrs = [#xmlattr{name = 'type', value = "groupchat"}], + attrs = [?XMLATTR('type', <<"groupchat">>)], children = [#xmlel{name = 'body', children = [#xmlcdata{cdata = Msg}]}]}, lists:foreach( @@ -1523,7 +1523,7 @@ add_new_user(From, Nick, Packet, StateData) -> if not (NewState#state.config)#config.anonymous -> WPacket = #xmlel{name = 'message', - attrs = [#xmlattr{name = 'type', value = "groupchat"}], + attrs = [?XMLATTR('type', <<"groupchat">>)], children = [ #xmlel{name = 'body', children = [#xmlcdata{cdata = @@ -1766,12 +1766,12 @@ send_new_presence(NJID, Reason, StateData) -> case (Info#user.role == moderator) orelse ((StateData#state.config)#config.anonymous == false) of true -> - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(RealJID)}, - #xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = SRole}]; + [?XMLATTR('jid', exmpp_jid:jid_to_binary(RealJID)), + ?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', SRole)]; _ -> - [#xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = SRole}] + [?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', SRole)] end, ItemEls = case Reason of <<>> -> @@ -1783,7 +1783,7 @@ send_new_presence(NJID, Reason, StateData) -> Status = case StateData#state.just_created of true -> [#xmlel{name = 'status', - attrs = [#xmlattr{name = 'code', value = "201"}]}]; + attrs = [?XMLATTR('code', <<"201">>)]}]; false -> [] end, @@ -1822,14 +1822,14 @@ send_existing_presences(ToJID, StateData) -> ((StateData#state.config)#config.anonymous == false) of true -> - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(FromJID)}, - #xmlattr{name = 'affiliation', - value = affiliation_to_binary(FromAffiliation)}, - #xmlattr{name = 'role', value = role_to_binary(FromRole)}]; + [?XMLATTR('jid', exmpp_jid:jid_to_binary(FromJID)), + ?XMLATTR('affiliation', + affiliation_to_binary(FromAffiliation)), + ?XMLATTR('role', role_to_binary(FromRole))]; _ -> - [#xmlattr{name = 'affiliation', - value = affiliation_to_binary(FromAffiliation)}, - #xmlattr{name = 'role', value = role_to_binary(FromRole)}] + [?XMLATTR('affiliation', + affiliation_to_binary(FromAffiliation)), + ?XMLATTR('role', role_to_binary(FromRole))] end, Packet = exmpp_xml:append_child(Presence, #xmlel{ns = ?NS_MUC_USER, name = 'x', @@ -1879,37 +1879,37 @@ send_nick_changing(JID, OldNick, StateData) -> case (Info#user.role == moderator) orelse ((StateData#state.config)#config.anonymous == false) of true -> - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(RealJID)}, - #xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = SRole}, - #xmlattr{name = 'nick', value = Nick}]; + [?XMLATTR('jid', exmpp_jid:jid_to_binary(RealJID)), + ?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', SRole), + ?XMLATTR('nick', Nick)]; _ -> - [#xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = SRole}, - #xmlattr{name = 'nick', value = Nick}] + [?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', SRole), + ?XMLATTR('nick', Nick)] end, ItemAttrs2 = case (Info#user.role == moderator) orelse ((StateData#state.config)#config.anonymous == false) of true -> - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(RealJID)}, - #xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = SRole}]; + [?XMLATTR('jid', exmpp_jid:jid_to_binary(RealJID)), + ?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', SRole)]; _ -> - [#xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = SRole}] + [?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', SRole)] end, Packet1 = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', - attrs = [#xmlattr{name = 'type', value = <<"unavailable">>}], + attrs = [?XMLATTR('type', <<"unavailable">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [ #xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = ItemAttrs1}, #xmlel{ns = ?NS_MUC_USER, name = 'status', - attrs = [#xmlattr{name = 'code', - value = "303"}]}]}]}, + attrs = [?XMLATTR('code', + <<"303">>)]}]}]}, Packet2 = exmpp_xml:append_child( Presence, @@ -2081,20 +2081,20 @@ items_with_affiliation(SAffiliation, StateData) -> fun({JID, {Affiliation, Reason}}) -> {N, D, R} = JID, #xmlel{name = 'item', - attrs = [#xmlattr{name = 'affiliation', - value = affiliation_to_binary(Affiliation)}, - #xmlattr{name = 'jid', - value = exmpp_jid:jid_to_binary(N, D, R)}], + attrs = [?XMLATTR('affiliation', + affiliation_to_binary(Affiliation)), + ?XMLATTR('jid', + exmpp_jid:jid_to_binary(N, D, R))], children = [ #xmlel{name = 'reason', children = [#xmlcdata{cdata = Reason}]}]}; ({JID, Affiliation}) -> {N, D, R} = JID, #xmlel{name = 'item', - attrs = [#xmlattr{name = 'affiliation', - value = affiliation_to_binary(Affiliation)}, - #xmlattr{name = 'jid', - value = exmpp_jid:jid_to_binary(N, D, R)}]} + attrs = [?XMLATTR('affiliation', + affiliation_to_binary(Affiliation)), + ?XMLATTR('jid', + exmpp_jid:jid_to_binary(N, D, R))]} end, search_affiliation(SAffiliation, StateData)). user_to_item(#user{role = Role, @@ -2104,10 +2104,10 @@ user_to_item(#user{role = Role, Affiliation = get_affiliation(JID, StateData), #xmlel{name = 'item', attrs = [ - #xmlattr{name = 'role', value = role_to_binary(Role)}, - #xmlattr{name = 'affiliation', value = affiliation_to_binary(Affiliation)}, - #xmlattr{name = 'nick', value = Nick}, - #xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(JID)}] + ?XMLATTR('role', role_to_binary(Role)), + ?XMLATTR('affiliation', affiliation_to_binary(Affiliation)), + ?XMLATTR('nick', Nick), + ?XMLATTR('jid', exmpp_jid:jid_to_binary(JID))] }. search_role(Role, StateData) -> @@ -2227,7 +2227,7 @@ find_changed_items(UJID, UAffiliation, URole, Lang, StateData, Res) -> TJID = case exmpp_xml:get_attribute_as_binary(Item, 'jid',false) of S when S =/= false -> - try exmpp_jid:binary_to_jid(S) of + try exmpp_jid:parse_jid(S) of J -> {value, J} catch @@ -2239,7 +2239,7 @@ find_changed_items(UJID, UAffiliation, URole, {error, ?ERR(Item, 'not-acceptable', Lang, ErrText)} end; _ -> - case exmpp_xml:get_attribute(Item, 'nick', false) of + case exmpp_xml:get_attribute_as_list(Item, 'nick', false) of N when N =/= false -> case find_jid_by_nick(N, StateData) of false -> @@ -2569,8 +2569,8 @@ send_kickban_presence1(UJID, Reason, Code, StateData) -> SAffiliation = affiliation_to_binary(Affiliation), lists:foreach( fun({_LJID, Info}) -> - ItemAttrs = [#xmlattr{name = 'affiliation', value = SAffiliation}, - #xmlattr{name = 'role', value = "none"}], + ItemAttrs = [?XMLATTR('affiliation', SAffiliation), + ?XMLATTR('role', <<"none">>)], ItemEls = case Reason of <<>> -> []; @@ -2581,15 +2581,15 @@ send_kickban_presence1(UJID, Reason, Code, StateData) -> Packet = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', - attrs = [#xmlattr{name = 'type', value = "unavailable"}], + attrs = [?XMLATTR('type', <<"unavailable">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = [ #xmlel{ns = ?NS_MUC_USER, name = 'item', attrs = ItemAttrs, children = ItemEls}, #xmlel{ns = ?NS_MUC_USER, name = 'status', - attrs = [#xmlattr{name='code', - value = Code}]}]}]}, + attrs = [?XMLATTR('code', + Code)]}]}]}, ejabberd_router:route( jid_replace_resource(StateData#state.jid, Nick), Info#user.jid, @@ -2688,9 +2688,9 @@ check_allowed_persistent_change(XEl, StateData, From) -> -define(XFIELD(Type, Label, Var, Val), #xmlel{name = 'field', - attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], + attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', translate:translate(Lang, Label)), + ?XMLATTR('var', Var)], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = Val} ]}]}). @@ -2729,8 +2729,8 @@ get_config(Lang, StateData, From) -> [#xmlel{name = 'title', children = [ #xmlcdata{cdata = translate:translate(Lang, "Configuration for ") ++ exmpp_jid:jid_to_list(StateData#state.jid)}]}, - #xmlel{name = 'field', attrs = [#xmlattr{name = 'type', value = "hidden"}, - #xmlattr{name = 'var', value = "FORM_TYPE"}], + #xmlel{name = 'field', attrs = [?XMLATTR('type', <<"hidden">>), + ?XMLATTR('var', <<"FORM_TYPE">>)], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = <<"http://jabber.org/protocol/muc#roomconfig">> }]}]}, @@ -2765,46 +2765,45 @@ get_config(Lang, StateData, From) -> false -> "" end), #xmlel{name = 'field', attrs = [ - #xmlattr{name = 'type', value = "list-single"}, - #xmlattr{name = 'label', value = translate:translate(Lang, - "Maximum Number of Occupants")}, - #xmlattr{name = 'var', value = "muc#roomconfig_maxusers"}], + ?XMLATTR('type', <<"list-single">>), + ?XMLATTR('label', translate:translate(Lang, + "Maximum Number of Occupants")), + ?XMLATTR('var', <<"muc#roomconfig_maxusers">>)], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = MaxUsersRoomString}]}] ++ if is_integer(ServiceMaxUsers) -> []; true -> - [#xmlel{name = 'option', attrs = [#xmlattr{name = 'label', - value = translate:translate(Lang, "No limit")}], + [#xmlel{name = 'option', attrs = [?XMLATTR('label', + translate:translate(Lang, "No limit"))], children = [#xmlel{name = 'value', children = [#xmlcdata{ cdata = <<"none">>}]}]}] end ++ - [#xmlel{name = 'option', attrs = [#xmlattr{name = 'label', - value = erlang:integer_to_list(N)}], + [#xmlel{name = 'option', attrs = [?XMLATTR('label', N)], children = [#xmlel{name = 'value', children = [ #xmlcdata{cdata = erlang:integer_to_list(N)}]}]} || N <- lists:usort([ServiceMaxUsers, DefaultRoomMaxUsers, MaxUsersRoomInteger | ?MAX_USERS_DEFAULT_LIST]), N =< ServiceMaxUsers]}, #xmlel{name = 'field', attrs = [ - #xmlattr{name = 'type', value = "list-single"}, - #xmlattr{name = 'label', - value = translate:translate(Lang, "Present real Jabber IDs to")}, - #xmlattr{name = 'var', value = "muc#roomconfig_whois"}], + ?XMLATTR('type', <<"list-single">>), + ?XMLATTR('label', + translate:translate(Lang, "Present real Jabber IDs to")), + ?XMLATTR('var', <<"muc#roomconfig_whois">>)], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = if Config#config.anonymous -> <<"moderators">>; true -> <<"anyone">> end}]}, #xmlel{name = 'option', attrs = [ - #xmlattr{name = 'label', value = - translate:translate(Lang, "moderators only")}], + ?XMLATTR('label', + translate:translate(Lang, "moderators only"))], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = <<"moderators">>}]}]}, #xmlel{name = 'option', attrs = [ - #xmlattr{name = 'label', value = - translate:translate(Lang, "anyone")}], + ?XMLATTR('label', + translate:translate(Lang, "anyone"))], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = <<"anyone">>}]}]}]}, @@ -2851,7 +2850,7 @@ get_config(Lang, StateData, From) -> #xmlcdata{cdata = translate:translate(Lang, "You need an x:data capable client to configure room")}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', - attrs = [#xmlattr{name = 'type', value = "form"}], + attrs = [?XMLATTR('type', <<"form">>)], children = Res}], StateData}. @@ -3072,12 +3071,12 @@ destroy_room(DEl, StateData) -> lists:foreach( fun({_LJID, Info}) -> Nick = Info#user.nick, - ItemAttrs = [#xmlattr{name = 'affiliation', value = "none"}, - #xmlattr{name = 'role', value = "none"}], + ItemAttrs = [?XMLATTR('affiliation', <<"none">>), + ?XMLATTR('role', <<"none">>)], Packet = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence', - attrs = [#xmlattr{name = 'type', - value = "unavailable"}], + attrs = [?XMLATTR('type', + <<"unavailable">>)], children = [ #xmlel{ns = ?NS_MUC_USER, name = 'x', children = [#xmlel{name = 'item', attrs = ItemAttrs}, @@ -3102,7 +3101,7 @@ destroy_room(DEl, StateData) -> % Disco -define(FEATURE(Var), #xmlel{name = 'feature', - attrs = [#xmlattr{name = 'var', value = Var}]}). + attrs = [?XMLATTR('var', Var)]}). -define(CONFIG_OPT_TO_FEATURE(Opt, Fiftrue, Fiffalse), case Opt of @@ -3118,13 +3117,13 @@ process_iq_disco_info(_From, set, _Lang, _StateData) -> process_iq_disco_info(_From, get, Lang, StateData) -> Config = StateData#state.config, {result, [ #xmlel{name = 'identity', - attrs = [#xmlattr{name = 'category', - value = "conference"}, - #xmlattr{name = 'type', value = "text"}, - #xmlattr{name = 'name', - value = get_title(StateData)}]}, + attrs = [?XMLATTR('category', + <<"conference">>), + ?XMLATTR('type', <<"text">>), + ?XMLATTR('name', + get_title(StateData))]}, #xmlel{name = 'feature', - attrs = [#xmlattr{name = 'var', value = ?NS_MUC_s}]}, + attrs = [?XMLATTR('var', ?NS_MUC_s)]}, ?CONFIG_OPT_TO_FEATURE(Config#config.public, "muc_public", "muc_hidden"), @@ -3141,15 +3140,15 @@ process_iq_disco_info(_From, get, Lang, StateData) -> ] ++ iq_disco_info_extras(Lang, StateData), StateData}. -define(RFIELDT(Type, Var, Val), - #xmlel{name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'var', value = Var}], + #xmlel{name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('var', Var)], children = [#xmlel{name = 'value', children = [#xmlcdata{cdata = Val}]}]}). -define(RFIELD(Label, Var, Val), - #xmlel{name = 'field', attrs = [#xmlattr{name = 'label', value = - translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], + #xmlel{name = 'field', attrs = [?XMLATTR('label', + translate:translate(Lang, Label)), + ?XMLATTR('var', Var)], children = [#xmlel{name = 'value', children = [ #xmlcdata{cdata = Val}]}]}). @@ -3157,7 +3156,7 @@ iq_disco_info_extras(Lang, StateData) -> Len = length(?DICT:to_list(StateData#state.users)), RoomDescription = (StateData#state.config)#config.description, [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', - attrs = [#xmlattr{name = 'type', value = "result"}], + attrs = [?XMLATTR('type', <<"result">>)], children = [?RFIELDT("hidden", "FORM_TYPE", "http://jabber.org/protocol/muc#roominfo"), @@ -3182,13 +3181,13 @@ process_iq_disco_items(From, get, _Lang, StateData) -> lists:map( fun({_LJID, Info}) -> Nick = Info#user.nick, - #xmlel{name = 'item', attrs = [#xmlattr{name = 'jid', - value = exmpp_jid:jid_to_binary( + #xmlel{name = 'item', attrs = [?XMLATTR('jid', + exmpp_jid:jid_to_binary( StateData#state.room, StateData#state.host, - Nick)}, - #xmlattr{name = 'name', - value = Nick}]} + Nick)), + ?XMLATTR('name', + Nick)]} end, ?DICT:to_list(StateData#state.users)), {result, UList, StateData}; @@ -3227,7 +3226,7 @@ check_invitation(From, Els, Lang, StateData) -> _ -> throw({error, 'bad-request'}) end, - JID = try exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(InviteEl, + JID = try exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(InviteEl, 'to', false)) of JID1 -> JID1 @@ -3253,8 +3252,8 @@ check_invitation(From, Els, Lang, StateData) -> IEl = [#xmlel{ns = ?NS_MUC_USER, name = 'invite', - attrs = [#xmlattr{name = 'from', - value = exmpp_jid:jid_to_binary(From)}], + attrs = [?XMLATTR('from', + exmpp_jid:jid_to_binary(From))], children = [#xmlel{ns =?NS_MUC_USER, name = 'reason', children = [#xmlcdata{cdata = Reason} ]}] ++ ContinueEl}], @@ -3295,15 +3294,15 @@ check_invitation(From, Els, Lang, StateData) -> %%TODO: always NS_JABBER_CLIENT? Msg = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', - attrs = [#xmlattr{name = 'type', value = "normal"}], + attrs = [?XMLATTR('type', <<"normal">>)], children = [#xmlel{ns = ?NS_MUC_USER, name = 'x', children = IEl ++ PasswdEl}, #xmlel{ns = 'jabber:x:conference', name = 'x', - attrs = [#xmlattr{name = 'jid', - value = exmpp_jid:jid_to_binary( + attrs = [?XMLATTR('jid', + exmpp_jid:jid_to_binary( StateData#state.room, StateData#state.host) - }], + )], children = [#xmlcdata{cdata = Reason}]}, Body]}, ejabberd_router:route(StateData#state.jid, JID, Msg), @@ -3330,7 +3329,7 @@ check_decline_invitation(Packet) -> #xmlel{ns = ?NS_MUC_USER} = XEl = exmpp_xml:get_element(Packet, 'x'), DEl = exmpp_xml:get_element(XEl, 'decline'), ToString = exmpp_xml:get_attribute_as_binary(DEl, 'to', false), - ToJID = exmpp_jid:binary_to_jid(ToString), + ToJID = exmpp_jid:parse_jid(ToString), {true, {Packet, XEl, DEl, ToJID}}. %% Send the decline to the inviter user. diff --git a/src/mod_offline.erl b/src/mod_offline.erl index ecd5185b1..80342c8e7 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -220,7 +220,7 @@ find_x_event([_ | Els]) -> find_x_expire(_, []) -> never; find_x_expire(TimeStamp, [#xmlel{ns = ?NS_MESSAGE_EXPIRE} = El | _Els]) -> - Val = exmpp_xml:get_attribute(El, 'seconds', ""), + Val = exmpp_xml:get_attribute_as_list(El, 'seconds', ""), case catch list_to_integer(Val) of {'EXIT', _} -> never; diff --git a/src/mod_offline_odbc.erl b/src/mod_offline_odbc.erl index 15d7f2545..77d4d806f 100644 --- a/src/mod_offline_odbc.erl +++ b/src/mod_offline_odbc.erl @@ -198,7 +198,7 @@ check_event(From, To, Packet) -> undefined -> true; _ -> - ID = case exmpp_xml:get_attribute(Packet, 'id', "") of + ID = case exmpp_xml:get_attribute_as_list(Packet, 'id', "") of "" -> #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id'}; S -> @@ -226,7 +226,7 @@ find_x_event([_ | Els]) -> find_x_expire(_, []) -> never; find_x_expire(TimeStamp, [#xmlel{ns = ?NS_MESSAGE_EXPIRE} = El | _Els]) -> - Val = exmpp_xml:get_attribute(El, 'seconds', ""), + Val = exmpp_xml:get_attribute_as_list(El, 'seconds', ""), case catch list_to_integer(Val) of {'EXIT', _} -> never; @@ -257,9 +257,9 @@ pop_offline_messages(Ls, User, Server) [El] = exmpp_xml:parse_document(XML, [names_as_atom, {check_elems, xmpp}, {check_nss,xmpp}, {check_attrs,xmpp}]), - To = exmpp_jid:binary_to_jid( + To = exmpp_jid:parse_jid( exmpp_stanza:get_recipient(El)), - From = exmpp_jid:binary_to_jid( + From = exmpp_jid:parse_jid( exmpp_stanza:get_sender(El)), [{route, From, To, El}] catch diff --git a/src/mod_privacy.erl b/src/mod_privacy.erl index ddfc5b608..5bc30db0c 100644 --- a/src/mod_privacy.erl +++ b/src/mod_privacy.erl @@ -95,7 +95,7 @@ process_iq_get(_, From, _To, #iq{payload = SubEl}, [#xmlel{name = Name} = Child] -> case Name of list -> - ListName = exmpp_xml:get_attribute(Child, name, false), + ListName = exmpp_xml:get_attribute_as_list(Child, name, false), process_list_get(LUser, LServer, ListName); _ -> {error, 'bad-request'} @@ -161,14 +161,14 @@ process_list_get(LUser, LServer, Name) -> item_to_xml(Item) -> - Attrs1 = [#xmlattr{name = 'action', value = action_to_binary(Item#listitem.action)}, - #xmlattr{name = 'order', value = order_to_binary(Item#listitem.order)}], + Attrs1 = [?XMLATTR('action', action_to_binary(Item#listitem.action)), + ?XMLATTR('order', order_to_binary(Item#listitem.order))], Attrs2 = case Item#listitem.type of none -> Attrs1; Type -> - [#xmlattr{name = 'type', value = type_to_binary(Item#listitem.type)}, - #xmlattr{name = 'value', value = value_to_binary(Type, Item#listitem.value)} | + [?XMLATTR('type', type_to_binary(Item#listitem.type)), + ?XMLATTR('value', value_to_binary(Type, Item#listitem.value)) | Attrs1] end, SubEls = case Item#listitem.match_all of @@ -250,7 +250,7 @@ process_iq_set(_, From, _To, #iq{payload = SubEl}) -> LServer = exmpp_jid:ldomain_as_list(From), case exmpp_xml:get_child_elements(SubEl) of [#xmlel{name = Name} = Child] -> - ListName = exmpp_xml:get_attribute(Child, 'name', false), + ListName = exmpp_xml:get_attribute_as_list(Child, 'name', false), case Name of list -> process_list_set(LUser, LServer, ListName, @@ -362,8 +362,8 @@ process_list_set(LUser, LServer, Name, Els) -> Error; {atomic, {result, _} = Res} -> ejabberd_router:route( - exmpp_jid:make_bare_jid(LUser, LServer), - exmpp_jid:make_bare_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), #xmlel{name = 'broadcast', children=[{privacy_list, #userlist{name = Name, list = []}, @@ -393,8 +393,8 @@ process_list_set(LUser, LServer, Name, Els) -> Error; {atomic, {result, _} = Res} -> ejabberd_router:route( - exmpp_jid:make_bare_jid(LUser, LServer), - exmpp_jid:make_bare_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), #xmlel{name = 'broadcast', children=[{privacy_list, #userlist{name = Name, list = List}, @@ -420,10 +420,10 @@ parse_items([], Res) -> %% record_info(fields, listitem))), lists:keysort(5, Res); parse_items([El = #xmlel{name = item} | Els], Res) -> - Type = exmpp_xml:get_attribute(El, type, false), - Value = exmpp_xml:get_attribute(El, value, false), - SAction =exmpp_xml:get_attribute(El, action, false), - SOrder = exmpp_xml:get_attribute(El, order, false), + Type = exmpp_xml:get_attribute_as_list(El, type, false), + Value = exmpp_xml:get_attribute_as_list(El, value, false), + SAction =exmpp_xml:get_attribute_as_list(El, action, false), + SOrder = exmpp_xml:get_attribute_as_list(El, order, false), Action = case catch list_to_action(SAction) of {'EXIT', _} -> false; Val -> Val @@ -447,7 +447,7 @@ parse_items([El = #xmlel{name = item} | Els], Res) -> case T of "jid" -> try - JID = exmpp_jid:list_to_jid(V), + JID = exmpp_jid:parse_jid(V), I1#listitem{ type = jid, value = jlib:short_prepd_jid(JID)} diff --git a/src/mod_privacy_odbc.erl b/src/mod_privacy_odbc.erl index 7cf9aba96..5aded06af 100644 --- a/src/mod_privacy_odbc.erl +++ b/src/mod_privacy_odbc.erl @@ -91,7 +91,7 @@ process_iq_get(_, From, _To, #iq{payload = SubEl}, [#xmlel{name = Name} = Child] -> case Name of list -> - ListName = exmpp_xml:get_attribute(Child, name, false), + ListName = exmpp_xml:get_attribute_as_list(Child, name, false), process_list_get(LUser, LServer, ListName); _ -> {error, 'bad-request'} @@ -167,14 +167,14 @@ process_list_get(LUser, LServer, Name) -> item_to_xml(Item) -> - Attrs1 = [#xmlattr{name = 'action', value = action_to_binary(Item#listitem.action)}, - #xmlattr{name = 'order', value = order_to_binary(Item#listitem.order)}], + Attrs1 = [?XMLATTR('action', action_to_binary(Item#listitem.action)), + ?XMLATTR('order', order_to_binary(Item#listitem.order))], Attrs2 = case Item#listitem.type of none -> Attrs1; Type -> - [#xmlattr{name = 'type', value = type_to_binary(Item#listitem.type)}, - #xmlattr{name = 'value', value = value_to_binary(Type, Item#listitem.value)} | + [?XMLATTR('type', type_to_binary(Item#listitem.type)), + ?XMLATTR('value', value_to_binary(Type, Item#listitem.value)) | Attrs1] end, SubEls = case Item#listitem.match_all of @@ -256,7 +256,7 @@ process_iq_set(_, From, _To, #iq{payload = SubEl}) -> LServer = exmpp_jid:ldomain_as_list(From), case exmpp_xml:get_child_elements(SubEl) of [#xmlel{name = Name} = Child] -> - ListName = exmpp_xml:get_attribute(Child, 'name', false), + ListName = exmpp_xml:get_attribute_as_list(Child, 'name', false), case Name of list -> process_list_set(LUser, LServer, ListName, @@ -362,8 +362,8 @@ process_list_set(LUser, LServer, Name, Els) -> Error; {atomic, {result, _} = Res} -> ejabberd_router:route( - exmpp_jid:make_bare_jid(LUser, LServer), - exmpp_jid:make_bare_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), #xmlel{name = 'broadcast', children=[{privacy_list, #userlist{name = Name, list = []}, @@ -394,8 +394,8 @@ process_list_set(LUser, LServer, Name, Els) -> Error; {atomic, {result, _} = Res} -> ejabberd_router:route( - exmpp_jid:make_bare_jid(LUser, LServer), - exmpp_jid:make_bare_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), + exmpp_jid:make_jid(LUser, LServer), #xmlel{name = 'broadcast', children=[{privacy_list, #userlist{name = Name, list = List}, @@ -421,10 +421,10 @@ parse_items([], Res) -> %% record_info(fields, listitem))), lists:keysort(5, Res); parse_items([El = #xmlel{name = item} | Els], Res) -> - Type = exmpp_xml:get_attribute(El, type, false), - Value = exmpp_xml:get_attribute(El, value, false), - SAction =exmpp_xml:get_attribute(El, action, false), - SOrder = exmpp_xml:get_attribute(El, order, false), + Type = exmpp_xml:get_attribute_as_list(El, type, false), + Value = exmpp_xml:get_attribute_as_list(El, value, false), + SAction =exmpp_xml:get_attribute_as_list(El, action, false), + SOrder = exmpp_xml:get_attribute_as_list(El, order, false), Action = case catch list_to_action(SAction) of {'EXIT', _} -> false; Val -> Val @@ -448,7 +448,7 @@ parse_items([El = #xmlel{name = item} | Els], Res) -> case T of "jid" -> try - JID = exmpp_jid:list_to_jid(V), + JID = exmpp_jid:parse_jid(V), I1#listitem{ type = jid, value = jlib:short_prepd_jid(JID)} @@ -700,7 +700,7 @@ raw_to_item({SType, SValue, SAction, SOrder, SMatchAll, SMatchIQ, "n" -> {none, none}; "j" -> - JID = exmpp_jid:list_to_jid(SValue), + JID = exmpp_jid:parse_jid(SValue), {jid, jlib:short_prepd_jid(JID)}; "g" -> {group, SValue}; diff --git a/src/mod_proxy65/mod_proxy65_service.erl b/src/mod_proxy65/mod_proxy65_service.erl index 654873853..3f9ba61c8 100644 --- a/src/mod_proxy65/mod_proxy65_service.erl +++ b/src/mod_proxy65/mod_proxy65_service.erl @@ -159,8 +159,8 @@ process_iq(InitiatorJID, #iq{type = set, payload = SubEl, ns = ?NS_BYTESTREAMS} case acl:match_rule(ServerHost, ACL, InitiatorJID) of allow -> ActivateEl = exmpp_xml:get_path(SubEl, [{element, 'activate'}]), - SID = exmpp_xml:get_attribute(SubEl, 'sid', ""), - case catch exmpp_jid:list_to_jid(exmpp_xml:get_cdata_as_string(ActivateEl)) of + SID = exmpp_xml:get_attribute_as_list(SubEl, 'sid', ""), + case catch exmpp_jid:parse_jid(exmpp_xml:get_cdata_as_string(ActivateEl)) of TargetJID when ?IS_JID(TargetJID), SID /= "", length(SID) =< 128, TargetJID /= InitiatorJID -> Target = exmpp_jid:prepd_jid_to_list(TargetJID), @@ -197,13 +197,13 @@ process_iq(_, _, _) -> %%% Auxiliary functions. %%%------------------------- -define(FEATURE(Feat), #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', - attrs = [#xmlattr{name = 'var', value = Feat}]}). + attrs = [?XMLATTR('var', Feat)]}). iq_disco_info(Lang, Name) -> [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = "proxy"}, - #xmlattr{name = 'type', value = "bytestreams"}, - #xmlattr{name = 'name', value = translate:translate(Lang, Name)}]}, + [?XMLATTR('category', <<"proxy">>), + ?XMLATTR('type', <<"bytestreams">>), + ?XMLATTR('name', translate:translate(Lang, Name))]}, ?FEATURE(?NS_DISCO_INFO_s), ?FEATURE(?NS_VCARD_s), ?FEATURE(?NS_BYTESTREAMS_s)]. @@ -227,7 +227,7 @@ parse_options(ServerHost, Opts) -> Addr -> Addr end, StrIP = inet_parse:ntoa(IP), - StreamAddr = [#xmlattr{name = 'jid', value = MyHost}, #xmlattr{name = 'host', value = StrIP}, #xmlattr{name = 'port', value = integer_to_list(Port)}], + StreamAddr = [?XMLATTR('jid', MyHost), ?XMLATTR('host', StrIP), ?XMLATTR('port', Port)], #state{myhost = MyHost, serverhost = ServerHost, name = Name, diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index ce9f9b7ae..622fc6b6d 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -311,18 +311,18 @@ update_database(Host) -> identity(Host) -> Identity = case lists:member(?PEPNODE, plugins(Host)) of - true -> [#xmlattr{name = 'category', value = "pubsub"}, #xmlattr{name = 'type', value = "pep"}]; - false -> [#xmlattr{name = 'category', value = "pubsub"}, #xmlattr{name = 'type', value = "service"}] + true -> [?XMLATTR('category', <<"pubsub">>), ?XMLATTR('type', <<"pep">>)]; + false -> [?XMLATTR('category', <<"pubsub">>), ?XMLATTR('type', <<"service">>)] end, #xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = Identity}. disco_local_identity(Acc, _From, To, <<>>, _Lang) -> - Acc ++ [identity(To#jid.ldomain)]; + Acc ++ [identity(exmpp_jid:ldomain_as_list(To))]; disco_local_identity(Acc, _From, _To, _Node, _Lang) -> Acc. disco_local_features(Acc, _From, To, <<>>, _Lang) -> - Host = To#jid.ldomain, + Host = exmpp_jid:ldomain_as_list(To), Feats = case Acc of {result, I} -> I; _ -> [] @@ -339,7 +339,7 @@ disco_local_items(Acc, _From, _To, _Node, _Lang) -> Acc. disco_sm_identity(Acc, _From, To, <<>>, _Lang) -> - Acc ++ [identity(To#jid.ldomain)]; + Acc ++ [identity(exmpp_jid:ldomain_as_list(To))]; disco_sm_identity(Acc, From, To, Node, _Lang) -> LOwner = jlib:short_prepd_bare_jid(To), Acc ++ case node_disco_identity(LOwner, From, Node) of @@ -363,7 +363,7 @@ disco_sm_features(Acc, From, To, Node, _Lang) -> disco_sm_items(Acc, From, To, <<>>, _Lang) -> %% TODO, use iq_disco_items(Host, [], From) - Host = To#jid.ldomain, + Host = exmpp_jid:ldomain_as_list(To), LJID = jlib:short_prepd_bare_jid(To), case tree_action(Host, get_nodes, [Host, From]) of [] -> @@ -376,8 +376,8 @@ disco_sm_items(Acc, From, To, <<>>, _Lang) -> NodeItems = lists:map( fun(Node) -> #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(LJID)}, - #xmlattr{name = 'node', value = node_to_string(Node)}]} + [?XMLATTR('jid', exmpp_jid:jid_to_binary(LJID)), + ?XMLATTR('node', node_to_string(Node))]} end, Nodes), {result, NodeItems ++ Items} end; @@ -385,7 +385,7 @@ disco_sm_items(Acc, From, To, <<>>, _Lang) -> disco_sm_items(Acc, From, To, NodeB, _Lang) -> Node = binary_to_list(NodeB), %% TODO, use iq_disco_items(Host, Node, From) - Host = To#jid.ldomain, + Host = exmpp_jid:ldomain_as_list(To), LJID = jlib:short_prepd_bare_jid(To), case get_items(Host, Node, From) of [] -> @@ -401,8 +401,8 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) -> %% "node" is forbidden by XEP-0060. {result, Name} = node_action(Host, Node, get_item_name, [Host, Node, Id]), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(LJID)}, - #xmlattr{name = 'name', value = Name}]} + [?XMLATTR('jid', exmpp_jid:jid_to_binary(LJID)), + ?XMLATTR('name', Name)]} end, AllItems), {result, NodeItems ++ Items} end. @@ -522,7 +522,7 @@ handle_cast({presence, JID, Pid}, State) -> handle_cast({remove_user, LUser, LServer}, State) -> Host = State#state.host, - Owner = exmpp_jid:make_bare_jid(LUser, LServer), + Owner = exmpp_jid:make_jid(LUser, LServer), %% remove user's subscriptions lists:foreach(fun(Type) -> {result, Subscriptions} = node_action(Type, get_entity_subscriptions, [Host, Owner]), @@ -555,7 +555,7 @@ handle_info({route, From, To, Packet}, #state{server_host = ServerHost, access = Access, plugins = Plugins} = State) -> - case catch do_route(ServerHost, Access, Plugins, To#jid.ldomain, From, To, Packet) of + case catch do_route(ServerHost, Access, Plugins, exmpp_jid:ldomain_as_list(To), From, To, Packet) of {'EXIT', Reason} -> ?ERROR_MSG("~p", [Reason]); _ -> ok end, @@ -608,15 +608,17 @@ code_change(_OldVsn, State, _Extra) -> %%-------------------------------------------------------------------- do_route(ServerHost, Access, Plugins, Host, From, To, Packet) -> #xmlel{name = Name} = Packet, - case To of - #jid{lnode = undefined, lresource = undefined} -> + LNode = exmpp_jid:lnode(To), + LRes = exmpp_jid:lresource(To), + case {LNode, LRes} of + {undefined, undefined} -> case Name of 'iq' -> case exmpp_iq:xmlel_to_iq(Packet) of #iq{type = get, ns = ?NS_DISCO_INFO, payload = SubEl, lang = Lang} -> QAttrs = SubEl#xmlel.attrs, - Node = exmpp_xml:get_attribute_from_list(QAttrs, + Node = exmpp_xml:get_attribute_from_list_as_list(QAttrs, 'node', ""), Res = case iq_disco_info(Host, Node, From, Lang) of {result, IQRes} -> @@ -631,7 +633,7 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) -> #iq{type = get, ns = ?NS_DISCO_ITEMS, payload = SubEl} -> QAttrs = SubEl#xmlel.attrs, - Node = exmpp_xml:get_attribute_from_list(QAttrs, + Node = exmpp_xml:get_attribute_from_list_as_list(QAttrs, 'node', ""), Res = case iq_disco_items(Host, Node, From) of {result, IQRes} -> @@ -732,17 +734,17 @@ node_disco_info(Host, Node, From, Identity, Features) -> end end, lists:map(fun(T) -> - #xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [#xmlattr{name = 'category', value = "pubsub"}, - #xmlattr{name = 'type', value = T}]} + #xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [?XMLATTR('category', <<"pubsub">>), + ?XMLATTR('type', T)]} end, Types) end, F = case Features of false -> []; true -> - [#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_PUBSUB_s}]} | + [#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} | lists:map(fun(T) -> - #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_PUBSUB_s++"#"++T}]} + #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s++"#"++T)]} end, features(Type))] end, %% TODO: add meta-data info (spec section 5.4) @@ -756,15 +758,15 @@ iq_disco_info(Host, SNode, From, Lang) -> [] -> {result, [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = - [#xmlattr{name = 'category', value = "pubsub"}, - #xmlattr{name = 'type', value = "service"}, - #xmlattr{name = 'name', value = translate:translate(Lang, "Publish-Subscribe")}]}, - #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_DISCO_INFO_s}]}, - #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_DISCO_ITEMS_s}]}, - #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_PUBSUB_s}]}, - #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_VCARD_s}]}] ++ + [?XMLATTR('category', "pubsub"), + ?XMLATTR('type', "service"), + ?XMLATTR('name', translate:translate(Lang, "Publish-Subscribe"))]}, + #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_DISCO_INFO_s)]}, + #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_DISCO_ITEMS_s)]}, + #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]}, + #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++ lists:map(fun(Feature) -> - #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [#xmlattr{name = 'var', value = ?NS_PUBSUB_s++"#"++Feature}]} + #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s++"#"++Feature)]} end, features(Host, SNode))}; _ -> node_disco_info(Host, Node, From) @@ -776,9 +778,9 @@ iq_disco_items(Host, [], From) -> SN = node_to_string(SubNode), RN = lists:last(SubNode), %% remove name attribute - #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [#xmlattr{name = 'jid', value = Host}, - #xmlattr{name = 'node', value = SN}, - #xmlattr{name = 'name', value = RN}]} + #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), + ?XMLATTR('node', SN), + ?XMLATTR('name', RN)]} end, tree_action(Host, get_subnodes, [Host, [], From]))}; iq_disco_items(Host, Item, From) -> case string:tokens(Item, "!") of @@ -800,15 +802,15 @@ iq_disco_items(Host, Item, From) -> fun(#pubsub_node{nodeid = {_, SubNode}}) -> SN = node_to_string(SubNode), RN = lists:last(SubNode), - #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [#xmlattr{name = 'jid', value = Host}, #xmlattr{name = 'node', value = SN}, - #xmlattr{name = 'name', value = RN}]} + #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('node', SN), + ?XMLATTR('name', RN)]} end, tree_call(Host, get_subnodes, [Host, Node, From])), Items = lists:map( fun(#pubsub_item{itemid = {RN, _}}) -> SN = node_to_string(Node) ++ "!" ++ RN, {result, Name} = node_call(Type, get_item_name, [Host, Node, RN]), - #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [#xmlattr{name = 'jid', value = Host}, #xmlattr{name = 'node', value = SN}, - #xmlattr{name = 'name', value = Name}]} + #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('node', SN), + ?XMLATTR('name', Name)]} end, NodeItems), {result, Nodes ++ Items} end, @@ -819,10 +821,11 @@ iq_local(From, To, #iq{type = Type, payload = SubEl, ns = XMLNS, lang = Lang} = IQ_Rec) -> - ServerHost = To#jid.ldomain, + ServerHost = exmpp_jid:ldomain_as_list(To), + FromHost = exmpp_jid:ldomain_as_list(To), %% Accept IQs to server only from our own users. if - From#jid.ldomain /= ServerHost -> + FromHost /= ServerHost -> exmpp_iq:error(IQ_Rec, 'forbidden'); true -> LOwner = jlib:short_prepd_bare_jid(From), @@ -838,7 +841,7 @@ iq_local(From, To, #iq{type = Type, end. iq_sm(From, To, #iq{type = Type, payload = SubEl, ns = XMLNS, lang = Lang} = IQ_Rec) -> - ServerHost = To#jid.ldomain, + ServerHost = exmpp_jid:ldomain_as_list(To), LOwner = jlib:short_prepd_bare_jid(To), Res = case XMLNS of ?NS_PUBSUB -> iq_pubsub(LOwner, ServerHost, From, Type, SubEl, Lang); @@ -871,15 +874,15 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, _Lang, Access, Plugins) -> case Action of [#xmlel{name = Name, attrs = Attrs, children = Els}] -> Node = case Host of - {_, _, _} -> exmpp_xml:get_attribute_from_list(Attrs, 'node', false); - _ -> string_to_node(exmpp_xml:get_attribute_from_list(Attrs, 'node', false)) + {_, _, _} -> exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', false); + _ -> string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', false)) end, case {IQType, Name} of {set, 'create'} -> case Configuration of [#xmlel{name = 'configure', children = Config}] -> %% Get the type of the node - Type = case exmpp_xml:get_attribute_from_list(Attrs, 'type', "") of + Type = case exmpp_xml:get_attribute_from_list_as_list(Attrs, 'type', "") of [] -> hd(Plugins); T -> T end, @@ -904,7 +907,7 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, _Lang, Access, Plugins) -> {set, 'publish'} -> case exmpp_xml:remove_cdata_from_list(Els) of [#xmlel{name = 'item', attrs = ItemAttrs, children = Payload}] -> - ItemId = exmpp_xml:get_attribute_from_list(ItemAttrs, 'id', ""), + ItemId = exmpp_xml:get_attribute_from_list_as_list(ItemAttrs, 'id', ""), publish_item(Host, ServerHost, Node, From, ItemId, Payload); [] -> %% Publisher attempts to publish to persistent node with no item @@ -916,14 +919,14 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, _Lang, Access, Plugins) -> "invalid-payload")} end; {set, 'retract'} -> - ForceNotify = case exmpp_xml:get_attribute_from_list(Attrs, 'notify', "") of + ForceNotify = case exmpp_xml:get_attribute_from_list_as_list(Attrs, 'notify', "") of "1" -> true; "true" -> true; _ -> false end, case exmpp_xml:remove_cdata_from_list(Els) of [#xmlel{name = 'item', attrs = ItemAttrs}] -> - ItemId = exmpp_xml:get_attribute_from_list(ItemAttrs, 'id', ""), + ItemId = exmpp_xml:get_attribute_from_list_as_list(ItemAttrs, 'id', ""), delete_item(Host, Node, From, ItemId, ForceNotify); _ -> %% Request does not specify an item @@ -931,18 +934,18 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, _Lang, Access, Plugins) -> "item-required")} end; {set, 'subscribe'} -> - JID = exmpp_xml:get_attribute_from_list(Attrs, 'jid', ""), + JID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', ""), subscribe_node(Host, Node, From, JID); {set, 'unsubscribe'} -> - JID = exmpp_xml:get_attribute_from_list(Attrs, 'jid', ""), - SubId = exmpp_xml:get_attribute_from_list(Attrs, 'subid', ""), + JID = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', ""), + SubId = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'subid', ""), unsubscribe_node(Host, Node, From, JID, SubId); {get, 'items'} -> - MaxItems = exmpp_xml:get_attribute_from_list(Attrs, 'max_items', ""), - SubId = exmpp_xml:get_attribute_from_list(Attrs, 'subid', ""), + MaxItems = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'max_items', ""), + SubId = exmpp_xml:get_attribute_from_list_as_list(Attrs, 'subid', ""), ItemIDs = lists:foldl(fun (#xmlel{name = 'item', attrs = ItemAttrs}, Acc) -> - case exmpp_xml:get_attribute_from_list(ItemAttrs, 'id', "") of + case exmpp_xml:get_attribute_from_list_as_list(ItemAttrs, 'id', "") of "" -> Acc; ItemID -> [ItemID|Acc] end; @@ -972,8 +975,8 @@ iq_pubsub_owner(Host, From, IQType, SubEl, Lang) -> case Action of [#xmlel{name = Name, attrs = Attrs, children = Els}] -> Node = case Host of - {_, _, _} -> exmpp_xml:get_attribute_from_list(Attrs, 'node', ""); - _ -> string_to_node(exmpp_xml:get_attribute_from_list(Attrs, 'node', "")) + {_, _, _} -> exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', ""); + _ -> string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")) end, case {IQType, Name} of {get, 'configure'} -> @@ -1008,28 +1011,28 @@ send_authorization_request(Host, Node, Subscriber) -> Lang = "en", %% TODO fix {U, S, R} = Subscriber, Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children = - [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [#xmlattr{name = 'type', value = "form"}], children = + [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "PubSub subscriber request"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'instructions', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Choose whether to approve this entity's subscription."))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = "FORM_TYPE"}, #xmlattr{name = 'type', value = "hidden"}], children = + [?XMLATTR('var', <<"FORM_TYPE">>), ?XMLATTR('type', <<"hidden">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(?NS_PUBSUB_SUBSCRIBE_AUTH_s)}]}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = "pubsub#node"}, #xmlattr{name = 'type', value = "text-single"}, - #xmlattr{name = 'label', value = translate:translate(Lang, "Node ID")}], children = + [?XMLATTR('var', <<"pubsub#node">>), ?XMLATTR('type', <<"text-single">>), + ?XMLATTR('label', translate:translate(Lang, "Node ID"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = node_to_string(Node)}]}]}, - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'var', value = "pubsub#subscriber_jid"}, - #xmlattr{name = 'type', value = "jid-single"}, - #xmlattr{name = 'label', value = translate:translate(Lang, "Subscriber Address")}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('var', <<"pubsub#subscriber_jid">>), + ?XMLATTR('type', <<"jid-single">>), + ?XMLATTR('label', translate:translate(Lang, "Subscriber Address"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = exmpp_jid:jid_to_binary(U, S, R)}]}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = "pubsub#allow"}, - #xmlattr{name = 'type', value = "boolean"}, - #xmlattr{name = 'label', value = translate:translate(Lang, "Allow this Jabber ID to subscribe to this pubsub node?")}], children = + [?XMLATTR('var', <<"pubsub#allow">>), + ?XMLATTR('type', <<"boolean">>), + ?XMLATTR('label', translate:translate(Lang, "Allow this Jabber ID to subscribe to this pubsub node?"))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = <<"false">>}]}]}]}]}, case tree_action(Host, get_node, [Host, Node, Subscriber]) of #pubsub_node{owners = Owners} -> @@ -1045,7 +1048,7 @@ send_authorization_request(Host, Node, Subscriber) -> find_authorization_response(Packet) -> Els = Packet#xmlel.children, XData1 = lists:map(fun(#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = XAttrs} = XEl) -> - case exmpp_xml:get_attribute_from_list(XAttrs, 'type', "") of + case exmpp_xml:get_attribute_from_list_as_list(XAttrs, 'type', "") of "cancel" -> none; _ -> @@ -1077,9 +1080,9 @@ find_authorization_response(Packet) -> send_authorization_approval(Host, JID, Node, Subscription) -> Stanza = event_stanza( [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs = - [#xmlattr{name = 'node', value = Node}, - #xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(JID)}, - #xmlattr{name = 'subscription', value = subscription_to_string(Subscription)}]}]), + [?XMLATTR('node', Node), + ?XMLATTR('jid', exmpp_jid:jid_to_binary(JID)), + ?XMLATTR('subscription', subscription_to_string(Subscription))]}]), ejabberd_router ! {route, service_jid(Host), JID, Stanza}. handle_authorization_response(Host, From, To, Packet, XFields) -> @@ -1092,7 +1095,7 @@ handle_authorization_response(Host, From, To, Packet, XFields) -> {_, _, _} -> [SNode]; _ -> string:tokens(SNode, "/") end, - Subscriber = exmpp_jid:list_to_jid(SSubscriber), + Subscriber = exmpp_jid:parse_jid(SSubscriber), Allow = case SAllow of "1" -> true; "true" -> true; @@ -1137,9 +1140,9 @@ handle_authorization_response(Host, From, To, Packet, XFields) -> end. -define(XFIELD(Type, Label, Var, Val), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', translate:translate(Lang, Label)), + ?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Val)}]}]}). -define(BOOLXFIELD(Label, Var, Val), @@ -1153,9 +1156,9 @@ handle_authorization_response(Host, From, To, Packet, XFields) -> ?XFIELD("text-single", Label, Var, Val)). -define(XFIELDOPT(Type, Label, Var, Val, Opts), - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', Type), + ?XMLATTR('label', translate:translate(Lang, Label)), + ?XMLATTR('var', Var)], children = lists:map(fun(Opt) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'option', children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = @@ -1202,7 +1205,7 @@ create_node(Host, ServerHost, [], Owner, Type, Access, Configuration) -> {result, []} -> {result, [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = - [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = [#xmlattr{name = 'node', value = node_to_string(NewNode)}]}]}]}; + [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = [?XMLATTR('node', node_to_string(NewNode))]}]}]}; Error -> Error end; false -> @@ -1254,7 +1257,7 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> end end, Reply = [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = - [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}]}]}], + [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = [?XMLATTR('node', node_to_string(Node))]}]}], case transaction(CreateNode, transaction) of {error, Error} -> %% in case we change transaction to sync_dirty... @@ -1359,7 +1362,7 @@ delete_node(Host, Node, Owner) -> %% subscribe_node(Host, Node, From, JID) -> Subscriber = try - jlib:short_prepd_jid(exmpp_jid:list_to_jid(JID)) + jlib:short_prepd_jid(exmpp_jid:parse_jid(JID)) catch _:_ -> {undefined, undefined, undefined} @@ -1397,13 +1400,13 @@ subscribe_node(Host, Node, From, JID) -> Reply = fun(Subscription) -> %% TODO, this is subscription-notification, should depends on node features Fields = - [#xmlattr{name = 'node', value = node_to_string(Node)}, - #xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(Subscriber)}, - #xmlattr{name = 'subscription', value = subscription_to_string(Subscription)}], + [?XMLATTR('node', node_to_string(Node)), + ?XMLATTR('jid', exmpp_jid:jid_to_binary(Subscriber)), + ?XMLATTR('subscription', subscription_to_string(Subscription))], [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = case Subscription of - subscribed -> [#xmlattr{name = 'subid', value = SubId}|Fields]; + subscribed -> [?XMLATTR('subid', SubId)|Fields]; _ -> Fields end}]}] end, @@ -1447,7 +1450,7 @@ subscribe_node(Host, Node, From, JID) -> %%
  • The request specifies a subscription ID that is not valid or current.
  • %% unsubscribe_node(Host, Node, From, JID, SubId) when is_list(JID) -> - Subscriber = try jlib:short_prepd_jid(exmpp_jid:list_to_jid(JID)) + Subscriber = try jlib:short_prepd_jid(exmpp_jid:parse_jid(JID)) catch _:_ -> {undefined, undefined, undefined} @@ -1725,12 +1728,12 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) -> payload = Payload}) -> ItemAttrs = case ItemId of "" -> []; - _ -> [#xmlattr{name = 'id', value = ItemId}] + _ -> [?XMLATTR('id', ItemId)] end, #xmlel{ns = ?NS_PUBSUB, name = 'item', attrs = ItemAttrs, children = Payload} end, lists:sublist(SendItems, MaxItems)), {result, [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = - [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], children = + [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = ItemsEls}]}]} end end. @@ -1785,12 +1788,12 @@ send_items(Host, Node, {LU, LS, LR} = LJID, Number) -> fun(#pubsub_item{itemid = {ItemId, _}, payload = Payload}) -> ItemAttrs = case ItemId of "" -> []; - _ -> [#xmlattr{name = 'id', value = ItemId}] + _ -> [?XMLATTR('id', ItemId)] end, #xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = ItemAttrs, children = Payload} end, ToSend), Stanza = event_stanza( - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], children = + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = ItemsEls}]), ejabberd_router ! {route, service_jid(Host), exmpp_jid:make_jid(LU, LS, LR), Stanza}. @@ -1821,8 +1824,8 @@ get_affiliations(Host, JID, Plugins) when is_list(Plugins) -> fun({_, none}) -> []; ({Node, Affiliation}) -> [#xmlel{ns = ?NS_PUBSUB, name = 'affiliation', attrs = - [#xmlattr{name = 'node', value = node_to_string(Node)}, - #xmlattr{name = 'affiliation', value = affiliation_to_string(Affiliation)}]}] + [?XMLATTR('node', node_to_string(Node)), + ?XMLATTR('affiliation', affiliation_to_string(Affiliation))]}] end, lists:usort(lists:flatten(Affiliations))), {result, [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'affiliations', children = @@ -1856,11 +1859,11 @@ get_affiliations(Host, Node, JID) -> fun({_, none}) -> []; ({{AU, AS, AR}, Affiliation}) -> [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'affiliation', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(AU, AS, AR)}, - #xmlattr{name = 'affiliation', value = affiliation_to_string(Affiliation)}]}] + [?XMLATTR('jid', exmpp_jid:jid_to_binary(AU, AS, AR)), + ?XMLATTR('affiliation', affiliation_to_string(Affiliation))]}] end, Affiliations), {result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = - [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'affiliations', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], children = + [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'affiliations', attrs = [?XMLATTR('node', node_to_string(Node))], children = Entities}]}]} end. @@ -1876,13 +1879,13 @@ set_affiliations(Host, Node, From, EntitiesEls) -> case El of #xmlel{name = 'affiliation', attrs = Attrs} -> JID = try - exmpp_jid:list_to_jid( - exmpp_xml:get_attribute_from_list(Attrs, 'jid', "")) + exmpp_jid:parse_jid( + exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', "")) catch _:_ -> error end, Affiliation = string_to_affiliation( - exmpp_xml:get_attribute_from_list(Attrs, 'affiliation', false)), + exmpp_xml:get_attribute_from_list_as_list(Attrs, 'affiliation', false)), if (JID == error) or (Affiliation == false) -> @@ -1958,14 +1961,14 @@ get_subscriptions(Host, JID, Plugins) when is_list(Plugins) -> fun({_, none}) -> []; ({Node, Subscription}) -> [#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = - [#xmlattr{name = 'node', value = node_to_string(Node)}, - #xmlattr{name = 'subscription', value = subscription_to_string(Subscription)}]}]; + [?XMLATTR('node', node_to_string(Node)), + ?XMLATTR('subscription', subscription_to_string(Subscription))]}]; ({_, none, _}) -> []; ({Node, Subscription, SubJID}) -> [#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = - [#xmlattr{name = 'node', value = node_to_string(Node)}, - #xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(SubJID)}, - #xmlattr{name = 'subscription', value = subscription_to_string(Subscription)}]}] + [?XMLATTR('node', node_to_string(Node)), + ?XMLATTR('jid', exmpp_jid:jid_to_binary(SubJID)), + ?XMLATTR('subscription', subscription_to_string(Subscription))]}] end, lists:usort(lists:flatten(Subscriptions))), {result, [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'subscriptions', children = @@ -1999,16 +2002,16 @@ get_subscriptions(Host, Node, JID) -> fun({_, none}) -> []; ({{AU, AS, AR}, Subscription}) -> [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'subscription', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(AU, AS, AR)}, - #xmlattr{name = 'subscription', value = subscription_to_string(Subscription)}]}]; + [?XMLATTR('jid', exmpp_jid:jid_to_binary(AU, AS, AR)), + ?XMLATTR('subscription', subscription_to_string(Subscription))]}]; ({{AU, AS, AR}, Subscription, SubId}) -> [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'subscription', attrs = - [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(AU, AS, AR)}, - #xmlattr{name = 'subscription', value = subscription_to_string(Subscription)}, - #xmlattr{name = 'subid', value =SubId}]}] + [?XMLATTR('jid', exmpp_jid:jid_to_binary(AU, AS, AR)), + ?XMLATTR('subscription', subscription_to_string(Subscription)), + ?XMLATTR('subid', SubId)]}] end, Subscriptions), {result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = - [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'subscriptions', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], children = + [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'subscriptions', attrs = [?XMLATTR('node', node_to_string(Node))], children = Entities}]}]} end. @@ -2024,14 +2027,14 @@ set_subscriptions(Host, Node, From, EntitiesEls) -> case El of #xmlel{name = 'subscription', attrs = Attrs} -> JID = try - exmpp_jid:list_to_jid( - exmpp_xml:get_attribute_from_list(Attrs, 'jid', "")) + exmpp_jid:parse_jid( + exmpp_xml:get_attribute_from_list_as_list(Attrs, 'jid', "")) catch _:_ -> error end, Subscription = string_to_subscription( - exmpp_xml:get_attribute_from_list(Attrs, 'subscription', false)), + exmpp_xml:get_attribute_from_list_as_list(Attrs, 'subscription', false)), if (JID == error) or (Subscription == false) -> @@ -2137,8 +2140,8 @@ string_to_node(SNode) -> %% @doc

    Generate pubsub service JID.

    service_jid(Host) -> case Host of - {U,S,_} -> #jid{node = U, domain = S, lnode = U, ldomain = S}; - _ -> #jid{domain = Host, ldomain = Host} + {U,S,_} -> exmpp_jid:make_jid(U, S); + _ -> exmpp_jid:make_jid(Host) end. %% @spec (LJID, Subscription, PresenceDelivery) -> boolean() @@ -2188,10 +2191,10 @@ broadcast_publish_item(Host, Node, ItemId, _From, Payload) -> end, ItemAttrs = case ItemId of "" -> []; - _ -> [#xmlattr{name = 'id', value = ItemId}] + _ -> [?XMLATTR('id', ItemId)] end, Stanza = event_stanza( - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], children = + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = ItemAttrs, children = Content}]}]), broadcast_stanza(Host, Options, States, Stanza), broadcast_by_caps(Host, Node, Type, Stanza), @@ -2217,12 +2220,12 @@ broadcast_retract_items(Host, Node, ItemIds, ForceNotify) -> fun(ItemId) -> ItemAttrs = case ItemId of "" -> []; - _ -> [#xmlattr{name = 'id', value = ItemId}] + _ -> [?XMLATTR('id', ItemId)] end, #xmlel{ns = ?NS_PUBSUB_EVENT, name = 'retract', attrs = ItemAttrs} end, ItemIds), Stanza = event_stanza( - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = RetractEls}]), broadcast_stanza(Host, Options, States, Stanza), broadcast_by_caps(Host, Node, Type, Stanza), @@ -2246,7 +2249,7 @@ broadcast_purge_node(Host, Node) -> {result, false}; {result, States} -> Stanza = event_stanza( - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'purge', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}]}]), + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'purge', attrs = [?XMLATTR('node', node_to_string(Node))]}]), broadcast_stanza(Host, Options, States, Stanza), broadcast_by_caps(Host, Node, Type, Stanza), {result, true}; @@ -2269,7 +2272,7 @@ broadcast_removed_node(Host, Node) -> {result, false}; {result, States} -> Stanza = event_stanza( - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'delete', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}]}]), + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'delete', attrs = [?XMLATTR('node', node_to_string(Node))]}]), broadcast_stanza(Host, Options, States, Stanza), broadcast_by_caps(Host, Node, Type, Stanza), {result, true}; @@ -2293,14 +2296,14 @@ broadcast_config_notification(Host, Node, Lang) -> {result, States} -> Content = case get_option(Options, deliver_payloads) of true -> - [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [#xmlattr{name = 'type', value = "form"}], children = + [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children = get_configure_xfields(Type, Options, Lang, Owners)}]; false -> [] end, Stanza = event_stanza( - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [#xmlattr{name = 'node', value = node_to_string(Node)}], children = - [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = [#xmlattr{name = 'id', value = "configuration"}], children = + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = + [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = [?XMLATTR('id', <<"configuration">>)], children = Content}]}]), broadcast_stanza(Host, Options, States, Stanza), broadcast_by_caps(Host, Node, Type, Stanza), @@ -2404,9 +2407,9 @@ get_configure(Host, Node, From, Lang) -> {result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'configure', attrs = - [#xmlattr{name = 'node', value = node_to_string(Node)}], children = + [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = "form"}], children = + [?XMLATTR('type', <<"form">>)], children = get_configure_xfields(Type, Options, Lang, Owners) }]}]}]}; _ -> @@ -2420,7 +2423,7 @@ get_default(Host, Node, _From, Lang) -> Options = node_options(Type), {result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'default', children = - [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [#xmlattr{name = 'type', value = "form"}], children = + [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [?XMLATTR('type', <<"form">>)], children = get_configure_xfields(Type, Options, Lang, []) }]}]}]}. @@ -2507,9 +2510,9 @@ get_configure_xfields(_Type, Options, Lang, _Owners) -> ?ALIST_CONFIG_FIELD("Specify the access model", access_model, [open, authorize, presence, roster, whitelist]), %% XXX: change to list-multi, include current roster groups as options - #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = "text-multi"}, - #xmlattr{name = 'label', value = translate:translate(Lang, "Roster groups allowed to subscribe")}, - #xmlattr{name = 'var', value = "pubsub#roster_groups_allowed"}], children = + #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [?XMLATTR('type', <<"text-multi">>), + ?XMLATTR('label', translate:translate(Lang, "Roster groups allowed to subscribe")), + ?XMLATTR('var', <<"pubsub#roster_groups_allowed">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Value)}]} || Value <- get_option(Options, roster_groups_allowed, [])]}, ?ALIST_CONFIG_FIELD("Specify the publisher model", publish_model, @@ -2531,7 +2534,7 @@ get_configure_xfields(_Type, Options, Lang, _Owners) -> set_configure(Host, Node, From, Els, Lang) -> case exmpp_xml:remove_cdata_from_list(Els) of [#xmlel{ns = ?NS_DATA_FORMS, name = 'x'} = XEl] -> - case exmpp_xml:get_attribute(XEl, 'type', undefined) of + case exmpp_xml:get_attribute_as_list(XEl, 'type', undefined) of "cancel" -> {result, []}; "submit" -> @@ -2660,9 +2663,8 @@ set_xoption([_ | Opts], NewOpts) -> %%%% plugin handling -plugins(Host) when is_binary(Host) -> - HostL = binary_to_list(Host), - case ets:lookup(gen_mod:get_module_proc(HostL, pubsub_state), plugins) of +plugins(Host) -> + case ets:lookup(gen_mod:get_module_proc(Host, pubsub_state), plugins) of [{plugins, PL}] -> PL; _ -> [?STDNODE] end. @@ -2812,7 +2814,7 @@ extended_error(Error, Ext) -> extended_error(Error, Ext, []). extended_error(Error, unsupported, Feature) -> extended_error(Error, unsupported, - [#xmlattr{name = 'feature', value = Feature}]); + [?XMLATTR('feature', Feature)]); extended_error(Error, Ext, ExtAttrs) -> Pubsub_Err = #xmlel{ns = ?NS_PUBSUB_ERRORS, name = Ext, attrs = ExtAttrs}, exmpp_xml:append_child(exmpp_stanza:error(?NS_JABBER_CLIENT, Error), diff --git a/src/mod_register.erl b/src/mod_register.erl index 8fbd09696..f7800e0b2 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -76,7 +76,7 @@ unauthenticated_iq_register(_Acc, {A, _Port} -> A; _ -> undefined end, - BareJID = exmpp_jid:make_bare_jid(Server), + BareJID = exmpp_jid:make_jid(Server), ResIQ = process_iq(exmpp_jid:make_jid(), BareJID, IQ_Rec, @@ -204,7 +204,7 @@ try_register(User, Server, Password, Source, Lang) -> false -> {error, 'bad-request'}; _ -> - JID = exmpp_jid:make_bare_jid(User, + JID = exmpp_jid:make_jid(User, Server), Access = gen_mod:get_module_opt(Server, ?MODULE, access, all), case acl:match_rule(Server, Access, JID) of @@ -247,7 +247,7 @@ send_welcome_message(JID) -> ok; {Subj, Body} -> ejabberd_router:route( - exmpp_jid:make_bare_jid(Host), + exmpp_jid:make_jid(Host), JID, exmpp_message:normal(Subj, Body)); _ -> @@ -266,9 +266,9 @@ send_registration_notifications(UJID) -> lists:foreach( fun(S) -> try - JID = exmpp_jid:list_to_jid(S), + JID = exmpp_jid:parse_jid(S), ejabberd_router:route( - exmpp_jid:make_bare_jid(Host), + exmpp_jid:make_jid(Host), JID, exmpp_message:chat(Body)) catch diff --git a/src/mod_roster.erl b/src/mod_roster.erl index b63642b8b..d16898e42 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -190,7 +190,7 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) -> process_item_set(From, To, #xmlel{} = El) -> try - JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), + JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), User = exmpp_jid:node(From), LUser = exmpp_jid:lnode(From), LServer = exmpp_jid:ldomain(From), @@ -311,7 +311,7 @@ process_item_els(Item, []) -> push_item(User, Server, From, Item) when is_binary(User), is_binary(Server) -> ejabberd_sm:route(exmpp_jid:make_jid(), - exmpp_jid:make_bare_jid(User, Server), + exmpp_jid:make_jid(User, Server), #xmlel{name = 'broadcast', children = [{item, Item#roster.jid, @@ -438,7 +438,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ok; _ -> ejabberd_router:route( - exmpp_jid:make_bare_jid(User, Server), JID1, + exmpp_jid:make_jid(User, Server), JID1, exmpp_presence:AutoReply()) end, case Push of @@ -449,7 +449,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ok; true -> push_item(User, Server, - exmpp_jid:make_bare_jid(User, Server), Item) + exmpp_jid:make_jid(User, Server), Item) end, true; none -> @@ -596,7 +596,7 @@ set_items(User, Server, #xmlel{children = Els}) -> process_item_set_t(LUser, LServer, #xmlel{} = El) -> try - JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute(El, 'jid', <<>>)), + JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_list(El, 'jid', <<>>)), JID = jlib:short_jid(JID1), LJID = jlib:short_prepd_jid(JID1), Item = #roster{usj = {LUser, LServer, LJID}, @@ -651,7 +651,7 @@ process_item_attrs_ws(Item, []) -> get_in_pending_subscriptions(Ls, User, Server) when is_binary(User), is_binary(Server) -> - JID = exmpp_jid:make_bare_jid(User, Server), + JID = exmpp_jid:make_jid(User, Server), US = {exmpp_jid:lnode(JID), exmpp_jid:ldomain(JID)}, case mnesia:dirty_index_read(roster, US, #roster.us) of Result when list(Result) -> @@ -948,9 +948,9 @@ build_contact_jid_td({U, S, R}) -> end, case JIDURI of [] -> - ?XAC('td', [#xmlattr{name = 'class', value = <<"valign">>}], exmpp_jid:jid_to_list(ContactJID)); + ?XAC('td', [?XMLATTR('class', <<"valign">>)], exmpp_jid:jid_to_list(ContactJID)); URI when is_list(URI) -> - ?XAE('td', [#xmlattr{name = 'class', value = <<"valign">>}], [?AC(JIDURI, exmpp_jid:jid_to_list(ContactJID))]) + ?XAE('td', [?XMLATTR('class', <<"valign">>)], [?AC(JIDURI, exmpp_jid:jid_to_list(ContactJID))]) end. user_roster_parse_query(User, Server, Items, Query) -> @@ -961,7 +961,7 @@ user_roster_parse_query(User, Server, Items, Query) -> error; {value, {_, SJID}} -> try - JID = exmpp_jid:list_to_jid(SJID), + JID = exmpp_jid:parse_jid(SJID), user_roster_subscribe_jid(User, Server, JID), ok catch @@ -986,7 +986,7 @@ user_roster_parse_query(User, Server, Items, Query) -> user_roster_subscribe_jid(User, Server, JID) -> out_subscription(User, Server, JID, subscribe), - UJID = exmpp_jid:make_bare_jid(User, Server), + UJID = exmpp_jid:make_jid(User, Server), ejabberd_router:route( UJID, JID, exmpp_presence:subscribe()). @@ -1001,7 +1001,7 @@ user_roster_item_parse_query(User, Server, Items, Query) -> JID1 = exmpp_jid:make_jid(U, S, R), out_subscription( User, Server, JID1, subscribed), - UJID = exmpp_jid:make_bare_jid(User, Server), + UJID = exmpp_jid:make_jid(User, Server), ejabberd_router:route( UJID, JID1, exmpp_presence:subscribed()), throw(submitted); @@ -1009,7 +1009,7 @@ user_roster_item_parse_query(User, Server, Items, Query) -> case lists:keysearch( "remove" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of {value, _} -> - UJID = exmpp_jid:make_bare_jid(User, Server), + UJID = exmpp_jid:make_jid(User, Server), Attrs1 = exmpp_xml:set_attribute_in_list([], 'jid', exmpp_jid:jid_to_list(JID)), Attrs2 = exmpp_xml:set_attribute_in_list(Attrs1, diff --git a/src/mod_roster_odbc.erl b/src/mod_roster_odbc.erl index 4ea9de82d..e56b70a77 100644 --- a/src/mod_roster_odbc.erl +++ b/src/mod_roster_odbc.erl @@ -216,7 +216,7 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) -> process_item_set(From, To, #xmlel{} = El) -> try - JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), + JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), LUser = exmpp_jid:lnode_as_list(From), LServer = exmpp_jid:ldomain_as_list(From), {U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1), @@ -346,7 +346,7 @@ process_item_els(Item, []) -> push_item(User, Server, From, Item) when is_binary(User), is_binary(Server) -> ejabberd_sm:route(exmpp_jid:make_jid(), - exmpp_jid:make_bare_jid(User, Server), + exmpp_jid:make_jid(User, Server), #xmlel{name = 'broadcast', children = [{item, Item#roster.jid, @@ -503,7 +503,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ok; _ -> ejabberd_router:route( - exmpp_jid:make_bare_jid(User, Server), JID1, + exmpp_jid:make_jid(User, Server), JID1, exmpp_presence:AutoReply()) end, case Push of @@ -514,7 +514,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) ok; true -> push_item(User, Server, - exmpp_jid:make_bare_jid(User, Server), Item) + exmpp_jid:make_jid(User, Server), Item) end, true; none -> @@ -650,7 +650,7 @@ set_items(User, Server, #xmlel{children = Els}) -> process_item_set_t(LUser, LServer, #xmlel{} = El) -> try - JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), + JID1 = exmpp_jid:parse_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)), {U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1), Username = ejabberd_odbc:escape(LUser), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U0, S0, R0)), @@ -708,7 +708,7 @@ process_item_attrs_ws(Item, []) -> get_in_pending_subscriptions(Ls, User, Server) when is_binary(User), is_binary(Server) -> - JID = exmpp_jid:make_bare_jid(User, Server), + JID = exmpp_jid:make_jid(User, Server), LUser = exmpp_jid:lnode_as_list(JID), LServer = exmpp_jid:ldomain_as_list(JID), Username = ejabberd_odbc:escape(LUser), @@ -809,7 +809,7 @@ get_jid_info(_, User, Server, JID) when is_binary(User), is_binary(Server) -> raw_to_record(LServer, {User, SJID, Nick, SSubscription, SAsk, SAskMessage, _SServer, _SSubscribe, _SType}) when is_binary(LServer) -> try - JID = exmpp_jid:list_to_jid(SJID), + JID = exmpp_jid:parse_jid(SJID), LJID = jlib:short_prepd_jid(JID), Subscription = case SSubscription of "B" -> both; @@ -987,9 +987,9 @@ build_contact_jid_td({U, S, R}) -> end, case JIDURI of [] -> - ?XAC('td', [#xmlattr{name = 'class', value = <<"valign">>}], exmpp_jid:jid_to_list(ContactJID)); + ?XAC('td', [?XMLATTR('class', <<"valign">>)], exmpp_jid:jid_to_list(ContactJID)); URI when is_list(URI) -> - ?XAE('td', [#xmlattr{name = 'class', value = <<"valign">>}], [?AC(JIDURI, exmpp_jid:jid_to_list(ContactJID))]) + ?XAE('td', [?XMLATTR('class', <<"valign">>)], [?AC(JIDURI, exmpp_jid:jid_to_list(ContactJID))]) end. user_roster_parse_query(User, Server, Items, Query) -> @@ -1000,7 +1000,7 @@ user_roster_parse_query(User, Server, Items, Query) -> error; {value, {_, SJID}} -> try - JID = exmpp_jid:list_to_jid(SJID), + JID = exmpp_jid:parse_jid(SJID), user_roster_subscribe_jid(User, Server, JID), ok catch @@ -1025,7 +1025,7 @@ user_roster_parse_query(User, Server, Items, Query) -> user_roster_subscribe_jid(User, Server, JID) -> out_subscription(User, Server, JID, subscribe), - UJID = exmpp_jid:make_bare_jid(User, Server), + UJID = exmpp_jid:make_jid(User, Server), ejabberd_router:route( UJID, JID, exmpp_presence:subscribe()). @@ -1040,7 +1040,7 @@ user_roster_item_parse_query(User, Server, Items, Query) -> JID1 = exmpp_jid:make_jid(U, S, R), out_subscription( User, Server, JID1, subscribed), - UJID = exmpp_jid:make_bare_jid(User, Server), + UJID = exmpp_jid:make_jid(User, Server), ejabberd_router:route( UJID, JID1, exmpp_presence:subscribed()), throw(submitted); @@ -1048,7 +1048,7 @@ user_roster_item_parse_query(User, Server, Items, Query) -> case lists:keysearch( "remove" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of {value, _} -> - UJID = exmpp_jid:make_bare_jid(User, Server), + UJID = exmpp_jid:make_jid(User, Server), Attrs1 = exmpp_xml:set_attribute_in_list([], 'jid', exmpp_jid:jid_to_list(JID)), Attrs2 = exmpp_xml:set_attribute_in_list(Attrs1, diff --git a/src/mod_service_log.erl b/src/mod_service_log.erl index ab9463d24..499f96e70 100644 --- a/src/mod_service_log.erl +++ b/src/mod_service_log.erl @@ -63,13 +63,13 @@ log_user_receive(_JID, From, To, Packet) -> log_packet(From, To, Packet, Host) -> Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []), - ServerJID = exmpp_jid:make_bare_jid(Host), + ServerJID = exmpp_jid:make_jid(Host), FixedPacket = exmpp_stanza:set_jids(Packet, From, To), lists:foreach( fun(Logger) -> ejabberd_router:route( ServerJID, - exmpp_jid:make_bare_jid(Logger), + exmpp_jid:make_jid(Logger), #xmlel{name = 'route', children = [FixedPacket]}) end, Loggers). diff --git a/src/mod_shared_roster.erl b/src/mod_shared_roster.erl index 2f37a5001..bac6cf5c9 100644 --- a/src/mod_shared_roster.erl +++ b/src/mod_shared_roster.erl @@ -224,9 +224,9 @@ set_new_rosteritems(UserFrom, ServerFrom, RIFrom = build_roster_record(UserFrom, ServerFrom, UserTo, ServerTo, NameTo, GroupsFrom), set_item(UserFrom, ServerFrom, ResourceTo, RIFrom), - JIDTo = exmpp_jid:make_bare_jid(UserTo, ServerTo), + JIDTo = exmpp_jid:make_jid(UserTo, ServerTo), - JIDFrom = exmpp_jid:make_bare_jid(UserFrom, ServerFrom), + JIDFrom = exmpp_jid:make_jid(UserFrom, ServerFrom), RITo = build_roster_record(UserTo, ServerTo, UserFrom, ServerFrom, UserFrom,[]), set_item(UserTo, ServerTo, undefined, RITo), @@ -256,7 +256,7 @@ set_item(User, Server, Resource, Item) -> "push" ++ randoms:get_string()), ejabberd_router:route( exmpp_jid:make_jid(User, Server, Resource), - exmpp_jid:make_bare_jid(Server), + exmpp_jid:make_jid(Server), ResIQ). @@ -634,7 +634,7 @@ push_item(User, Server, From, Item) -> %% ejabberd_sm:route(jlib:make_jid("", "", ""), %% jlib:make_jid(User, Server, "") %% why? - ejabberd_sm:route(From, exmpp_jid:make_bare_jid(User, Server), + ejabberd_sm:route(From, exmpp_jid:make_jid(User, Server), #xmlel{name = 'broadcast', children = [{item, Item#roster.jid, @@ -890,7 +890,7 @@ shared_roster_group_parse_query(Host, Group, Query) -> USs; _ -> try - JID = exmpp_jid:list_to_jid(SJID), + JID = exmpp_jid:parse_jid(SJID), [{exmpp_jid:lnode_as_list(JID), exmpp_jid:ldomain_as_list(JID)} | USs] catch _ -> diff --git a/src/mod_stats.erl b/src/mod_stats.erl index a3430f437..f20e1580f 100644 --- a/src/mod_stats.erl +++ b/src/mod_stats.erl @@ -46,7 +46,7 @@ stop(Host) -> process_local_iq(_From, To, #iq{type = get, ns = XMLNS, payload = SubEl} = IQ_Rec) -> - Node = string:tokens(exmpp_xml:get_attribute(SubEl, 'node', ""), "/"), + Node = string:tokens(exmpp_xml:get_attribute_as_list(SubEl, 'node', ""), "/"), Names = get_names(exmpp_xml:get_child_elements(SubEl), []), case get_local_stats(exmpp_jid:domain_as_list(To), Node, Names) of @@ -74,7 +74,7 @@ get_names([_ | Els], Res) -> get_names(Els, Res). --define(STAT(Name), #xmlel{ns = ?NS_STATS, name = 'stat', attrs = [#xmlattr{name = 'name', value = Name}]}). +-define(STAT(Name), #xmlel{ns = ?NS_STATS, name = 'stat', attrs = [?XMLATTR('name', Name)]}). get_local_stats(_Server, [], []) -> {result, @@ -116,16 +116,16 @@ get_local_stats(_Server, _, _) -> -define(STATVAL(Val, Unit), #xmlel{ns = ?NS_STATS, name = 'stat', attrs = - [#xmlattr{name = 'name', value = Name}, - #xmlattr{name = 'units', value = Unit}, - #xmlattr{name = 'value', value = Val} + [?XMLATTR('name', Name), + ?XMLATTR('units', Unit), + ?XMLATTR('value', Val) ]}). -define(STATERR(Code, Desc), #xmlel{ns = ?NS_STATS, name = 'stat', attrs= - [#xmlattr{name = 'name', value = Name}], children = + [?XMLATTR('name', Name)], children = [#xmlel{ns = ?NS_STATS, name = 'error', attrs = - [#xmlattr{name = 'code', value = Code}], children = + [?XMLATTR('code', Code)], children = [#xmlcdata{cdata = Desc}]}]}). diff --git a/src/mod_vcard.erl b/src/mod_vcard.erl index c4c8ff1b1..c98802b80 100644 --- a/src/mod_vcard.erl +++ b/src/mod_vcard.erl @@ -275,16 +275,16 @@ set_vcard(User, LServer, VCARD) -> -define(TLFIELD(Type, Label, Var), #xmlel{ns = ?NS_VCARD, name = 'field', attrs = [ - #xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}]}). + ?XMLATTR('type', Type), + ?XMLATTR('label', translate:translate(Lang, Label)), + ?XMLATTR('var', Var)]}). -define(FORM(JID), [#xmlel{ns = ?NS_SEARCH, name = 'instructions', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "You need an x:data capable client to search"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = <<"form">>}], children = + [?XMLATTR('type', <<"form">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Search users in ") ++ exmpp_jid:jid_to_list(JID))}]}, #xmlel{ns = ?NS_SEARCH, name = 'instructions', children = @@ -345,8 +345,8 @@ do_route(ServerHost, From, To, Packet) -> #xmlel{ ns = ?NS_DATA_FORMS, name = 'x', - attrs = [#xmlattr{name = 'type', - value = <<"result">>}], + attrs = [?XMLATTR('type', + <<"result">>)], children = search_result(Lang, To, ServerHost, XData)}]}, ResIQ = exmpp_iq:result(Packet, @@ -370,25 +370,19 @@ do_route(ServerHost, From, To, Packet) -> children = [ #xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [ - #xmlattr{name = 'category', - value = <<"directory">>}, - #xmlattr{name = 'type', - value = <<"user">>}, - #xmlattr{name = 'name', - value = list_to_binary(translate:translate(Lang, - "vCard User Search"))}]}, + ?XMLATTR('category', <<"directory">>), + ?XMLATTR('type', <<"user">>), + ?XMLATTR('name', translate:translate(Lang, + "vCard User Search"))]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_DISCO_INFO_s)}]}, + ?XMLATTR('var', ?NS_DISCO_INFO_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_SEARCH_s)}]}, + ?XMLATTR('var', ?NS_SEARCH_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_VCARD_s)}]} + ?XMLATTR('var', ?NS_VCARD_s)]} ]}, ResIQ = exmpp_iq:result(Packet, Result), ejabberd_router:route(To, @@ -465,7 +459,7 @@ search_result(Lang, JID, ServerHost, Data) -> -define(FIELD(Var, Val), #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = Var}], children = + [?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}). diff --git a/src/mod_vcard_ldap.erl b/src/mod_vcard_ldap.erl index f625a1cf7..4f907be80 100644 --- a/src/mod_vcard_ldap.erl +++ b/src/mod_vcard_ldap.erl @@ -385,15 +385,15 @@ ldap_attribute_to_vcard(_, _) -> -define(TLFIELD(Type, Label, Var), #xmlel{ns = ?NS_VCARD, name = 'field', attrs = [ - #xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = translate:translate(Lang, Label)}, - #xmlattr{name = 'var', value = Var}]}). + ?XMLATTR('type', Type), + ?XMLATTR('label', translate:translate(Lang, Label)), + ?XMLATTR('var', Var)]}). -define(FORM(JID, SearchFields), [#xmlel{ns = ?NS_SEARCH, name = 'instructions', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "You need an x:data capable client to search"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = <<"form">>}], children = + [?XMLATTR('type', <<"form">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Search users in ") ++ exmpp_jid:jid_to_list(JID))}]}, @@ -440,8 +440,8 @@ route(State, From, To, Packet) -> #xmlel{ ns = ?NS_DATA_FORMS, name = 'x', - attrs = [#xmlattr{name = 'type', - value = <<"result">>}], + attrs = [?XMLATTR('type', + <<"result">>)], children = search_result(Lang, To, State, XData)}]}, ResIQ = exmpp_iq:result(Packet, Result), @@ -465,21 +465,16 @@ route(State, From, To, Packet) -> children = [ #xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [ - #xmlattr{name = 'category', - value = <<"directory">>}, - #xmlattr{name = 'type', - value = <<"user">>}, - #xmlattr{name = 'name', - value = list_to_binary(translate:translate(Lang, - "vCard User Search"))}]}, + ?XMLATTR('category', <<"directory">>), + ?XMLATTR('type', <<"user">>), + ?XMLATTR('name', translate:translate(Lang, + "vCard User Search"))]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_SEARCH_s)}]}, + ?XMLATTR('var', ?NS_SEARCH_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_VCARD_s)}]} + ?XMLATTR('var', ?NS_VCARD_s)]} ]}, ResIQ = exmpp_iq:result(Packet, Result), ejabberd_router:route(To, @@ -544,7 +539,7 @@ search_result(Lang, JID, State, Data) -> -define(FIELD(Var, Val), #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = Var}], children = + [?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}). diff --git a/src/mod_vcard_odbc.erl b/src/mod_vcard_odbc.erl index 96bad68bb..d2db1f9e0 100644 --- a/src/mod_vcard_odbc.erl +++ b/src/mod_vcard_odbc.erl @@ -249,16 +249,16 @@ set_vcard(User, LServer, VCARD) -> -define(TLFIELD(Type, Label, Var), #xmlel{ns = ?NS_VCARD, name = 'field', attrs = [ - #xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'label', value = list_to_binary(translate:translate(Lang, Label))}, - #xmlattr{name = 'var', value = Var}]}). + ?XMLATTR('type', Type), + ?XMLATTR('label', translate:translate(Lang, Label)), + ?XMLATTR('var', Var)]}). -define(FORM(JID), [#xmlel{ns = ?NS_SEARCH, name = 'instructions', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "You need an x:data capable client to search"))}]}, #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = - [#xmlattr{name = 'type', value = <<"form">>}], children = + [?XMLATTR('type', <<"form">>)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Search users in ") ++ exmpp_jid:jid_to_list(JID))}]}, #xmlel{ns = ?NS_SEARCH, name = 'instructions', children = @@ -313,8 +313,8 @@ do_route(ServerHost, From, To, Packet) -> #xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [ - #xmlattr{name = 'type', - value = <<"result">>}], + ?XMLATTR('type', + <<"result">>)], children = search_result(Lang, To, ServerHost, XData)}]}, ResIQ = exmpp_iq:result(Packet, Result), @@ -337,21 +337,16 @@ do_route(ServerHost, From, To, Packet) -> children = [ #xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [ - #xmlattr{name = 'category', - value = <<"directory">>}, - #xmlattr{name = 'type', - value = <<"user">>}, - #xmlattr{name = 'name', - value = list_to_binary(translate:translate(Lang, - "vCard User Search"))}]}, + ?XMLATTR('category', <<"directory">>), + ?XMLATTR('type', <<"user">>), + ?XMLATTR('name', translate:translate(Lang, + "vCard User Search"))]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_SEARCH_s)}]}, + ?XMLATTR('var', ?NS_SEARCH_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [ - #xmlattr{name = 'var', - value = list_to_binary(?NS_VCARD_s)}]} + ?XMLATTR('var', ?NS_VCARD_s)]} ]}, ResIQ = exmpp_iq:result(Packet, Result), ejabberd_router:route(To, @@ -429,7 +424,7 @@ search_result(Lang, JID, ServerHost, Data) -> -define(FIELD(Var, Val), #xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = - [#xmlattr{name = 'var', value = Var}], children = + [?XMLATTR('var', Var)], children = [#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = Val}]}]}). diff --git a/src/web/ejabberd_http_poll.erl b/src/web/ejabberd_http_poll.erl index bd006db25..257a6f821 100644 --- a/src/web/ejabberd_http_poll.erl +++ b/src/web/ejabberd_http_poll.erl @@ -414,14 +414,14 @@ resend_message(Packet) -> get_jid("from", ParsedPacket) -> case exmpp_stanza:get_sender(ParsedPacket) of undefined -> - #jid{}; + exmpp_jid:make_jid(); From -> - exmpp_jid:binary_to_jid(From) + exmpp_jid:parse_jid(From) end; get_jid("to", ParsedPacket) -> case exmpp_stanza:get_recipient(ParsedPacket) of undefined -> - #jid{}; + exmpp_jid:make_jid(); From -> - exmpp_jid:binary_to_jid(From) + exmpp_jid:parse_jid(From) end. diff --git a/src/web/ejabberd_web.erl b/src/web/ejabberd_web.erl index 5d1abff76..0d675dee4 100644 --- a/src/web/ejabberd_web.erl +++ b/src/web/ejabberd_web.erl @@ -47,12 +47,12 @@ make_xhtml(Els) -> make_xhtml(HeadEls, Els) -> #xmlel{ns = ?NS_XHTML, name = 'html', attrs = [ - #xmlattr{ns = ?NS_XML, name = 'lang', value = "en"}, - #xmlattr{name = 'lang', value = "en"}], children = [ + exmpp_xml:attribute(?NS_XML, 'lang', <<"en">>), + ?XMLATTR('lang', <<"en">>)], children = [ #xmlel{ns = ?NS_XHTML, name = 'head', children = [ #xmlel{ns = ?NS_XHTML, name = 'meta', attrs = [ - #xmlattr{name = 'http-equiv', value = "Content-Type"}, - #xmlattr{name = 'content', value = "text/html; charset=utf-8"} + ?XMLATTR('http-equiv', <<"Content-Type">>), + ?XMLATTR('content', <<"text/html; charset=utf-8">>) ]} | HeadEls ]}, @@ -70,14 +70,14 @@ make_xhtml(HeadEls, Els) -> -define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])). -define(LI(Els), ?XE('li', Els)). --define(A(URL, Els), ?XAE('a', [#xmlattr{name = 'href', value = URL}], Els)). +-define(A(URL, Els), ?XAE('a', [?XMLATTR('href', URL)], Els)). -define(AC(URL, Text), ?A(URL, [?C(Text)])). -define(P, ?X('p')). -define(BR, ?X('br')). -define(INPUT(Type, Name, Value), - ?XA('input', [#xmlattr{name = 'type', value = Type}, - #xmlattr{name = 'name', value = Name}, - #xmlattr{name = 'value', value = Value}])). + ?XA('input', [?XMLATTR('type', Type), + ?XMLATTR('name', Name), + ?XMLATTR('value', Value)])). error(not_found) -> {404, [], make_xhtml([?XC('h1', "404 Not Found")])}; diff --git a/src/web/ejabberd_web_admin.erl b/src/web/ejabberd_web_admin.erl index aa5121bfd..dc3f7201b 100644 --- a/src/web/ejabberd_web_admin.erl +++ b/src/web/ejabberd_web_admin.erl @@ -71,7 +71,7 @@ process(["server", SHost | RPath], #request{auth = Auth} = Request) -> case get_auth(Auth) of {User, Server} -> case acl:match_rule( - Host, configure, exmpp_jid:make_bare_jid(User, Server)) of + Host, configure, exmpp_jid:make_jid(User, Server)) of deny -> ejabberd_web:error(not_allowed); allow -> @@ -93,7 +93,7 @@ process(RPath, #request{auth = Auth} = Request) -> case get_auth(Auth) of {User, Server} -> case acl:match_rule( - global, configure, exmpp_jid:make_bare_jid(User, Server)) of + global, configure, exmpp_jid:make_jid(User, Server)) of deny -> ejabberd_web:error(not_allowed); allow -> @@ -114,7 +114,9 @@ get_auth(Auth) -> case Auth of {SJID, P} -> try - #jid{node = U, domain = S} = exmpp_jid:list_to_jid(SJID), + JID = exmpp_jid:parse_jid(SJID), + U = exmpp_jid:node_as_list(JID), + S = exmpp_jid:domain_as_list(JID), case ejabberd_auth:check_password(U, S, P) of true -> {U, S}; @@ -140,44 +142,44 @@ make_xhtml(Els, Host, Node, Lang) -> MenuItems = make_navigation(Host, Node, Lang), {200, [html], #xmlel{ns = ?NS_XHTML, name = 'html', attrs = [ - #xmlattr{ns = ?NS_XML, name = 'lang', value = Lang}, - #xmlattr{name = 'lang', value = Lang}], children = + exmpp_xml:attribute(?NS_XML, 'lang', Lang), + ?XMLATTR('lang', Lang)], children = [#xmlel{ns = ?NS_XHTML, name = 'head', children = [?XCT('title', "ejabberd Web Admin"), #xmlel{ns = ?NS_XHTML, name = 'meta', attrs = [ - #xmlattr{name = 'http-equiv', value = "Content-Type"}, - #xmlattr{name = 'content', value = "text/html; charset=utf-8"}]}, + ?XMLATTR('http-equiv', <<"Content-Type">>), + ?XMLATTR('content', <<"text/html; charset=utf-8">>)]}, #xmlel{ns = ?NS_XHTML, name = 'link', attrs = [ - #xmlattr{name = 'href', value = Base ++ "favicon.ico"}, - #xmlattr{name = 'type', value = "image/x-icon"}, - #xmlattr{name = 'rel', value = "shortcut icon"}]}, + ?XMLATTR('href', Base ++ "favicon.ico"), + ?XMLATTR('type', <<"image/x-icon">>), + ?XMLATTR('rel', <<"shortcut icon">>)]}, #xmlel{ns = ?NS_XHTML, name = 'link', attrs = [ - #xmlattr{name = 'href', value = Base ++ "style.css"}, - #xmlattr{name = 'type', value = "text/css"}, - #xmlattr{name = 'rel', value = "stylesheet"}]}]}, + ?XMLATTR('href', Base ++ "style.css"), + ?XMLATTR('type', <<"text/css">>), + ?XMLATTR('rel', <<"stylesheet">>)]}]}, ?XE('body', [?XAE('div', - [#xmlattr{name = 'id', value = "container"}], + [?XMLATTR('id', <<"container">>)], [?XAE('div', - [#xmlattr{name = 'id', value = "header"}], + [?XMLATTR('id', <<"header">>)], [?XE('h1', [?ACT("/admin/", "ejabberd Web Admin")] )]), ?XAE('div', - [#xmlattr{name = 'id', value = "navigation"}], + [?XMLATTR('id', <<"navigation">>)], [?XE('ul', MenuItems )]), ?XAE('div', - [#xmlattr{name = 'id', value = "content"}], + [?XMLATTR('id', <<"content">>)], Els), ?XAE('div', - [#xmlattr{name = 'id', value = "clearcopyright"}], + [?XMLATTR('id', <<"clearcopyright">>)], [#xmlcdata{cdata = <<>>}])]), ?XAE('div', - [#xmlattr{name = 'id', value = "copyrightouter"}], + [?XMLATTR('id', <<"copyrightouter">>)], [?XAE('div', - [#xmlattr{name = 'id', value = "copyright"}], + [?XMLATTR('id', <<"copyright">>)], [?XC('p', "ejabberd (c) 2002-2009 ProcessOne") ])])]) @@ -678,7 +680,7 @@ process_admin(Host, error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?TEXTAREA("acls", integer_to_list(lists:max([16, NumLines])), "80", ACLsP++"."), ?BR, ?INPUTT("submit", "submit", "Submit") @@ -719,7 +721,7 @@ process_admin(Host, nothing -> [] end ++ [?XE('p', [?ACT("../acls-raw/", "Raw")])] ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [acls_to_xhtml(ACLs), ?BR, ?INPUTT("submit", "delete", "Delete Selected"), @@ -785,7 +787,7 @@ process_admin(Host, error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?TEXTAREA("access", integer_to_list(lists:max([16, NumLines])), "80", AccessP++"."), ?BR, ?INPUTT("submit", "submit", "Submit") @@ -821,7 +823,7 @@ process_admin(Host, nothing -> [] end ++ [?XE('p', [?ACT("../access-raw/", "Raw")])] ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [access_rules_to_xhtml(AccessRules, Lang), ?BR, ?INPUTT("submit", "delete", "Delete Selected") @@ -860,7 +862,7 @@ process_admin(Host, error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [access_rule_to_xhtml(Rules), ?BR, ?INPUTT("submit", "submit", "Submit") @@ -911,17 +913,17 @@ process_admin(Host, list_last_activity(Host, Lang, true, Month) end, make_xhtml([?XCT('h1', "Users Last Activity")] ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?CT("Period: "), - ?XAE('select', [#xmlattr{name = 'name', value = "period"}], + ?XAE('select', [?XMLATTR('name', <<"period">>)], lists:map( fun({O, V}) -> Sel = if - O == Month -> [#xmlattr{name = 'selected', value = "selected"}]; + O == Month -> [?XMLATTR('selected', <<"selected">>)]; true -> [] end, ?XAC('option', - Sel ++ [#xmlattr{name = 'value', value = O}], V) + Sel ++ [?XMLATTR('value', O)], V) end, [{"month", ?T("Last month")}, {"year", ?T("Last year")}, {"all", ?T("All activity")}])), @@ -1046,15 +1048,15 @@ acl_spec_to_xhtml(ID, Spec) -> acl_spec_select(ID, Opt) -> ?XE('td', - [?XAE('select', [#xmlattr{name = 'name', value = "type" ++ ID}], + [?XAE('select', [?XMLATTR('name', "type" ++ ID)], lists:map( fun(O) -> Sel = if - O == Opt -> [#xmlattr{name = 'selected', value = "selected"}]; + O == Opt -> [?XMLATTR('selected', <<"selected">>)]; true -> [] end, ?XAC('option', - Sel ++ [#xmlattr{name = 'value', value = atom_to_list(O)}], + Sel ++ [?XMLATTR('value', O)], atom_to_list(O)) end, [user, server, user_regexp, server_regexp, node_regexp, user_glob, server_glob, node_glob, all, raw]))]). @@ -1135,14 +1137,20 @@ string_to_spec("user_regexp", Val) -> string_to_spec("server_regexp", Val) -> {server_regexp, Val}; string_to_spec("node_regexp", Val) -> - #jid{lnode = U, ldomain = S, resource = undefined} = exmpp_jid:list_to_jid(Val), + JID = exmpp_jid:parse_jid(Val), + U = exmpp_jid:lnode_as_list(JID), + S = exmpp_jid:ldomain_as_list(JID), + undefined = exmpp_jid:resource(JID), {node_regexp, U, S}; string_to_spec("user_glob", Val) -> string_to_spec2(user_glob, Val); string_to_spec("server_glob", Val) -> {server_glob, Val}; string_to_spec("node_glob", Val) -> - #jid{lnode = U, ldomain = S, resource = undefined} = exmpp_jid:list_to_jid(Val), + JID = exmpp_jid:parse_jid(Val), + U = exmpp_jid:lnode_as_list(JID), + S = exmpp_jid:ldomain_as_list(JID), + undefined = exmpp_jid:resource(JID), {node_glob, U, S}; string_to_spec("all", _) -> all; @@ -1152,9 +1160,12 @@ string_to_spec("raw", Val) -> NewSpec. string_to_spec2(ACLName, Val) -> - #jid{lnode = U, ldomain = S, resource = undefined} = exmpp_jid:list_to_jid(Val), + JID = exmpp_jid:parse_jid(Val), + U = exmpp_jid:lnode_as_list(JID), + S = exmpp_jid:ldomain_as_list(JID), + undefined = exmpp_jid:resource(JID), case U of - "" -> + undefined -> {ACLName, S}; _ -> {ACLName, U, S} @@ -1322,7 +1333,7 @@ list_users(Host, Query, Lang, URLFunc) -> error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?XE('table', [?XE('tr', [?XC('td', ?T("User") ++ ":"), @@ -1336,7 +1347,7 @@ list_users(Host, Query, Lang, URLFunc) -> ]), ?XE('tr', [?X('td'), - ?XAE('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAE('td', [?XMLATTR('class', <<"alignright">>)], [?INPUTT("submit", "addnewuser", "Add User")]), ?X('td') ])]), @@ -1352,7 +1363,9 @@ list_users_parse_query(Query, Host) -> {value, {_, Password}} = lists:keysearch("newuserpassword", 1, Query), try - #jid{node = User, domain = Server} = exmpp_jid:list_to_jid(Username++"@"++Host), + JID = exmpp_jid:parse_jid(Username++"@"++Host), + User = exmpp_jid:node(JID), + Server = exmpp_jid:domain(JID), case ejabberd_auth:try_register(User, Server, Password) of {error, _Reason} -> error; @@ -1519,7 +1532,7 @@ user_info(User, Server, Query, Lang) -> error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?XCT('h3', "Connected Resources:")] ++ FResources ++ [?XCT('h3', "Password:")] ++ FPassword ++ UserItems ++ @@ -1598,11 +1611,11 @@ list_last_activity(Host, Lang, Integral, Period) -> end, Max = lists:max(Hist), [?XAE('ol', - [#xmlattr{name = 'id', value = "lastactivity"}, #xmlattr{name = 'start', value = "0"}], + [?XMLATTR('id', <<"lastactivity">>), ?XMLATTR('start', <<"0">>)], [?XAE('li', - [#xmlattr{name = 'style', value = + [?XMLATTR('style', "width:" ++ integer_to_list( - trunc(90 * V / Max)) ++ "%;"}], + trunc(90 * V / Max)) ++ "%;")], [#xmlcdata{cdata = list_to_binary(integer_to_list(V))}]) || V <- Hist ++ Tail])] end @@ -1694,7 +1707,7 @@ get_node(global, Node, [], Query, Lang) -> ?LI([?ACT(Base ++ "stats/", "Statistics")]), ?LI([?ACT(Base ++ "update/", "Update")]) ] ++ MenuItems2), - ?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + ?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?INPUTT('submit', "restart", "Restart"), ?C(" "), ?INPUTT('submit', "stop", "Stop")]) @@ -1746,15 +1759,15 @@ get_node(global, Node, ["db"], Query, Lang) -> [?XC('td', STable), ?XE('td', [db_storage_select( STable, Type, Lang)]), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(Size)), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(Memory)) ]) end, STables), [?XC('h1', ?T("Database Tables at ") ++ atom_to_list(Node))] ++ ResS ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?XAE('table', [], [?XE('thead', [?XE('tr', @@ -1766,8 +1779,8 @@ get_node(global, Node, ["db"], Query, Lang) -> ?XE('tbody', Rows ++ [?XE('tr', - [?XAE('td', [#xmlattr{name = 'colspan', value = "4"}, - #xmlattr{name = 'class', value = "alignright"}], + [?XAE('td', [?XMLATTR('colspan', <<"4">>), + ?XMLATTR('class', <<"alignright">>)], [?INPUTT("submit", "submit", "Submit")]) ])] @@ -1783,7 +1796,7 @@ get_node(global, Node, ["backup"], Query, Lang) -> [?XC('h1', ?T("Backup of ") ++ atom_to_list(Node))] ++ ResS ++ [?XCT('p', "Remark that these options will only backup the builtin Mnesia database. If you are using the ODBC module, you also need to backup your SQL database separately."), - ?XAE('form', [#xmlattr{name = 'action', value = <<>>}, #xmlattr{name = 'method', value = <<"post">>}], + ?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [?XAE('table', [], [?XE('tbody', [?XE('tr', @@ -1850,7 +1863,7 @@ get_node(global, Node, ["ports"], Query, Lang) -> {error, ReasonT} -> [?XRES(?T("Error") ++ ": " ++ ReasonT)]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [node_ports_to_xhtml(NewPorts, Lang)]) ]; @@ -1874,7 +1887,7 @@ get_node(Host, Node, ["modules"], Query, Lang) when is_list(Host) -> error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [node_modules_to_xhtml(NewModules, Lang)]) ]; @@ -1897,25 +1910,25 @@ get_node(global, Node, ["stats"], _Query, Lang) -> ?XAE('table', [], [?XE('tbody', [?XE('tr', [?XCT('td', "Uptime:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], UpTimeS)]), ?XE('tr', [?XCT('td', "CPU Time:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], CPUTimeS)]), ?XE('tr', [?XCT('td', "Online Users:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(OnlineUsers))]), ?XE('tr', [?XCT('td', "Transactions Committed:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(TransactionsCommitted))]), ?XE('tr', [?XCT('td', "Transactions Aborted:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(TransactionsAborted))]), ?XE('tr', [?XCT('td', "Transactions Restarted:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(TransactionsRestarted))]), ?XE('tr', [?XCT('td', "Transactions Logged:"), - ?XAC('td', [#xmlattr{name = 'class', value = "alignright"}], + ?XAC('td', [?XMLATTR('class', <<"alignright">>)], integer_to_list(TransactionsLogged))]) ]) ])]; @@ -1943,7 +1956,7 @@ get_node(global, Node, ["update"], Query, Lang) -> error -> [?XREST("Bad format")]; nothing -> [] end ++ - [?XAE('form', [#xmlattr{name = 'action', value = ""}, #xmlattr{name = 'method', value = "post"}], + [?XAE('form', [?XMLATTR('action', <<>>), ?XMLATTR('method', <<"post">>)], [ ?XCT('h2', "Update plan"), ?XCT('h3', "Modified modules"), Mods, @@ -1991,15 +2004,15 @@ node_parse_query(Node, Query) -> db_storage_select(ID, Opt, Lang) -> - ?XAE('select', [#xmlattr{name = 'name', value = "table" ++ ID}], + ?XAE('select', [?XMLATTR('name', "table" ++ ID)], lists:map( fun({O, Desc}) -> Sel = if - O == Opt -> [#xmlattr{name = 'selected', value = "selected"}]; + O == Opt -> [?XMLATTR('selected', <<"selected">>)]; true -> [] end, ?XACT('option', - Sel ++ [#xmlattr{name = 'value', value = atom_to_list(O)}], + Sel ++ [?XMLATTR('value', O)], Desc) end, [{ram_copies, "RAM copy"}, {disc_copies, "RAM and disc copy"}, @@ -2088,7 +2101,7 @@ node_backup_parse_query(Node, Query) -> node_ports_to_xhtml(Ports, Lang) -> - ?XAE('table', [#xmlattr{name = 'class', value = <<"withtextareas">>}], + ?XAE('table', [?XMLATTR('class', <<"withtextareas">>)], [?XE('thead', [?XE('tr', [?XCT('td', "Port"), @@ -2105,8 +2118,8 @@ node_ports_to_xhtml(Ports, Lang) -> {NumLines, SOptsClean} = term_to_paragraph(OptsClean, 40), %%ID = term_to_id(E), ?XE('tr', - [?XAE('td', [#xmlattr{name = 'size', value = <<"6">>}], [?C(SPort)]), - ?XAE('td', [#xmlattr{name = 'size', value = <<"15">>}], [?C(SIP)]), + [?XAE('td', [?XMLATTR('size', <<"6">>)], [?C(SPort)]), + ?XAE('td', [?XMLATTR('size', <<"15">>)], [?C(SIP)]), ?XE('td', [?INPUTS("text", "module" ++ SSPort, SModule, "15")]), ?XE('td', [?TEXTAREA("opts" ++ SSPort, integer_to_list(NumLines), "35", SOptsClean)]), @@ -2199,7 +2212,7 @@ node_ports_parse_query(Node, Ports, Query) -> end. node_modules_to_xhtml(Modules, Lang) -> - ?XAE('table', [#xmlattr{name = 'class', value = <<"withtextareas">>}], + ?XAE('table', [?XMLATTR('class', <<"withtextareas">>)], [?XE('thead', [?XE('tr', [?XCT('td', "Module"), @@ -2424,14 +2437,14 @@ make_menu_items2(Lang, Deep, {MURI, MName, [Item | Items]}, Res) -> make_menu_items2(Lang, Deep, {MURI, MName, Items}, Res2). make_menu_item(header, 1, URI, Name, _Lang) -> - ?LI([?XAE('div', [#xmlattr{name = 'id', value = <<"navhead">>}], [?AC(URI, Name)] )]); + ?LI([?XAE('div', [?XMLATTR('id', <<"navhead">>)], [?AC(URI, Name)] )]); make_menu_item(header, 2, URI, Name, _Lang) -> - ?LI([?XAE('div', [#xmlattr{name = 'id', value = <<"navheadsub">>}], [?AC(URI, Name)] )]); + ?LI([?XAE('div', [?XMLATTR('id', <<"navheadsub">>)], [?AC(URI, Name)] )]); make_menu_item(header, 3, URI, Name, _Lang) -> - ?LI([?XAE('div', [#xmlattr{name = 'id', value = <<"navheadsubsub">>}], [?AC(URI, Name)] )]); + ?LI([?XAE('div', [?XMLATTR('id', <<"navheadsubsub">>)], [?AC(URI, Name)] )]); make_menu_item(item, 1, URI, Name, Lang) -> - ?LI([?XAE('div', [#xmlattr{name = 'id', value = "navitem"}], [?ACT(URI, Name)] )]); + ?LI([?XAE('div', [?XMLATTR('id', <<"navitem">>)], [?ACT(URI, Name)] )]); make_menu_item(item, 2, URI, Name, Lang) -> - ?LI([?XAE('div', [#xmlattr{name = 'id', value = "navitemsub"}], [?ACT(URI, Name)] )]); + ?LI([?XAE('div', [?XMLATTR('id', <<"navitemsub">>)], [?ACT(URI, Name)] )]); make_menu_item(item, 3, URI, Name, Lang) -> - ?LI([?XAE('div', [#xmlattr{name = 'id', value = "navitemsubsub"}], [?ACT(URI, Name)] )]). + ?LI([?XAE('div', [?XMLATTR('id', <<"navitemsubsub">>)], [?ACT(URI, Name)] )]).