24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-14 22:00:16 +02:00

Adapt to new exmpp API where get_id/1, get_lang/1, get_initiating_entity/1, get_receiving_entity/1 and get_type/1 returns binary().

SVN Revision: 1791
This commit is contained in:
Pablo Polvorin 2009-01-09 19:18:46 +00:00
parent d2524b20d5
commit 98f51dc91f
16 changed files with 136 additions and 103 deletions

View File

@ -1,3 +1,20 @@
2009-01-09 Pablo Polvorin <pablo.polvorin@process-one.net>
* src/mod_muc/mod_muc_room.erl, src/mod_muc/mod_muc.erl
src/mod_offline_odbc.erl, src/mod_irc/mod_irc_connection.erl,
src/mod_irc/mod_irc.erl, src/ejabberd_c2s.erl, src/ejabberd_local.erl,
src/mod_pubsub/mod_pubsub.erl, src/ejabberd_s2s.erl, src/mod_roster.erl,
src/mod_roster_odbc.erl, src/ejabberd_s2s_out.erl, src/mod_offline.erl,
src/translate.erl: Adapt to new exmpp API where get_id/1, get_lang/1,
get_initiating_entity/1, get_receiving_entity/1 and get_type/1
returns binary().
* src/mod_pubsub/node_default.erl: Fix typo in variable name.
* src/ejabberd_c2s.erl: Fix bug in handle_info/3 when dealing with
VCARD requests: convert to IQ struct before invoking gen_iq_handler.
2009-01-08 Christophe Romain <christophe.romain@process-one.net> 2009-01-08 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: completely support subscription using * src/mod_pubsub/mod_pubsub.erl: completely support subscription using

View File

