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

ODBC support for mod_shared_roster

This commit is contained in:
Evgeniy Khramtsov 2012-04-04 20:37:43 +10:00
parent 5fab00011e
commit 41a0eae0bd
7 changed files with 1294 additions and 19 deletions

View File

@ -98,6 +98,7 @@
\newcommand{\modrosterodbc}{\module{mod\_roster\_odbc}}
\newcommand{\modservicelog}{\module{mod\_service\_log}}
\newcommand{\modsharedroster}{\module{mod\_shared\_roster}}
\newcommand{\modsharedrosterodbc}{\module{mod\_shared\_roster\_odbc}}
\newcommand{\modsharedrosterldap}{\module{mod\_shared\_roster\_ldap}}
\newcommand{\modsic}{\module{mod\_sic}}
\newcommand{\modstats}{\module{mod\_stats}}
@ -2616,6 +2617,8 @@ The following table lists all modules included in \ejabberd{}.
\hline \ahrefloc{modservicelog}{\modservicelog{}} & Copy user messages to logger service & \\
\hline \ahrefloc{modsharedroster}{\modsharedroster{}} & Shared roster management & \modroster{} or \\
& & \modrosterodbc\\
\hline \ahrefloc{modsharedroster}{\modsharedrosterodbc{}} & Shared roster management & supported DB (*) and\\
& & \modroster{} or \modrosterodbc\\
\hline \ahrefloc{modsharedrosterldap}{\modsharedrosterldap{}} & LDAP Shared roster management & \modroster{} or \\
& & \modrosterodbc\\
\hline \ahrefloc{modsic}{\modsic{}} & Server IP Check (\xepref{0279}) & \\
@ -2656,6 +2659,7 @@ database for the following data:
\item Offline messages: Use \term{mod\_offline\_odbc} instead of
\term{mod\_offline}.
\item Rosters: Use \term{mod\_roster\_odbc} instead of \term{mod\_roster}.
\item Shared Rosters: Use \term{mod\_shared\_roster\_odbc} instead of \term{mod\_shared\_roster}.
\item Users' VCARD: Use \term{mod\_vcard\_odbc} instead of \term{mod\_vcard}.
\item vCard-Based Avatars: Use \term{mod\_vcard\_xupdate\_odbc} instead of \term{mod\_vcard\_xupdate}.
\item Private XML storage: Use \term{mod\_private\_odbc} instead of \term{mod\_private}.
@ -4062,7 +4066,7 @@ Options:
This option does not affect the client in any way.
This option is only useful if Roster Versioning is enabled.
This option is disabled by default.
Important: if you use \modsharedroster{} or \modsharedrosterldap{},
Important: if you use \modsharedroster{}, \modsharedrosterodbc{} or \modsharedrosterldap{},
you must disable this option.
\end{description}

View File

@ -181,9 +181,11 @@ match_acl(ACL, JID, Host) ->
lists:member(Server, ?MYHOSTS)))
andalso is_regexp_match(User, UR);
{shared_group, G} ->
mod_shared_roster:is_user_in_group({User, Server}, G, Host);
Mod = loaded_shared_roster_module(Host),
Mod:is_user_in_group({User, Server}, G, Host);
{shared_group, G, H} ->
mod_shared_roster:is_user_in_group({User, Server}, G, H);
Mod = loaded_shared_roster_module(H),
Mod:is_user_in_group({User, Server}, G, H);
{user_regexp, UR, S} ->
(S == Server) andalso
is_regexp_match(User, UR);
@ -238,4 +240,10 @@ is_regexp_match(String, RegExp) ->
is_glob_match(String, Glob) ->
is_regexp_match(String, ejabberd_regexp:sh_to_awk(Glob)).
loaded_shared_roster_module(Host) ->
case {gen_mod:is_loaded(Host, mod_shared_roster_odbc),
gen_mod:is_loaded(Host, mod_shared_roster_ldap)} of
{true, _} -> mod_shared_roster_odbc;
{_, true} -> mod_shared_roster_ldap;
_ -> mod_shared_roster
end.

View File

