mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Convert to exmpp.
SVN Revision: 1568
This commit is contained in:
parent
35a7342416
commit
5803c51633
@ -6,6 +6,8 @@
|
|||||||
atom_to_list/1.
|
atom_to_list/1.
|
||||||
(filter_fields): A call to the stringprep module was left.
|
(filter_fields): A call to the stringprep module was left.
|
||||||
|
|
||||||
|
* src/mod_vcard_ldap.erl, src/mod_vcard_odbc.erl: Convert to exmpp.
|
||||||
|
|
||||||
2008-09-18 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-09-18 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/mod_roster_odbc.erl: Convert to exmpp.
|
* src/mod_roster_odbc.erl: Convert to exmpp.
|
||||||
|
@ -49,9 +49,10 @@
|
|||||||
route/4
|
route/4
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("eldap/eldap.hrl").
|
-include("eldap/eldap.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
|
|
||||||
-define(PROCNAME, ejabberd_mod_vcard_ldap).
|
-define(PROCNAME, ejabberd_mod_vcard_ldap).
|
||||||
|
|
||||||
@ -193,7 +194,8 @@ handle_info({route, From, To, Packet}, State) ->
|
|||||||
Pid when is_pid(Pid) ->
|
Pid when is_pid(Pid) ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_INTERNAL_SERVER_ERROR),
|
Err = exmpp_stanza:reply_with_error(Packet,
|
||||||
|
'internal-server-error'),
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
@ -208,53 +210,45 @@ get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
|||||||
[] ->
|
[] ->
|
||||||
case Acc of
|
case Acc of
|
||||||
{result, Features} ->
|
{result, Features} ->
|
||||||
{result, [?NS_VCARD | Features]};
|
{result, [?NS_VCARD_s | Features]};
|
||||||
empty ->
|
empty ->
|
||||||
{result, [?NS_VCARD]}
|
{result, [?NS_VCARD_s]}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_local_iq(_From, _To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
process_local_iq(_From, _To, #iq{type = get, lang = Lang} = IQ_Rec) ->
|
||||||
case Type of
|
Result = #xmlel{ns = ?NS_VCARD, name = 'vCard', children = [
|
||||||
set ->
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'FN'},
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
"ejabberd"),
|
||||||
get ->
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'URL'},
|
||||||
IQ#iq{type = result,
|
?EJABBERD_URI),
|
||||||
sub_el = [{xmlelement, "vCard",
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'DESC'},
|
||||||
[{"xmlns", ?NS_VCARD}],
|
translate:translate(Lang, "Erlang Jabber Server") ++
|
||||||
[{xmlelement, "FN", [],
|
"\nCopyright (c) 2002-2008 ProcessOne"),
|
||||||
[{xmlcdata, "ejabberd"}]},
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'BDAY'},
|
||||||
{xmlelement, "URL", [],
|
"2002-11-16")
|
||||||
[{xmlcdata, ?EJABBERD_URI}]},
|
]},
|
||||||
{xmlelement, "DESC", [],
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
[{xmlcdata,
|
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
translate:translate(
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
Lang,
|
|
||||||
"Erlang Jabber Server") ++
|
|
||||||
"\nCopyright (c) 2002-2008 ProcessOne"}]},
|
|
||||||
{xmlelement, "BDAY", [],
|
|
||||||
[{xmlcdata, "2002-11-16"}]}
|
|
||||||
]}]}
|
|
||||||
end.
|
|
||||||
|
|
||||||
process_sm_iq(_From, #jid{lserver=LServer} = To, #iq{sub_el = SubEl} = IQ) ->
|
process_sm_iq(_From, #jid{ldomain=LServer} = To, #iq{} = IQ_Rec) ->
|
||||||
case catch process_vcard_ldap(To, IQ, LServer) of
|
case catch process_vcard_ldap(To, IQ_Rec, LServer) of
|
||||||
{'EXIT', _} ->
|
{'EXIT', _} ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
|
exmpp_iq:error(IQ_Rec, 'internal-server-error');
|
||||||
Other ->
|
Other ->
|
||||||
Other
|
Other
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_vcard_ldap(To, IQ, Server) ->
|
process_vcard_ldap(To, IQ_Rec, Server) ->
|
||||||
{ok, State} = eldap_utils:get_state(Server, ?PROCNAME),
|
{ok, State} = eldap_utils:get_state(Server, ?PROCNAME),
|
||||||
#iq{type = Type, sub_el = SubEl} = IQ,
|
case IQ_Rec#iq.type of
|
||||||
case Type of
|
|
||||||
set ->
|
set ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
exmpp_iq:error(IQ_Rec, 'not-allowed');
|
||||||
get ->
|
get ->
|
||||||
#jid{luser = LUser} = To,
|
#jid{lnode = LUser} = To,
|
||||||
LServer = State#state.serverhost,
|
LServer = State#state.serverhost,
|
||||||
case ejabberd_auth:is_user_exists(LUser, LServer) of
|
case ejabberd_auth:is_user_exists(LUser, LServer) of
|
||||||
true ->
|
true ->
|
||||||
@ -262,12 +256,12 @@ process_vcard_ldap(To, IQ, Server) ->
|
|||||||
case find_ldap_user(LUser, State) of
|
case find_ldap_user(LUser, State) of
|
||||||
#eldap_entry{attributes = Attributes} ->
|
#eldap_entry{attributes = Attributes} ->
|
||||||
Vcard = ldap_attributes_to_vcard(Attributes, VCardMap, {LUser, LServer}),
|
Vcard = ldap_attributes_to_vcard(Attributes, VCardMap, {LUser, LServer}),
|
||||||
IQ#iq{type = result, sub_el = Vcard};
|
exmpp_iq:result(IQ_Rec, Vcard);
|
||||||
_ ->
|
_ ->
|
||||||
IQ#iq{type = result, sub_el = []}
|
exmpp_iq:result(IQ_Rec)
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
IQ#iq{type = result, sub_el = []}
|
exmpp_iq:result(IQ_Rec)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -300,247 +294,237 @@ find_ldap_user(User, State) ->
|
|||||||
ldap_attributes_to_vcard(Attributes, VCardMap, UD) ->
|
ldap_attributes_to_vcard(Attributes, VCardMap, UD) ->
|
||||||
Attrs = lists:map(
|
Attrs = lists:map(
|
||||||
fun({VCardName, _, _}) ->
|
fun({VCardName, _, _}) ->
|
||||||
{stringprep:tolower(VCardName),
|
{exmpp_stringprep:to_lower(VCardName),
|
||||||
map_vcard_attr(VCardName, Attributes, VCardMap, UD)}
|
map_vcard_attr(VCardName, Attributes, VCardMap, UD)}
|
||||||
end, VCardMap),
|
end, VCardMap),
|
||||||
Elts = [ldap_attribute_to_vcard(vCard, Attr) || Attr <- Attrs],
|
Elts = [ldap_attribute_to_vcard(vCard, Attr) || Attr <- Attrs],
|
||||||
NElts = [ldap_attribute_to_vcard(vCardN, Attr) || Attr <- Attrs],
|
NElts = [ldap_attribute_to_vcard(vCardN, Attr) || Attr <- Attrs],
|
||||||
OElts = [ldap_attribute_to_vcard(vCardO, Attr) || Attr <- Attrs],
|
OElts = [ldap_attribute_to_vcard(vCardO, Attr) || Attr <- Attrs],
|
||||||
AElts = [ldap_attribute_to_vcard(vCardA, Attr) || Attr <- Attrs],
|
AElts = [ldap_attribute_to_vcard(vCardA, Attr) || Attr <- Attrs],
|
||||||
[{xmlelement, "vCard", [{"xmlns", ?NS_VCARD}],
|
[#xmlel{ns = ?NS_VCARD, name = 'vCard', children =
|
||||||
lists:append([X || X <- Elts, X /= none],
|
lists:append([X || X <- Elts, X /= none],
|
||||||
[{xmlelement,"N",[], [X || X <- NElts, X /= none]},
|
[#xmlel{ns = ?NS_VCARD, name = 'N', children = [X || X <- NElts, X /= none]},
|
||||||
{xmlelement,"ORG",[], [X || X <- OElts, X /= none]},
|
#xmlel{ns = ?NS_VCARD, name = 'ORG', children = [X || X <- OElts, X /= none]},
|
||||||
{xmlelement,"ADR",[], [X || X <- AElts, X /= none]}])
|
#xmlel{ns = ?NS_VCARD, name = 'ADR', children = [X || X <- AElts, X /= none]}])
|
||||||
}].
|
}].
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"fn", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"fn", Value}) ->
|
||||||
{xmlelement,"FN",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'FN'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"nickname", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"nickname", Value}) ->
|
||||||
{xmlelement,"NICKNAME",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'NICKNAME'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"title", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"title", Value}) ->
|
||||||
{xmlelement,"TITLE",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'TITLE'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"bday", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"bday", Value}) ->
|
||||||
{xmlelement,"BDAY",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'BDAY'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"url", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"url", Value}) ->
|
||||||
{xmlelement,"URL",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'URL'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"desc", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"desc", Value}) ->
|
||||||
{xmlelement,"DESC",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'DESC'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"role", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"role", Value}) ->
|
||||||
{xmlelement,"ROLE",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'ROLE'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"tel", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"tel", Value}) ->
|
||||||
{xmlelement,"TEL",[],[{xmlelement,"VOICE",[],[]},
|
#xmlel{ns = ?NS_VCARD, name = 'TEL', children = [
|
||||||
{xmlelement,"WORK",[],[]},
|
#xmlel{ns = ?NS_VCARD, name = 'VOICE'},
|
||||||
{xmlelement,"NUMBER",[],[{xmlcdata,Value}]}]};
|
#xmlel{ns = ?NS_VCARD, name = 'WORK'},
|
||||||
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'NUMBER'}, Value)]};
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"email", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"email", Value}) ->
|
||||||
{xmlelement,"EMAIL",[],[{xmlelement,"INTERNET",[],[]},
|
#xmlel{ns = ?NS_VCARD, name = 'EMAIL', children = [
|
||||||
{xmlelement,"PREF",[],[]},
|
#xmlel{ns = ?NS_VCARD, name = 'INTERNET'},
|
||||||
{xmlelement,"USERID",[],[{xmlcdata,Value}]}]};
|
#xmlel{ns = ?NS_VCARD, name = 'PREF'},
|
||||||
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'USERID'}, Value)]};
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {"photo", Value}) ->
|
ldap_attribute_to_vcard(vCard, {"photo", Value}) ->
|
||||||
{xmlelement,"PHOTO",[],[
|
#xmlel{ns = ?NS_VCARD, name = 'PHOTO', children = [
|
||||||
{xmlelement,"BINVAL",[],[{xmlcdata, jlib:encode_base64(Value)}]}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'BINVAL'},
|
||||||
|
jlib:encode_base64(Value))]};
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardN, {"family", Value}) ->
|
ldap_attribute_to_vcard(vCardN, {"family", Value}) ->
|
||||||
{xmlelement,"FAMILY",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'FAMILY'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardN, {"given", Value}) ->
|
ldap_attribute_to_vcard(vCardN, {"given", Value}) ->
|
||||||
{xmlelement,"GIVEN",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'GIVEN'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardN, {"middle", Value}) ->
|
ldap_attribute_to_vcard(vCardN, {"middle", Value}) ->
|
||||||
{xmlelement,"MIDDLE",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'MIDDLE'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardO, {"orgname", Value}) ->
|
ldap_attribute_to_vcard(vCardO, {"orgname", Value}) ->
|
||||||
{xmlelement,"ORGNAME",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'ORGNAME'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardO, {"orgunit", Value}) ->
|
ldap_attribute_to_vcard(vCardO, {"orgunit", Value}) ->
|
||||||
{xmlelement,"ORGUNIT",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'ORGUNIT'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardA, {"locality", Value}) ->
|
ldap_attribute_to_vcard(vCardA, {"locality", Value}) ->
|
||||||
{xmlelement,"LOCALITY",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'LOCALITY'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardA, {"street", Value}) ->
|
ldap_attribute_to_vcard(vCardA, {"street", Value}) ->
|
||||||
{xmlelement,"STREET",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'STREET'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardA, {"ctry", Value}) ->
|
ldap_attribute_to_vcard(vCardA, {"ctry", Value}) ->
|
||||||
{xmlelement,"CTRY",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'CTRY'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardA, {"region", Value}) ->
|
ldap_attribute_to_vcard(vCardA, {"region", Value}) ->
|
||||||
{xmlelement,"REGION",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'REGION'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCardA, {"pcode", Value}) ->
|
ldap_attribute_to_vcard(vCardA, {"pcode", Value}) ->
|
||||||
{xmlelement,"PCODE",[],[{xmlcdata,Value}]};
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'PCODE'}, Value);
|
||||||
|
|
||||||
ldap_attribute_to_vcard(_, _) ->
|
ldap_attribute_to_vcard(_, _) ->
|
||||||
none.
|
none.
|
||||||
|
|
||||||
-define(TLFIELD(Type, Label, Var),
|
-define(TLFIELD(Type, Label, Var),
|
||||||
{xmlelement, "field", [{"type", Type},
|
#xmlel{ns = ?NS_VCARD, name = 'field', attrs = [
|
||||||
{"label", translate:translate(Lang, Label)},
|
#xmlattr{name = 'type', value = Type},
|
||||||
{"var", Var}], []}).
|
#xmlattr{name = 'label', value = translate:translate(Lang, Label)},
|
||||||
|
#xmlattr{name = 'var', value = Var}]}).
|
||||||
|
|
||||||
-define(FORM(JID, SearchFields),
|
-define(FORM(JID, SearchFields),
|
||||||
[{xmlelement, "instructions", [],
|
[#xmlel{ns = ?NS_SEARCH, name = 'instructions', children =
|
||||||
[{xmlcdata, translate:translate(Lang, "You need an x:data capable client to search")}]},
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "You need an x:data capable client to search"))}]},
|
||||||
{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs =
|
||||||
[{xmlelement, "title", [],
|
[#xmlattr{name = 'type', value = "form"}], children =
|
||||||
[{xmlcdata, translate:translate(Lang, "Search users in ") ++
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
||||||
jlib:jid_to_string(JID)}]},
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Search users in ") ++
|
||||||
{xmlelement, "instructions", [],
|
exmpp_jid:jid_to_list(JID))}]},
|
||||||
[{xmlcdata, translate:translate(Lang, "Fill in fields to search "
|
#xmlel{ns = ?NS_SEARCH, name = 'instructions', children =
|
||||||
"for any matching Jabber User")}]}
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Fill in fields to search "
|
||||||
|
"for any matching Jabber User"))}]}
|
||||||
] ++ lists:map(fun({X,Y}) -> ?TLFIELD("text-single", X, Y) end, SearchFields)}]).
|
] ++ lists:map(fun({X,Y}) -> ?TLFIELD("text-single", X, Y) end, SearchFields)}]).
|
||||||
|
|
||||||
do_route(State, From, To, Packet) ->
|
do_route(State, From, To, Packet) ->
|
||||||
spawn(?MODULE, route, [State, From, To, Packet]).
|
spawn(?MODULE, route, [State, From, To, Packet]).
|
||||||
|
|
||||||
route(State, From, To, Packet) ->
|
route(State, From, To, Packet) ->
|
||||||
#jid{user = User, resource = Resource} = To,
|
#jid{node = User, resource = Resource} = To,
|
||||||
if
|
if
|
||||||
(User /= "") or (Resource /= "") ->
|
(User /= undefined) or (Resource /= undefined) ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_SERVICE_UNAVAILABLE),
|
Err = exmpp_stanza:reply_with_error(Packet, 'service-unavailable'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
true ->
|
true ->
|
||||||
IQ = jlib:iq_query_info(Packet),
|
try
|
||||||
case IQ of
|
Request = exmpp_iq:get_request(Packet),
|
||||||
#iq{type = Type, xmlns = ?NS_SEARCH, lang = Lang, sub_el = SubEl} ->
|
Type = exmpp_iq:get_type(Packet),
|
||||||
case Type of
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
set ->
|
case {Type, Request#xmlel.ns} of
|
||||||
XDataEl = find_xdata_el(SubEl),
|
{set, ?NS_SEARCH} ->
|
||||||
case XDataEl of
|
XDataEl = find_xdata_el(Request),
|
||||||
false ->
|
case XDataEl of
|
||||||
Err = jlib:make_error_reply(
|
false ->
|
||||||
Packet, ?ERR_BAD_REQUEST),
|
Err = exmpp_iq:error(Packet, 'bad-request'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
_ ->
|
_ ->
|
||||||
XData = jlib:parse_xdata_submit(XDataEl),
|
XData = jlib:parse_xdata_submit(XDataEl),
|
||||||
case XData of
|
case XData of
|
||||||
invalid ->
|
invalid ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(Packet,
|
||||||
Packet,
|
'bad-request'),
|
||||||
?ERR_BAD_REQUEST),
|
ejabberd_router:route(To, From,
|
||||||
ejabberd_router:route(To, From,
|
Err);
|
||||||
Err);
|
_ ->
|
||||||
_ ->
|
Result = #xmlel{
|
||||||
ResIQ =
|
ns = ?NS_SEARCH,
|
||||||
IQ#iq{
|
name = 'query',
|
||||||
type = result,
|
children = [
|
||||||
sub_el =
|
#xmlel{
|
||||||
[{xmlelement,
|
ns = ?NS_DATA_FORMS,
|
||||||
"query",
|
name = 'x',
|
||||||
[{"xmlns", ?NS_SEARCH}],
|
attrs = [#xmlattr{name = 'type',
|
||||||
[{xmlelement, "x",
|
value = "result"}],
|
||||||
[{"xmlns", ?NS_XDATA},
|
children = search_result(Lang, To, State, XData)}]},
|
||||||
{"type", "result"}],
|
ResIQ = exmpp_iq:result(Packet,
|
||||||
search_result(Lang, To, State, XData)
|
Result),
|
||||||
}]}]},
|
ejabberd_router:route(
|
||||||
ejabberd_router:route(
|
To, From, ResIQ)
|
||||||
To, From, jlib:iq_to_xml(ResIQ))
|
end
|
||||||
end
|
end;
|
||||||
end;
|
{get, ?NS_SEARCH} ->
|
||||||
get ->
|
SearchFields = State#state.search_fields,
|
||||||
SearchFields = State#state.search_fields,
|
Result = #xmlel{ns = ?NS_SEARCH, name = 'query',
|
||||||
ResIQ = IQ#iq{type = result,
|
children = ?FORM(To, SearchFields)},
|
||||||
sub_el = [{xmlelement,
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
"query",
|
ejabberd_router:route(To,
|
||||||
[{"xmlns", ?NS_SEARCH}],
|
From,
|
||||||
?FORM(To, SearchFields)
|
ResIQ);
|
||||||
}]},
|
{set, ?NS_DISCO_INFO} ->
|
||||||
ejabberd_router:route(To,
|
Err = exmpp_iq:error(Packet, 'not-allowed'),
|
||||||
From,
|
ejabberd_router:route(To, From, Err);
|
||||||
jlib:iq_to_xml(ResIQ))
|
{get, ?NS_DISCO_INFO} ->
|
||||||
end;
|
Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query',
|
||||||
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
|
children = [
|
||||||
case Type of
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'identity',
|
||||||
set ->
|
attrs = [
|
||||||
Err = jlib:make_error_reply(
|
#xmlattr{name = 'category',
|
||||||
Packet, ?ERR_NOT_ALLOWED),
|
value = "directory"},
|
||||||
ejabberd_router:route(To, From, Err);
|
#xmlattr{name = 'type',
|
||||||
get ->
|
value = "user"},
|
||||||
ResIQ =
|
#xmlattr{name = 'name',
|
||||||
IQ#iq{type = result,
|
value = translate:translate(Lang,
|
||||||
sub_el = [{xmlelement,
|
"vCard User Search")}]},
|
||||||
"query",
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature',
|
||||||
[{"xmlns", ?NS_DISCO_INFO}],
|
attrs = [
|
||||||
[{xmlelement, "identity",
|
#xmlattr{name = 'var',
|
||||||
[{"category", "directory"},
|
value = ?NS_SEARCH_s}]},
|
||||||
{"type", "user"},
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature',
|
||||||
{"name",
|
attrs = [
|
||||||
translate:translate(Lang, "vCard User Search")}],
|
#xmlattr{name = 'var',
|
||||||
[]},
|
value = ?NS_VCARD_s}]}
|
||||||
{xmlelement, "feature",
|
]},
|
||||||
[{"var", ?NS_SEARCH}], []},
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
{xmlelement, "feature",
|
ejabberd_router:route(To,
|
||||||
[{"var", ?NS_VCARD}], []}
|
From,
|
||||||
]
|
ResIQ);
|
||||||
}]},
|
{set, ?NS_DISCO_ITEMS} ->
|
||||||
ejabberd_router:route(To,
|
Err = exmpp_iq:error(Packet, 'not-allowed'),
|
||||||
From,
|
ejabberd_router:route(To, From, Err);
|
||||||
jlib:iq_to_xml(ResIQ))
|
{get, ?NS_DISCO_ITEMS} ->
|
||||||
end;
|
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query'},
|
||||||
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} ->
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
case Type of
|
ejabberd_router:route(To,
|
||||||
set ->
|
From,
|
||||||
Err = jlib:make_error_reply(
|
ResIQ);
|
||||||
Packet, ?ERR_NOT_ALLOWED),
|
{get, ?NS_VCARD} ->
|
||||||
ejabberd_router:route(To, From, Err);
|
Result = #xmlel{ns = ?NS_VCARD, name = 'vCard',
|
||||||
get ->
|
children = iq_get_vcard(Lang)},
|
||||||
ResIQ =
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
IQ#iq{type = result,
|
ejabberd_router:route(To,
|
||||||
sub_el = [{xmlelement,
|
From,
|
||||||
"query",
|
ResIQ);
|
||||||
[{"xmlns", ?NS_DISCO_ITEMS}],
|
_ ->
|
||||||
[]}]},
|
Err = exmpp_iq:error(Packet, 'service-unavailable'),
|
||||||
ejabberd_router:route(To,
|
ejabberd_router:route(To, From, Err)
|
||||||
From,
|
end
|
||||||
jlib:iq_to_xml(ResIQ))
|
catch
|
||||||
end;
|
|
||||||
#iq{type = get, xmlns = ?NS_VCARD, lang = Lang} ->
|
|
||||||
ResIQ =
|
|
||||||
IQ#iq{type = result,
|
|
||||||
sub_el = [{xmlelement,
|
|
||||||
"vCard",
|
|
||||||
[{"xmlns", ?NS_VCARD}],
|
|
||||||
iq_get_vcard(Lang)}]},
|
|
||||||
ejabberd_router:route(To,
|
|
||||||
From,
|
|
||||||
jlib:iq_to_xml(ResIQ));
|
|
||||||
_ ->
|
_ ->
|
||||||
Err = jlib:make_error_reply(Packet,
|
Err1 = exmpp_iq:error(Packet, 'service-unavailable'),
|
||||||
?ERR_SERVICE_UNAVAILABLE),
|
ejabberd_router:route(To, From, Err1)
|
||||||
ejabberd_router:route(To, From, Err)
|
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
iq_get_vcard(Lang) ->
|
iq_get_vcard(Lang) ->
|
||||||
[{xmlelement, "FN", [],
|
[
|
||||||
[{xmlcdata, "ejabberd/mod_vcard"}]},
|
#xmlel{ns = ?NS_SEARCH, name = 'FN', children = [
|
||||||
{xmlelement, "URL", [],
|
#xmlcdata{cdata = <<"ejabberd/mod_vcard">>}]},
|
||||||
[{xmlcdata, ?EJABBERD_URI}]},
|
#xmlel{ns = ?NS_SEARCH, name = 'URL', children = [
|
||||||
{xmlelement, "DESC", [],
|
#xmlcdata{cdata = list_to_binary(?EJABBERD_URI)}]},
|
||||||
[{xmlcdata, translate:translate(
|
#xmlel{ns = ?NS_SEARCH, name ='DESC', children = [
|
||||||
Lang,
|
#xmlcdata{cdata = list_to_binary(
|
||||||
"ejabberd vCard module") ++
|
translate:translate(Lang, "ejabberd vCard module") ++
|
||||||
"\nCopyright (c) 2003-2008 ProcessOne"}]}].
|
"\nCopyright (c) 2003-2008 ProcessOne")}]}
|
||||||
|
].
|
||||||
-define(LFIELD(Label, Var),
|
|
||||||
{xmlelement, "field", [{"label", translate:translate(Lang, Label)},
|
|
||||||
{"var", Var}], []}).
|
|
||||||
|
|
||||||
search_result(Lang, JID, State, Data) ->
|
search_result(Lang, JID, State, Data) ->
|
||||||
SearchReported = State#state.search_reported,
|
SearchReported = State#state.search_reported,
|
||||||
Header = [{xmlelement, "title", [],
|
Header = [#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
||||||
[{xmlcdata, translate:translate(Lang, "Search Results for ") ++
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Search Results for ") ++
|
||||||
jlib:jid_to_string(JID)}]},
|
exmpp_jid:jid_to_list(JID))}]},
|
||||||
{xmlelement, "reported", [],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'reported', children =
|
||||||
[?TLFIELD("text-single", "Jabber ID", "jid")] ++
|
[?TLFIELD("text-single", "Jabber ID", "jid")] ++
|
||||||
lists:map(
|
lists:map(
|
||||||
fun({Name, Value}) -> ?TLFIELD("text-single", Name, Value) end,
|
fun({Name, Value}) -> ?TLFIELD("text-single", Name, Value) end,
|
||||||
@ -554,9 +538,10 @@ search_result(Lang, JID, State, Data) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-define(FIELD(Var, Val),
|
-define(FIELD(Var, Val),
|
||||||
{xmlelement, "field", [{"var", Var}],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
||||||
[{xmlelement, "value", [],
|
[#xmlattr{name = 'var', value = Var}], children =
|
||||||
[{xmlcdata, Val}]}]}).
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =
|
||||||
|
[#xmlcdata{cdata = list_to_binary(Val)}]}]}).
|
||||||
|
|
||||||
search(State, Data) ->
|
search(State, Data) ->
|
||||||
Base = State#state.base,
|
Base = State#state.base,
|
||||||
@ -605,7 +590,7 @@ search_items(Entries, State) ->
|
|||||||
end, SearchReported),
|
end, SearchReported),
|
||||||
Result = [?FIELD("jid", Username ++ "@" ++ LServer)] ++
|
Result = [?FIELD("jid", Username ++ "@" ++ LServer)] ++
|
||||||
[?FIELD(Name, Value) || {Name, Value} <- RFields],
|
[?FIELD(Name, Value) || {Name, Value} <- RFields],
|
||||||
[{xmlelement, "item", [], Result}];
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'item', children = Result}];
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
end;
|
end;
|
||||||
@ -645,13 +630,8 @@ find_xdata_el({xmlelement, _Name, _Attrs, SubEls}) ->
|
|||||||
|
|
||||||
find_xdata_el1([]) ->
|
find_xdata_el1([]) ->
|
||||||
false;
|
false;
|
||||||
find_xdata_el1([{xmlelement, Name, Attrs, SubEls} | Els]) ->
|
find_xdata_el1([#xmlel{ns = ?NS_DATA_FORMS} = El | _Els]) ->
|
||||||
case xml:get_attr_s("xmlns", Attrs) of
|
El;
|
||||||
?NS_XDATA ->
|
|
||||||
{xmlelement, Name, Attrs, SubEls};
|
|
||||||
_ ->
|
|
||||||
find_xdata_el1(Els)
|
|
||||||
end;
|
|
||||||
find_xdata_el1([_ | Els]) ->
|
find_xdata_el1([_ | Els]) ->
|
||||||
find_xdata_el1(Els).
|
find_xdata_el1(Els).
|
||||||
|
|
||||||
|
@ -36,8 +36,9 @@
|
|||||||
%reindex_vcards/0,
|
%reindex_vcards/0,
|
||||||
remove_user/2]).
|
remove_user/2]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
|
|
||||||
|
|
||||||
-define(JUD_MATCHES, 30).
|
-define(JUD_MATCHES, 30).
|
||||||
@ -102,85 +103,85 @@ get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
|||||||
[] ->
|
[] ->
|
||||||
case Acc of
|
case Acc of
|
||||||
{result, Features} ->
|
{result, Features} ->
|
||||||
{result, [?NS_VCARD | Features]};
|
{result, [?NS_VCARD_s | Features]};
|
||||||
empty ->
|
empty ->
|
||||||
{result, [?NS_VCARD]}
|
{result, [?NS_VCARD_s]}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_local_iq(_From, _To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
process_local_iq(_From, _To, #iq{type = get, lang = Lang} = IQ_Rec) ->
|
||||||
case Type of
|
Result = #xmlel{ns = ?NS_VCARD, name = 'vCard', children = [
|
||||||
set ->
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'FN'},
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
"ejabberd"),
|
||||||
get ->
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'URL'},
|
||||||
IQ#iq{type = result,
|
?EJABBERD_URI),
|
||||||
sub_el = [{xmlelement, "vCard",
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'DESC'},
|
||||||
[{"xmlns", ?NS_VCARD}],
|
translate:translate(Lang, "Erlang Jabber Server") ++
|
||||||
[{xmlelement, "FN", [],
|
"\nCopyright (c) 2002-2008 ProcessOne"),
|
||||||
[{xmlcdata, "ejabberd"}]},
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'BDAY'},
|
||||||
{xmlelement, "URL", [],
|
"2002-11-16")
|
||||||
[{xmlcdata, ?EJABBERD_URI}]},
|
]},
|
||||||
{xmlelement, "DESC", [],
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
[{xmlcdata,
|
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
translate:translate(
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
Lang,
|
|
||||||
"Erlang Jabber Server") ++
|
|
||||||
"\nCopyright (c) 2002-2008 ProcessOne"}]},
|
|
||||||
{xmlelement, "BDAY", [],
|
|
||||||
[{xmlcdata, "2002-11-16"}]}
|
|
||||||
]}]}
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
|
process_sm_iq(_From, To, #iq{type = get} = IQ_Rec) ->
|
||||||
case Type of
|
#jid{lnode = LUser, ldomain = LServer} = To,
|
||||||
set ->
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
#jid{user = User, lserver = LServer} = From,
|
case catch ejabberd_odbc:sql_query(
|
||||||
case lists:member(LServer, ?MYHOSTS) of
|
LServer,
|
||||||
true ->
|
["select vcard from vcard "
|
||||||
set_vcard(User, LServer, SubEl),
|
"where username='", Username, "';"]) of
|
||||||
IQ#iq{type = result, sub_el = []};
|
{selected, ["vcard"], [{SVCARD}]} ->
|
||||||
false ->
|
case exmpp_xml:parse_document(SVCARD) of
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
|
{error, _Reason} ->
|
||||||
end;
|
exmpp_iq:error(IQ_Rec, 'service-unavailable');
|
||||||
get ->
|
VCARD ->
|
||||||
#jid{luser = LUser, lserver = LServer} = To,
|
exmpp_iq:result(IQ_Rec, VCARD)
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
end;
|
||||||
case catch ejabberd_odbc:sql_query(
|
{selected, ["vcard"], []} ->
|
||||||
LServer,
|
exmpp_iq:result(IQ_Rec);
|
||||||
["select vcard from vcard "
|
_ ->
|
||||||
"where username='", Username, "';"]) of
|
exmpp_iq:error(IQ_Rec, 'internal-server-error')
|
||||||
{selected, ["vcard"], [{SVCARD}]} ->
|
end;
|
||||||
case xml_stream:parse_element(SVCARD) of
|
process_sm_iq(From, _To, #iq{type = set, payload = Request} = IQ_Rec) ->
|
||||||
{error, _Reason} ->
|
#jid{node = User, ldomain = LServer} = From,
|
||||||
IQ#iq{type = error,
|
case lists:member(LServer, ?MYHOSTS) of
|
||||||
sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]};
|
true ->
|
||||||
VCARD ->
|
set_vcard(User, LServer, Request),
|
||||||
IQ#iq{type = result, sub_el = [VCARD]}
|
exmpp_iq:result(IQ_Rec);
|
||||||
end;
|
false ->
|
||||||
{selected, ["vcard"], []} ->
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
IQ#iq{type = result, sub_el = []};
|
|
||||||
_ ->
|
|
||||||
IQ#iq{type = error,
|
|
||||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_vcard(User, LServer, VCARD) ->
|
set_vcard(User, LServer, VCARD) ->
|
||||||
FN = xml:get_path_s(VCARD, [{elem, "FN"}, cdata]),
|
FN = exmpp_xml:get_path(VCARD,
|
||||||
Family = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "FAMILY"}, cdata]),
|
[{element, 'FN'}, cdata_as_list]),
|
||||||
Given = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "GIVEN"}, cdata]),
|
Family = exmpp_xml:get_path(VCARD,
|
||||||
Middle = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "MIDDLE"}, cdata]),
|
[{element, 'N'}, {element, 'FAMILY'}, cdata_as_list]),
|
||||||
Nickname = xml:get_path_s(VCARD, [{elem, "NICKNAME"}, cdata]),
|
Given = exmpp_xml:get_path(VCARD,
|
||||||
BDay = xml:get_path_s(VCARD, [{elem, "BDAY"}, cdata]),
|
[{element, 'N'}, {element, 'GIVEN'}, cdata_as_list]),
|
||||||
CTRY = xml:get_path_s(VCARD, [{elem, "ADR"}, {elem, "CTRY"}, cdata]),
|
Middle = exmpp_xml:get_path(VCARD,
|
||||||
Locality = xml:get_path_s(VCARD, [{elem, "ADR"}, {elem, "LOCALITY"},cdata]),
|
[{element, 'N'}, {element, 'MIDDLE'}, cdata_as_list]),
|
||||||
EMail1 = xml:get_path_s(VCARD, [{elem, "EMAIL"}, {elem, "USERID"},cdata]),
|
Nickname = exmpp_xml:get_path(VCARD,
|
||||||
EMail2 = xml:get_path_s(VCARD, [{elem, "EMAIL"}, cdata]),
|
[{element, 'NICKNAME'}, cdata_as_list]),
|
||||||
OrgName = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGNAME"}, cdata]),
|
BDay = exmpp_xml:get_path(VCARD,
|
||||||
OrgUnit = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]),
|
[{element, 'BDAY'}, cdata_as_list]),
|
||||||
|
CTRY = exmpp_xml:get_path(VCARD,
|
||||||
|
[{element, 'ADR'}, {element, 'CTRY'}, cdata_as_list]),
|
||||||
|
Locality = exmpp_xml:get_path(VCARD,
|
||||||
|
[{element, 'ADR'}, {element, 'LOCALITY'}, cdata_as_list]),
|
||||||
|
EMail1 = exmpp_xml:get_path(VCARD,
|
||||||
|
[{element, 'EMAIL'}, {element, 'USERID'}, cdata_as_list]),
|
||||||
|
EMail2 = exmpp_xml:get_path(VCARD,
|
||||||
|
[{element, 'EMAIL'}, cdata_as_list]),
|
||||||
|
OrgName = exmpp_xml:get_path(VCARD,
|
||||||
|
[{element, 'ORG'}, {element, 'ORGNAME'}, cdata_as_list]),
|
||||||
|
OrgUnit = exmpp_xml:get_path(VCARD,
|
||||||
|
[{element, 'ORG'}, {element, 'ORGUNIT'}, cdata_as_list]),
|
||||||
EMail = case EMail1 of
|
EMail = case EMail1 of
|
||||||
"" ->
|
"" ->
|
||||||
EMail2;
|
EMail2;
|
||||||
@ -188,106 +189,96 @@ set_vcard(User, LServer, VCARD) ->
|
|||||||
EMail1
|
EMail1
|
||||||
end,
|
end,
|
||||||
|
|
||||||
LUser = jlib:nodeprep(User),
|
try
|
||||||
LFN = stringprep:tolower(FN),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LFamily = stringprep:tolower(Family),
|
LFN = exmpp_stringprep:to_lower(FN),
|
||||||
LGiven = stringprep:tolower(Given),
|
LFamily = exmpp_stringprep:to_lower(Family),
|
||||||
LMiddle = stringprep:tolower(Middle),
|
LGiven = exmpp_stringprep:to_lower(Given),
|
||||||
LNickname = stringprep:tolower(Nickname),
|
LMiddle = exmpp_stringprep:to_lower(Middle),
|
||||||
LBDay = stringprep:tolower(BDay),
|
LNickname = exmpp_stringprep:to_lower(Nickname),
|
||||||
LCTRY = stringprep:tolower(CTRY),
|
LBDay = exmpp_stringprep:to_lower(BDay),
|
||||||
LLocality = stringprep:tolower(Locality),
|
LCTRY = exmpp_stringprep:to_lower(CTRY),
|
||||||
LEMail = stringprep:tolower(EMail),
|
LLocality = exmpp_stringprep:to_lower(Locality),
|
||||||
LOrgName = stringprep:tolower(OrgName),
|
LEMail = exmpp_stringprep:to_lower(EMail),
|
||||||
LOrgUnit = stringprep:tolower(OrgUnit),
|
LOrgName = exmpp_stringprep:to_lower(OrgName),
|
||||||
|
LOrgUnit = exmpp_stringprep:to_lower(OrgUnit),
|
||||||
|
|
||||||
if
|
Username = ejabberd_odbc:escape(User),
|
||||||
(LUser == error) or
|
LUsername = ejabberd_odbc:escape(LUser),
|
||||||
(LFN == error) or
|
SVCARD = ejabberd_odbc:escape(exmpp_xml:document_to_list(VCARD)),
|
||||||
(LFamily == error) or
|
|
||||||
(LGiven == error) or
|
|
||||||
(LMiddle == error) or
|
|
||||||
(LNickname == error) or
|
|
||||||
(LBDay == error) or
|
|
||||||
(LCTRY == error) or
|
|
||||||
(LLocality == error) or
|
|
||||||
(LEMail == error) or
|
|
||||||
(LOrgName == error) or
|
|
||||||
(LOrgUnit == error) ->
|
|
||||||
{error, badarg};
|
|
||||||
true ->
|
|
||||||
Username = ejabberd_odbc:escape(User),
|
|
||||||
LUsername = ejabberd_odbc:escape(LUser),
|
|
||||||
SVCARD = ejabberd_odbc:escape(
|
|
||||||
lists:flatten(xml:element_to_string(VCARD))),
|
|
||||||
|
|
||||||
SFN = ejabberd_odbc:escape(FN),
|
SFN = ejabberd_odbc:escape(FN),
|
||||||
SLFN = ejabberd_odbc:escape(LFN),
|
SLFN = ejabberd_odbc:escape(LFN),
|
||||||
SFamily = ejabberd_odbc:escape(Family),
|
SFamily = ejabberd_odbc:escape(Family),
|
||||||
SLFamily = ejabberd_odbc:escape(LFamily),
|
SLFamily = ejabberd_odbc:escape(LFamily),
|
||||||
SGiven = ejabberd_odbc:escape(Given),
|
SGiven = ejabberd_odbc:escape(Given),
|
||||||
SLGiven = ejabberd_odbc:escape(LGiven),
|
SLGiven = ejabberd_odbc:escape(LGiven),
|
||||||
SMiddle = ejabberd_odbc:escape(Middle),
|
SMiddle = ejabberd_odbc:escape(Middle),
|
||||||
SLMiddle = ejabberd_odbc:escape(LMiddle),
|
SLMiddle = ejabberd_odbc:escape(LMiddle),
|
||||||
SNickname = ejabberd_odbc:escape(Nickname),
|
SNickname = ejabberd_odbc:escape(Nickname),
|
||||||
SLNickname = ejabberd_odbc:escape(LNickname),
|
SLNickname = ejabberd_odbc:escape(LNickname),
|
||||||
SBDay = ejabberd_odbc:escape(BDay),
|
SBDay = ejabberd_odbc:escape(BDay),
|
||||||
SLBDay = ejabberd_odbc:escape(LBDay),
|
SLBDay = ejabberd_odbc:escape(LBDay),
|
||||||
SCTRY = ejabberd_odbc:escape(CTRY),
|
SCTRY = ejabberd_odbc:escape(CTRY),
|
||||||
SLCTRY = ejabberd_odbc:escape(LCTRY),
|
SLCTRY = ejabberd_odbc:escape(LCTRY),
|
||||||
SLocality = ejabberd_odbc:escape(Locality),
|
SLocality = ejabberd_odbc:escape(Locality),
|
||||||
SLLocality = ejabberd_odbc:escape(LLocality),
|
SLLocality = ejabberd_odbc:escape(LLocality),
|
||||||
SEMail = ejabberd_odbc:escape(EMail),
|
SEMail = ejabberd_odbc:escape(EMail),
|
||||||
SLEMail = ejabberd_odbc:escape(LEMail),
|
SLEMail = ejabberd_odbc:escape(LEMail),
|
||||||
SOrgName = ejabberd_odbc:escape(OrgName),
|
SOrgName = ejabberd_odbc:escape(OrgName),
|
||||||
SLOrgName = ejabberd_odbc:escape(LOrgName),
|
SLOrgName = ejabberd_odbc:escape(LOrgName),
|
||||||
SOrgUnit = ejabberd_odbc:escape(OrgUnit),
|
SOrgUnit = ejabberd_odbc:escape(OrgUnit),
|
||||||
SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
|
SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
|
||||||
|
|
||||||
ejabberd_odbc:sql_transaction(
|
ejabberd_odbc:sql_transaction(
|
||||||
LServer,
|
LServer,
|
||||||
[["delete from vcard where username='", LUsername, "';"],
|
[["delete from vcard where username='", LUsername, "';"],
|
||||||
["insert into vcard(username, vcard) "
|
["insert into vcard(username, vcard) "
|
||||||
"values ('", LUsername, "', '", SVCARD, "');"],
|
"values ('", LUsername, "', '", SVCARD, "');"],
|
||||||
["delete from vcard_search where lusername='", LUsername, "';"],
|
["delete from vcard_search where lusername='", LUsername, "';"],
|
||||||
["insert into vcard_search("
|
["insert into vcard_search("
|
||||||
" username, lusername, fn, lfn, family, lfamily,"
|
" username, lusername, fn, lfn, family, lfamily,"
|
||||||
" given, lgiven, middle, lmiddle, nickname, lnickname,"
|
" given, lgiven, middle, lmiddle, nickname, lnickname,"
|
||||||
" bday, lbday, ctry, lctry, locality, llocality,"
|
" bday, lbday, ctry, lctry, locality, llocality,"
|
||||||
" email, lemail, orgname, lorgname, orgunit, lorgunit)"
|
" email, lemail, orgname, lorgname, orgunit, lorgunit)"
|
||||||
"values (",
|
"values (",
|
||||||
" '", Username, "', '", LUsername, "',"
|
" '", Username, "', '", LUsername, "',"
|
||||||
" '", SFN, "', '", SLFN, "',"
|
" '", SFN, "', '", SLFN, "',"
|
||||||
" '", SFamily, "', '", SLFamily, "',"
|
" '", SFamily, "', '", SLFamily, "',"
|
||||||
" '", SGiven, "', '", SLGiven, "',"
|
" '", SGiven, "', '", SLGiven, "',"
|
||||||
" '", SMiddle, "', '", SLMiddle, "',"
|
" '", SMiddle, "', '", SLMiddle, "',"
|
||||||
" '", SNickname, "', '", SLNickname, "',"
|
" '", SNickname, "', '", SLNickname, "',"
|
||||||
" '", SBDay, "', '", SLBDay, "',"
|
" '", SBDay, "', '", SLBDay, "',"
|
||||||
" '", SCTRY, "', '", SLCTRY, "',"
|
" '", SCTRY, "', '", SLCTRY, "',"
|
||||||
" '", SLocality, "', '", SLLocality, "',"
|
" '", SLocality, "', '", SLLocality, "',"
|
||||||
" '", SEMail, "', '", SLEMail, "',"
|
" '", SEMail, "', '", SLEMail, "',"
|
||||||
" '", SOrgName, "', '", SLOrgName, "',"
|
" '", SOrgName, "', '", SLOrgName, "',"
|
||||||
" '", SOrgUnit, "', '", SLOrgUnit, "');"]])
|
" '", SOrgUnit, "', '", SLOrgUnit, "');"]])
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
{error, badarg}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-define(TLFIELD(Type, Label, Var),
|
-define(TLFIELD(Type, Label, Var),
|
||||||
{xmlelement, "field", [{"type", Type},
|
#xmlel{ns = ?NS_VCARD, name = 'field', attrs = [
|
||||||
{"label", translate:translate(Lang, Label)},
|
#xmlattr{name = 'type', value = Type},
|
||||||
{"var", Var}], []}).
|
#xmlattr{name = 'label', value = translate:translate(Lang, Label)},
|
||||||
|
#xmlattr{name = 'var', value = Var}]}).
|
||||||
|
|
||||||
|
|
||||||
-define(FORM(JID),
|
-define(FORM(JID),
|
||||||
[{xmlelement, "instructions", [],
|
[#xmlel{ns = ?NS_SEARCH, name = 'instructions', children =
|
||||||
[{xmlcdata, translate:translate(Lang, "You need an x:data capable client to search")}]},
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "You need an x:data capable client to search"))}]},
|
||||||
{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs =
|
||||||
[{xmlelement, "title", [],
|
[#xmlattr{name = 'type', value = "form"}], children =
|
||||||
[{xmlcdata, translate:translate(Lang, "Search users in ") ++
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
||||||
jlib:jid_to_string(JID)}]},
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang, "Search users in ") ++ exmpp_jid:jid_to_list(JID))}]},
|
||||||
{xmlelement, "instructions", [],
|
#xmlel{ns = ?NS_SEARCH, name = 'instructions', children =
|
||||||
[{xmlcdata, translate:translate(Lang, "Fill in the form to search "
|
[#xmlcdata{cdata = list_to_binary(translate:translate(Lang,
|
||||||
"for any matching Jabber User "
|
"Fill in the form to search "
|
||||||
"(Add * to the end of field to "
|
"for any matching Jabber User "
|
||||||
"match substring)")}]},
|
"(Add * to the end of field to "
|
||||||
|
"match substring)"))}]},
|
||||||
?TLFIELD("text-single", "User", "user"),
|
?TLFIELD("text-single", "User", "user"),
|
||||||
?TLFIELD("text-single", "Full Name", "fn"),
|
?TLFIELD("text-single", "Full Name", "fn"),
|
||||||
?TLFIELD("text-single", "Name", "first"),
|
?TLFIELD("text-single", "Name", "first"),
|
||||||
@ -303,157 +294,139 @@ set_vcard(User, LServer, VCARD) ->
|
|||||||
]}]).
|
]}]).
|
||||||
|
|
||||||
do_route(ServerHost, From, To, Packet) ->
|
do_route(ServerHost, From, To, Packet) ->
|
||||||
#jid{user = User, resource = Resource} = To,
|
#jid{node = User, resource = Resource} = To,
|
||||||
if
|
if
|
||||||
(User /= "") or (Resource /= "") ->
|
(User /= undefined) or (Resource /= undefined) ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_SERVICE_UNAVAILABLE),
|
Err = exmpp_stanza:reply_with_error(Packet, 'service-unavailable'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
true ->
|
true ->
|
||||||
IQ = jlib:iq_query_info(Packet),
|
try
|
||||||
case IQ of
|
Request = exmpp_iq:get_request(Packet),
|
||||||
#iq{type = Type, xmlns = ?NS_SEARCH, lang = Lang, sub_el = SubEl} ->
|
Type = exmpp_iq:get_type(Packet),
|
||||||
case Type of
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
set ->
|
case {Type, Request#xmlel.ns} of
|
||||||
XDataEl = find_xdata_el(SubEl),
|
{set, ?NS_SEARCH} ->
|
||||||
case XDataEl of
|
XDataEl = find_xdata_el(Request),
|
||||||
false ->
|
case XDataEl of
|
||||||
Err = jlib:make_error_reply(
|
false ->
|
||||||
Packet, ?ERR_BAD_REQUEST),
|
Err = exmpp_iq:error(Packet, 'bad-request'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
_ ->
|
_ ->
|
||||||
XData = jlib:parse_xdata_submit(XDataEl),
|
XData = jlib:parse_xdata_submit(XDataEl),
|
||||||
case XData of
|
case XData of
|
||||||
invalid ->
|
invalid ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(Packet,
|
||||||
Packet,
|
'bad-request'),
|
||||||
?ERR_BAD_REQUEST),
|
ejabberd_router:route(To, From,
|
||||||
ejabberd_router:route(To, From,
|
Err);
|
||||||
Err);
|
_ ->
|
||||||
_ ->
|
Result = #xmlel{
|
||||||
ResIQ =
|
ns = ?NS_SEARCH,
|
||||||
IQ#iq{
|
name = 'query',
|
||||||
type = result,
|
children = [
|
||||||
sub_el =
|
#xmlel{
|
||||||
[{xmlelement,
|
ns = ?NS_DATA_FORMS,
|
||||||
"query",
|
name = 'x',
|
||||||
[{"xmlns", ?NS_SEARCH}],
|
attrs = [#xmlattr{name = 'type',
|
||||||
[{xmlelement, "x",
|
value = "result"}],
|
||||||
[{"xmlns", ?NS_XDATA},
|
children = search_result(Lang,
|
||||||
{"type", "result"}],
|
To, ServerHost, XData)}]},
|
||||||
search_result(Lang, To, ServerHost, XData)
|
ResIQ = exmpp_iq:result(Packet,
|
||||||
}]}]},
|
Result),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
To, From, jlib:iq_to_xml(ResIQ))
|
To, From, jlib:iq_to_xml(ResIQ))
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
get ->
|
{get, ?NS_SEARCH} ->
|
||||||
ResIQ = IQ#iq{type = result,
|
Result = #xmlel{ns = ?NS_SEARCH, name = 'query',
|
||||||
sub_el = [{xmlelement,
|
children = ?FORM(To)},
|
||||||
"query",
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
[{"xmlns", ?NS_SEARCH}],
|
ejabberd_router:route(To,
|
||||||
?FORM(To)
|
From,
|
||||||
}]},
|
ResIQ);
|
||||||
ejabberd_router:route(To,
|
{set, ?NS_DISCO_INFO} ->
|
||||||
From,
|
Err = exmpp_iq:error(Packet, 'not-allowed'),
|
||||||
jlib:iq_to_xml(ResIQ))
|
ejabberd_router:route(To, From, Err);
|
||||||
end;
|
{get, ?NS_DISCO_INFO} ->
|
||||||
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
|
Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query',
|
||||||
case Type of
|
children = [
|
||||||
set ->
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'identity',
|
||||||
Err = jlib:make_error_reply(
|
attrs = [
|
||||||
Packet, ?ERR_NOT_ALLOWED),
|
#xmlattr{name = 'category',
|
||||||
ejabberd_router:route(To, From, Err);
|
value = "directory"},
|
||||||
get ->
|
#xmlattr{name = 'type',
|
||||||
ResIQ =
|
value = "user"},
|
||||||
IQ#iq{type = result,
|
#xmlattr{name = 'name',
|
||||||
sub_el = [{xmlelement,
|
value = translate:translate(Lang,
|
||||||
"query",
|
"vCard User Search")}]},
|
||||||
[{"xmlns", ?NS_DISCO_INFO}],
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature',
|
||||||
[{xmlelement, "identity",
|
attrs = [
|
||||||
[{"category", "directory"},
|
#xmlattr{name = 'var',
|
||||||
{"type", "user"},
|
value = ?NS_SEARCH_s}]},
|
||||||
{"name",
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature',
|
||||||
translate:translate(Lang, "vCard User Search")}],
|
attrs = [
|
||||||
[]},
|
#xmlattr{name = 'var',
|
||||||
{xmlelement, "feature",
|
value = ?NS_VCARD_s}]}
|
||||||
[{"var", ?NS_SEARCH}], []},
|
]},
|
||||||
{xmlelement, "feature",
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
[{"var", ?NS_VCARD}], []}
|
ejabberd_router:route(To,
|
||||||
]
|
From,
|
||||||
}]},
|
ResIQ);
|
||||||
ejabberd_router:route(To,
|
{set, ?NS_DISCO_ITEMS} ->
|
||||||
From,
|
Err = exmpp_iq:error(Packet, 'not-allowed'),
|
||||||
jlib:iq_to_xml(ResIQ))
|
ejabberd_router:route(To, From, Err);
|
||||||
end;
|
{get, ?NS_DISCO_ITEMS} ->
|
||||||
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} ->
|
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query'},
|
||||||
case Type of
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
set ->
|
ejabberd_router:route(To,
|
||||||
Err = jlib:make_error_reply(
|
From,
|
||||||
Packet, ?ERR_NOT_ALLOWED),
|
ResIQ);
|
||||||
ejabberd_router:route(To, From, Err);
|
{get, ?NS_VCARD} ->
|
||||||
get ->
|
Result = #xmlel{ns = ?NS_VCARD, name = 'vCard',
|
||||||
ResIQ =
|
children = iq_get_vcard(Lang)},
|
||||||
IQ#iq{type = result,
|
ResIQ = exmpp_iq:result(Packet, Result),
|
||||||
sub_el = [{xmlelement,
|
ejabberd_router:route(To,
|
||||||
"query",
|
From,
|
||||||
[{"xmlns", ?NS_DISCO_ITEMS}],
|
ResIQ);
|
||||||
[]}]},
|
_ ->
|
||||||
ejabberd_router:route(To,
|
Err = exmpp_iq:error(Packet, 'service-unavailable'),
|
||||||
From,
|
ejabberd_router:route(To, From, Err)
|
||||||
jlib:iq_to_xml(ResIQ))
|
end
|
||||||
end;
|
catch
|
||||||
#iq{type = get, xmlns = ?NS_VCARD, lang = Lang} ->
|
|
||||||
ResIQ =
|
|
||||||
IQ#iq{type = result,
|
|
||||||
sub_el = [{xmlelement,
|
|
||||||
"vCard",
|
|
||||||
[{"xmlns", ?NS_VCARD}],
|
|
||||||
iq_get_vcard(Lang)}]},
|
|
||||||
ejabberd_router:route(To,
|
|
||||||
From,
|
|
||||||
jlib:iq_to_xml(ResIQ));
|
|
||||||
_ ->
|
_ ->
|
||||||
Err = jlib:make_error_reply(Packet,
|
Err1 = exmpp_iq:error(Packet, 'service-unavailable'),
|
||||||
?ERR_SERVICE_UNAVAILABLE),
|
ejabberd_router:route(To, From, Err1)
|
||||||
ejabberd_router:route(To, From, Err)
|
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
iq_get_vcard(Lang) ->
|
iq_get_vcard(Lang) ->
|
||||||
[{xmlelement, "FN", [],
|
[
|
||||||
[{xmlcdata, "ejabberd/mod_vcard"}]},
|
#xmlel{ns = ?NS_SEARCH, name = 'FN', children = [
|
||||||
{xmlelement, "URL", [],
|
#xmlcdata{cdata = <<"ejabberd/mod_vcard">>}]},
|
||||||
[{xmlcdata, ?EJABBERD_URI}]},
|
#xmlel{ns = ?NS_SEARCH, name = 'URL', children = [
|
||||||
{xmlelement, "DESC", [],
|
#xmlcdata{cdata = list_to_binary(?EJABBERD_URI)}]},
|
||||||
[{xmlcdata, translate:translate(
|
#xmlel{ns = ?NS_SEARCH, name ='DESC', children = [
|
||||||
Lang,
|
#xmlcdata{cdata = list_to_binary(
|
||||||
"ejabberd vCard module") ++
|
translate:translate(Lang, "ejabberd vCard module") ++
|
||||||
"\nCopyright (c) 2003-2008 ProcessOne"}]}].
|
"\nCopyright (c) 2003-2008 ProcessOne")}]}
|
||||||
|
].
|
||||||
|
|
||||||
find_xdata_el({xmlelement, _Name, _Attrs, SubEls}) ->
|
find_xdata_el(#xmlel{children = SubEls}) ->
|
||||||
find_xdata_el1(SubEls).
|
find_xdata_el1(SubEls).
|
||||||
|
|
||||||
find_xdata_el1([]) ->
|
find_xdata_el1([]) ->
|
||||||
false;
|
false;
|
||||||
find_xdata_el1([{xmlelement, Name, Attrs, SubEls} | Els]) ->
|
find_xdata_el1([#xmlel{ns = ?NS_DATA_FORMS} = El | _Els]) ->
|
||||||
case xml:get_attr_s("xmlns", Attrs) of
|
El;
|
||||||
?NS_XDATA ->
|
|
||||||
{xmlelement, Name, Attrs, SubEls};
|
|
||||||
_ ->
|
|
||||||
find_xdata_el1(Els)
|
|
||||||
end;
|
|
||||||
find_xdata_el1([_ | Els]) ->
|
find_xdata_el1([_ | Els]) ->
|
||||||
find_xdata_el1(Els).
|
find_xdata_el1(Els).
|
||||||
|
|
||||||
-define(LFIELD(Label, Var),
|
|
||||||
{xmlelement, "field", [{"label", translate:translate(Lang, Label)},
|
|
||||||
{"var", Var}], []}).
|
|
||||||
|
|
||||||
search_result(Lang, JID, ServerHost, Data) ->
|
search_result(Lang, JID, ServerHost, Data) ->
|
||||||
[{xmlelement, "title", [],
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children =
|
||||||
[{xmlcdata, translate:translate(Lang, "Search Results for ") ++
|
[#xmlcdata{cdata = list_to_binary(
|
||||||
jlib:jid_to_string(JID)}]},
|
translate:translate(Lang, "Search Results for ") ++
|
||||||
{xmlelement, "reported", [],
|
exmpp_jid:jid_to_list(JID))}]},
|
||||||
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'reported', children =
|
||||||
[?TLFIELD("text-single", "Jabber ID", "jid"),
|
[?TLFIELD("text-single", "Jabber ID", "jid"),
|
||||||
?TLFIELD("text-single", "Full Name", "fn"),
|
?TLFIELD("text-single", "Full Name", "fn"),
|
||||||
?TLFIELD("text-single", "Name", "first"),
|
?TLFIELD("text-single", "Name", "first"),
|
||||||
@ -470,15 +443,16 @@ search_result(Lang, JID, ServerHost, Data) ->
|
|||||||
search(ServerHost, Data)).
|
search(ServerHost, Data)).
|
||||||
|
|
||||||
-define(FIELD(Var, Val),
|
-define(FIELD(Var, Val),
|
||||||
{xmlelement, "field", [{"var", Var}],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
||||||
[{xmlelement, "value", [],
|
[#xmlattr{name = 'var', value = Var}], children =
|
||||||
[{xmlcdata, Val}]}]}).
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =
|
||||||
|
[#xmlcdata{cdata = list_to_binary(Val)}]}]}).
|
||||||
|
|
||||||
|
|
||||||
record_to_item(LServer, {Username, FN, Family, Given, Middle,
|
record_to_item(LServer, {Username, FN, Family, Given, Middle,
|
||||||
Nickname, BDay, CTRY, Locality,
|
Nickname, BDay, CTRY, Locality,
|
||||||
EMail, OrgName, OrgUnit}) ->
|
EMail, OrgName, OrgUnit}) ->
|
||||||
{xmlelement, "item", [],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'item', children =
|
||||||
[
|
[
|
||||||
?FIELD("jid", Username ++ "@" ++ LServer),
|
?FIELD("jid", Username ++ "@" ++ LServer),
|
||||||
?FIELD("fn", FN),
|
?FIELD("fn", FN),
|
||||||
@ -546,7 +520,7 @@ filter_fields([], Match, _LServer) ->
|
|||||||
end;
|
end;
|
||||||
filter_fields([{SVar, [Val]} | Ds], Match, LServer)
|
filter_fields([{SVar, [Val]} | Ds], Match, LServer)
|
||||||
when is_list(Val) and (Val /= "") ->
|
when is_list(Val) and (Val /= "") ->
|
||||||
LVal = stringprep:tolower(Val),
|
LVal = exmpp_stringprep:to_lower(Val),
|
||||||
NewMatch = case SVar of
|
NewMatch = case SVar of
|
||||||
"user" -> make_val(Match, "lusername", LVal);
|
"user" -> make_val(Match, "lusername", LVal);
|
||||||
"fn" -> make_val(Match, "lfn", LVal);
|
"fn" -> make_val(Match, "lfn", LVal);
|
||||||
@ -659,8 +633,8 @@ make_val(Match, Field, Val) ->
|
|||||||
|
|
||||||
|
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
ejabberd_odbc:sql_transaction(
|
ejabberd_odbc:sql_transaction(
|
||||||
LServer,
|
LServer,
|
||||||
|
Loading…
Reference in New Issue
Block a user