@ -239,9 +239,9 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
StateData#state.streamid, DefaultLang), StateData#state.streamid, DefaultLang),
case NS of case NS of
?NS_XMPP -> ?NS_XMPP ->
Server = exmpp_stringprep:nameprep( ServerB = exmpp_stringprep:nameprep(
exmpp_stream:get_receiving_entity(Opening)), exmpp_stream:get_receiving_entity(Opening)),
ServerB = list_to_binary(Server), Server = binary_to_list(ServerB),
case lists:member(Server, ?MYHOSTS) of case lists:member(Server, ?MYHOSTS) of
true -> true ->
Lang = exmpp_stream:get_lang(Opening), Lang = exmpp_stream:get_lang(Opening),
@ -900,9 +900,9 @@ session_established2(El, StateData) ->
catch catch
throw:{stringprep, _, _, _} -> throw:{stringprep, _, _, _} ->
case exmpp_stanza:get_type(El) of case exmpp_stanza:get_type(El) of
"error" -> <<"error">> ->
ok; ok;
"result" -> <<"result">> ->
ok; ok;
_ -> _ ->
Err = exmpp_stanza:reply_with_error(El, 'jid-malformed'), Err = exmpp_stanza:reply_with_error(El, 'jid-malformed'),
@ -1166,7 +1166,7 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
case ets:lookup(sm_iqtable, {?NS_VCARD, Host}) of case ets:lookup(sm_iqtable, {?NS_VCARD, Host}) of
[{_, Module, Function, Opts}] -> [{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts, gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet); From, To, exmpp_iq:xmlel_to_iq(Packet));
[] -> [] ->
Res = exmpp_iq:error(Packet, 'feature-not-implemented'), Res = exmpp_iq:error(Packet, 'feature-not-implemented'),
ejabberd_router:route(To, From, Res) ejabberd_router:route(To, From, Res)
@ -1857,7 +1857,6 @@ resend_subscription_requests(#state{user = UserB,
PendingSubscriptions). PendingSubscriptions).
process_unauthenticated_stanza(StateData, El) when ?IS_IQ(El) -> process_unauthenticated_stanza(StateData, El) when ?IS_IQ(El) ->
ServerString = binary_to_list(StateData#state.server),
case exmpp_iq:get_kind(El) of case exmpp_iq:get_kind(El) of
request -> request ->
IQ_Rec = exmpp_iq:xmlel_to_iq(El), IQ_Rec = exmpp_iq:xmlel_to_iq(El),
@ -1873,7 +1872,7 @@ process_unauthenticated_stanza(StateData, El) when ?IS_IQ(El) ->
ResIQ = exmpp_iq:error_without_original(El, ResIQ = exmpp_iq:error_without_original(El,
'service-unavailable'), 'service-unavailable'),
Res1 = exmpp_stanza:set_sender(ResIQ, Res1 = exmpp_stanza:set_sender(ResIQ,
exmpp_jid:make_bare_jid(ServerString)), exmpp_jid:make_bare_jid(StateData#state.server)),
Res2 = exmpp_stanza:remove_recipient(Res1), Res2 = exmpp_stanza:remove_recipient(Res1),
send_element(StateData, Res2); send_element(StateData, Res2);
_ -> _ ->

View File

@ -321,8 +321,8 @@ do_route(From, To, Packet) ->
end; end;
true -> true ->
case exmpp_stanza:get_type(Packet) of case exmpp_stanza:get_type(Packet) of
"error" -> ok; <<"error">> -> ok;
"result" -> ok; <<"result">> -> ok;
_ -> _ ->
ejabberd_hooks:run(local_send_to_resource_hook, ejabberd_hooks:run(local_send_to_resource_hook,
exmpp_jid:ldomain(To), exmpp_jid:ldomain(To),

View File

@ -290,8 +290,8 @@ do_route(From, To, Packet) ->
ok; ok;
{aborted, _Reason} -> {aborted, _Reason} ->
case exmpp_stanza:get_type(Packet) of case exmpp_stanza:get_type(Packet) of
"error" -> ok; <<"error">> -> ok;
"result" -> ok; <<"result">> -> ok;
_ -> _ ->
Err = exmpp_stanza:reply_with_error(Packet, Err = exmpp_stanza:reply_with_error(Packet,
'service-unavailable'), 'service-unavailable'),

View File

@ -803,8 +803,8 @@ send_queue(StateData, Q) ->
%% Bounce a single message (xmlel) %% Bounce a single message (xmlel)
bounce_element(El, Condition) -> bounce_element(El, Condition) ->
case exmpp_stanza:get_type(El) of case exmpp_stanza:get_type(El) of
"error" -> ok; <<"error">> -> ok;
"result" -> ok; <<"result">> -> ok;
_ -> _ ->
Err = exmpp_stanza:reply_with_error(El, Condition), Err = exmpp_stanza:reply_with_error(El, Condition),
From = exmpp_jid:binary_to_jid(exmpp_stanza:get_sender(El)), From = exmpp_jid:binary_to_jid(exmpp_stanza:get_sender(El)),
@ -882,14 +882,14 @@ is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'result',
exmpp_stanza:get_recipient_from_attrs(Attrs), exmpp_stanza:get_recipient_from_attrs(Attrs),
exmpp_stanza:get_sender_from_attrs(Attrs), exmpp_stanza:get_sender_from_attrs(Attrs),
exmpp_stanza:get_id_from_attrs(Attrs), exmpp_stanza:get_id_from_attrs(Attrs),
exmpp_stanza:get_type_from_attrs(Attrs)}; binary_to_list(exmpp_stanza:get_type_from_attrs(Attrs))};
is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'verify', is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'verify',
attrs = Attrs}) -> attrs = Attrs}) ->
{verify, {verify,
exmpp_stanza:get_recipient_from_attrs(Attrs), exmpp_stanza:get_recipient_from_attrs(Attrs),
exmpp_stanza:get_sender_from_attrs(Attrs), exmpp_stanza:get_sender_from_attrs(Attrs),
exmpp_stanza:get_id_from_attrs(Attrs), exmpp_stanza:get_id_from_attrs(Attrs),
exmpp_stanza:get_type_from_attrs(Attrs)}; binary_to_list(exmpp_stanza:get_type_from_attrs(Attrs))};
is_verify_res(_) -> is_verify_res(_) ->
false. false.

View File