@ -40,6 +40,8 @@
export_motd/2,
export_motd_users/2,
export_irc_custom/2,
export_sr_group/2,
export_sr_user/2,
export_muc_room/2,
export_muc_registered/2]).
@ -70,6 +72,8 @@
-record(irc_custom, {us_host, data}).
-record(muc_room, {name_host, opts}).
-record(muc_registered, {us_host, nick}).
-record(sr_group, {group_host, opts}).
-record(sr_user, {us, group_host}).
-record(motd, {server, packet}).
-record(motd_users, {us, dummy = []}).
@ -397,6 +401,38 @@ export_privacy(Server, Output) ->
[]
end).
export_sr_group(Server, Output) ->
export_common(
Server, sr_group, Output,
fun(Host, #sr_group{group_host = {Group, LServer}, opts = Opts})
when LServer == Host ->
SGroup = ejabberd_odbc:escape(Group),
SOpts = mod_shared_roster_odbc:encode_opts(Opts),
["delete from sr_group where name='", Group, "';"
"insert into sr_group(name, opts) values ('",
SGroup, "', '", SOpts, "');"];
(_Host, _R) ->
[]
end).
export_sr_user(Server, Output) ->
export_common(
Server, sr_user, Output,
fun(Host, #sr_user{us = {U, S}, group_host = {Group, LServer}})
when LServer == Host ->
SGroup = ejabberd_odbc:escape(Group),
SJID = ejabberd_odbc:escape(
jlib:jid_to_string(
jlib:jid_tolower(
jlib:make_jid(U, S, "")))),
["delete from sr_user where jid='", SJID,
"'and grp='", Group, "';"
"insert into sr_user(jid, grp) values ('",
SJID, "', '", SGroup, "');"];
(_Host, _R) ->
[]
end).
export_motd(Server, Output) ->
export_common(
Server, motd, Output,

View File

@ -186,7 +186,7 @@ get_vcard_module(Server) ->
get_rosteritem_name([], _, _) ->
"";
get_rosteritem_name([ModVcard], U, S) ->
From = jlib:make_jid("", S, mod_shared_roster),
From = jlib:make_jid("", S, ?MODULE),
To = jlib:make_jid(U, S, ""),
IQ = {iq,"",get,"vcard-temp","",
{xmlelement,"vCard",[{"xmlns","vcard-temp"}],[]}},
@ -619,14 +619,14 @@ add_user_to_group(Host, US, Group) ->
{LUser, LServer} = US,
case ejabberd_regexp:run(LUser, "^@.+@$") of
match ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
GroupOpts = ?MODULE:get_group_opts(Host, Group),
MoreGroupOpts =
case LUser of
"@all@" -> [{all_users, true}];
"@online@" -> [{online_users, true}];
_ -> []
end,
mod_shared_roster:set_group_opts(
?MODULE:set_group_opts(
Host, Group,
GroupOpts ++ MoreGroupOpts);
nomatch ->
@ -652,7 +652,7 @@ remove_user_from_group(Host, US, Group) ->
{LUser, LServer} = US,
case ejabberd_regexp:run(LUser, "^@.+@$") of
match ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
GroupOpts = ?MODULE:get_group_opts(Host, Group),
NewGroupOpts =
case LUser of
"@all@" ->
@ -660,7 +660,7 @@ remove_user_from_group(Host, US, Group) ->
"@online@" ->
lists:filter(fun(X) -> X/={online_users,true} end, GroupOpts)
end,
mod_shared_roster:set_group_opts(Host, Group, NewGroupOpts);
?MODULE:set_group_opts(Host, Group, NewGroupOpts);
nomatch ->
R = #sr_user{us = US, group_host = GroupHost},
F = fun() ->
@ -876,7 +876,7 @@ webadmin_page(Acc, _, _) -> Acc.
list_shared_roster_groups(Host, Query, Lang) ->
Res = list_sr_groups_parse_query(Host, Query),
SRGroups = mod_shared_roster:list_groups(Host),
SRGroups = ?MODULE:list_groups(Host),
FGroups =
?XAE("table", [],
[?XE("tbody",
@ -925,19 +925,19 @@ list_sr_groups_parse_query(Host, Query) ->
list_sr_groups_parse_addnew(Host, Query) ->
case lists:keysearch("namenew", 1, Query) of
{value, {_, Group}} when Group /= "" ->
mod_shared_roster:create_group(Host, Group),
?MODULE:create_group(Host, Group),
ok;
_ ->
error
end.
list_sr_groups_parse_delete(Host, Query) ->
SRGroups = mod_shared_roster:list_groups(Host),
SRGroups = ?MODULE:list_groups(Host),
lists:foreach(
fun(Group) ->
case lists:member({"selected", Group}, Query) of
true ->
mod_shared_roster:delete_group(Host, Group);
?MODULE:delete_group(Host, Group);
_ ->
ok
end
@ -947,14 +947,14 @@ list_sr_groups_parse_delete(Host, Query) ->
shared_roster_group(Host, Group, Query, Lang) ->
Res = shared_roster_group_parse_query(Host, Group, Query),
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
GroupOpts = ?MODULE:get_group_opts(Host, Group),
Name = get_opt(GroupOpts, name, ""),
Description = get_opt(GroupOpts, description, ""),
AllUsers = get_opt(GroupOpts, all_users, false),
OnlineUsers = get_opt(GroupOpts, online_users, false),
%%Disabled = false,
DisplayedGroups = get_opt(GroupOpts, displayed_groups, []),
Members = mod_shared_roster:get_group_explicit_users(Host, Group),
Members = ?MODULE:get_group_explicit_users(Host, Group),
FMembers =
if
AllUsers ->
@ -1042,7 +1042,7 @@ shared_roster_group_parse_query(Host, Group, Query) ->
true -> [{displayed_groups, DispGroups}]
end,
OldMembers = mod_shared_roster:get_group_explicit_users(
OldMembers = ?MODULE:get_group_explicit_users(
Host, Group),
SJIDs = string:tokens(SMembers, ", \r\n"),
NewMembers =
@ -1074,7 +1074,7 @@ shared_roster_group_parse_query(Host, Group, Query) ->
false -> []
end,
mod_shared_roster:set_group_opts(
?MODULE:set_group_opts(
Host, Group,
NameOpt ++ DispGroupsOpt ++ DescriptionOpt ++ AllUsersOpt ++ OnlineUsersOpt),
@ -1085,12 +1085,12 @@ shared_roster_group_parse_query(Host, Group, Query) ->
RemovedMembers = OldMembers -- NewMembers,
lists:foreach(
fun(US) ->
mod_shared_roster:remove_user_from_group(
?MODULE:remove_user_from_group(
Host, US, Group)
end, RemovedMembers),
lists:foreach(
fun(US) ->
mod_shared_roster:add_user_to_group(
?MODULE:add_user_to_group(
Host, US, Group)
end, AddedMembers),
ok

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,21 @@ CREATE TABLE rostergroups (
CREATE INDEX pk_rosterg_user_jid ON rostergroups(username(75), jid(75));
CREATE TABLE sr_group (
name varchar(250) NOT NULL,
opts text NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8;
CREATE TABLE sr_user (
jid varchar(250) NOT NULL,
grp varchar(250) NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8;
CREATE UNIQUE INDEX i_sr_user_jid_group ON sr_user(jid(75), grp(75));
CREATE INDEX i_sr_user_jid ON sr_user(jid);
CREATE INDEX i_sr_user_grp ON sr_user(grp);
CREATE TABLE spool (
username varchar(250) NOT NULL,

View File

@ -57,6 +57,21 @@ CREATE TABLE rostergroups (
CREATE INDEX pk_rosterg_user_jid ON rostergroups USING btree (username, jid);
CREATE TABLE sr_group (
name text NOT NULL,
opts text NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()
);
CREATE TABLE sr_user (
jid text NOT NULL,
grp text NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX i_sr_user_jid_grp ON sr_user USING btree (jid, grp);
CREATE INDEX i_sr_user_jid ON sr_user USING btree (jid);
CREATE INDEX i_sr_user_grp ON sr_user USING btree (grp);
CREATE TABLE spool (
username text NOT NULL,