diff options
author | Badlop <badlop@process-one.net> | 2019-05-15 10:57:55 +0200 |
---|---|---|
committer | Badlop <badlop@process-one.net> | 2019-05-15 10:57:55 +0200 |
commit | e996579dd19a7830b09aa36fb537883732e5bd18 (patch) | |
tree | b44f06af83239a675d91b5c2dac8618e4423aab6 /src/mod_roster_sql.erl | |
parent | Don't put duplicate polling attribute in bosh payload (diff) |
Preliminary support for SQL in process_rosteritems, and move code (#2448)
Diffstat (limited to 'src/mod_roster_sql.erl')
-rw-r--r-- | src/mod_roster_sql.erl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mod_roster_sql.erl b/src/mod_roster_sql.erl index 91242f61..a512f1bf 100644 --- a/src/mod_roster_sql.erl +++ b/src/mod_roster_sql.erl @@ -33,11 +33,13 @@ get_roster/2, get_roster_item/3, roster_subscribe/4, read_subscription_and_groups/3, remove_user/2, update_roster/4, del_roster/3, transaction/2, + process_rosteritems/5, import/3, export/1, raw_to_record/2]). -include("mod_roster.hrl"). -include("ejabberd_sql_pt.hrl"). -include("logger.hrl"). +-include("jid.hrl"). %%%=================================================================== %%% API @@ -375,3 +377,39 @@ format_row_error(User, Server, Why) -> {ask, Ask} -> ["Malformed 'ask' field with value '", Ask, "'"] end, " detected for ", User, "@", Server, " in table 'rosterusers'"]. + +process_rosteritems(ActionS, SubsS, AsksS, UsersS, ContactsS) -> + process_rosteritems_sql(ActionS, list_to_atom(SubsS), list_to_atom(AsksS), + list_to_binary(UsersS), list_to_binary(ContactsS)). + +process_rosteritems_sql(ActionS, Subscription, Ask, SLocalJID, SJID) -> + [LUser, LServer] = binary:split(SLocalJID, <<"@">>), + SSubscription = case Subscription of + any -> <<"_">>; + both -> <<"B">>; + to -> <<"T">>; + from -> <<"F">>; + none -> <<"N">> + end, + SAsk = case Ask of + any -> <<"_">>; + subscribe -> <<"S">>; + unsubscribe -> <<"U">>; + both -> <<"B">>; + out -> <<"O">>; + in -> <<"I">>; + none -> <<"N">> + end, + {selected, List} = ejabberd_sql:sql_query( + LServer, + ?SQL("select @(username)s, @(jid)s from rosterusers " + "where username LIKE %(LUser)s" + " and %(LServer)H" + " and jid LIKE %(SJID)s" + " and subscription LIKE %(SSubscription)s" + " and ask LIKE %(SAsk)s")), + case ActionS of + "delete" -> [mod_roster:del_roster(User, LServer, jid:decode(Contact)) || {User, Contact} <- List]; + "list" -> ok + end, + List. |