mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-12 21:52:07 +02:00
Improve vCard creation from LDAP result
This commit is contained in:
parent
0bcbd12776
commit
e258462b6b
|
@ -75,8 +75,9 @@ get_vcard(LUser, LServer) ->
|
||||||
VCardMap = State#state.vcard_map,
|
VCardMap = State#state.vcard_map,
|
||||||
case find_ldap_user(LUser, State) of
|
case find_ldap_user(LUser, State) of
|
||||||
#eldap_entry{attributes = Attributes} ->
|
#eldap_entry{attributes = Attributes} ->
|
||||||
ldap_attributes_to_vcard(Attributes, VCardMap,
|
VCard = ldap_attributes_to_vcard(Attributes, VCardMap,
|
||||||
{LUser, LServer});
|
{LUser, LServer}),
|
||||||
|
[xmpp:encode(VCard)];
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
end.
|
end.
|
||||||
|
@ -218,108 +219,47 @@ ldap_attributes_to_vcard(Attributes, VCardMap, UD) ->
|
||||||
UD)}
|
UD)}
|
||||||
end,
|
end,
|
||||||
VCardMap),
|
VCardMap),
|
||||||
Elts = [ldap_attribute_to_vcard(vCard, Attr)
|
lists:foldl(fun ldap_attribute_to_vcard/2, #vcard_temp{}, Attrs).
|
||||||
|| Attr <- Attrs],
|
|
||||||
NElts = [ldap_attribute_to_vcard(vCardN, Attr)
|
|
||||||
|| Attr <- Attrs],
|
|
||||||
OElts = [ldap_attribute_to_vcard(vCardO, Attr)
|
|
||||||
|| Attr <- Attrs],
|
|
||||||
AElts = [ldap_attribute_to_vcard(vCardA, Attr)
|
|
||||||
|| Attr <- Attrs],
|
|
||||||
[#xmlel{name = <<"vCard">>,
|
|
||||||
attrs = [{<<"xmlns">>, ?NS_VCARD}],
|
|
||||||
children =
|
|
||||||
lists:append([X || X <- Elts, X /= none],
|
|
||||||
[#xmlel{name = <<"N">>, attrs = [],
|
|
||||||
children = [X || X <- NElts, X /= none]},
|
|
||||||
#xmlel{name = <<"ORG">>, attrs = [],
|
|
||||||
children = [X || X <- OElts, X /= none]},
|
|
||||||
#xmlel{name = <<"ADR">>, attrs = [],
|
|
||||||
children =
|
|
||||||
[X || X <- AElts, X /= none]}])}].
|
|
||||||
|
|
||||||
ldap_attribute_to_vcard(vCard, {<<"fn">>, Value}) ->
|
-spec ldap_attribute_to_vcard({binary(), binary()}, vcard_temp()) -> vcard_temp().
|
||||||
#xmlel{name = <<"FN">>, attrs = [],
|
ldap_attribute_to_vcard({Attr, Value}, V) ->
|
||||||
children = [{xmlcdata, Value}]};
|
Ts = V#vcard_temp.tel,
|
||||||
ldap_attribute_to_vcard(vCard,
|
Es = V#vcard_temp.email,
|
||||||
{<<"nickname">>, Value}) ->
|
N = case V#vcard_temp.n of
|
||||||
#xmlel{name = <<"NICKNAME">>, attrs = [],
|
undefined -> #vcard_name{};
|
||||||
children = [{xmlcdata, Value}]};
|
_ -> V#vcard_temp.n
|
||||||
ldap_attribute_to_vcard(vCard, {<<"title">>, Value}) ->
|
end,
|
||||||
#xmlel{name = <<"TITLE">>, attrs = [],
|
O = case V#vcard_temp.org of
|
||||||
children = [{xmlcdata, Value}]};
|
undefined -> #vcard_org{};
|
||||||
ldap_attribute_to_vcard(vCard, {<<"bday">>, Value}) ->
|
_ -> V#vcard_temp.org
|
||||||
#xmlel{name = <<"BDAY">>, attrs = [],
|
end,
|
||||||
children = [{xmlcdata, Value}]};
|
A = case V#vcard_temp.adr of
|
||||||
ldap_attribute_to_vcard(vCard, {<<"url">>, Value}) ->
|
[] -> #vcard_adr{};
|
||||||
#xmlel{name = <<"URL">>, attrs = [],
|
As -> hd(As)
|
||||||
children = [{xmlcdata, Value}]};
|
end,
|
||||||
ldap_attribute_to_vcard(vCard, {<<"desc">>, Value}) ->
|
case Attr of
|
||||||
#xmlel{name = <<"DESC">>, attrs = [],
|
<<"fn">> -> V#vcard_temp{fn = Value};
|
||||||
children = [{xmlcdata, Value}]};
|
<<"nickname">> -> V#vcard_temp{nickname = Value};
|
||||||
ldap_attribute_to_vcard(vCard, {<<"role">>, Value}) ->
|
<<"title">> -> V#vcard_temp{title = Value};
|
||||||
#xmlel{name = <<"ROLE">>, attrs = [],
|
<<"bday">> -> V#vcard_temp{bday = Value};
|
||||||
children = [{xmlcdata, Value}]};
|
<<"url">> -> V#vcard_temp{url = Value};
|
||||||
ldap_attribute_to_vcard(vCard, {<<"tel">>, Value}) ->
|
<<"desc">> -> V#vcard_temp{desc = Value};
|
||||||
#xmlel{name = <<"TEL">>, attrs = [],
|
<<"role">> -> V#vcard_temp{role = Value};
|
||||||
children =
|
<<"tel">> -> V#vcard_temp{tel = [#vcard_tel{number = Value}|Ts]};
|
||||||
[#xmlel{name = <<"VOICE">>, attrs = [], children = []},
|
<<"email">> -> V#vcard_temp{email = [#vcard_email{userid = Value}|Es]};
|
||||||
#xmlel{name = <<"WORK">>, attrs = [], children = []},
|
<<"photo">> -> V#vcard_temp{photo = #vcard_photo{binval = Value}};
|
||||||
#xmlel{name = <<"NUMBER">>, attrs = [],
|
<<"family">> -> V#vcard_temp{n = N#vcard_name{family = V}};
|
||||||
children = [{xmlcdata, Value}]}]};
|
<<"given">> -> V#vcard_temp{n = N#vcard_name{given = V}};
|
||||||
ldap_attribute_to_vcard(vCard, {<<"email">>, Value}) ->
|
<<"middle">> -> V#vcard_temp{n = N#vcard_name{middle = V}};
|
||||||
#xmlel{name = <<"EMAIL">>, attrs = [],
|
<<"orgname">> -> V#vcard_temp{org = O#vcard_org{name = V}};
|
||||||
children =
|
<<"orgunit">> -> V#vcard_temp{org = O#vcard_org{units = [Value]}};
|
||||||
[#xmlel{name = <<"INTERNET">>, attrs = [],
|
<<"locality">> -> V#vcard_temp{adr = [A#vcard_adr{locality = Value}]};
|
||||||
children = []},
|
<<"street">> -> V#vcard_temp{adr = [A#vcard_adr{street = Value}]};
|
||||||
#xmlel{name = <<"PREF">>, attrs = [], children = []},
|
<<"ctry">> -> V#vcard_temp{adr = [A#vcard_adr{ctry = Value}]};
|
||||||
#xmlel{name = <<"USERID">>, attrs = [],
|
<<"region">> -> V#vcard_temp{adr = [A#vcard_adr{region = Value}]};
|
||||||
children = [{xmlcdata, Value}]}]};
|
<<"pcode">> -> V#vcard_temp{adr = [A#vcard_adr{pcode = Value}]};
|
||||||
ldap_attribute_to_vcard(vCard, {<<"photo">>, Value}) ->
|
_ -> V
|
||||||
#xmlel{name = <<"PHOTO">>, attrs = [],
|
end.
|
||||||
children =
|
|
||||||
[#xmlel{name = <<"TYPE">>, attrs = [],
|
|
||||||
children = [{xmlcdata, <<"image/jpeg">>}]},
|
|
||||||
#xmlel{name = <<"BINVAL">>, attrs = [],
|
|
||||||
children = [{xmlcdata, jlib:encode_base64(Value)}]}]};
|
|
||||||
ldap_attribute_to_vcard(vCardN,
|
|
||||||
{<<"family">>, Value}) ->
|
|
||||||
#xmlel{name = <<"FAMILY">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardN, {<<"given">>, Value}) ->
|
|
||||||
#xmlel{name = <<"GIVEN">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardN,
|
|
||||||
{<<"middle">>, Value}) ->
|
|
||||||
#xmlel{name = <<"MIDDLE">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardO,
|
|
||||||
{<<"orgname">>, Value}) ->
|
|
||||||
#xmlel{name = <<"ORGNAME">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardO,
|
|
||||||
{<<"orgunit">>, Value}) ->
|
|
||||||
#xmlel{name = <<"ORGUNIT">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardA,
|
|
||||||
{<<"locality">>, Value}) ->
|
|
||||||
#xmlel{name = <<"LOCALITY">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardA,
|
|
||||||
{<<"street">>, Value}) ->
|
|
||||||
#xmlel{name = <<"STREET">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardA, {<<"ctry">>, Value}) ->
|
|
||||||
#xmlel{name = <<"CTRY">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardA,
|
|
||||||
{<<"region">>, Value}) ->
|
|
||||||
#xmlel{name = <<"REGION">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(vCardA, {<<"pcode">>, Value}) ->
|
|
||||||
#xmlel{name = <<"PCODE">>, attrs = [],
|
|
||||||
children = [{xmlcdata, Value}]};
|
|
||||||
ldap_attribute_to_vcard(_, _) -> none.
|
|
||||||
|
|
||||||
map_vcard_attr(VCardName, Attributes, Pattern, UD) ->
|
map_vcard_attr(VCardName, Attributes, Pattern, UD) ->
|
||||||
Res = lists:filter(fun ({Name, _, _}) ->
|
Res = lists:filter(fun ({Name, _, _}) ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user