@ -371,10 +371,10 @@ process_irc_register(Host, From, _To, _DefEnc,
exmpp_iq:error(IQ_Rec, 'not-acceptable'); exmpp_iq:error(IQ_Rec, 'not-acceptable');
_ -> _ ->
case exmpp_stanza:get_type(XDataEl) of case exmpp_stanza:get_type(XDataEl) of
"cancel" -> <<"cancel">> ->
Result = #xmlel{ns = XMLNS, name = 'query'}, Result = #xmlel{ns = XMLNS, name = 'query'},
exmpp_iq:result(IQ_Rec, Result); exmpp_iq:result(IQ_Rec, Result);
"submit" -> <<"submit">> ->
XData = jlib:parse_xdata_submit(XDataEl), XData = jlib:parse_xdata_submit(XDataEl),
case XData of case XData of
invalid -> invalid ->

View File

@ -625,7 +625,7 @@ bounce_messages(Reason) ->
receive receive
{send_element, El} -> {send_element, El} ->
case exmpp_stanza:get_type(El) of case exmpp_stanza:get_type(El) of
"error" -> <<"error">> ->
ok; ok;
_ -> _ ->
Error = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'error', Error = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'error',

View File

@ -401,9 +401,9 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
end; end;
_ -> _ ->
case exmpp_stanza:get_type(Packet) of case exmpp_stanza:get_type(Packet) of
"error" -> <<"error">> ->
ok; ok;
"result" -> <<"result">> ->
ok; ok;
_ -> _ ->
Err = exmpp_iq:error(Packet,'item-not-found'), Err = exmpp_iq:error(Packet,'item-not-found'),
@ -638,9 +638,9 @@ process_iq_register_set(Host, From, SubEl, Lang) ->
case exmpp_xml:get_child_elements(SubEl) of case exmpp_xml:get_child_elements(SubEl) of
[#xmlel{ns= NS, name = 'x'} = XEl] -> [#xmlel{ns= NS, name = 'x'} = XEl] ->
case {NS, exmpp_stanza:get_type(XEl)} of case {NS, exmpp_stanza:get_type(XEl)} of
{?NS_DATA_FORMS, "cancel"} -> {?NS_DATA_FORMS, <<"cancel">>} ->
ok; ok;
{?NS_DATA_FORMS, "submit"} -> {?NS_DATA_FORMS, <<"submit">>} ->
XData = jlib:parse_xdata_submit(XEl), XData = jlib:parse_xdata_submit(XEl),
case XData of case XData of
invalid -> invalid ->

View File

@ -966,38 +966,38 @@ is_user_online(JID, StateData) ->
LJID = jlib:short_prepd_jid(JID), LJID = jlib:short_prepd_jid(JID),
?DICT:is_key(LJID, StateData#state.users). ?DICT:is_key(LJID, StateData#state.users).
role_to_list(Role) -> role_to_binary(Role) ->
case Role of case Role of
moderator -> "moderator"; moderator -> <<"moderator">>;
participant -> "participant"; participant -> <<"participant">>;
visitor -> "visitor"; visitor -> <<"visitor">>;
none -> "none" none -> <<"none">>
end. end.
affiliation_to_list(Affiliation) -> affiliation_to_binary(Affiliation) ->
case Affiliation of case Affiliation of
owner -> "owner"; owner -> <<"owner">>;
admin -> "admin"; admin -> <<"admin">>;
member -> "member"; member -> <<"member">>;
outcast -> "outcast"; outcast -> <<"outcast">>;
none -> "none" none -> <<"none">>
end. end.
list_to_role(Role) -> binary_to_role(Role) ->
case Role of case Role of
"moderator" -> moderator; <<"moderator">> -> moderator;
"participant" -> participant; <<"participant">> -> participant;
"visitor" -> visitor; <<"visitor">> -> visitor;
"none" -> none <<"none">> -> none
end. end.
list_to_affiliation(Affiliation) -> binary_to_affiliation(Affiliation) ->
case Affiliation of case Affiliation of
"owner" -> owner; <<"owner">> -> owner;
"admin" -> admin; <<"admin">> -> admin;
"member" -> member; <<"member">> -> member;
"outcast" -> outcast; <<"outcast">> -> outcast;
"none" -> none <<"none">> -> none
end. end.
%% Decide the fate of the message and its sender %% Decide the fate of the message and its sender
@ -1758,8 +1758,8 @@ send_new_presence(NJID, Reason, StateData) ->
last_presence = Presence}} = last_presence = Presence}} =
?DICT:find(jlib:short_prepd_jid(NJID), StateData#state.users), ?DICT:find(jlib:short_prepd_jid(NJID), StateData#state.users),
Affiliation = get_affiliation(NJID, StateData), Affiliation = get_affiliation(NJID, StateData),
SAffiliation = affiliation_to_list(Affiliation), SAffiliation = affiliation_to_binary(Affiliation),
SRole = role_to_list(Role), SRole = role_to_binary(Role),
lists:foreach( lists:foreach(
fun({_LJID, Info}) -> fun({_LJID, Info}) ->
ItemAttrs = ItemAttrs =
@ -1824,12 +1824,12 @@ send_existing_presences(ToJID, StateData) ->
true -> true ->
[#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(FromJID)}, [#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(FromJID)},
#xmlattr{name = 'affiliation', #xmlattr{name = 'affiliation',
value = affiliation_to_list(FromAffiliation)}, value = affiliation_to_binary(FromAffiliation)},
#xmlattr{name = 'role', value = role_to_list(FromRole)}]; #xmlattr{name = 'role', value = role_to_binary(FromRole)}];
_ -> _ ->
[#xmlattr{name = 'affiliation', [#xmlattr{name = 'affiliation',
value = affiliation_to_list(FromAffiliation)}, value = affiliation_to_binary(FromAffiliation)},
#xmlattr{name = 'role', value = role_to_list(FromRole)}] #xmlattr{name = 'role', value = role_to_binary(FromRole)}]
end, end,
Packet = exmpp_xml:append_child(Presence, Packet = exmpp_xml:append_child(Presence,
#xmlel{ns = ?NS_MUC_USER, name = 'x', #xmlel{ns = ?NS_MUC_USER, name = 'x',
@ -1871,8 +1871,8 @@ send_nick_changing(JID, OldNick, StateData) ->
last_presence = Presence}} = last_presence = Presence}} =
?DICT:find(jlib:short_prepd_jid(JID), StateData#state.users), ?DICT:find(jlib:short_prepd_jid(JID), StateData#state.users),
Affiliation = get_affiliation(JID, StateData), Affiliation = get_affiliation(JID, StateData),
SAffiliation = affiliation_to_list(Affiliation), SAffiliation = affiliation_to_binary(Affiliation),
SRole = role_to_list(Role), SRole = role_to_binary(Role),
lists:foreach( lists:foreach(
fun({_LJID, Info}) -> fun({_LJID, Info}) ->
ItemAttrs1 = ItemAttrs1 =
@ -2030,13 +2030,13 @@ process_iq_admin(From, get, Lang, SubEl, StateData) ->
Item -> Item ->
FAffiliation = get_affiliation(From, StateData), FAffiliation = get_affiliation(From, StateData),
FRole = get_role(From, StateData), FRole = get_role(From, StateData),
case exmpp_xml:get_attribute(Item, 'role', false) of case exmpp_xml:get_attribute_as_binary(Item, 'role', false) of
false -> false ->
case exmpp_xml:get_attribute(Item, 'affiliation', false) of case exmpp_xml:get_attribute_as_binary(Item, 'affiliation', false) of
false -> false ->
{error, 'bad-request'}; {error, 'bad-request'};
StrAffiliation -> StrAffiliation ->
case catch list_to_affiliation(StrAffiliation) of case catch binary_to_affiliation(StrAffiliation) of
{'EXIT', _} -> {'EXIT', _} ->
{error, 'bad-request'}; {error, 'bad-request'};
SAffiliation -> SAffiliation ->
@ -2053,7 +2053,7 @@ process_iq_admin(From, get, Lang, SubEl, StateData) ->
end end
end; end;
StrRole -> StrRole ->
case catch list_to_role(StrRole) of case catch binary_to_role(StrRole) of
{'EXIT', _} -> {'EXIT', _} ->
{error, 'bad-request'}; {error, 'bad-request'};
SRole -> SRole ->
@ -2082,9 +2082,9 @@ items_with_affiliation(SAffiliation, StateData) ->
{N, D, R} = JID, {N, D, R} = JID,
#xmlel{name = 'item', #xmlel{name = 'item',
attrs = [#xmlattr{name = 'affiliation', attrs = [#xmlattr{name = 'affiliation',
value = affiliation_to_list(Affiliation)}, value = affiliation_to_binary(Affiliation)},
#xmlattr{name = 'jid', #xmlattr{name = 'jid',
value = exmpp_jid:jid_to_list(N, D, R)}], value = exmpp_jid:jid_to_binary(N, D, R)}],
children = [ #xmlel{name = 'reason', children = [ #xmlel{name = 'reason',
children = [#xmlcdata{cdata = Reason}]}]}; children = [#xmlcdata{cdata = Reason}]}]};
@ -2092,9 +2092,9 @@ items_with_affiliation(SAffiliation, StateData) ->
{N, D, R} = JID, {N, D, R} = JID,
#xmlel{name = 'item', #xmlel{name = 'item',
attrs = [#xmlattr{name = 'affiliation', attrs = [#xmlattr{name = 'affiliation',
value = affiliation_to_list(Affiliation)}, value = affiliation_to_binary(Affiliation)},
#xmlattr{name = 'jid', #xmlattr{name = 'jid',
value = exmpp_jid:jid_to_list(N, D, R)}]} value = exmpp_jid:jid_to_binary(N, D, R)}]}
end, search_affiliation(SAffiliation, StateData)). end, search_affiliation(SAffiliation, StateData)).
user_to_item(#user{role = Role, user_to_item(#user{role = Role,
@ -2104,10 +2104,10 @@ user_to_item(#user{role = Role,
Affiliation = get_affiliation(JID, StateData), Affiliation = get_affiliation(JID, StateData),
#xmlel{name = 'item', #xmlel{name = 'item',
attrs = [ attrs = [
#xmlattr{name = 'role', value = role_to_list(Role)}, #xmlattr{name = 'role', value = role_to_binary(Role)},
#xmlattr{name = 'affiliation', value = affiliation_to_list(Affiliation)}, #xmlattr{name = 'affiliation', value = affiliation_to_binary(Affiliation)},
#xmlattr{name = 'nick', value = Nick}, #xmlattr{name = 'nick', value = Nick},
#xmlattr{name = 'jid', value = exmpp_jid:jid_to_list(JID)}] #xmlattr{name = 'jid', value = exmpp_jid:jid_to_binary(JID)}]
}. }.
search_role(Role, StateData) -> search_role(Role, StateData) ->
@ -2225,9 +2225,9 @@ find_changed_items(UJID, UAffiliation, URole, [#xmlcdata{} | Items],
find_changed_items(UJID, UAffiliation, URole, find_changed_items(UJID, UAffiliation, URole,
[#xmlel{name = 'item'} = Item | Items], [#xmlel{name = 'item'} = Item | Items],
Lang, StateData, Res) -> Lang, StateData, Res) ->
TJID = case exmpp_xml:get_attribute(Item, 'jid',false) of TJID = case exmpp_xml:get_attribute_as_binary(Item, 'jid',false) of
S when S =/= false -> S when S =/= false ->
try exmpp_jid:list_to_jid(S) of try exmpp_jid:binary_to_jid(S) of
J -> J ->
{value, J} {value, J}
catch catch
@ -2261,13 +2261,13 @@ find_changed_items(UJID, UAffiliation, URole,
{value, JID} -> {value, JID} ->
TAffiliation = get_affiliation(JID, StateData), TAffiliation = get_affiliation(JID, StateData),
TRole = get_role(JID, StateData), TRole = get_role(JID, StateData),
case exmpp_xml:get_attribute(Item, 'role',false) of case exmpp_xml:get_attribute_as_binary(Item, 'role',false) of
false -> false ->
case exmpp_xml:get_attribute(Item, 'affiliation', false) of case exmpp_xml:get_attribute_as_binary(Item, 'affiliation', false) of
false -> false ->
{error, 'bad-request'}; {error, 'bad-request'};
StrAffiliation -> StrAffiliation ->
case catch list_to_affiliation(StrAffiliation) of case catch binary_to_affiliation(StrAffiliation) of
{'EXIT', _} -> {'EXIT', _} ->
ErrText1 = ErrText1 =
io_lib:format( io_lib:format(
@ -2324,7 +2324,7 @@ find_changed_items(UJID, UAffiliation, URole,
end end
end; end;
StrRole -> StrRole ->
case catch list_to_role(StrRole) of case catch binary_to_role(StrRole) of
{'EXIT', _} -> {'EXIT', _} ->
ErrText1 = ErrText1 =
io_lib:format( io_lib:format(
@ -2566,7 +2566,7 @@ send_kickban_presence1(UJID, Reason, Code, StateData) ->
nick = Nick}} = ?DICT:find(UJID, StateData#state.users), nick = Nick}} = ?DICT:find(UJID, StateData#state.users),
{N,D,R} = UJID, {N,D,R} = UJID,
Affiliation = get_affiliation(exmpp_jid:make_jid(N,D,R), StateData), Affiliation = get_affiliation(exmpp_jid:make_jid(N,D,R), StateData),
SAffiliation = affiliation_to_list(Affiliation), SAffiliation = affiliation_to_binary(Affiliation),
lists:foreach( lists:foreach(
fun({_LJID, Info}) -> fun({_LJID, Info}) ->
ItemAttrs = [#xmlattr{name = 'affiliation', value = SAffiliation}, ItemAttrs = [#xmlattr{name = 'affiliation', value = SAffiliation},
@ -2607,10 +2607,10 @@ process_iq_owner(From, set, Lang, SubEl, StateData) ->
owner -> owner ->
case exmpp_xml:get_child_elements(SubEl) of case exmpp_xml:get_child_elements(SubEl) of
[#xmlel{ns = XMLNS, name = 'x'} = XEl] -> [#xmlel{ns = XMLNS, name = 'x'} = XEl] ->
case {XMLNS, exmpp_xml:get_attribute(XEl, 'type',false)} of case {XMLNS, exmpp_xml:get_attribute_as_binary(XEl, 'type',false)} of
{?NS_DATA_FORMS, "cancel"} -> {?NS_DATA_FORMS, <<"cancel">>} ->
{result, [], StateData}; {result, [], StateData};
{?NS_DATA_FORMS, "submit"} -> {?NS_DATA_FORMS, <<"submit">>} ->
case {check_allowed_log_change(XEl, StateData, From), case {check_allowed_log_change(XEl, StateData, From),
check_allowed_persistent_change(XEl, StateData, From)} of check_allowed_persistent_change(XEl, StateData, From)} of
{allow, allow} -> set_config(XEl, StateData); {allow, allow} -> set_config(XEl, StateData);
@ -2639,11 +2639,11 @@ process_iq_owner(From, get, Lang, SubEl, StateData) ->
[] -> [] ->
get_config(Lang, StateData, From); get_config(Lang, StateData, From);
[Item] -> [Item] ->
case exmpp_xml:get_attribute(Item, 'affiliation',false) of case exmpp_xml:get_attribute_as_binary(Item, 'affiliation',false) of
false -> false ->
{error, 'bad-request'}; {error, 'bad-request'};
StrAffiliation -> StrAffiliation ->
case catch list_to_affiliation(StrAffiliation) of case catch binary_to_affiliation(StrAffiliation) of
{'EXIT', _} -> {'EXIT', _} ->
ErrText = ErrText =
io_lib:format( io_lib:format(
@ -3227,7 +3227,7 @@ check_invitation(From, Els, Lang, StateData) ->
_ -> _ ->
throw({error, 'bad-request'}) throw({error, 'bad-request'})
end, end,
JID = try exmpp_jid:list_to_jid(exmpp_xml:get_attribute(InviteEl, JID = try exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(InviteEl,
'to', 'to',
false)) of false)) of
JID1 -> JID1 JID1 -> JID1
@ -3330,8 +3330,8 @@ check_decline_invitation(Packet) ->
#xmlel{name = 'message'} = Packet, #xmlel{name = 'message'} = Packet,
#xmlel{ns = ?NS_MUC_USER} = XEl = exmpp_xml:get_element(Packet, 'x'), #xmlel{ns = ?NS_MUC_USER} = XEl = exmpp_xml:get_element(Packet, 'x'),
DEl = exmpp_xml:get_element(XEl, 'decline'), DEl = exmpp_xml:get_element(XEl, 'decline'),
ToString = exmpp_xml:get_attribute(DEl, 'to', false), ToString = exmpp_xml:get_attribute_as_binary(DEl, 'to', false),
ToJID = exmpp_jid:list_to_jid(ToString), ToJID = exmpp_jid:binary_to_jid(ToString),
{true, {Packet, XEl, DEl, ToJID}}. {true, {Packet, XEl, DEl, ToJID}}.
%% Send the decline to the inviter user. %% Send the decline to the inviter user.

View File

@ -157,8 +157,8 @@ stop(Host) ->
store_packet(From, To, Packet) -> store_packet(From, To, Packet) ->
Type = exmpp_stanza:get_type(Packet), Type = exmpp_stanza:get_type(Packet),
if if
(Type /= "error") and (Type /= "groupchat") and (Type /= <<"error">>) and (Type /= <<"groupchat">>) and
(Type /= "headline") -> (Type /= <<"headline">>) ->
case check_event(From, To, Packet) of case check_event(From, To, Packet) of
true -> true ->
LUser = exmpp_jid:lnode_as_list(To), LUser = exmpp_jid:lnode_as_list(To),
@ -197,7 +197,7 @@ check_event(From, To, Packet) ->
S -> S ->
#xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id', #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'id',
children = [#xmlcdata{cdata = children = [#xmlcdata{cdata =
list_to_binary(S)}]} S}]}
end, end,
X = #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'x', children = X = #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'x', children =
[ID, #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'offline'}]}, [ID, #xmlel{ns = ?NS_MESSAGE_EVENT, name = 'offline'}]},

View File

@ -165,8 +165,8 @@ stop(Host) ->
store_packet(From, To, Packet) -> store_packet(From, To, Packet) ->
Type = exmpp_stanza:get_type(Packet), Type = exmpp_stanza:get_type(Packet),
if if
(Type /= "error") and (Type /= "groupchat") and (Type /= <<"error">>) and (Type /= <<"groupchat">>) and
(Type /= "headline") -> (Type /= <<"headline">>) ->
case check_event(From, To, Packet) of case check_event(From, To, Packet) of
true -> true ->
LUser = exmpp_jid:lnode_as_list(To), LUser = exmpp_jid:lnode_as_list(To),

View File

@ -694,9 +694,9 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
end; end;
_ -> _ ->
case exmpp_stanza:get_type(Packet) of case exmpp_stanza:get_type(Packet) of
"error" -> <<"error">> ->
ok; ok;
"result" -> <<"result">> ->
ok; ok;
_ -> _ ->
Err = exmpp_stanza:reply_with_error(Packet, Err = exmpp_stanza:reply_with_error(Packet,

View File

@ -279,7 +279,7 @@ delete_node(Host, Removed) ->
%% <p>In the default plugin module, the record is unchanged.</p> %% <p>In the default plugin module, the record is unchanged.</p>
subscribe_node(Host, Node, Sender, Subscriber, AccessModel, subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup) -> SendLast, PresenceSubscription, RosterGroup) ->
SubKey = jlib:short_prepd_jid(Owner), SubKey = jlib:short_prepd_jid(Subscriber),
GenKey = jlib:short_prepd_bare_jid(SubKey), GenKey = jlib:short_prepd_bare_jid(SubKey),
Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey), Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey),
GenState = get_state(Host, Node, GenKey), GenState = get_state(Host, Node, GenKey),

View File

@ -190,7 +190,7 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
process_item_set(From, To, #xmlel{} = El) -> process_item_set(From, To, #xmlel{} = El) ->
try try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")), JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
User = exmpp_jid:node(From), User = exmpp_jid:node(From),
LUser = exmpp_jid:lnode(From), LUser = exmpp_jid:lnode(From),
LServer = exmpp_jid:ldomain(From), LServer = exmpp_jid:ldomain(From),
@ -596,7 +596,7 @@ set_items(User, Server, #xmlel{children = Els}) ->
process_item_set_t(LUser, LServer, #xmlel{} = El) -> process_item_set_t(LUser, LServer, #xmlel{} = El) ->
try try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")), JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute(El, 'jid', <<>>)),
JID = jlib:short_jid(JID1), JID = jlib:short_jid(JID1),
LJID = jlib:short_prepd_jid(JID1), LJID = jlib:short_prepd_jid(JID1),
Item = #roster{usj = {LUser, LServer, LJID}, Item = #roster{usj = {LUser, LServer, LJID},

View File

@ -216,7 +216,7 @@ process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
process_item_set(From, To, #xmlel{} = El) -> process_item_set(From, To, #xmlel{} = El) ->
try try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")), JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
LUser = exmpp_jid:lnode_as_list(From), LUser = exmpp_jid:lnode_as_list(From),
LServer = exmpp_jid:ldomain_as_list(From), LServer = exmpp_jid:ldomain_as_list(From),
{U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1), {U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1),
@ -655,7 +655,7 @@ set_items(User, Server, #xmlel{children = Els}) ->
process_item_set_t(LUser, LServer, #xmlel{} = El) -> process_item_set_t(LUser, LServer, #xmlel{} = El) ->
try try
JID1 = exmpp_jid:list_to_jid(exmpp_xml:get_attribute(El, 'jid', "")), JID1 = exmpp_jid:binary_to_jid(exmpp_xml:get_attribute_as_binary(El, 'jid', <<>>)),
{U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1), {U0, S0, R0} = LJID = jlib:short_prepd_jid(JID1),
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U0, S0, R0)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U0, S0, R0)),

View File

@ -32,6 +32,8 @@
load_file/2, load_file/2,
translate/2]). translate/2]).
-export([tokens/2, ascii_tolower/1]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
start() -> start() ->
@ -68,7 +70,8 @@ load_dir(Dir) ->
lists:foreach( lists:foreach(
fun(FN) -> fun(FN) ->
L = ascii_tolower( L = ascii_tolower(
string:substr(FN, 1, string:len(FN) - 4)), list_to_binary(
string:substr(FN, 1, string:len(FN) - 4))),
load_file(L, Dir ++ "/" ++ FN) load_file(L, Dir ++ "/" ++ FN)
end, MsgFiles), end, MsgFiles),
ok; ok;
@ -107,14 +110,14 @@ translate(Lang, Msg) ->
[{_, Trans}] -> [{_, Trans}] ->
Trans; Trans;
_ -> _ ->
ShortLang = case string:tokens(LLang, "-") of ShortLang = case tokens(LLang, $-) of
[] -> [] ->
LLang; LLang;
[SL | _] -> [SL | _] ->
SL SL
end, end,
case ShortLang of case ShortLang of
"en" -> <<"en">> ->
Msg; Msg;
LLang -> LLang ->
translate(Msg); translate(Msg);
@ -132,7 +135,7 @@ translate(Msg) ->
case ?MYLANG of case ?MYLANG of
undefined -> undefined ->
Msg; Msg;
"en" -> <<"en">> ->
Msg; Msg;
Lang -> Lang ->
LLang = ascii_tolower(Lang), LLang = ascii_tolower(Lang),
@ -140,14 +143,14 @@ translate(Msg) ->
[{_, Trans}] -> [{_, Trans}] ->
Trans; Trans;
_ -> _ ->
ShortLang = case string:tokens(LLang, "-") of ShortLang = case tokens(LLang, $-) of
[] -> [] ->
LLang; LLang;
[SL | _] -> [SL | _] ->
SL SL
end, end,
case ShortLang of case ShortLang of
"en" -> <<"en">> ->
Msg; Msg;
Lang -> Lang ->
Msg; Msg;
@ -162,11 +165,25 @@ translate(Msg) ->
end end
end. end.
ascii_tolower([C | Cs]) when C >= $A, C =< $Z ->
[C + ($a - $A) | ascii_tolower(Cs)];
ascii_tolower([C | Cs]) ->
[C | ascii_tolower(Cs)];
ascii_tolower([]) ->
[];
ascii_tolower(undefined) -> ascii_tolower(undefined) ->
[]. <<>>;
ascii_tolower(Bin) ->
<< <<(char_tolower(X))>> || <<X>> <= Bin >>.
char_tolower(C) when C >= $A, C =< $Z ->
C + ($a -$A);
char_tolower(C) ->
C.
tokens(<<>>,_Sep) ->
[];
tokens(Bin, Sep) ->
tokens(Bin, Sep, <<>>, []).
tokens(<<>>, _Sep, T, Tokens) ->
lists:reverse([T|Tokens]);
tokens(<<Sep, R/binary>>, Sep, T, Tokens) ->
tokens(R, Sep, <<>>, [T | Tokens]);
tokens(<<C, R/binary>>, Sep, T, Tokens) ->
tokens(R, Sep, <<T/binary, C>>, Tokens).