25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Work also with some unicode strings in PgSQL (EJAB-1490)

This commit is contained in:
Badlop 2012-02-14 13:18:18 +01:00
parent 7d623d5eb4
commit 112a18f966
2 changed files with 47 additions and 35 deletions

View File

@ -219,17 +219,17 @@ set_vcard(User, LServer, VCARD) ->
end, end,
LUser = jlib:nodeprep(User), LUser = jlib:nodeprep(User),
LFN = string:to_lower(FN), LFN = string2lower(FN),
LFamily = string:to_lower(Family), LFamily = string2lower(Family),
LGiven = string:to_lower(Given), LGiven = string2lower(Given),
LMiddle = string:to_lower(Middle), LMiddle = string2lower(Middle),
LNickname = string:to_lower(Nickname), LNickname = string2lower(Nickname),
LBDay = string:to_lower(BDay), LBDay = string2lower(BDay),
LCTRY = string:to_lower(CTRY), LCTRY = string2lower(CTRY),
LLocality = string:to_lower(Locality), LLocality = string2lower(Locality),
LEMail = string:to_lower(EMail), LEMail = string2lower(EMail),
LOrgName = string:to_lower(OrgName), LOrgName = string2lower(OrgName),
LOrgUnit = string:to_lower(OrgUnit), LOrgUnit = string2lower(OrgUnit),
US = {LUser, LServer}, US = {LUser, LServer},
@ -271,6 +271,12 @@ set_vcard(User, LServer, VCARD) ->
ejabberd_hooks:run(vcard_set, LServer, [LUser, LServer, VCARD]) ejabberd_hooks:run(vcard_set, LServer, [LUser, LServer, VCARD])
end. end.
string2lower(String) ->
case stringprep:tolower(String) of
Lower when is_list(Lower) -> Lower;
error -> string:to_lower(String)
end.
-define(TLFIELD(Type, Label, Var), -define(TLFIELD(Type, Label, Var),
{xmlelement, "field", [{"type", Type}, {xmlelement, "field", [{"type", Type},
{"label", translate:translate(Lang, Label)}, {"label", translate:translate(Lang, Label)},
@ -541,7 +547,7 @@ filter_fields([], Match, _LServer) ->
Match; Match;
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 = string:to_lower(Val), LVal = string2lower(Val),
NewMatch = case SVar of NewMatch = case SVar of
"user" -> "user" ->
case gen_mod:get_module_opt(LServer, ?MODULE, case gen_mod:get_module_opt(LServer, ?MODULE,
@ -618,17 +624,17 @@ set_vcard_t(R, _) ->
OrgUnit = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]), OrgUnit = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]),
{LUser, _LServer} = US, {LUser, _LServer} = US,
LFN = string:to_lower(FN), LFN = string2lower(FN),
LFamily = string:to_lower(Family), LFamily = string2lower(Family),
LGiven = string:to_lower(Given), LGiven = string2lower(Given),
LMiddle = string:to_lower(Middle), LMiddle = string2lower(Middle),
LNickname = string:to_lower(Nickname), LNickname = string2lower(Nickname),
LBDay = string:to_lower(BDay), LBDay = string2lower(BDay),
LCTRY = string:to_lower(CTRY), LCTRY = string2lower(CTRY),
LLocality = string:to_lower(Locality), LLocality = string2lower(Locality),
LEMail = string:to_lower(EMail), LEMail = string2lower(EMail),
LOrgName = string:to_lower(OrgName), LOrgName = string2lower(OrgName),
LOrgUnit = string:to_lower(OrgUnit), LOrgUnit = string2lower(OrgUnit),
if if
(LUser == error) or (LUser == error) or

View File

@ -186,17 +186,17 @@ set_vcard(User, LServer, VCARD) ->
end, end,
LUser = jlib:nodeprep(User), LUser = jlib:nodeprep(User),
LFN = string:to_lower(FN), LFN = string2lower(FN),
LFamily = string:to_lower(Family), LFamily = string2lower(Family),
LGiven = string:to_lower(Given), LGiven = string2lower(Given),
LMiddle = string:to_lower(Middle), LMiddle = string2lower(Middle),
LNickname = string:to_lower(Nickname), LNickname = string2lower(Nickname),
LBDay = string:to_lower(BDay), LBDay = string2lower(BDay),
LCTRY = string:to_lower(CTRY), LCTRY = string2lower(CTRY),
LLocality = string:to_lower(Locality), LLocality = string2lower(Locality),
LEMail = string:to_lower(EMail), LEMail = string2lower(EMail),
LOrgName = string:to_lower(OrgName), LOrgName = string2lower(OrgName),
LOrgUnit = string:to_lower(OrgUnit), LOrgUnit = string2lower(OrgUnit),
if if
(LUser == error) or (LUser == error) or
@ -252,6 +252,12 @@ set_vcard(User, LServer, VCARD) ->
ejabberd_hooks:run(vcard_set, LServer, [LUser, LServer, VCARD]) ejabberd_hooks:run(vcard_set, LServer, [LUser, LServer, VCARD])
end. end.
string2lower(String) ->
case stringprep:tolower(String) of
Lower when is_list(Lower) -> Lower;
error -> string:to_lower(String)
end.
-define(TLFIELD(Type, Label, Var), -define(TLFIELD(Type, Label, Var),
{xmlelement, "field", [{"type", Type}, {xmlelement, "field", [{"type", Type},
{"label", translate:translate(Lang, Label)}, {"label", translate:translate(Lang, Label)},
@ -531,7 +537,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 = string:to_lower(Val), LVal = string2lower(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);