## extauth_program: "/path/to/authentication/script"
##
-## Authentication using ODBC
+## Authentication using SQL
## Remember to setup a database in the next section.
##
-## auth_method: odbc
+## auth_method: sql
##
## Authentication using PAM
##
## MySQL server:
##
-## odbc_type: mysql
-## odbc_server: "server"
-## odbc_database: "database"
-## odbc_username: "username"
-## odbc_password: "password"
+## sql_type: mysql
+## sql_server: "server"
+## sql_database: "database"
+## sql_username: "username"
+## sql_password: "password"
##
## If you want to specify the port:
-## odbc_port: 1234
+## sql_port: 1234
##
## PostgreSQL server:
##
-## odbc_type: pgsql
-## odbc_server: "server"
-## odbc_database: "database"
-## odbc_username: "username"
-## odbc_password: "password"
+## sql_type: pgsql
+## sql_server: "server"
+## sql_database: "database"
+## sql_username: "username"
+## sql_password: "password"
##
## If you want to specify the port:
-## odbc_port: 1234
+## sql_port: 1234
##
## If you use PostgreSQL, have a large database, and need a
## faster but inexact replacement for "select count(*) from users"
##
## SQLite:
##
-## odbc_type: sqlite
-## odbc_database: "/path/to/database.db"
+## sql_type: sqlite
+## sql_database: "/path/to/database.db"
##
## ODBC compatible or MSSQL server:
##
-## odbc_type: odbc
-## odbc_server: "DSN=ejabberd;UID=ejabberd;PWD=ejabberd"
+## sql_type: odbc
+## sql_server: "DSN=ejabberd;UID=ejabberd;PWD=ejabberd"
##
## Number of connections to open to the database for each virtual host
##
-## odbc_pool_size: 10
+## sql_pool_size: 10
##
## Interval to make a dummy SQL request to keep the connections to the
## database alive. Specify in seconds: for example 28800 means 8 hours
##
-## odbc_keepalive_interval: undefined
+## sql_keepalive_interval: undefined
###. ===============
###' TRAFFIC SHAPERS
-define(SQL_UPSERT_MARK, sql_upsert__mark_).
-define(SQL_UPSERT(Host, Table, Fields),
- ejabberd_odbc:sql_query(Host, ?SQL_UPSERT_MARK(Table, Fields))).
+ ejabberd_sql:sql_query(Host, ?SQL_UPSERT_MARK(Table, Fields))).
-define(SQL_UPSERT_T(Table, Fields),
- ejabberd_odbc:sql_query_t(?SQL_UPSERT_MARK(Table, Fields))).
+ ejabberd_sql:sql_query_t(?SQL_UPSERT_MARK(Table, Fields))).
-record(sql_query, {hash, format_query, format_res, args, loc}).
%% note: pos_integer() should always be used, but we allow anything else coded
%% as binary, so one can have a custom implementation of nodetree with custom
%% indexing (see nodetree_virtual). this also allows to use any kind of key for
-%% indexing nodes, as this can be usefull with external backends such as odbc.
+%% indexing nodes, as this can be usefull with external backends such as sql.
-type(itemId() :: binary()).
%% @type itemId() = string().
module = ejabberd_piefxis, function = export_host,
args = [{dir, string}, {host, string}], result = {res, rescode}},
- #ejabberd_commands{name = export_odbc, tags = [mnesia, odbc],
+ #ejabberd_commands{name = export_sql, tags = [mnesia, sql],
desc = "Export all tables as SQL queries to a file",
- module = ejd2odbc, function = export,
+ module = ejd2sql, function = export,
args = [{host, string}, {file, string}], result = {res, rescode}},
- #ejabberd_commands{name = delete_mnesia, tags = [mnesia, odbc],
+ #ejabberd_commands{name = delete_mnesia, tags = [mnesia, sql],
desc = "Export all tables as SQL queries to a file",
- module = ejd2odbc, function = delete,
+ module = ejd2sql, function = delete,
args = [{host, string}], result = {res, rescode}},
- #ejabberd_commands{name = convert_to_scram, tags = [odbc],
+ #ejabberd_commands{name = convert_to_scram, tags = [sql],
desc = "Convert the passwords in 'users' ODBC table to SCRAM",
- module = ejabberd_auth_odbc, function = convert_to_scram,
+ module = ejabberd_auth_sql, function = convert_to_scram,
args = [{host, binary}], result = {res, rescode}},
- #ejabberd_commands{name = import_prosody, tags = [mnesia, odbc, riak],
+ #ejabberd_commands{name = import_prosody, tags = [mnesia, sql, riak],
desc = "Import data from Prosody",
module = prosody2ejabberd, function = from_dir,
args = [{dir, string}], result = {res, rescode}},
module = ?MODULE, function = delete_old_messages,
args = [{days, integer}], result = {res, rescode}},
- #ejabberd_commands{name = export2odbc, tags = [mnesia],
+ #ejabberd_commands{name = export2sql, tags = [mnesia],
desc = "Export virtual host information from Mnesia tables to SQL files",
- module = ejd2odbc, function = export,
+ module = ejd2sql, function = export,
args = [{host, string}, {directory, string}],
result = {res, rescode}},
#ejabberd_commands{name = set_master, tags = [mnesia],
%% where
%% AuthModule = ejabberd_auth_anonymous | ejabberd_auth_external
%% | ejabberd_auth_internal | ejabberd_auth_ldap
-%% | ejabberd_auth_odbc | ejabberd_auth_pam | ejabberd_auth_riak
+%% | ejabberd_auth_sql | ejabberd_auth_pam | ejabberd_auth_riak
-spec check_password_with_authmodule(binary(), binary(), binary(), binary()) -> false |
{true, atom()}.
[{passwd,
fun(Host, #passwd{us = {LUser, LServer}, password = Password})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
- Pass = ejabberd_odbc:escape(Password),
+ Username = ejabberd_sql:escape(LUser),
+ Pass = ejabberd_sql:escape(Password),
[[<<"delete from users where username='">>, Username, <<"';">>],
[<<"insert into users(username, password) "
"values ('">>, Username, <<"', '">>, Pass, <<"');">>]];
[{passwd,
fun(Host, #passwd{us = {LUser, LServer}, password = Password})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
- Pass = ejabberd_odbc:escape(Password),
+ Username = ejabberd_sql:escape(LUser),
+ Pass = ejabberd_sql:escape(Password),
[[<<"delete from users where username='">>, Username, <<"';">>],
[<<"insert into users(username, password) "
"values ('">>, Username, <<"', '">>, Pass, <<"');">>]];
%%%----------------------------------------------------------------------
-%%% File : ejabberd_auth_odbc.erl
+%%% File : ejabberd_auth_sql.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
%%% Purpose : Authentification via ODBC
%%% Created : 12 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%----------------------------------------------------------------------
--module(ejabberd_auth_odbc).
+-module(ejabberd_auth_sql).
-behaviour(ejabberd_config).
true ->
case is_scrammed() of
true ->
- try odbc_queries:get_password_scram(LServer, LUser) of
+ try sql_queries:get_password_scram(LServer, LUser) of
{selected,
[{StoredKey, ServerKey, Salt, IterationCount}]} ->
Scram =
false %% Typical error is database not accessible
end;
false ->
- try odbc_queries:get_password(LServer, LUser) of
+ try sql_queries:get_password(LServer, LUser) of
{selected, [{Password}]} ->
Password /= <<"">>;
{selected, [{_Password2}]} ->
true ->
case is_scrammed() of
false ->
- try odbc_queries:get_password(LServer, LUser) of
+ try sql_queries:get_password(LServer, LUser) of
%% Account exists, check if password is valid
{selected, [{Passwd}]} ->
DigRes = if Digest /= <<"">> ->
case is_scrammed() of
true ->
Scram = password_to_scram(Password),
- case catch odbc_queries:set_password_scram_t(
+ case catch sql_queries:set_password_scram_t(
LServer,
LUser,
Scram#scram.storedkey,
Other -> {error, Other}
end;
false ->
- case catch odbc_queries:set_password_t(LServer,
+ case catch sql_queries:set_password_t(LServer,
LUser, Password)
of
{atomic, ok} -> ok;
case is_scrammed() of
true ->
Scram = password_to_scram(Password),
- case catch odbc_queries:add_user_scram(
+ case catch sql_queries:add_user_scram(
LServer,
LUser,
Scram#scram.storedkey,
_ -> {atomic, exists}
end;
false ->
- case catch odbc_queries:add_user(LServer, LUser,
+ case catch sql_queries:add_user(LServer, LUser,
Password) of
{updated, 1} -> {atomic, ok};
_ -> {atomic, exists}
end.
dirty_get_registered_users() ->
- Servers = ejabberd_config:get_vh_by_auth_method(odbc),
+ Servers = ejabberd_config:get_vh_by_auth_method(sql),
lists:flatmap(fun (Server) ->
get_vh_registered_users(Server)
end,
error -> [];
<<>> -> [];
LServer ->
- case catch odbc_queries:list_users(LServer) of
+ case catch sql_queries:list_users(LServer) of
{selected, Res} ->
[{U, LServer} || {U} <- Res];
_ -> []
error -> [];
<<>> -> [];
LServer ->
- case catch odbc_queries:list_users(LServer, Opts) of
+ case catch sql_queries:list_users(LServer, Opts) of
{selected, Res} ->
[{U, LServer} || {U} <- Res];
_ -> []
error -> 0;
<<>> -> 0;
LServer ->
- case catch odbc_queries:users_number(LServer) of
+ case catch sql_queries:users_number(LServer) of
{selected, [{Res}]} ->
Res;
_ -> 0
error -> 0;
<<>> -> 0;
LServer ->
- case catch odbc_queries:users_number(LServer, Opts) of
+ case catch sql_queries:users_number(LServer, Opts) of
{selected, [{Res}]} ->
Res;
_Other -> 0
true ->
case is_scrammed() of
true ->
- case catch odbc_queries:get_password_scram(
+ case catch sql_queries:get_password_scram(
LServer, LUser) of
{selected,
[{StoredKey, ServerKey, Salt, IterationCount}]} ->
_ -> false
end;
false ->
- case catch odbc_queries:get_password(LServer, LUser)
+ case catch sql_queries:get_password(LServer, LUser)
of
{selected, [{Password}]} -> Password;
_ -> false
true ->
case is_scrammed() of
false ->
- case catch odbc_queries:get_password(LServer, LUser) of
+ case catch sql_queries:get_password(LServer, LUser) of
{selected, [{Password}]} -> Password;
_ -> <<"">>
end;
(LUser == <<>>) or (LServer == <<>>) ->
false;
true ->
- try odbc_queries:get_password(LServer, LUser) of
+ try sql_queries:get_password(LServer, LUser) of
{selected, [{_Password}]} ->
true; %% Account exists
{selected, []} ->
(LUser == <<>>) or (LServer == <<>>) ->
error;
true ->
- catch odbc_queries:del_user(LServer, LUser),
+ catch sql_queries:del_user(LServer, LUser),
ok
end.
end;
false ->
F = fun () ->
- Result = odbc_queries:del_user_return_password(
+ Result = sql_queries:del_user_return_password(
LServer, LUser, Password),
case Result of
{selected, [{Password}]} -> ok;
_ -> not_allowed
end
end,
- {atomic, Result} = odbc_queries:sql_transaction(
+ {atomic, Result} = sql_queries:sql_transaction(
LServer, F),
Result
end
set_password_scram_t(Username,
StoredKey, ServerKey, Salt, IterationCount) ->
- odbc_queries:update_t(<<"users">>,
+ sql_queries:update_t(<<"users">>,
[<<"username">>,
<<"password">>,
<<"serverkey">>,
{error, {incorrect_server_name, Server}};
true ->
F = fun () ->
- case ejabberd_odbc:sql_query_t(
+ case ejabberd_sql:sql_query_t(
[<<"select username, password from users where "
"iterationcount=0 limit ">>,
integer_to_binary(?BATCH_SIZE),
{selected, [<<"username">>, <<"password">>], Rs} ->
lists:foreach(
fun([LUser, Password]) ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
Scram = password_to_scram(Password),
set_password_scram_t(
Username,
- ejabberd_odbc:escape(Scram#scram.storedkey),
- ejabberd_odbc:escape(Scram#scram.serverkey),
- ejabberd_odbc:escape(Scram#scram.salt),
+ ejabberd_sql:escape(Scram#scram.storedkey),
+ ejabberd_sql:escape(Scram#scram.serverkey),
+ ejabberd_sql:escape(Scram#scram.salt),
integer_to_binary(Scram#scram.iterationcount)
)
end, Rs),
Err -> {bad_reply, Err}
end
end,
- case odbc_queries:sql_transaction(LServer, F) of
+ case sql_queries:sql_transaction(LServer, F) of
{atomic, ok} -> ok;
{atomic, continue} -> convert_to_scram(Server);
{atomic, Error} -> {error, Error};
{hosts, _} ->
State;
{Opt, Val} when Action == set ->
- set_option({Opt, Host}, Val, State);
+ set_option({rename_option(Opt), Host}, Val, State);
{Opt, Val} when Action == append ->
- append_option({Opt, Host}, Val, State);
+ append_option({rename_option(Opt), Host}, Val, State);
Opt ->
?WARNING_MSG("Ignore invalid (outdated?) option ~p", [Opt]),
State
end.
+rename_option(Option) when is_atom(Option) ->
+ case atom_to_list(Option) of
+ "odbc_" ++ T ->
+ NewOption = list_to_atom("sql_" ++ T),
+ ?WARNING_MSG("Option '~s' is obsoleted, use '~s' instead",
+ [Option, NewOption]),
+ NewOption;
+ _ ->
+ Option
+ end;
+rename_option(Option) ->
+ Option.
+
set_option(Opt, Val, State) ->
State#state{opts = [#local_config{key = Opt, value = Val} |
State#state.opts]}.
fun iolist_to_binary/1,
<<"en">>).
-replace_module(mod_announce_odbc) -> {mod_announce, odbc};
-replace_module(mod_blocking_odbc) -> {mod_blocking, odbc};
-replace_module(mod_caps_odbc) -> {mod_caps, odbc};
-replace_module(mod_irc_odbc) -> {mod_irc, odbc};
-replace_module(mod_last_odbc) -> {mod_last, odbc};
-replace_module(mod_muc_odbc) -> {mod_muc, odbc};
-replace_module(mod_offline_odbc) -> {mod_offline, odbc};
-replace_module(mod_privacy_odbc) -> {mod_privacy, odbc};
-replace_module(mod_private_odbc) -> {mod_private, odbc};
-replace_module(mod_roster_odbc) -> {mod_roster, odbc};
-replace_module(mod_shared_roster_odbc) -> {mod_shared_roster, odbc};
-replace_module(mod_vcard_odbc) -> {mod_vcard, odbc};
-replace_module(mod_vcard_xupdate_odbc) -> {mod_vcard_xupdate, odbc};
-replace_module(mod_pubsub_odbc) -> {mod_pubsub, odbc};
+replace_module(mod_announce_odbc) -> {mod_announce, sql};
+replace_module(mod_blocking_odbc) -> {mod_blocking, sql};
+replace_module(mod_caps_odbc) -> {mod_caps, sql};
+replace_module(mod_irc_odbc) -> {mod_irc, sql};
+replace_module(mod_last_odbc) -> {mod_last, sql};
+replace_module(mod_muc_odbc) -> {mod_muc, sql};
+replace_module(mod_offline_odbc) -> {mod_offline, sql};
+replace_module(mod_privacy_odbc) -> {mod_privacy, sql};
+replace_module(mod_private_odbc) -> {mod_private, sql};
+replace_module(mod_roster_odbc) -> {mod_roster, sql};
+replace_module(mod_shared_roster_odbc) -> {mod_shared_roster, sql};
+replace_module(mod_vcard_odbc) -> {mod_vcard, sql};
+replace_module(mod_vcard_xupdate_odbc) -> {mod_vcard_xupdate, sql};
+replace_module(mod_pubsub_odbc) -> {mod_pubsub, sql};
replace_module(Module) ->
case is_elixir_module(Module) of
true -> expand_elixir_module(Module);
mod_last,
ejabberd_s2s,
ejabberd_listener,
- ejabberd_odbc_sup,
+ ejabberd_sql_sup,
shaper,
ejabberd_s2s_out,
acl,
%%% Not implemented:
%%% - write mod_piefxis with ejabberdctl commands
-%%% - Export from mod_offline_odbc.erl
-%%% - Export from mod_private_odbc.erl
+%%% - Export from mod_offline_sql.erl
+%%% - Export from mod_private_sql.erl
%%% - XEP-227: 6. Security Considerations
%%% - Other schemas of XInclude are not tested, and may not be imported correctly.
%%% - If a host has many users, split that host in XML files with 50 users each.
-include("logger.hrl").
start() ->
- file:delete(ejabberd_odbc:freetds_config()),
- file:delete(ejabberd_odbc:odbc_config()),
- file:delete(ejabberd_odbc:odbcinst_config()),
- case lists:any(fun(H) -> needs_odbc(H) /= false end,
+ file:delete(ejabberd_sql:freetds_config()),
+ file:delete(ejabberd_sql:odbc_config()),
+ file:delete(ejabberd_sql:odbcinst_config()),
+ case lists:any(fun(H) -> needs_sql(H) /= false end,
?MYHOSTS) of
true ->
start_hosts();
%% Start relationnal DB module on the nodes where it is needed
start_hosts() ->
lists:foreach(fun (Host) ->
- case needs_odbc(Host) of
- {true, App} -> start_odbc(Host, App);
+ case needs_sql(Host) of
+ {true, App} -> start_sql(Host, App);
false -> ok
end
end,
?MYHOSTS).
-%% Start the ODBC module on the given host
-start_odbc(Host, App) ->
+%% Start the SQL module on the given host
+start_sql(Host, App) ->
ejabberd:start_app(App),
Supervisor_name = gen_mod:get_module_proc(Host,
- ejabberd_odbc_sup),
+ ejabberd_sql_sup),
ChildSpec = {Supervisor_name,
- {ejabberd_odbc_sup, start_link, [Host]}, transient,
- infinity, supervisor, [ejabberd_odbc_sup]},
+ {ejabberd_sql_sup, start_link, [Host]}, transient,
+ infinity, supervisor, [ejabberd_sql_sup]},
case supervisor:start_child(ejabberd_sup, ChildSpec) of
{ok, _PID} -> ok;
_Error ->
?ERROR_MSG("Start of supervisor ~p failed:~n~p~nRetrying."
"..~n",
[Supervisor_name, _Error]),
- start_odbc(Host, App)
+ start_sql(Host, App)
end.
-%% Returns {true, App} if we have configured odbc for the given host
-needs_odbc(Host) ->
+%% Returns {true, App} if we have configured sql for the given host
+needs_sql(Host) ->
LHost = jid:nameprep(Host),
- case ejabberd_config:get_option({odbc_type, LHost},
+ case ejabberd_config:get_option({sql_type, LHost},
fun(mysql) -> mysql;
(pgsql) -> pgsql;
(sqlite) -> sqlite;
undefined -> false
end.
-opt_type(odbc_type) ->
+opt_type(sql_type) ->
fun (mysql) -> mysql;
(pgsql) -> pgsql;
(sqlite) -> sqlite;
(mssql) -> mssql;
(odbc) -> odbc
end;
-opt_type(_) -> [odbc_type].
+opt_type(_) -> [sql_type].
opt_type(sm_db_type) ->
fun (mnesia) -> mnesia;
(internal) -> mnesia;
- (odbc) -> odbc;
+ (sql) -> sql;
+ (odbc) -> sql;
(redis) -> redis
end;
opt_type(_) -> [sm_db_type].
%%%===================================================================
-spec init() -> ok | {error, any()}.
init() ->
- Node = ejabberd_odbc:escape(jlib:atom_to_binary(node())),
+ Node = ejabberd_sql:escape(jlib:atom_to_binary(node())),
?INFO_MSG("Cleaning SQL SM table...", []),
lists:foldl(
fun(Host, ok) ->
- case ejabberd_odbc:sql_query(
+ case ejabberd_sql:sql_query(
Host, [<<"delete from sm where node='">>, Node, <<"'">>]) of
{updated, _} ->
ok;
set_session(#session{sid = {Now, Pid}, usr = {U, LServer, R},
priority = Priority, info = Info}) ->
- Username = ejabberd_odbc:escape(U),
- Resource = ejabberd_odbc:escape(R),
- InfoS = ejabberd_odbc:encode_term(Info),
+ Username = ejabberd_sql:escape(U),
+ Resource = ejabberd_sql:escape(R),
+ InfoS = ejabberd_sql:encode_term(Info),
PrioS = enc_priority(Priority),
TS = now_to_timestamp(Now),
PidS = list_to_binary(erlang:pid_to_list(Pid)),
- Node = ejabberd_odbc:escape(jlib:atom_to_binary(node(Pid))),
- case odbc_queries:update(
+ Node = ejabberd_sql:escape(jlib:atom_to_binary(node(Pid))),
+ case sql_queries:update(
LServer,
<<"sm">>,
[<<"usec">>, <<"pid">>, <<"node">>, <<"username">>,
delete_session(_LUser, LServer, _LResource, {Now, Pid}) ->
TS = now_to_timestamp(Now),
PidS = list_to_binary(erlang:pid_to_list(Pid)),
- case ejabberd_odbc:sql_query(
+ case ejabberd_sql:sql_query(
LServer,
[<<"select usec, pid, username, resource, priority, info ">>,
<<"from sm where usec='">>, TS, <<"' and pid='">>,PidS, <<"'">>]) of
{selected, _, [Row]} ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer, [<<"delete from sm where usec='">>,
TS, <<"' and pid='">>, PidS, <<"'">>]),
{ok, row_to_session(LServer, Row)};
end, ejabberd_sm:get_vh_by_backend(?MODULE)).
get_sessions(LServer) ->
- case ejabberd_odbc:sql_query(
+ case ejabberd_sql:sql_query(
LServer, [<<"select usec, pid, username, ">>,
<<"resource, priority, info from sm">>]) of
{selected, _, Rows} ->
end.
get_sessions(LUser, LServer) ->
- Username = ejabberd_odbc:escape(LUser),
- case ejabberd_odbc:sql_query(
+ Username = ejabberd_sql:escape(LUser),
+ case ejabberd_sql:sql_query(
LServer, [<<"select usec, pid, username, ">>,
<<"resource, priority, info from sm where ">>,
<<"username='">>, Username, <<"'">>]) of
end.
get_sessions(LUser, LServer, LResource) ->
- Username = ejabberd_odbc:escape(LUser),
- Resource = ejabberd_odbc:escape(LResource),
- case ejabberd_odbc:sql_query(
+ Username = ejabberd_sql:escape(LUser),
+ Resource = ejabberd_sql:escape(LResource),
+ case ejabberd_sql:sql_query(
LServer, [<<"select usec, pid, username, ">>,
<<"resource, priority, info from sm where ">>,
<<"username='">>, Username, <<"' and resource='">>,
Now = timestamp_to_now(USec),
Pid = erlang:list_to_pid(binary_to_list(PidS)),
Priority = dec_priority(PrioS),
- Info = ejabberd_odbc:decode_term(InfoS),
+ Info = ejabberd_sql:decode_term(InfoS),
#session{sid = {Now, Pid}, us = {User, LServer},
usr = {User, LServer, Resource},
priority = Priority,
%%%
%%%----------------------------------------------------------------------
--module(ejabberd_odbc).
+-module(ejabberd_sql).
-behaviour(ejabberd_config).
max_pending_requests_len :: non_neg_integer(),
pending_requests = {0, queue:new()} :: {non_neg_integer(), ?TQUEUE}}).
--define(STATE_KEY, ejabberd_odbc_state).
+-define(STATE_KEY, ejabberd_sql_state).
--define(NESTING_KEY, ejabberd_odbc_nesting_level).
+-define(NESTING_KEY, ejabberd_sql_nesting_level).
-define(TOP_LEVEL_TXN, 0).
-define(KEEPALIVE_QUERY, [<<"SELECT 1;">>]).
--define(PREPARE_KEY, ejabberd_odbc_prepare).
+-define(PREPARE_KEY, ejabberd_sql_prepare).
%%-define(DBGFSM, true).
%%% API
%%%----------------------------------------------------------------------
start(Host) ->
- (?GEN_FSM):start(ejabberd_odbc, [Host],
+ (?GEN_FSM):start(ejabberd_sql, [Host],
fsm_limit_opts() ++ (?FSMOPTS)).
start_link(Host, StartInterval) ->
- (?GEN_FSM):start_link(ejabberd_odbc,
+ (?GEN_FSM):start_link(ejabberd_sql,
[Host, StartInterval],
fsm_limit_opts() ++ (?FSMOPTS)).
sql_call(Host, Msg) ->
case get(?STATE_KEY) of
undefined ->
- case ejabberd_odbc_sup:get_random_pid(Host) of
+ case ejabberd_sql_sup:get_random_pid(Host) of
none -> {error, <<"Unknown Host">>};
Pid ->
(?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg,
%% Escape character that will confuse an SQL engine
escape(S) ->
- << <<(odbc_queries:escape(Char))/binary>> || <<Char>> <= S >>.
+ << <<(sql_queries:escape(Char))/binary>> || <<Char>> <= S >>.
%% Escape character that will confuse an SQL engine
%% Percent and underscore only need to be escaped for pattern matching like
<< <<(escape_like(C))/binary>> || <<C>> <= S >>;
escape_like($%) -> <<"\\%">>;
escape_like($_) -> <<"\\_">>;
-escape_like(C) when is_integer(C), C >= 0, C =< 255 -> odbc_queries:escape(C).
+escape_like(C) when is_integer(C), C >= 0, C =< 255 -> sql_queries:escape(C).
escape_like_arg(S) when is_binary(S) ->
<< <<(escape_like_arg(C))/binary>> || <<C>> <= S >>;
-spec sqlite_file(binary()) -> string().
sqlite_file(Host) ->
- case ejabberd_config:get_option({odbc_database, Host},
+ case ejabberd_config:get_option({sql_database, Host},
fun iolist_to_binary/1) of
undefined ->
{ok, Cwd} = file:get_cwd(),
%%%----------------------------------------------------------------------
init([Host, StartInterval]) ->
case ejabberd_config:get_option(
- {odbc_keepalive_interval, Host},
+ {sql_keepalive_interval, Host},
fun(I) when is_integer(I), I>0 -> I end) of
undefined ->
ok;
end,
[DBType | _] = db_opts(Host),
(?GEN_FSM):send_event(self(), connect),
- ejabberd_odbc_sup:add_pid(Host, self()),
+ ejabberd_sql_sup:add_pid(Host, self()),
{ok, connecting,
#state{db_type = DBType, host = Host,
max_pending_requests_len = max_fsm_queue(),
{next_state, StateName, State}.
terminate(_Reason, _StateName, State) ->
- ejabberd_odbc_sup:remove_pid(State#state.host, self()),
+ ejabberd_sql_sup:remove_pid(State#state.host, self()),
case State#state.db_type of
mysql -> catch p1_mysql_conn:stop(State#state.db_ref);
sqlite -> catch sqlite3:close(sqlite_db(State#state.host));
end.
db_opts(Host) ->
- Type = ejabberd_config:get_option({odbc_type, Host},
+ Type = ejabberd_config:get_option({sql_type, Host},
fun(mysql) -> mysql;
(pgsql) -> pgsql;
(sqlite) -> sqlite;
(mssql) -> mssql;
(odbc) -> odbc
end, odbc),
- Server = ejabberd_config:get_option({odbc_server, Host},
+ Server = ejabberd_config:get_option({sql_server, Host},
fun iolist_to_binary/1,
<<"localhost">>),
case Type of
[sqlite, Host];
_ ->
Port = ejabberd_config:get_option(
- {odbc_port, Host},
+ {sql_port, Host},
fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
case Type of
mssql -> ?MSSQL_PORT;
mysql -> ?MYSQL_PORT;
pgsql -> ?PGSQL_PORT
end),
- DB = ejabberd_config:get_option({odbc_database, Host},
+ DB = ejabberd_config:get_option({sql_database, Host},
fun iolist_to_binary/1,
<<"ejabberd">>),
- User = ejabberd_config:get_option({odbc_username, Host},
+ User = ejabberd_config:get_option({sql_username, Host},
fun iolist_to_binary/1,
<<"ejabberd">>),
- Pass = ejabberd_config:get_option({odbc_password, Host},
+ Pass = ejabberd_config:get_option({sql_password, Host},
fun iolist_to_binary/1,
<<"">>),
case Type of
end.
init_mssql(Host) ->
- Server = ejabberd_config:get_option({odbc_server, Host},
+ Server = ejabberd_config:get_option({sql_server, Host},
fun iolist_to_binary/1,
<<"localhost">>),
Port = ejabberd_config:get_option(
- {odbc_port, Host},
+ {sql_port, Host},
fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
?MSSQL_PORT),
- DB = ejabberd_config:get_option({odbc_database, Host},
+ DB = ejabberd_config:get_option({sql_database, Host},
fun iolist_to_binary/1,
<<"ejabberd">>),
FreeTDS = io_lib:fwrite("[~s]~n"
opt_type(max_fsm_queue) ->
fun (N) when is_integer(N), N > 0 -> N end;
-opt_type(odbc_database) -> fun iolist_to_binary/1;
-opt_type(odbc_keepalive_interval) ->
+opt_type(sql_database) -> fun iolist_to_binary/1;
+opt_type(sql_keepalive_interval) ->
fun (I) when is_integer(I), I > 0 -> I end;
-opt_type(odbc_password) -> fun iolist_to_binary/1;
-opt_type(odbc_port) ->
+opt_type(sql_password) -> fun iolist_to_binary/1;
+opt_type(sql_port) ->
fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
-opt_type(odbc_server) -> fun iolist_to_binary/1;
-opt_type(odbc_type) ->
+opt_type(sql_server) -> fun iolist_to_binary/1;
+opt_type(sql_type) ->
fun (mysql) -> mysql;
(pgsql) -> pgsql;
(sqlite) -> sqlite;
(mssql) -> mssql;
(odbc) -> odbc
end;
-opt_type(odbc_username) -> fun iolist_to_binary/1;
+opt_type(sql_username) -> fun iolist_to_binary/1;
opt_type(_) ->
- [max_fsm_queue, odbc_database, odbc_keepalive_interval,
- odbc_password, odbc_port, odbc_server, odbc_type,
- odbc_username].
+ [max_fsm_queue, sql_database, sql_keepalive_interval,
+ sql_password, sql_port, sql_server, sql_type,
+ sql_username].
EVar;
boolean ->
erl_syntax:application(
- erl_syntax:atom(ejabberd_odbc),
+ erl_syntax:atom(ejabberd_sql),
erl_syntax:atom(to_bool),
[EVar])
end,
InsertBranch =
erl_syntax:case_expr(
erl_syntax:application(
- erl_syntax:atom(ejabberd_odbc),
+ erl_syntax:atom(ejabberd_sql),
erl_syntax:atom(sql_query_t),
[Insert]),
[erl_syntax:clause(
[erl_syntax:variable("__UpdateRes")])]),
erl_syntax:case_expr(
erl_syntax:application(
- erl_syntax:atom(ejabberd_odbc),
+ erl_syntax:atom(ejabberd_sql),
erl_syntax:atom(sql_query_t),
[Update]),
[erl_syntax:clause(
]),
Upsert = make_sql_query(State),
erl_syntax:application(
- erl_syntax:atom(ejabberd_odbc),
+ erl_syntax:atom(ejabberd_sql),
erl_syntax:atom(sql_query_t),
[Upsert]).
%%%----------------------------------------------------------------------
-%%% File : ejabberd_odbc_sup.erl
+%%% File : ejabberd_sql_sup.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
-%%% Purpose : ODBC connections supervisor
+%%% Purpose : SQL connections supervisor
%%% Created : 22 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%
%%%
%%%----------------------------------------------------------------------
--module(ejabberd_odbc_sup).
+-module(ejabberd_sql_sup).
-behaviour(ejabberd_config).
-define(DEFAULT_POOL_SIZE, 10).
--define(DEFAULT_ODBC_START_INTERVAL, 30).
+-define(DEFAULT_SQL_START_INTERVAL, 30).
-define(CONNECT_TIMEOUT, 500).
init([Host]) ->
PoolSize = ejabberd_config:get_option(
- {odbc_pool_size, Host},
+ {sql_pool_size, Host},
fun(I) when is_integer(I), I>0 -> I end,
?DEFAULT_POOL_SIZE),
StartInterval = ejabberd_config:get_option(
- {odbc_start_interval, Host},
+ {sql_start_interval, Host},
fun(I) when is_integer(I), I>0 -> I end,
- ?DEFAULT_ODBC_START_INTERVAL),
- Type = ejabberd_config:get_option({odbc_type, Host},
+ ?DEFAULT_SQL_START_INTERVAL),
+ Type = ejabberd_config:get_option({sql_type, Host},
fun(mysql) -> mysql;
(pgsql) -> pgsql;
(sqlite) -> sqlite;
sqlite ->
check_sqlite_db(Host);
mssql ->
- ejabberd_odbc:init_mssql(Host);
+ ejabberd_sql:init_mssql(Host);
_ ->
ok
end,
{{one_for_one, PoolSize * 10, 1},
lists:map(fun (I) ->
{I,
- {ejabberd_odbc, start_link,
+ {ejabberd_sql, start_link,
[Host, StartInterval * 1000]},
transient, 2000, worker, [?MODULE]}
end,
lists:foldl(fun transform_options/2, [], Opts).
transform_options({odbc_server, {Type, Server, Port, DB, User, Pass}}, Opts) ->
- [{odbc_type, Type},
- {odbc_server, Server},
- {odbc_port, Port},
- {odbc_database, DB},
- {odbc_username, User},
- {odbc_password, Pass}|Opts];
+ [{sql_type, Type},
+ {sql_server, Server},
+ {sql_port, Port},
+ {sql_database, DB},
+ {sql_username, User},
+ {sql_password, Pass}|Opts];
transform_options({odbc_server, {mysql, Server, DB, User, Pass}}, Opts) ->
transform_options({odbc_server, {mysql, Server, ?MYSQL_PORT, DB, User, Pass}}, Opts);
transform_options({odbc_server, {pgsql, Server, DB, User, Pass}}, Opts) ->
[Opt|Opts].
check_sqlite_db(Host) ->
- DB = ejabberd_odbc:sqlite_db(Host),
- File = ejabberd_odbc:sqlite_file(Host),
+ DB = ejabberd_sql:sqlite_db(Host),
+ File = ejabberd_sql:sqlite_file(Host),
Ret = case filelib:ensure_dir(File) of
ok ->
case sqlite3:open(DB, [{file, File}]) of
[]
end.
-opt_type(odbc_pool_size) ->
+opt_type(sql_pool_size) ->
fun (I) when is_integer(I), I > 0 -> I end;
-opt_type(odbc_start_interval) ->
+opt_type(sql_start_interval) ->
fun (I) when is_integer(I), I > 0 -> I end;
-opt_type(odbc_type) ->
+opt_type(sql_type) ->
fun (mysql) -> mysql;
(pgsql) -> pgsql;
(sqlite) -> sqlite;
(odbc) -> odbc
end;
opt_type(_) ->
- [odbc_pool_size, odbc_start_interval, odbc_type].
+ [sql_pool_size, sql_start_interval, sql_type].
lists:keysearch(<<Action/binary,
"host">>,
1, Query),
- ejabberd_cluster:call(Node, ejd2odbc,
+ ejabberd_cluster:call(Node, ejd2sql,
export, [Host, Path]);
<<"import_file">> ->
ejabberd_cluster:call(Node, ejabberd_admin,
%%%----------------------------------------------------------------------
-%%% File : ejd2odbc.erl
+%%% File : ejd2sql.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
%%% Purpose : Export some mnesia tables to SQL DB
%%% Created : 22 Aug 2005 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%----------------------------------------------------------------------
--module(ejd2odbc).
+-module(ejd2sql).
-author('alexey@process-one.net').
%%% A table can be converted from Mnesia to an ODBC database by calling
%%% one of the API function with the following parameters:
%%% - Server is the server domain you want to convert
-%%% - Output can be either odbc to export to the configured relational
+%%% - Output can be either sql to export to the configured relational
%%% database or "Filename" to export to text file.
modules() ->
output(_LServer, _Table, _IO, []) ->
ok;
-output(LServer, _Table, odbc, SQLs) ->
- ejabberd_odbc:sql_transaction(LServer, SQLs);
+output(LServer, _Table, sql, SQLs) ->
+ ejabberd_sql:sql_transaction(LServer, SQLs);
output(_LServer, Table, Fd, SQLs) ->
file:write(Fd, ["-- \n-- Mnesia table: ", atom_to_list(Table),
"\n--\n", SQLs]).
F = case proplists:get_bool(fast, Opts) of
true ->
fun() ->
- case ejabberd_odbc:sql_query_t(SelectQuery) of
+ case ejabberd_sql:sql_query_t(SelectQuery) of
{selected, _, Rows} ->
lists:foldl(fun process_sql_row/2,
{IO, ConvertFun, undefined}, Rows);
end;
false ->
fun() ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[iolist_to_binary(
[<<"declare c cursor for ">>, SelectQuery])]),
fetch(IO, ConvertFun, undefined)
end
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
fetch(IO, ConvertFun, PrevRow) ->
- case ejabberd_odbc:sql_query_t([<<"fetch c;">>]) of
+ case ejabberd_sql:sql_query_t([<<"fetch c;">>]) of
{selected, _, [Row]} ->
process_sql_row(Row, {IO, ConvertFun, PrevRow}),
fetch(IO, ConvertFun, Row);
opts = [] :: opts() | '_' | '$2'}).
-type opts() :: [{atom(), any()}].
--type db_type() :: odbc | mnesia | riak.
+-type db_type() :: sql | mnesia | riak.
-callback start(binary(), opts()) -> any().
-callback stop(binary()) -> any().
-spec v_db(db_type() | internal) -> db_type().
-v_db(odbc) -> odbc;
+v_db(odbc) -> sql;
+v_db(sql) -> sql;
v_db(internal) -> mnesia;
v_db(mnesia) -> mnesia;
v_db(riak) -> riak.
-spec db_mod(binary() | global | db_type(), module()) -> module().
db_mod(odbc, Module) -> list_to_atom(atom_to_list(Module) ++ "_sql");
+db_mod(sql, Module) -> list_to_atom(atom_to_list(Module) ++ "_sql");
db_mod(mnesia, Module) -> list_to_atom(atom_to_list(Module) ++ "_mnesia");
db_mod(riak, Module) -> list_to_atom(atom_to_list(Module) ++ "_riak");
db_mod(Host, Module) when is_binary(Host) orelse Host == global ->
F = fun() ->
lists:foreach(
fun({U, _S, _R}) ->
- Username = ejabberd_odbc:escape(U),
- odbc_queries:update_t(
+ Username = ejabberd_sql:escape(U),
+ sql_queries:update_t(
<<"motd">>,
[<<"username">>, <<"xml">>],
[Username, <<"">>],
[<<"username='">>, Username, <<"'">>])
end, USRs)
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
set_motd(LServer, Packet) ->
- XML = ejabberd_odbc:escape(fxml:element_to_binary(Packet)),
+ XML = ejabberd_sql:escape(fxml:element_to_binary(Packet)),
F = fun() ->
- odbc_queries:update_t(
+ sql_queries:update_t(
<<"motd">>,
[<<"username">>, <<"xml">>],
[<<"">>, XML],
[<<"username=''">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
delete_motd(LServer) ->
F = fun() ->
- ejabberd_odbc:sql_query_t([<<"delete from motd;">>])
+ ejabberd_sql:sql_query_t([<<"delete from motd;">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
get_motd(LServer) ->
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
LServer, [<<"select xml from motd where username='';">>]) of
{selected, [<<"xml">>], [[XML]]} ->
case fxml_stream:parse_element(XML) of
end.
is_motd_user(LUser, LServer) ->
- Username = ejabberd_odbc:escape(LUser),
- case catch ejabberd_odbc:sql_query(
+ Username = ejabberd_sql:escape(LUser),
+ case catch ejabberd_sql:sql_query(
LServer,
[<<"select username from motd "
"where username='">>, Username, <<"';">>]) of
end.
set_motd_user(LUser, LServer) ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
F = fun() ->
- odbc_queries:update_t(
+ sql_queries:update_t(
<<"motd">>,
[<<"username">>, <<"xml">>],
[Username, <<"">>],
[<<"username='">>, Username, <<"'">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
export(_Server) ->
[{motd,
when LServer == Host ->
[[<<"delete from motd where username='';">>],
[<<"insert into motd(username, xml) values ('', '">>,
- ejabberd_odbc:escape(fxml:element_to_binary(El)),
+ ejabberd_sql:escape(fxml:element_to_binary(El)),
<<"');">>]];
(_Host, _R) ->
[]
{motd_users,
fun(Host, #motd_users{us = {LUser, LServer}})
when LServer == Host, LUser /= <<"">> ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
[[<<"delete from motd where username='">>, Username, <<"';">>],
[<<"insert into motd(username, xml) values ('">>,
Username, <<"', '');">>]];
mod_privacy_sql:sql_set_privacy_list(ID, NewRItems),
{ok, Default, NewList}
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
unblock_by_filter(LUser, LServer, Filter) ->
F = fun () ->
_ -> ok
end
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
process_blocklist_get(LUser, LServer) ->
case catch mod_privacy_sql:sql_get_default_privacy_list(LUser, LServer) of
Mod:init(LServer, []),
ok.
-import(_LServer, {odbc, _}, _DBType, <<"caps_features">>,
+import(_LServer, {sql, _}, _DBType, <<"caps_features">>,
[Node, SubNode, Feature, _TimeStamp]) ->
Feature1 = case catch jlib:binary_to_integer(Feature) of
I when is_integer(I), I>0 -> I;
ejabberd_riak:put(
#caps_features{node_pair = NodePair, features = Features},
caps_features_schema());
- _ when DBType == odbc ->
+ _ when DBType == sql ->
ok
end,
import_next(LServer, DBType, ets:next(caps_features_tmp, NodePair)).
ok.
caps_read(LServer, {Node, SubNode}) ->
- SNode = ejabberd_odbc:escape(Node),
- SSubNode = ejabberd_odbc:escape(SubNode),
- case ejabberd_odbc:sql_query(
+ SNode = ejabberd_sql:escape(Node),
+ SSubNode = ejabberd_sql:escape(SubNode),
+ case ejabberd_sql:sql_query(
LServer, [<<"select feature from caps_features where ">>,
<<"node='">>, SNode, <<"' and subnode='">>,
SSubNode, <<"';">>]) of
end.
caps_write(LServer, NodePair, Features) ->
- ejabberd_odbc:sql_transaction(
+ ejabberd_sql:sql_transaction(
LServer,
sql_write_features_t(NodePair, Features)).
%%% Internal functions
%%%===================================================================
sql_write_features_t({Node, SubNode}, Features) ->
- SNode = ejabberd_odbc:escape(Node),
- SSubNode = ejabberd_odbc:escape(SubNode),
+ SNode = ejabberd_sql:escape(Node),
+ SSubNode = ejabberd_sql:escape(SubNode),
NewFeatures = if is_integer(Features) ->
[jlib:integer_to_binary(Features)];
true ->
SNode, <<"' and subnode='">>, SSubNode, <<"';">>]|
[[<<"insert into caps_features(node, subnode, feature) ">>,
<<"values ('">>, SNode, <<"', '">>, SSubNode, <<"', '">>,
- ejabberd_odbc:escape(F), <<"');">>] || F <- NewFeatures]].
+ ejabberd_sql:escape(F), <<"');">>] || F <- NewFeatures]].
get_data(LServer, Host, From) ->
LJID = jid:tolower(jid:remove_resource(From)),
- SJID = ejabberd_odbc:escape(jid:to_string(LJID)),
- SHost = ejabberd_odbc:escape(Host),
- case catch ejabberd_odbc:sql_query(
+ SJID = ejabberd_sql:escape(jid:to_string(LJID)),
+ SHost = ejabberd_sql:escape(Host),
+ case catch ejabberd_sql:sql_query(
LServer,
[<<"select data from irc_custom where jid='">>,
SJID, <<"' and host='">>, SHost,
<<"';">>]) of
{selected, [<<"data">>], [[SData]]} ->
- mod_irc:data_to_binary(From, ejabberd_odbc:decode_term(SData));
+ mod_irc:data_to_binary(From, ejabberd_sql:decode_term(SData));
{'EXIT', _} -> error;
{selected, _, _} -> empty
end.
set_data(LServer, Host, From, Data) ->
LJID = jid:tolower(jid:remove_resource(From)),
- SJID = ejabberd_odbc:escape(jid:to_string(LJID)),
- SHost = ejabberd_odbc:escape(Host),
- SData = ejabberd_odbc:encode_term(Data),
+ SJID = ejabberd_sql:escape(jid:to_string(LJID)),
+ SHost = ejabberd_sql:escape(Host),
+ SData = ejabberd_sql:encode_term(Data),
F = fun () ->
- odbc_queries:update_t(<<"irc_custom">>,
+ sql_queries:update_t(<<"irc_custom">>,
[<<"jid">>, <<"host">>, <<"data">>],
[SJID, SHost, SData],
[<<"jid='">>, SJID, <<"' and host='">>,
SHost, <<"'">>]),
ok
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
export(_Server) ->
[{irc_custom,
data = Data}) ->
case str:suffix(Host, IRCHost) of
true ->
- SJID = ejabberd_odbc:escape(
+ SJID = ejabberd_sql:escape(
jid:to_string(
jid:make(U, S, <<"">>))),
- SIRCHost = ejabberd_odbc:escape(IRCHost),
- SData = ejabberd_odbc:encode_term(Data),
+ SIRCHost = ejabberd_sql:escape(IRCHost),
+ SData = ejabberd_sql:encode_term(Data),
[[<<"delete from irc_custom where jid='">>, SJID,
<<"' and host='">>, SIRCHost, <<"';">>],
[<<"insert into irc_custom(jid, host, "
[{<<"select jid, host, data from irc_custom;">>,
fun([SJID, IRCHost, SData]) ->
#jid{luser = U, lserver = S} = jid:from_string(SJID),
- Data = ejabberd_odbc:decode_term(SData),
+ Data = ejabberd_sql:decode_term(SData),
#irc_custom{us_host = {{U, S}, IRCHost},
data = Data}
end}].
ok.
get_last(LUser, LServer) ->
- case catch odbc_queries:get_last(LServer, LUser) of
+ case catch sql_queries:get_last(LServer, LUser) of
{selected, []} ->
not_found;
{selected, [{TimeStamp, Status}]} ->
end.
store_last_info(LUser, LServer, TimeStamp, Status) ->
- odbc_queries:set_last_t(LServer, LUser, TimeStamp, Status).
+ sql_queries:set_last_t(LServer, LUser, TimeStamp, Status).
remove_user(LUser, LServer) ->
- odbc_queries:del_last(LServer, LUser).
+ sql_queries:del_last(LServer, LUser).
import(_LServer, _LA) ->
pass.
fun(Host, #last_activity{us = {LUser, LServer},
timestamp = TimeStamp, status = Status})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
Seconds =
- ejabberd_odbc:escape(jlib:integer_to_binary(TimeStamp)),
- State = ejabberd_odbc:escape(Status),
+ ejabberd_sql:escape(jlib:integer_to_binary(TimeStamp)),
+ State = ejabberd_sql:escape(Status),
[[<<"delete from last where username='">>, Username, <<"';">>],
[<<"insert into last(username, seconds, "
"state) values ('">>,
lists:map(
fun(Host) ->
case gen_mod:db_type(Host, ?MODULE) of
- odbc -> {odbc, Host};
+ sql -> {sql, Host};
Other -> {Other, global}
end
end, ?MYHOSTS)),
mod_opt_type(cache_size) ->
fun (I) when is_integer(I), I > 0 -> I end;
mod_opt_type(db_type) ->
- fun(odbc) -> odbc;
+ fun(sql) -> sql;
+ (odbc) -> sql;
(internal) -> mnesia;
(mnesia) -> mnesia
end;
ok.
remove_user(LUser, LServer) ->
- SUser = ejabberd_odbc:escape(LUser),
- ejabberd_odbc:sql_query(
+ SUser = ejabberd_sql:escape(LUser),
+ ejabberd_sql:sql_query(
LServer,
[<<"delete from archive where username='">>, SUser, <<"';">>]),
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
[<<"delete from archive_prefs where username='">>, SUser, <<"';">>]).
true -> [<<" and kind='">>, jlib:atom_to_binary(Type), <<"'">>]
end,
TS = integer_to_binary(now_to_usec(TimeStamp)),
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
ServerHost, [<<"delete from archive where timestamp<">>,
TS, TypeClause, <<";">>]),
ok.
jid:tolower(Peer)),
XML = fxml:element_to_binary(Pkt),
Body = fxml:get_subtag_cdata(Pkt, <<"body">>),
- case ejabberd_odbc:sql_query(
+ case ejabberd_sql:sql_query(
LServer,
[<<"insert into archive (username, timestamp, "
"peer, bare_peer, xml, txt, kind, nick) values (">>,
- <<"'">>, ejabberd_odbc:escape(SUser), <<"', ">>,
+ <<"'">>, ejabberd_sql:escape(SUser), <<"', ">>,
<<"'">>, TS, <<"', ">>,
- <<"'">>, ejabberd_odbc:escape(LPeer), <<"', ">>,
- <<"'">>, ejabberd_odbc:escape(BarePeer), <<"', ">>,
- <<"'">>, ejabberd_odbc:escape(XML), <<"', ">>,
- <<"'">>, ejabberd_odbc:escape(Body), <<"', ">>,
+ <<"'">>, ejabberd_sql:escape(LPeer), <<"', ">>,
+ <<"'">>, ejabberd_sql:escape(BarePeer), <<"', ">>,
+ <<"'">>, ejabberd_sql:escape(XML), <<"', ">>,
+ <<"'">>, ejabberd_sql:escape(Body), <<"', ">>,
<<"'">>, jlib:atom_to_binary(Type), <<"', ">>,
- <<"'">>, ejabberd_odbc:escape(Nick), <<"');">>]) of
+ <<"'">>, ejabberd_sql:escape(Nick), <<"');">>]) of
{updated, _} ->
{ok, ID};
Err ->
never = Never,
always = Always},
ServerHost) ->
- SUser = ejabberd_odbc:escape(LUser),
+ SUser = ejabberd_sql:escape(LUser),
SDefault = erlang:atom_to_binary(Default, utf8),
- SAlways = ejabberd_odbc:encode_term(Always),
- SNever = ejabberd_odbc:encode_term(Never),
+ SAlways = ejabberd_sql:encode_term(Always),
+ SNever = ejabberd_sql:encode_term(Never),
case update(ServerHost, <<"archive_prefs">>,
[<<"username">>, <<"def">>, <<"always">>, <<"never">>],
[SUser, SDefault, SAlways, SNever],
end.
get_prefs(LUser, LServer) ->
- case ejabberd_odbc:sql_query(
+ case ejabberd_sql:sql_query(
LServer,
[<<"select def, always, never from archive_prefs ">>,
<<"where username='">>,
- ejabberd_odbc:escape(LUser), <<"';">>]) of
+ ejabberd_sql:escape(LUser), <<"';">>]) of
{selected, _, [[SDefault, SAlways, SNever]]} ->
Default = erlang:binary_to_existing_atom(SDefault, utf8),
- Always = ejabberd_odbc:decode_term(SAlways),
- Never = ejabberd_odbc:decode_term(SNever),
+ Always = ejabberd_sql:decode_term(SAlways),
+ Never = ejabberd_sql:decode_term(SNever),
{ok, #archive_prefs{us = {LUser, LServer},
default = Default,
always = Always,
% and the client did not specify a limit using RSM then the server should
% return a policy-violation error to the client." We currently don't do this
% for v0.2 requests, but we do limit #rsm_in.max for v0.3 and newer.
- case {ejabberd_odbc:sql_query(LServer, Query),
- ejabberd_odbc:sql_query(LServer, CountQuery)} of
+ case {ejabberd_sql:sql_query(LServer, Query),
+ ejabberd_sql:sql_query(LServer, CountQuery)} of
{{selected, _, Res}, {selected, _, [[Count]]}} ->
{Max, Direction} = case RSM of
#rsm_in{max = M, direction = D} -> {M, D};
{none, none, <<>>}
end,
ODBCType = ejabberd_config:get_option(
- {odbc_type, LServer},
- ejabberd_odbc:opt_type(odbc_type)),
+ {sql_type, LServer},
+ ejabberd_sql:opt_type(sql_type)),
LimitClause = if is_integer(Max), Max >= 0, ODBCType /= mssql ->
[<<" limit ">>, jlib:integer_to_binary(Max+1)];
true ->
[];
{text, Txt} ->
[<<" and match (txt) against ('">>,
- ejabberd_odbc:escape(Txt), <<"')">>];
+ ejabberd_sql:escape(Txt), <<"')">>];
{_, _, <<>>} ->
[<<" and bare_peer='">>,
- ejabberd_odbc:escape(jid:to_string(With)),
+ ejabberd_sql:escape(jid:to_string(With)),
<<"'">>];
{_, _, _} ->
[<<" and peer='">>,
- ejabberd_odbc:escape(jid:to_string(With)),
+ ejabberd_sql:escape(jid:to_string(With)),
<<"'">>];
none ->
[]
_ ->
[]
end,
- SUser = ejabberd_odbc:escape(User),
+ SUser = ejabberd_sql:escape(User),
Query = [<<"SELECT ">>, TopClause, <<" timestamp, xml, peer, kind, nick"
" FROM archive WHERE username='">>,
<<A/binary, "='", B/binary, "'">>
end,
Fields, Vals),
- case ejabberd_odbc:sql_query(LServer,
+ case ejabberd_sql:sql_query(LServer,
[<<"update ">>, Table, <<" set ">>,
join(UPairs, <<", ">>), <<" where ">>, Where,
<<";">>])
of
{updated, 1} -> {updated, 1};
_ ->
- ejabberd_odbc:sql_query(LServer,
+ ejabberd_sql:sql_query(LServer,
[<<"insert into ">>, Table, <<"(">>,
join(Fields, <<", ">>), <<") values ('">>,
join(Vals, <<"', '">>), <<"');">>])
ok.
store_room(LServer, Host, Name, Opts) ->
- SName = ejabberd_odbc:escape(Name),
- SHost = ejabberd_odbc:escape(Host),
- SOpts = ejabberd_odbc:encode_term(Opts),
+ SName = ejabberd_sql:escape(Name),
+ SHost = ejabberd_sql:escape(Host),
+ SOpts = ejabberd_sql:encode_term(Opts),
F = fun () ->
- odbc_queries:update_t(<<"muc_room">>,
+ sql_queries:update_t(<<"muc_room">>,
[<<"name">>, <<"host">>, <<"opts">>],
[SName, SHost, SOpts],
[<<"name='">>, SName, <<"' and host='">>,
SHost, <<"'">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
restore_room(LServer, Host, Name) ->
- SName = ejabberd_odbc:escape(Name),
- SHost = ejabberd_odbc:escape(Host),
- case catch ejabberd_odbc:sql_query(LServer,
+ SName = ejabberd_sql:escape(Name),
+ SHost = ejabberd_sql:escape(Host),
+ case catch ejabberd_sql:sql_query(LServer,
[<<"select opts from muc_room where name='">>,
SName, <<"' and host='">>, SHost,
<<"';">>]) of
{selected, [<<"opts">>], [[Opts]]} ->
- mod_muc:opts_to_binary(ejabberd_odbc:decode_term(Opts));
+ mod_muc:opts_to_binary(ejabberd_sql:decode_term(Opts));
_ ->
error
end.
forget_room(LServer, Host, Name) ->
- SName = ejabberd_odbc:escape(Name),
- SHost = ejabberd_odbc:escape(Host),
+ SName = ejabberd_sql:escape(Name),
+ SHost = ejabberd_sql:escape(Host),
F = fun () ->
- ejabberd_odbc:sql_query_t([<<"delete from muc_room where name='">>,
+ ejabberd_sql:sql_query_t([<<"delete from muc_room where name='">>,
SName, <<"' and host='">>, SHost,
<<"';">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
can_use_nick(LServer, Host, JID, Nick) ->
SJID = jid:to_string(jid:tolower(jid:remove_resource(JID))),
- SNick = ejabberd_odbc:escape(Nick),
- SHost = ejabberd_odbc:escape(Host),
- case catch ejabberd_odbc:sql_query(LServer,
+ SNick = ejabberd_sql:escape(Nick),
+ SHost = ejabberd_sql:escape(Host),
+ case catch ejabberd_sql:sql_query(LServer,
[<<"select jid from muc_registered ">>,
<<"where nick='">>, SNick,
<<"' and host='">>, SHost, <<"';">>]) of
end.
get_rooms(LServer, Host) ->
- SHost = ejabberd_odbc:escape(Host),
- case catch ejabberd_odbc:sql_query(LServer,
+ SHost = ejabberd_sql:escape(Host),
+ case catch ejabberd_sql:sql_query(LServer,
[<<"select name, opts from muc_room ">>,
<<"where host='">>, SHost, <<"';">>]) of
{selected, [<<"name">>, <<"opts">>], RoomOpts} ->
fun([Room, Opts]) ->
#muc_room{name_host = {Room, Host},
opts = mod_muc:opts_to_binary(
- ejabberd_odbc:decode_term(Opts))}
+ ejabberd_sql:decode_term(Opts))}
end, RoomOpts);
Err ->
?ERROR_MSG("failed to get rooms: ~p", [Err]),
end.
get_nick(LServer, Host, From) ->
- SJID = ejabberd_odbc:escape(jid:to_string(jid:tolower(jid:remove_resource(From)))),
- SHost = ejabberd_odbc:escape(Host),
- case catch ejabberd_odbc:sql_query(LServer,
+ SJID = ejabberd_sql:escape(jid:to_string(jid:tolower(jid:remove_resource(From)))),
+ SHost = ejabberd_sql:escape(Host),
+ case catch ejabberd_sql:sql_query(LServer,
[<<"select nick from muc_registered where "
"jid='">>,
SJID, <<"' and host='">>, SHost,
set_nick(LServer, Host, From, Nick) ->
JID = jid:to_string(jid:tolower(jid:remove_resource(From))),
- SJID = ejabberd_odbc:escape(JID),
- SNick = ejabberd_odbc:escape(Nick),
- SHost = ejabberd_odbc:escape(Host),
+ SJID = ejabberd_sql:escape(JID),
+ SNick = ejabberd_sql:escape(Nick),
+ SHost = ejabberd_sql:escape(Host),
F = fun () ->
case Nick of
<<"">> ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[<<"delete from muc_registered where ">>,
<<"jid='">>, SJID,
<<"' and host='">>, Host,
<<"';">>]),
ok;
_ ->
- Allow = case ejabberd_odbc:sql_query_t(
+ Allow = case ejabberd_sql:sql_query_t(
[<<"select jid from muc_registered ">>,
<<"where nick='">>,
SNick,
_ -> true
end,
if Allow ->
- odbc_queries:update_t(<<"muc_registered">>,
+ sql_queries:update_t(<<"muc_registered">>,
[<<"jid">>, <<"host">>,
<<"nick">>],
[SJID, SHost, SNick],
end
end
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
export(_Server) ->
[{muc_room,
fun(Host, #muc_room{name_host = {Name, RoomHost}, opts = Opts}) ->
case str:suffix(Host, RoomHost) of
true ->
- SName = ejabberd_odbc:escape(Name),
- SRoomHost = ejabberd_odbc:escape(RoomHost),
- SOpts = ejabberd_odbc:encode_term(Opts),
+ SName = ejabberd_sql:escape(Name),
+ SRoomHost = ejabberd_sql:escape(RoomHost),
+ SOpts = ejabberd_sql:encode_term(Opts),
[[<<"delete from muc_room where name='">>, SName,
<<"' and host='">>, SRoomHost, <<"';">>],
[<<"insert into muc_room(name, host, opts) ",
nick = Nick}) ->
case str:suffix(Host, RoomHost) of
true ->
- SJID = ejabberd_odbc:escape(
+ SJID = ejabberd_sql:escape(
jid:to_string(
jid:make(U, S, <<"">>))),
- SNick = ejabberd_odbc:escape(Nick),
- SRoomHost = ejabberd_odbc:escape(RoomHost),
+ SNick = ejabberd_sql:escape(Nick),
+ SRoomHost = ejabberd_sql:escape(RoomHost),
[[<<"delete from muc_registered where jid='">>,
SJID, <<"' and host='">>, SRoomHost, <<"';">>],
[<<"insert into muc_registered(jid, host, "
import(_LServer) ->
[{<<"select name, host, opts from muc_room;">>,
fun([Name, RoomHost, SOpts]) ->
- Opts = mod_muc:opts_to_binary(ejabberd_odbc:decode_term(SOpts)),
+ Opts = mod_muc:opts_to_binary(ejabberd_sql:decode_term(SOpts)),
#muc_room{name_host = {Name, RoomHost}, opts = Opts}
end},
{<<"select jid, host, nick from muc_registered;">>,
after 0 ->
case DBType of
mnesia -> Msgs;
- odbc -> lists:reverse(Msgs);
+ sql -> lists:reverse(Msgs);
riak -> Msgs
end
end.
Query = lists:map(
fun(M) ->
Username =
- ejabberd_odbc:escape((M#offline_msg.to)#jid.luser),
+ ejabberd_sql:escape((M#offline_msg.to)#jid.luser),
From = M#offline_msg.from,
To = M#offline_msg.to,
Packet =
M#offline_msg.timestamp,
<<"Offline Storage">>),
XML =
- ejabberd_odbc:escape(fxml:element_to_binary(NewPacket)),
- odbc_queries:add_spool_sql(Username, XML)
+ ejabberd_sql:escape(fxml:element_to_binary(NewPacket)),
+ sql_queries:add_spool_sql(Username, XML)
end,
Msgs),
- odbc_queries:add_spool(Host, Query)
+ sql_queries:add_spool(Host, Query)
end.
pop_messages(LUser, LServer) ->
- case odbc_queries:get_and_del_spool_msg_t(LServer, LUser) of
+ case sql_queries:get_and_del_spool_msg_t(LServer, LUser) of
{atomic, {selected, Rs}} ->
{ok, lists:flatmap(
fun({_, XML}) ->
{atomic, ok}.
remove_old_messages(Days, LServer) ->
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
LServer,
[<<"DELETE FROM spool"
" WHERE created_at < "
{atomic, ok}.
remove_user(LUser, LServer) ->
- odbc_queries:del_spool_msg(LServer, LUser).
+ sql_queries:del_spool_msg(LServer, LUser).
read_message_headers(LUser, LServer) ->
- Username = ejabberd_odbc:escape(LUser),
- case catch ejabberd_odbc:sql_query(
+ Username = ejabberd_sql:escape(LUser),
+ case catch ejabberd_sql:sql_query(
LServer, [<<"select xml, seq from spool where username ='">>,
Username, <<"' order by seq;">>]) of
{selected, [<<"xml">>, <<"seq">>], Rows} ->
end.
read_message(LUser, LServer, Seq) ->
- Username = ejabberd_odbc:escape(LUser),
- SSeq = ejabberd_odbc:escape(integer_to_binary(Seq)),
- case ejabberd_odbc:sql_query(
+ Username = ejabberd_sql:escape(LUser),
+ SSeq = ejabberd_sql:escape(integer_to_binary(Seq)),
+ case ejabberd_sql:sql_query(
LServer,
[<<"select xml from spool where username='">>, Username,
<<"' and seq='">>, SSeq, <<"';">>]) of
end.
remove_message(LUser, LServer, Seq) ->
- Username = ejabberd_odbc:escape(LUser),
- SSeq = ejabberd_odbc:escape(integer_to_binary(Seq)),
- ejabberd_odbc:sql_query(
+ Username = ejabberd_sql:escape(LUser),
+ SSeq = ejabberd_sql:escape(integer_to_binary(Seq)),
+ ejabberd_sql:sql_query(
LServer,
[<<"delete from spool where username='">>, Username,
<<"' and seq='">>, SSeq, <<"';">>]),
ok.
read_all_messages(LUser, LServer) ->
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
LServer,
?SQL("select @(xml)s from spool where "
"username=%(LUser)s order by seq")) of
end.
remove_all_messages(LUser, LServer) ->
- odbc_queries:del_spool_msg(LServer, LUser),
+ sql_queries:del_spool_msg(LServer, LUser),
{atomic, ok}.
count_messages(LUser, LServer) ->
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
LServer,
?SQL("select @(count(*))d from spool "
"where username=%(LUser)s")) of
timestamp = TimeStamp, from = From, to = To,
packet = Packet})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
Packet1 = jlib:replace_from_to(From, To, Packet),
Packet2 = jlib:add_delay_info(Packet1, LServer, TimeStamp,
<<"Offline Storage">>),
- XML = ejabberd_odbc:escape(fxml:element_to_binary(Packet2)),
+ XML = ejabberd_sql:escape(fxml:element_to_binary(Packet2)),
[[<<"delete from spool where username='">>, Username, <<"';">>],
[<<"insert into spool(username, xml) values ('">>,
Username, <<"', '">>, XML, <<"');">>]];
end
end
end,
- odbc_queries:sql_transaction(LServer, F);
+ sql_queries:sql_transaction(LServer, F);
process_default_set(LUser, LServer, false) ->
case catch sql_unset_default_privacy_list(LUser,
LServer)
end
end
end,
- odbc_queries:sql_transaction(LServer, F).
+ sql_queries:sql_transaction(LServer, F).
set_privacy_list(#privacy{us = {LUser, LServer},
default = Default,
end
end, Lists)
end,
- odbc_queries:sql_transaction(LServer, F).
+ sql_queries:sql_transaction(LServer, F).
set_privacy_list(LUser, LServer, Name, List) ->
RItems = lists:map(fun item_to_raw/1, List),
sql_set_privacy_list(ID, RItems),
ok
end,
- odbc_queries:sql_transaction(LServer, F).
+ sql_queries:sql_transaction(LServer, F).
get_user_list(LUser, LServer) ->
case catch sql_get_default_privacy_list(LUser, LServer)
sql_del_privacy_lists(LUser, LServer).
export(Server) ->
- case catch ejabberd_odbc:sql_query(jid:nameprep(Server),
+ case catch ejabberd_sql:sql_query(jid:nameprep(Server),
[<<"select id from privacy_list order by "
"id desc limit 1;">>]) of
{selected, [<<"id">>], [[I]]} ->
fun(Host, #privacy{us = {LUser, LServer}, lists = Lists,
default = Default})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
if Default /= none ->
- SDefault = ejabberd_odbc:escape(Default),
+ SDefault = ejabberd_sql:escape(Default),
[[<<"delete from privacy_default_list where ">>,
<<"username='">>, Username, <<"';">>],
[<<"insert into privacy_default_list(username, "
end ++
lists:flatmap(
fun({Name, List}) ->
- SName = ejabberd_odbc:escape(Name),
+ SName = ejabberd_sql:escape(Name),
RItems = lists:map(fun item_to_raw/1, List),
ID = jlib:integer_to_binary(get_id()),
[[<<"delete from privacy_list where username='">>,
none -> {<<"n">>, <<"">>};
jid ->
{<<"j">>,
- ejabberd_odbc:escape(jid:to_string(Value))};
- group -> {<<"g">>, ejabberd_odbc:escape(Value)};
+ ejabberd_sql:escape(jid:to_string(Value))};
+ group -> {<<"g">>, ejabberd_sql:escape(Value)};
subscription ->
case Value of
none -> {<<"s">>, <<"none">>};
MatchMessage, MatchPresenceIn, MatchPresenceOut}.
sql_get_default_privacy_list(LUser, LServer) ->
- odbc_queries:get_default_privacy_list(LServer, LUser).
+ sql_queries:get_default_privacy_list(LServer, LUser).
sql_get_default_privacy_list_t(LUser) ->
- odbc_queries:get_default_privacy_list_t(LUser).
+ sql_queries:get_default_privacy_list_t(LUser).
sql_get_privacy_list_names(LUser, LServer) ->
- odbc_queries:get_privacy_list_names(LServer, LUser).
+ sql_queries:get_privacy_list_names(LServer, LUser).
sql_get_privacy_list_names_t(LUser) ->
- odbc_queries:get_privacy_list_names_t(LUser).
+ sql_queries:get_privacy_list_names_t(LUser).
sql_get_privacy_list_id(LUser, LServer, Name) ->
- odbc_queries:get_privacy_list_id(LServer, LUser, Name).
+ sql_queries:get_privacy_list_id(LServer, LUser, Name).
sql_get_privacy_list_id_t(LUser, Name) ->
- odbc_queries:get_privacy_list_id_t(LUser, Name).
+ sql_queries:get_privacy_list_id_t(LUser, Name).
sql_get_privacy_list_data(LUser, LServer, Name) ->
- odbc_queries:get_privacy_list_data(LServer, LUser, Name).
+ sql_queries:get_privacy_list_data(LServer, LUser, Name).
sql_get_privacy_list_data_t(LUser, Name) ->
- Username = ejabberd_odbc:escape(LUser),
- SName = ejabberd_odbc:escape(Name),
- odbc_queries:get_privacy_list_data_t(Username, SName).
+ Username = ejabberd_sql:escape(LUser),
+ SName = ejabberd_sql:escape(Name),
+ sql_queries:get_privacy_list_data_t(Username, SName).
sql_get_privacy_list_data_by_id(ID, LServer) ->
- odbc_queries:get_privacy_list_data_by_id(LServer, ID).
+ sql_queries:get_privacy_list_data_by_id(LServer, ID).
sql_get_privacy_list_data_by_id_t(ID) ->
- odbc_queries:get_privacy_list_data_by_id_t(ID).
+ sql_queries:get_privacy_list_data_by_id_t(ID).
sql_set_default_privacy_list(LUser, Name) ->
- odbc_queries:set_default_privacy_list(LUser, Name).
+ sql_queries:set_default_privacy_list(LUser, Name).
sql_unset_default_privacy_list(LUser, LServer) ->
- odbc_queries:unset_default_privacy_list(LServer, LUser).
+ sql_queries:unset_default_privacy_list(LServer, LUser).
sql_remove_privacy_list(LUser, Name) ->
- odbc_queries:remove_privacy_list(LUser, Name).
+ sql_queries:remove_privacy_list(LUser, Name).
sql_add_privacy_list(LUser, Name) ->
- odbc_queries:add_privacy_list(LUser, Name).
+ sql_queries:add_privacy_list(LUser, Name).
sql_set_privacy_list(ID, RItems) ->
- odbc_queries:set_privacy_list(ID, RItems).
+ sql_queries:set_privacy_list(ID, RItems).
sql_del_privacy_lists(LUser, LServer) ->
- odbc_queries:del_privacy_lists(LServer, LUser).
+ sql_queries:del_privacy_lists(LServer, LUser).
lists:foreach(
fun({XMLNS, El}) ->
SData = fxml:element_to_binary(El),
- odbc_queries:set_private_data(
+ sql_queries:set_private_data(
LServer, LUser, XMLNS, SData)
end, Data)
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
get_data(LUser, LServer, XMLNS) ->
- case catch odbc_queries:get_private_data(LServer, LUser, XMLNS) of
+ case catch sql_queries:get_private_data(LServer, LUser, XMLNS) of
{selected, [{SData}]} ->
case fxml_stream:parse_element(SData) of
Data when is_record(Data, xmlel) ->
end.
get_all_data(LUser, LServer) ->
- case catch odbc_queries:get_private_data(LServer, LUser) of
+ case catch sql_queries:get_private_data(LServer, LUser) of
{selected, Res} ->
lists:flatmap(
fun({_, SData}) ->
end.
remove_user(LUser, LServer) ->
- odbc_queries:del_user_private_storage(LServer, LUser).
+ sql_queries:del_user_private_storage(LServer, LUser).
export(_Server) ->
[{private_storage,
fun(Host, #private_storage{usns = {LUser, LServer, XMLNS},
xml = Data})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
- LXMLNS = ejabberd_odbc:escape(XMLNS),
+ Username = ejabberd_sql:escape(LUser),
+ LXMLNS = ejabberd_sql:escape(XMLNS),
SData =
- ejabberd_odbc:escape(fxml:element_to_binary(Data)),
- odbc_queries:set_private_data_sql(Username, LXMLNS,
+ ejabberd_sql:escape(fxml:element_to_binary(Data)),
+ sql_queries:set_private_data_sql(Username, LXMLNS,
SData);
(_Host, _R) ->
[]
{result, {[LastItem|_], _}} -> LastItem;
_ -> undefined
end;
-get_last_item(Host, Type, Nidx, LJID, odbc) ->
+get_last_item(Host, Type, Nidx, LJID, sql) ->
case node_action(Host, Type, get_last_items, [Nidx, LJID, 1]) of
{result, [LastItem]} -> LastItem;
_ -> undefined
{result, {Items, _}} -> lists:sublist(Items, Number);
_ -> []
end;
-get_last_items(Host, Type, Nidx, LJID, Number, odbc) ->
+get_last_items(Host, Type, Nidx, LJID, Number, sql) ->
case node_action(Host, Type, get_last_items, [Nidx, LJID, Number]) of
{result, Items} -> Items;
_ -> []
|| {Node, Sub, SubId, SubJID} <- Subs,
Sub =:= subscribed, (SubJID == LJID) or (SubJID == BJID),
match_option(Node, send_last_published_item, on_sub_and_presence)];
-get_subscriptions_for_send_last(Host, PType, odbc, JID, LJID, BJID) ->
+get_subscriptions_for_send_last(Host, PType, sql, JID, LJID, BJID) ->
case catch node_action(Host, PType,
get_entity_subscriptions_for_send_last,
[Host, JID])
node_owners_action(Host, Type, Nidx, []) ->
case gen_mod:db_type(serverhost(Host), ?MODULE) of
- odbc ->
+ sql ->
case node_action(Host, Type, get_node_affiliations, [Nidx]) of
{result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
_ -> []
node_owners_call(Host, Type, Nidx, []) ->
case gen_mod:db_type(serverhost(Host), ?MODULE) of
- odbc ->
+ sql ->
case node_call(Host, Type, get_node_affiliations, [Nidx]) of
{result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
_ -> []
tree(Host, Name) ->
case gen_mod:db_type(serverhost(Host), ?MODULE) of
mnesia -> jlib:binary_to_atom(<<"nodetree_", Name/binary>>);
- odbc -> jlib:binary_to_atom(<<"nodetree_", Name/binary, "_odbc">>);
+ sql -> jlib:binary_to_atom(<<"nodetree_", Name/binary, "_sql">>);
_ -> Name
end.
plugin(Host, Name) ->
case gen_mod:db_type(serverhost(Host), ?MODULE) of
mnesia -> jlib:binary_to_atom(<<"node_", Name/binary>>);
- odbc -> jlib:binary_to_atom(<<"node_", Name/binary, "_odbc">>);
+ sql -> jlib:binary_to_atom(<<"node_", Name/binary, "_sql">>);
_ -> Name
end.
subscription_plugin(Host) ->
case gen_mod:db_type(serverhost(Host), ?MODULE) of
mnesia -> pubsub_subscription;
- odbc -> pubsub_subscription_odbc;
+ sql -> pubsub_subscription_sql;
_ -> none
end.
case gen_mod:db_type(ServerHost, ?MODULE) of
mnesia ->
catch mnesia:sync_dirty(Fun);
- odbc ->
- case catch ejabberd_odbc:sql_bloc(ServerHost, Fun) of
+ sql ->
+ case catch ejabberd_sql:sql_bloc(ServerHost, Fun) of
{atomic, Result} ->
Result;
{aborted, Reason} ->
ServerHost = serverhost(Host),
DBType = gen_mod:db_type(ServerHost, ?MODULE),
Retry = case DBType of
- odbc -> 2;
+ sql -> 2;
_ -> 1
end,
transaction_retry(Host, ServerHost, Fun, Trans, DBType, Retry).
Res = case DBType of
mnesia ->
catch mnesia:Trans(Fun);
- odbc ->
+ sql ->
SqlFun = case Trans of
transaction -> sql_transaction;
_ -> sql_bloc
end,
- catch ejabberd_odbc:SqlFun(ServerHost, Fun);
+ catch ejabberd_sql:SqlFun(ServerHost, Fun);
_ ->
{unsupported, DBType}
end,
ok.
read_roster_version(LUser, LServer) ->
- case odbc_queries:get_roster_version(LServer, LUser) of
+ case sql_queries:get_roster_version(LServer, LUser) of
{selected, [{Version}]} -> Version;
{selected, []} -> error
end.
write_roster_version(LUser, LServer, InTransaction, Ver) ->
- Username = ejabberd_odbc:escape(LUser),
- EVer = ejabberd_odbc:escape(Ver),
+ Username = ejabberd_sql:escape(LUser),
+ EVer = ejabberd_sql:escape(Ver),
if InTransaction ->
- odbc_queries:set_roster_version(Username, EVer);
+ sql_queries:set_roster_version(Username, EVer);
true ->
- odbc_queries:sql_transaction(
+ sql_queries:sql_transaction(
LServer,
fun () ->
- odbc_queries:set_roster_version(Username, EVer)
+ sql_queries:set_roster_version(Username, EVer)
end)
end.
get_roster(LUser, LServer) ->
- case catch odbc_queries:get_roster(LServer, LUser) of
+ case catch sql_queries:get_roster(LServer, LUser) of
{selected, Items} when is_list(Items) ->
- JIDGroups = case catch odbc_queries:get_roster_jid_groups(
+ JIDGroups = case catch sql_queries:get_roster_jid_groups(
LServer, LUser) of
{selected, JGrps} when is_list(JGrps) ->
JGrps;
get_roster_by_jid(LUser, LServer, LJID) ->
{selected, Res} =
- odbc_queries:get_roster_by_jid(LServer, LUser, jid:to_string(LJID)),
+ sql_queries:get_roster_by_jid(LServer, LUser, jid:to_string(LJID)),
case Res of
[] ->
#roster{usj = {LUser, LServer, LJID},
end.
get_only_items(LUser, LServer) ->
- case catch odbc_queries:get_roster(LServer, LUser) of
+ case catch sql_queries:get_roster(LServer, LUser) of
{selected, Is} when is_list(Is) ->
lists:map(fun(I) -> raw_to_record(LServer, I) end, Is);
_ -> []
roster_subscribe(_LUser, _LServer, _LJID, Item) ->
ItemVals = record_to_row(Item),
- odbc_queries:roster_subscribe(ItemVals).
+ sql_queries:roster_subscribe(ItemVals).
transaction(LServer, F) ->
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
get_roster_by_jid_with_groups(LUser, LServer, LJID) ->
SJID = jid:to_string(LJID),
- case odbc_queries:get_roster_by_jid(LServer, LUser, SJID) of
+ case sql_queries:get_roster_by_jid(LServer, LUser, SJID) of
{selected, [I]} ->
R = raw_to_record(LServer, I),
Groups =
- case odbc_queries:get_roster_groups(LServer, LUser, SJID) of
+ case sql_queries:get_roster_groups(LServer, LUser, SJID) of
{selected, JGrps} when is_list(JGrps) ->
[JGrp || {JGrp} <- JGrps];
_ -> []
end.
remove_user(LUser, LServer) ->
- odbc_queries:del_user_roster_t(LServer, LUser),
+ sql_queries:del_user_roster_t(LServer, LUser),
{atomic, ok}.
update_roster(LUser, LServer, LJID, Item) ->
SJID = jid:to_string(LJID),
ItemVals = record_to_row(Item),
ItemGroups = Item#roster.groups,
- odbc_queries:update_roster(LServer, LUser, SJID, ItemVals,
+ sql_queries:update_roster(LServer, LUser, SJID, ItemVals,
ItemGroups).
del_roster(LUser, LServer, LJID) ->
SJID = jid:to_string(LJID),
- odbc_queries:del_roster(LServer, LUser, SJID).
+ sql_queries:del_roster(LServer, LUser, SJID).
read_subscription_and_groups(LUser, LServer, LJID) ->
SJID = jid:to_string(LJID),
- case catch odbc_queries:get_subscription(LServer, LUser, SJID) of
+ case catch sql_queries:get_subscription(LServer, LUser, SJID) of
{selected, [{SSubscription}]} ->
Subscription = case SSubscription of
<<"B">> -> both;
<<"F">> -> from;
_ -> none
end,
- Groups = case catch odbc_queries:get_rostergroup_by_jid(
+ Groups = case catch sql_queries:get_rostergroup_by_jid(
LServer, LUser, SJID) of
{selected, JGrps} when is_list(JGrps) ->
[JGrp || {JGrp} <- JGrps];
[{roster,
fun(Host, #roster{usj = {LUser, LServer, LJID}} = R)
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
- SJID = ejabberd_odbc:escape(jid:to_string(LJID)),
+ Username = ejabberd_sql:escape(LUser),
+ SJID = ejabberd_sql:escape(jid:to_string(LJID)),
ItemVals = record_to_string(R),
ItemGroups = groups_to_string(R),
- odbc_queries:update_roster_sql(Username, SJID,
+ sql_queries:update_roster_sql(Username, SJID,
ItemVals, ItemGroups);
(_Host, _R) ->
[]
{roster_version,
fun(Host, #roster_version{us = {LUser, LServer}, version = Ver})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
- SVer = ejabberd_odbc:escape(Ver),
+ Username = ejabberd_sql:escape(LUser),
+ SVer = ejabberd_sql:escape(Ver),
[[<<"delete from roster_version where username='">>,
Username, <<"';">>],
[<<"insert into roster_version(username, version) values('">>,
"ask, askmessage, server, subscribe, type from rosterusers;">>,
fun([LUser, JID|_] = Row) ->
Item = raw_to_record(LServer, Row),
- Username = ejabberd_odbc:escape(LUser),
- SJID = ejabberd_odbc:escape(JID),
+ Username = ejabberd_sql:escape(LUser),
+ SJID = ejabberd_sql:escape(JID),
{selected, _, Rows} =
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[<<"select grp from rostergroups where username='">>,
Username, <<"' and jid='">>, SJID, <<"'">>]),
Groups = [Grp || [Grp] <- Rows],
record_to_string(#roster{us = {User, _Server},
jid = JID, name = Name, subscription = Subscription,
ask = Ask, askmessage = AskMessage}) ->
- Username = ejabberd_odbc:escape(User),
+ Username = ejabberd_sql:escape(User),
SJID =
- ejabberd_odbc:escape(jid:to_string(jid:tolower(JID))),
- Nick = ejabberd_odbc:escape(Name),
+ ejabberd_sql:escape(jid:to_string(jid:tolower(JID))),
+ Nick = ejabberd_sql:escape(Name),
SSubscription = case Subscription of
both -> <<"B">>;
to -> <<"T">>;
in -> <<"I">>;
none -> <<"N">>
end,
- SAskMessage = ejabberd_odbc:escape(AskMessage),
+ SAskMessage = ejabberd_sql:escape(AskMessage),
[Username, SJID, Nick, SSubscription, SAsk, SAskMessage,
<<"N">>, <<"">>, <<"item">>].
groups_to_string(#roster{us = {User, _Server},
jid = JID, groups = Groups}) ->
- Username = ejabberd_odbc:escape(User),
+ Username = ejabberd_sql:escape(User),
SJID =
- ejabberd_odbc:escape(jid:to_string(jid:tolower(JID))),
+ ejabberd_sql:escape(jid:to_string(jid:tolower(JID))),
lists:foldl(fun (<<"">>, Acc) -> Acc;
(Group, Acc) ->
- G = ejabberd_odbc:escape(Group),
+ G = ejabberd_sql:escape(Group),
[[Username, SJID, G] | Acc]
end,
[], Groups).
ok.
list_groups(Host) ->
- case ejabberd_odbc:sql_query(
+ case ejabberd_sql:sql_query(
Host, [<<"select name from sr_group;">>]) of
{selected, [<<"name">>], Rs} -> [G || [G] <- Rs];
_ -> []
end.
groups_with_opts(Host) ->
- case ejabberd_odbc:sql_query(Host,
+ case ejabberd_sql:sql_query(Host,
[<<"select name, opts from sr_group;">>])
of
{selected, [<<"name">>, <<"opts">>], Rs} ->
- [{G, mod_shared_roster:opts_to_binary(ejabberd_odbc:decode_term(Opts))}
+ [{G, mod_shared_roster:opts_to_binary(ejabberd_sql:decode_term(Opts))}
|| [G, Opts] <- Rs];
_ -> []
end.
create_group(Host, Group, Opts) ->
- SGroup = ejabberd_odbc:escape(Group),
- SOpts = ejabberd_odbc:encode_term(Opts),
+ SGroup = ejabberd_sql:escape(Group),
+ SOpts = ejabberd_sql:encode_term(Opts),
F = fun () ->
- odbc_queries:update_t(<<"sr_group">>,
+ sql_queries:update_t(<<"sr_group">>,
[<<"name">>, <<"opts">>], [SGroup, SOpts],
[<<"name='">>, SGroup, <<"'">>])
end,
- ejabberd_odbc:sql_transaction(Host, F).
+ ejabberd_sql:sql_transaction(Host, F).
delete_group(Host, Group) ->
- SGroup = ejabberd_odbc:escape(Group),
+ SGroup = ejabberd_sql:escape(Group),
F = fun () ->
- ejabberd_odbc:sql_query_t([<<"delete from sr_group where name='">>,
+ ejabberd_sql:sql_query_t([<<"delete from sr_group where name='">>,
SGroup, <<"';">>]),
- ejabberd_odbc:sql_query_t([<<"delete from sr_user where grp='">>,
+ ejabberd_sql:sql_query_t([<<"delete from sr_user where grp='">>,
SGroup, <<"';">>])
end,
- case ejabberd_odbc:sql_transaction(Host, F) of
+ case ejabberd_sql:sql_transaction(Host, F) of
{atomic,{updated,_}} -> {atomic, ok};
Res -> Res
end.
get_group_opts(Host, Group) ->
- SGroup = ejabberd_odbc:escape(Group),
- case catch ejabberd_odbc:sql_query(
+ SGroup = ejabberd_sql:escape(Group),
+ case catch ejabberd_sql:sql_query(
Host,
[<<"select opts from sr_group where name='">>,
SGroup, <<"';">>]) of
{selected, [<<"opts">>], [[SOpts]]} ->
- mod_shared_roster:opts_to_binary(ejabberd_odbc:decode_term(SOpts));
+ mod_shared_roster:opts_to_binary(ejabberd_sql:decode_term(SOpts));
_ -> error
end.
set_group_opts(Host, Group, Opts) ->
- SGroup = ejabberd_odbc:escape(Group),
- SOpts = ejabberd_odbc:encode_term(Opts),
+ SGroup = ejabberd_sql:escape(Group),
+ SOpts = ejabberd_sql:encode_term(Opts),
F = fun () ->
- odbc_queries:update_t(<<"sr_group">>,
+ sql_queries:update_t(<<"sr_group">>,
[<<"name">>, <<"opts">>], [SGroup, SOpts],
[<<"name='">>, SGroup, <<"'">>])
end,
- ejabberd_odbc:sql_transaction(Host, F).
+ ejabberd_sql:sql_transaction(Host, F).
get_user_groups(US, Host) ->
SJID = make_jid_s(US),
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
Host,
[<<"select grp from sr_user where jid='">>,
SJID, <<"';">>]) of
end.
get_group_explicit_users(Host, Group) ->
- SGroup = ejabberd_odbc:escape(Group),
- case catch ejabberd_odbc:sql_query(
+ SGroup = ejabberd_sql:escape(Group),
+ case catch ejabberd_sql:sql_query(
Host,
[<<"select jid from sr_user where grp='">>,
SGroup, <<"';">>]) of
get_user_displayed_groups(LUser, LServer, GroupsOpts) ->
SJID = make_jid_s(LUser, LServer),
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
LServer,
[<<"select grp from sr_user where jid='">>,
SJID, <<"';">>]) of
is_user_in_group(US, Group, Host) ->
SJID = make_jid_s(US),
- SGroup = ejabberd_odbc:escape(Group),
- case catch ejabberd_odbc:sql_query(Host,
+ SGroup = ejabberd_sql:escape(Group),
+ case catch ejabberd_sql:sql_query(Host,
[<<"select * from sr_user where jid='">>,
SJID, <<"' and grp='">>, SGroup,
<<"';">>]) of
add_user_to_group(Host, US, Group) ->
SJID = make_jid_s(US),
- SGroup = ejabberd_odbc:escape(Group),
+ SGroup = ejabberd_sql:escape(Group),
F = fun () ->
- odbc_queries:update_t(<<"sr_user">>,
+ sql_queries:update_t(<<"sr_user">>,
[<<"jid">>, <<"grp">>], [SJID, SGroup],
[<<"jid='">>, SJID, <<"' and grp='">>,
SGroup, <<"'">>])
end,
- ejabberd_odbc:sql_transaction(Host, F).
+ ejabberd_sql:sql_transaction(Host, F).
remove_user_from_group(Host, US, Group) ->
SJID = make_jid_s(US),
- SGroup = ejabberd_odbc:escape(Group),
+ SGroup = ejabberd_sql:escape(Group),
F = fun () ->
- ejabberd_odbc:sql_query_t([<<"delete from sr_user where jid='">>,
+ ejabberd_sql:sql_query_t([<<"delete from sr_user where jid='">>,
SJID, <<"' and grp='">>, SGroup,
<<"';">>]),
ok
end,
- ejabberd_odbc:sql_transaction(Host, F).
+ ejabberd_sql:sql_transaction(Host, F).
export(_Server) ->
[{sr_group,
fun(Host, #sr_group{group_host = {Group, LServer}, opts = Opts})
when LServer == Host ->
- SGroup = ejabberd_odbc:escape(Group),
- SOpts = ejabberd_odbc:encode_term(Opts),
+ SGroup = ejabberd_sql:escape(Group),
+ SOpts = ejabberd_sql:encode_term(Opts),
[[<<"delete from sr_group where name='">>, Group, <<"';">>],
[<<"insert into sr_group(name, opts) values ('">>,
SGroup, <<"', '">>, SOpts, <<"');">>]];
{sr_user,
fun(Host, #sr_user{us = {U, S}, group_host = {Group, LServer}})
when LServer == Host ->
- SGroup = ejabberd_odbc:escape(Group),
- SJID = ejabberd_odbc:escape(
+ SGroup = ejabberd_sql:escape(Group),
+ SJID = ejabberd_sql:escape(
jid:to_string(
jid:tolower(
jid:make(U, S, <<"">>)))),
[{<<"select name, opts from sr_group;">>,
fun([Group, SOpts]) ->
#sr_group{group_host = {Group, LServer},
- opts = ejabberd_odbc:decode_term(SOpts)}
+ opts = ejabberd_sql:decode_term(SOpts)}
end},
{<<"select jid, grp from sr_user;">>,
fun([SJID, Group]) ->
%%% Internal functions
%%%===================================================================
make_jid_s(U, S) ->
- ejabberd_odbc:escape(jid:to_string(jid:tolower(jid:make(U, S, <<"">>)))).
+ ejabberd_sql:escape(jid:to_string(jid:tolower(jid:make(U, S, <<"">>)))).
make_jid_s({U, S}) -> make_jid_s(U, S).
ok.
get_vcard(LUser, LServer) ->
- case catch odbc_queries:get_vcard(LServer, LUser) of
+ case catch sql_queries:get_vcard(LServer, LUser) of
{selected, [{SVCARD}]} ->
case fxml_stream:parse_element(SVCARD) of
{error, _Reason} -> error;
orgunit = OrgUnit,
lorgunit = LOrgUnit}) ->
SVCARD = fxml:element_to_binary(VCARD),
- odbc_queries:set_vcard(LServer, LUser, BDay, CTRY,
+ sql_queries:set_vcard(LServer, LUser, BDay, CTRY,
EMail, FN, Family, Given, LBDay,
LCTRY, LEMail, LFN, LFamily,
LGiven, LLocality, LMiddle,
Val ->
[<<" LIMIT ">>, jlib:integer_to_binary(Val)]
end,
- case catch ejabberd_odbc:sql_query(
+ case catch ejabberd_sql:sql_query(
LServer,
[<<"select username, fn, family, given, "
"middle, nickname, bday, ctry, "
end.
remove_user(LUser, LServer) ->
- ejabberd_odbc:sql_transaction(
+ ejabberd_sql:sql_transaction(
LServer,
fun() ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from vcard where username=%(LUser)s")),
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from vcard_search where lusername=%(LUser)s"))
end).
[{vcard,
fun(Host, #vcard{us = {LUser, LServer}, vcard = VCARD})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
SVCARD =
- ejabberd_odbc:escape(fxml:element_to_binary(VCARD)),
+ ejabberd_sql:escape(fxml:element_to_binary(VCARD)),
[[<<"delete from vcard where username='">>, Username, <<"';">>],
[<<"insert into vcard(username, vcard) values ('">>,
Username, <<"', '">>, SVCARD, <<"');">>]];
orgname = OrgName, lorgname = LOrgName,
orgunit = OrgUnit, lorgunit = LOrgUnit})
when LServer == Host ->
- Username = ejabberd_odbc:escape(User),
- LUsername = ejabberd_odbc:escape(LUser),
- SFN = ejabberd_odbc:escape(FN),
- SLFN = ejabberd_odbc:escape(LFN),
- SFamily = ejabberd_odbc:escape(Family),
- SLFamily = ejabberd_odbc:escape(LFamily),
- SGiven = ejabberd_odbc:escape(Given),
- SLGiven = ejabberd_odbc:escape(LGiven),
- SMiddle = ejabberd_odbc:escape(Middle),
- SLMiddle = ejabberd_odbc:escape(LMiddle),
- SNickname = ejabberd_odbc:escape(Nickname),
- SLNickname = ejabberd_odbc:escape(LNickname),
- SBDay = ejabberd_odbc:escape(BDay),
- SLBDay = ejabberd_odbc:escape(LBDay),
- SCTRY = ejabberd_odbc:escape(CTRY),
- SLCTRY = ejabberd_odbc:escape(LCTRY),
- SLocality = ejabberd_odbc:escape(Locality),
- SLLocality = ejabberd_odbc:escape(LLocality),
- SEMail = ejabberd_odbc:escape(EMail),
- SLEMail = ejabberd_odbc:escape(LEMail),
- SOrgName = ejabberd_odbc:escape(OrgName),
- SLOrgName = ejabberd_odbc:escape(LOrgName),
- SOrgUnit = ejabberd_odbc:escape(OrgUnit),
- SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
+ Username = ejabberd_sql:escape(User),
+ LUsername = ejabberd_sql:escape(LUser),
+ SFN = ejabberd_sql:escape(FN),
+ SLFN = ejabberd_sql:escape(LFN),
+ SFamily = ejabberd_sql:escape(Family),
+ SLFamily = ejabberd_sql:escape(LFamily),
+ SGiven = ejabberd_sql:escape(Given),
+ SLGiven = ejabberd_sql:escape(LGiven),
+ SMiddle = ejabberd_sql:escape(Middle),
+ SLMiddle = ejabberd_sql:escape(LMiddle),
+ SNickname = ejabberd_sql:escape(Nickname),
+ SLNickname = ejabberd_sql:escape(LNickname),
+ SBDay = ejabberd_sql:escape(BDay),
+ SLBDay = ejabberd_sql:escape(LBDay),
+ SCTRY = ejabberd_sql:escape(CTRY),
+ SLCTRY = ejabberd_sql:escape(LCTRY),
+ SLocality = ejabberd_sql:escape(Locality),
+ SLLocality = ejabberd_sql:escape(LLocality),
+ SEMail = ejabberd_sql:escape(EMail),
+ SLEMail = ejabberd_sql:escape(LEMail),
+ SOrgName = ejabberd_sql:escape(OrgName),
+ SLOrgName = ejabberd_sql:escape(LOrgName),
+ SOrgUnit = ejabberd_sql:escape(OrgUnit),
+ SLOrgUnit = ejabberd_sql:escape(LOrgUnit),
[[<<"delete from vcard_search where lusername='">>,
LUsername, <<"';">>],
[<<"insert into vcard_search( username, "
Condition = case str:suffix(<<"*">>, Val) of
true ->
Val1 = str:substr(Val, 1, byte_size(Val) - 1),
- SVal = <<(ejabberd_odbc:escape_like(Val1))/binary,
+ SVal = <<(ejabberd_sql:escape_like(Val1))/binary,
"%">>,
[Field, <<" LIKE '">>, SVal, <<"'">>];
_ ->
- SVal = ejabberd_odbc:escape(Val),
+ SVal = ejabberd_sql:escape(Val),
[Field, <<" = '">>, SVal, <<"'">>]
end,
case Match of
ok.
add_xupdate(LUser, LServer, Hash) ->
- Username = ejabberd_odbc:escape(LUser),
- SHash = ejabberd_odbc:escape(Hash),
+ Username = ejabberd_sql:escape(LUser),
+ SHash = ejabberd_sql:escape(Hash),
F = fun () ->
- odbc_queries:update_t(<<"vcard_xupdate">>,
+ sql_queries:update_t(<<"vcard_xupdate">>,
[<<"username">>, <<"hash">>],
[Username, SHash],
[<<"username='">>, Username, <<"'">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
get_xupdate(LUser, LServer) ->
- Username = ejabberd_odbc:escape(LUser),
- case ejabberd_odbc:sql_query(LServer,
+ Username = ejabberd_sql:escape(LUser),
+ case ejabberd_sql:sql_query(LServer,
[<<"select hash from vcard_xupdate where "
"username='">>,
Username, <<"';">>])
end.
remove_xupdate(LUser, LServer) ->
- Username = ejabberd_odbc:escape(LUser),
+ Username = ejabberd_sql:escape(LUser),
F = fun () ->
- ejabberd_odbc:sql_query_t([<<"delete from vcard_xupdate where username='">>,
+ ejabberd_sql:sql_query_t([<<"delete from vcard_xupdate where username='">>,
Username, <<"';">>])
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
export(_Server) ->
[{vcard_xupdate,
fun(Host, #vcard_xupdate{us = {LUser, LServer}, hash = Hash})
when LServer == Host ->
- Username = ejabberd_odbc:escape(LUser),
- SHash = ejabberd_odbc:escape(Hash),
+ Username = ejabberd_sql:escape(LUser),
+ SHash = ejabberd_sql:escape(Hash),
[[<<"delete from vcard_xupdate where username='">>,
Username, <<"';">>],
[<<"insert into vcard_xupdate(username, "
%%%----------------------------------------------------------------------
-%%% File : node_flat_odbc.erl
+%%% File : node_flat_sql.erl
%%% Author : Christophe Romain <christophe.romain@process-one.net>
%%% Purpose : Standard PubSub node plugin with ODBC backend
%%% Created : 1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
%%% types.</p>
%%% <p>PubSub plugin nodes are using the {@link gen_node} behaviour.</p>
--module(node_flat_odbc).
+-module(node_flat_sql).
-behaviour(gen_pubsub_node).
-author('christophe.romain@process-one.net').
encode_host/1]).
init(_Host, _ServerHost, _Opts) ->
- %%pubsub_subscription_odbc:init(),
+ %%pubsub_subscription_sql:init(),
ok.
terminate(_Host, _ServerHost) ->
ok.
options() ->
- [{odbc, true}, {rsm, true} | node_flat:options()].
+ [{sql, true}, {rsm, true} | node_flat:options()].
features() ->
[<<"rsm">> | node_flat:features()].
create_node(Nidx, Owner) ->
{_U, _S, _R} = OwnerKey = jid:tolower(jid:remove_resource(Owner)),
State = #pubsub_state{stateid = {OwnerKey, Nidx}, affiliation = owner},
- catch ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+ catch ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values(">>, state_to_raw(Nidx, State), <<");">>]),
{result, {default, broadcast}}.
delete_node(Nodes) ->
Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
Subscriptions = case catch
- ejabberd_odbc:sql_query_t([<<"select jid, subscriptions "
+ ejabberd_sql:sql_query_t([<<"select jid, subscriptions "
"from pubsub_state where nodeid='">>, Nidx, <<"';">>])
of
{selected, [<<"jid">>, <<"subscriptions">>], RItems} ->
%% % Requesting entity is anonymous
%% {error, ?ERR_FORBIDDEN};
true ->
- %%{result, SubId} = pubsub_subscription_odbc:subscribe_node(Subscriber, Nidx, Options),
+ %%{result, SubId} = pubsub_subscription_sql:subscribe_node(Subscriber, Nidx, Options),
{NewSub, SubId} = case Subscriptions of
[{subscribed, Id}|_] ->
{subscribed, Id};
[] ->
- Id = pubsub_subscription_odbc:make_subid(),
+ Id = pubsub_subscription_sql:make_subid(),
Sub = case AccessModel of
authorize -> pending;
_ -> subscribed
delete_subscription(SubKey, Nidx, {Subscription, SubId}, Affiliation, Subscriptions) ->
NewSubs = Subscriptions -- [{Subscription, SubId}],
- %%pubsub_subscription_odbc:unsubscribe_node(SubKey, Nidx, SubId),
+ %%pubsub_subscription_sql:unsubscribe_node(SubKey, Nidx, SubId),
case {Affiliation, NewSubs} of
{none, []} -> del_state(Nidx, SubKey);
_ -> update_subscription(Nidx, SubKey, NewSubs)
H = encode_host(Host),
J = encode_jid(GenKey),
Reply = case catch
- ejabberd_odbc:sql_query_t([<<"select node, type, i.nodeid, affiliation "
+ ejabberd_sql:sql_query_t([<<"select node, type, i.nodeid, affiliation "
"from pubsub_state i, pubsub_node n where "
"i.nodeid = n.nodeid and jid='">>, J, <<"' and host='">>, H, <<"';">>])
of
{selected, [<<"node">>, <<"type">>, <<"nodeid">>, <<"affiliation">>], RItems} ->
- [{nodetree_tree_odbc:raw_to_node(Host, [N, <<"">>, T, I]), decode_affiliation(A)}
+ [{nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]), decode_affiliation(A)}
|| [N, T, I, A] <- RItems];
_ ->
[]
get_node_affiliations(Nidx) ->
Reply = case catch
- ejabberd_odbc:sql_query_t([<<"select jid, affiliation from pubsub_state "
+ ejabberd_sql:sql_query_t([<<"select jid, affiliation from pubsub_state "
"where nodeid='">>, Nidx, <<"';">>])
of
{selected, [<<"jid">>, <<"affiliation">>], RItems} ->
GenKey = jid:remove_resource(SubKey),
J = encode_jid(GenKey),
Reply = case catch
- ejabberd_odbc:sql_query_t([<<"select affiliation from pubsub_state "
+ ejabberd_sql:sql_query_t([<<"select affiliation from pubsub_state "
"where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
of
{selected, [<<"affiliation">>], [[A]]} ->
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid and jid in ('">>, SJ, <<"', '">>, GJ, <<"') and host='">>, H, <<"';">>]
end,
- Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+ Reply = case catch ejabberd_sql:sql_query_t(Query) of
{selected,
[<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} ->
lists:foldl(fun ([N, T, I, J, S], Acc) ->
- Node = nodetree_tree_odbc:raw_to_node(Host, [N, <<"">>, T, I]),
+ Node = nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]),
Jid = decode_jid(J),
case decode_subscriptions(S) of
[] ->
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and name='send_last_published_item' "
"and val='on_sub_and_presence' and jid in ('">>, SJ, <<"', '">>, GJ, <<"') and host='">>, H, <<"';">>]
end,
- Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+ Reply = case catch ejabberd_sql:sql_query_t(Query) of
{selected,
[<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} ->
lists:foldl(fun ([N, T, I, J, S], Acc) ->
- Node = nodetree_tree_odbc:raw_to_node(Host, [N, <<"">>, T, I]),
+ Node = nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]),
Jid = decode_jid(J),
case decode_subscriptions(S) of
[] ->
get_node_subscriptions(Nidx) ->
Reply = case catch
- ejabberd_odbc:sql_query_t([<<"select jid, subscriptions from pubsub_state "
+ ejabberd_sql:sql_query_t([<<"select jid, subscriptions from pubsub_state "
"where nodeid='">>, Nidx, <<"';">>])
of
{selected, [<<"jid">>, <<"subscriptions">>], RItems} ->
SubKey = jid:tolower(Owner),
J = encode_jid(SubKey),
Reply = case catch
- ejabberd_odbc:sql_query_t([<<"select subscriptions from pubsub_state where "
+ ejabberd_sql:sql_query_t([<<"select subscriptions from pubsub_state where "
"nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
of
{selected, [<<"subscriptions">>], [[S]]} ->
replace_subscription({Sub, SubId}, T, [{Sub, SubId} | Acc]).
new_subscription(_Nidx, _Owner, Subscription, SubState) ->
- %%{result, SubId} = pubsub_subscription_odbc:subscribe_node(Owner, Nidx, []),
- SubId = pubsub_subscription_odbc:make_subid(),
+ %%{result, SubId} = pubsub_subscription_sql:subscribe_node(Owner, Nidx, []),
+ SubId = pubsub_subscription_sql:make_subid(),
Subscriptions = [{Subscription, SubId} | SubState#pubsub_state.subscriptions],
set_state(SubState#pubsub_state{subscriptions = Subscriptions}),
{Subscription, SubId}.
unsub_with_subid(Nidx, SubId, SubState) ->
- %%pubsub_subscription_odbc:unsubscribe_node(SubState#pubsub_state.stateid, Nidx, SubId),
+ %%pubsub_subscription_sql:unsubscribe_node(SubState#pubsub_state.stateid, Nidx, SubId),
NewSubs = [{S, Sid}
|| {S, Sid} <- SubState#pubsub_state.subscriptions,
SubId =/= Sid],
get_states(Nidx) ->
case catch
- ejabberd_odbc:sql_query_t([<<"select jid, affiliation, subscriptions "
+ ejabberd_sql:sql_query_t([<<"select jid, affiliation, subscriptions "
"from pubsub_state where nodeid='">>, Nidx, <<"';">>])
of
{selected,
get_state_without_itemids(Nidx, JID) ->
J = encode_jid(JID),
case catch
- ejabberd_odbc:sql_query_t([<<"select jid, affiliation, subscriptions "
+ ejabberd_sql:sql_query_t([<<"select jid, affiliation, subscriptions "
"from pubsub_state where jid='">>, J, <<"' and nodeid='">>, Nidx, <<"';">>])
of
{selected,
S = encode_subscriptions(State#pubsub_state.subscriptions),
A = encode_affiliation(State#pubsub_state.affiliation),
case catch
- ejabberd_odbc:sql_query_t([<<"update pubsub_state set subscriptions='">>, S, <<"', affiliation='">>, A,
+ ejabberd_sql:sql_query_t([<<"update pubsub_state set subscriptions='">>, S, <<"', affiliation='">>, A,
<<"' where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
of
{updated, 1} ->
ok;
_ ->
catch
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values('">>,
Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '">>, S, <<"');">>])
end,
del_state(Nidx, JID) ->
J = encode_jid(JID),
- catch ejabberd_odbc:sql_query_t([<<"delete from pubsub_state where jid='">>,
+ catch ejabberd_sql:sql_query_t([<<"delete from pubsub_state where jid='">>,
J, <<"' and nodeid='">>, Nidx, <<"';">>]),
ok.
%get_items(Nidx, _From) ->
% case catch
-% ejabberd_odbc:sql_query_t([<<"select itemid, publisher, creation, modification, payload "
+% ejabberd_sql:sql_query_t([<<"select itemid, publisher, creation, modification, payload "
% "from pubsub_item where nodeid='">>, Nidx,
% <<"' order by modification desc;">>])
% of
get_items(Nidx, From, none) ->
MaxItems = case catch
- ejabberd_odbc:sql_query_t([<<"select val from pubsub_node_option "
+ ejabberd_sql:sql_query_t([<<"select val from pubsub_node_option "
"where nodeid='">>, Nidx, <<"' and name='max_items';">>])
of
{selected, [<<"val">>], [[Value]]} ->
get_items(Nidx, From, #rsm_in{max = MaxItems});
get_items(Nidx, _From,
#rsm_in{max = M, direction = Direction, id = I, index = IncIndex}) ->
- Max = ejabberd_odbc:escape(jlib:i2l(M)),
+ Max = ejabberd_sql:escape(jlib:i2l(M)),
{Way, Order} = case Direction of
% aft -> {<<"<">>, <<"desc">>};
% before when I == <<>> -> {<<"is not">>, <<"asc">>};
[AttrName, Id] = case I of
undefined when IncIndex =/= undefined ->
case catch
- ejabberd_odbc:sql_query_t([<<"select modification from pubsub_item pi "
+ ejabberd_sql:sql_query_t([<<"select modification from pubsub_item pi "
"where exists ( select count(*) as count1 "
"from pubsub_item where nodeid='">>, Nidx,
<<"' and modification > pi.modification having count1 = ">>,
- ejabberd_odbc:escape(jlib:i2l(IncIndex)), <<" );">>])
+ ejabberd_sql:escape(jlib:i2l(IncIndex)), <<" );">>])
of
{selected, [_], [[O]]} ->
[<<"modification">>, <<"'", O/binary, "'">>];
<<>> ->
[<<"modification">>, <<"null">>];
I ->
- [A, B] = str:tokens(ejabberd_odbc:escape(jlib:i2l(I)), <<"@">>),
+ [A, B] = str:tokens(ejabberd_sql:escape(jlib:i2l(I)), <<"@">>),
[A, <<"'", B/binary, "'">>]
end,
Count = case catch
- ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, Nidx, <<"';">>])
+ ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, Nidx, <<"';">>])
of
{selected, [_], [[C]]} -> C;
_ -> <<"0">>
end,
Query = fun(mssql, _) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[<<"select top ">>, jlib:i2l(Max),
<<" itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx,
<<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
AttrName, <<" ">>, Order, <<";">>]);
(_, _) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[<<"select itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx,
<<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
AttrName, <<" ">>, Order, <<" limit ">>, jlib:i2l(Max), <<" ;">>])
end,
- case catch ejabberd_odbc:sql_query_t(Query) of
+ case catch ejabberd_sql:sql_query_t(Query) of
{selected,
[<<"itemid">>, <<"publisher">>, <<"creation">>, <<"modification">>, <<"payload">>], RItems} ->
case RItems of
[[_, _, _, F, _]|_] ->
Index = case catch
- ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item "
+ ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item "
"where nodeid='">>, Nidx, <<"' and ">>,
AttrName, <<" > '">>, F, <<"';">>])
of
get_last_items(Nidx, _From, Count) ->
Limit = jlib:i2l(Count),
Query = fun(mssql, _) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[<<"select top ">>, Limit,
<<" itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx,
<<"' order by modification desc ;">>]);
(_, _) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
[<<"select itemid, publisher, creation, modification, payload "
"from pubsub_item where nodeid='">>, Nidx,
<<"' order by modification desc limit ">>, Limit, <<";">>])
end,
- case catch ejabberd_odbc:sql_query_t(Query) of
+ case catch ejabberd_sql:sql_query_t(Query) of
{selected,
[<<"itemid">>, <<"publisher">>, <<"creation">>, <<"modification">>, <<"payload">>], RItems} ->
{result, [raw_to_item(Nidx, RItem) || RItem <- RItems]};
end.
get_item(Nidx, ItemId) ->
- I = ejabberd_odbc:escape(ItemId),
+ I = ejabberd_sql:escape(ItemId),
case catch
- ejabberd_odbc:sql_query_t([<<"select itemid, publisher, creation, "
+ ejabberd_sql:sql_query_t([<<"select itemid, publisher, creation, "
"modification, payload from pubsub_item "
"where nodeid='">>, Nidx, <<"' and itemid='">>, I, <<"';">>])
of
set_item(Item) ->
{ItemId, Nidx} = Item#pubsub_item.itemid,
- I = ejabberd_odbc:escape(ItemId),
+ I = ejabberd_sql:escape(ItemId),
{C, _} = Item#pubsub_item.creation,
{M, JID} = Item#pubsub_item.modification,
P = encode_jid(JID),
Payload = Item#pubsub_item.payload,
- XML = ejabberd_odbc:escape(str:join([fxml:element_to_binary(X) || X<-Payload], <<>>)),
+ XML = ejabberd_sql:escape(str:join([fxml:element_to_binary(X) || X<-Payload], <<>>)),
S = fun ({T1, T2, T3}) ->
str:join([jlib:i2l(T1, 6), jlib:i2l(T2, 6), jlib:i2l(T3, 6)], <<":">>)
end,
case catch
- ejabberd_odbc:sql_query_t([<<"update pubsub_item set publisher='">>, P,
+ ejabberd_sql:sql_query_t([<<"update pubsub_item set publisher='">>, P,
<<"', modification='">>, S(M),
<<"', payload='">>, XML,
<<"' where nodeid='">>, Nidx, <<"' and itemid='">>, I, <<"';">>])
ok;
_ ->
catch
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_item (nodeid, itemid, "
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_item (nodeid, itemid, "
"publisher, creation, modification, payload) "
"values('">>, Nidx, <<"', '">>, I, <<"', '">>, P,
<<"', '">>, S(C), <<"', '">>, S(M),
ok.
del_item(Nidx, ItemId) ->
- I = ejabberd_odbc:escape(ItemId),
- catch ejabberd_odbc:sql_query_t([<<"delete from pubsub_item where itemid='">>,
+ I = ejabberd_sql:escape(ItemId),
+ catch ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid='">>,
I, <<"' and nodeid='">>, Nidx, <<"';">>]).
del_items(_, []) ->
del_items(Nidx, [ItemId]) ->
del_item(Nidx, ItemId);
del_items(Nidx, ItemIds) ->
- I = str:join([[<<"'">>, ejabberd_odbc:escape(X), <<"'">>] || X <- ItemIds], <<",">>),
+ I = str:join([[<<"'">>, ejabberd_sql:escape(X), <<"'">>] || X <- ItemIds], <<",">>),
catch
- ejabberd_odbc:sql_query_t([<<"delete from pubsub_item where itemid in (">>,
+ ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid in (">>,
I, <<") and nodeid='">>, Nidx, <<"';">>]).
get_item_name(_Host, _Node, Id) ->
itemids(Nidx, encode_jid({U, S, R}));
itemids(Nidx, SJID) ->
case catch
- ejabberd_odbc:sql_query_t([<<"select itemid from pubsub_item where "
+ ejabberd_sql:sql_query_t([<<"select itemid from pubsub_item where "
"nodeid='">>, Nidx, <<"' and publisher like '">>, SJID,
<<"%' order by modification desc;">>])
of
select_affiliation_subscriptions(Nidx, JID) ->
J = encode_jid(JID),
case catch
- ejabberd_odbc:sql_query_t([<<"select affiliation,subscriptions from "
+ ejabberd_sql:sql_query_t([<<"select affiliation,subscriptions from "
"pubsub_state where nodeid='">>,
Nidx, <<"' and jid='">>, J, <<"';">>])
of
J = encode_jid(JID),
A = encode_affiliation(Affiliation),
case catch
- ejabberd_odbc:sql_query_t([<<"update pubsub_state set affiliation='">>,
+ ejabberd_sql:sql_query_t([<<"update pubsub_state set affiliation='">>,
A, <<"' where nodeid='">>, Nidx,
<<"' and jid='">>, J, <<"';">>])
of
ok;
_ ->
catch
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values('">>, Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '');">>])
end.
J = encode_jid(JID),
S = encode_subscriptions(Subscription),
case catch
- ejabberd_odbc:sql_query_t([<<"update pubsub_state set subscriptions='">>, S,
+ ejabberd_sql:sql_query_t([<<"update pubsub_state set subscriptions='">>, S,
<<"' where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
of
{updated, 1} ->
ok;
_ ->
catch
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
"values('">>, Nidx, <<"', '">>, J, <<"', 'n', '">>, S, <<"');">>])
end.
-> binary()
).
encode_jid(JID) ->
- ejabberd_odbc:escape(jid:to_string(JID)).
+ ejabberd_sql:escape(jid:to_string(JID)).
-spec(encode_host/1 ::
( Host :: host())
-> binary()
).
encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID);
-encode_host(Host) -> ejabberd_odbc:escape(Host).
+encode_host(Host) -> ejabberd_sql:escape(Host).
-spec(encode_affiliation/1 ::
( Arg :: atom())
%%%----------------------------------------------------------------------
-%%% File : node_hometree_odbc.erl
+%%% File : node_hometree_sql.erl
%%% Author : Christophe Romain <christophe.romain@process-one.net>
%%% Purpose : Standard tree ordered node plugin with ODBC backend
%%% Created : 1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
%%%
%%%----------------------------------------------------------------------
--module(node_hometree_odbc).
+-module(node_hometree_sql).
-behaviour(gen_pubsub_node).
-author('christophe.romain@process-one.net').
get_entity_subscriptions_for_send_last/2, get_last_items/3]).
init(Host, ServerHost, Opts) ->
- node_flat_odbc:init(Host, ServerHost, Opts),
+ node_flat_sql:init(Host, ServerHost, Opts),
Owner = mod_pubsub:service_jid(Host),
mod_pubsub:create_node(Host, ServerHost, <<"/home">>, Owner, <<"hometree">>),
mod_pubsub:create_node(Host, ServerHost, <<"/home/", ServerHost/binary>>, Owner, <<"hometree">>),
ok.
terminate(Host, ServerHost) ->
- node_flat_odbc:terminate(Host, ServerHost).
+ node_flat_sql:terminate(Host, ServerHost).
options() ->
- [{odbc, true}, {rsm, true} | node_hometree:options()].
+ [{sql, true}, {rsm, true} | node_hometree:options()].
features() ->
[<<"rsm">> | node_hometree:features()].
node_hometree:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
create_node(Nidx, Owner) ->
- node_flat_odbc:create_node(Nidx, Owner).
+ node_flat_sql:create_node(Nidx, Owner).
delete_node(Nodes) ->
- node_flat_odbc:delete_node(Nodes).
+ node_flat_sql:delete_node(Nodes).
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup, Options) ->
- node_flat_odbc:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
+ node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
PresenceSubscription, RosterGroup, Options).
unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
- node_flat_odbc:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
+ node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
- node_flat_odbc:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
+ node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
remove_extra_items(Nidx, MaxItems, ItemIds) ->
- node_flat_odbc:remove_extra_items(Nidx, MaxItems, ItemIds).
+ node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
- node_flat_odbc:delete_item(Nidx, Publisher, PublishModel, ItemId).
+ node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
purge_node(Nidx, Owner) ->
- node_flat_odbc:purge_node(Nidx, Owner).
+ node_flat_sql:purge_node(Nidx, Owner).
get_entity_affiliations(Host, Owner) ->
- node_flat_odbc:get_entity_affiliations(Host, Owner).
+ node_flat_sql:get_entity_affiliations(Host, Owner).
get_node_affiliations(Nidx) ->
- node_flat_odbc:get_node_affiliations(Nidx).
+ node_flat_sql:get_node_affiliations(Nidx).
get_affiliation(Nidx, Owner) ->
- node_flat_odbc:get_affiliation(Nidx, Owner).
+ node_flat_sql:get_affiliation(Nidx, Owner).
set_affiliation(Nidx, Owner, Affiliation) ->
- node_flat_odbc:set_affiliation(Nidx, Owner, Affiliation).
+ node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
get_entity_subscriptions(Host, Owner) ->
- node_flat_odbc:get_entity_subscriptions(Host, Owner).
+ node_flat_sql:get_entity_subscriptions(Host, Owner).
get_entity_subscriptions_for_send_last(Host, Owner) ->
- node_flat_odbc:get_entity_subscriptions_for_send_last(Host, Owner).
+ node_flat_sql:get_entity_subscriptions_for_send_last(Host, Owner).
get_node_subscriptions(Nidx) ->
- node_flat_odbc:get_node_subscriptions(Nidx).
+ node_flat_sql:get_node_subscriptions(Nidx).
get_subscriptions(Nidx, Owner) ->
- node_flat_odbc:get_subscriptions(Nidx, Owner).
+ node_flat_sql:get_subscriptions(Nidx, Owner).
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
- node_flat_odbc:set_subscriptions(Nidx, Owner, Subscription, SubId).
+ node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
get_pending_nodes(Host, Owner) ->
- node_flat_odbc:get_pending_nodes(Host, Owner).
+ node_flat_sql:get_pending_nodes(Host, Owner).
get_states(Nidx) ->
- node_flat_odbc:get_states(Nidx).
+ node_flat_sql:get_states(Nidx).
get_state(Nidx, JID) ->
- node_flat_odbc:get_state(Nidx, JID).
+ node_flat_sql:get_state(Nidx, JID).
set_state(State) ->
- node_flat_odbc:set_state(State).
+ node_flat_sql:set_state(State).
get_items(Nidx, From, RSM) ->
- node_flat_odbc:get_items(Nidx, From, RSM).
+ node_flat_sql:get_items(Nidx, From, RSM).
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
- node_flat_odbc:get_items(Nidx, JID, AccessModel,
+ node_flat_sql:get_items(Nidx, JID, AccessModel,
PresenceSubscription, RosterGroup, SubId, RSM).
get_item(Nidx, ItemId) ->
- node_flat_odbc:get_item(Nidx, ItemId).
+ node_flat_sql:get_item(Nidx, ItemId).
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
- node_flat_odbc:get_item(Nidx, ItemId, JID,
+ node_flat_sql:get_item(Nidx, ItemId, JID,
AccessModel, PresenceSubscription, RosterGroup, SubId).
set_item(Item) ->
- node_flat_odbc:set_item(Item).
+ node_flat_sql:set_item(Item).
get_item_name(Host, Node, Id) ->
- node_flat_odbc:get_item_name(Host, Node, Id).
+ node_flat_sql:get_item_name(Host, Node, Id).
get_last_items(Nidx, From, Count) ->
- node_flat_odbc:get_last_items(Nidx, From, Count).
+ node_flat_sql:get_last_items(Nidx, From, Count).
node_to_path(Node) ->
node_hometree:node_to_path(Node).
%%% @end
%%% Created : 8 Mar 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
%%%-------------------------------------------------------------------
--module(node_mix_odbc).
+-module(node_mix_sql).
-behaviour(gen_pubsub_node).
%%% API
%%%===================================================================
init(Host, ServerHost, Opts) ->
- node_flat_odbc:init(Host, ServerHost, Opts).
+ node_flat_sql:init(Host, ServerHost, Opts).
terminate(Host, ServerHost) ->
- node_flat_odbc:terminate(Host, ServerHost).
+ node_flat_sql:terminate(Host, ServerHost).
options() ->
[{deliver_payloads, true},
<<"subscription-notifications">>].
create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
- node_flat_odbc:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
+ node_flat_sql:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
create_node(Nidx, Owner) ->
- node_flat_odbc:create_node(Nidx, Owner).
+ node_flat_sql:create_node(Nidx, Owner).
delete_node(Removed) ->
- node_flat_odbc:delete_node(Removed).
+ node_flat_sql:delete_node(Removed).
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup, Options) ->
- node_flat_odbc:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
+ node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
PresenceSubscription, RosterGroup, Options).
unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
- node_flat_odbc:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
+ node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
- node_flat_odbc:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
+ node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
remove_extra_items(Nidx, MaxItems, ItemIds) ->
- node_flat_odbc:remove_extra_items(Nidx, MaxItems, ItemIds).
+ node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
- node_flat_odbc:delete_item(Nidx, Publisher, PublishModel, ItemId).
+ node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
purge_node(Nidx, Owner) ->
- node_flat_odbc:purge_node(Nidx, Owner).
+ node_flat_sql:purge_node(Nidx, Owner).
get_entity_affiliations(Host, Owner) ->
- node_flat_odbc:get_entity_affiliations(Host, Owner).
+ node_flat_sql:get_entity_affiliations(Host, Owner).
get_node_affiliations(Nidx) ->
- node_flat_odbc:get_node_affiliations(Nidx).
+ node_flat_sql:get_node_affiliations(Nidx).
get_affiliation(Nidx, Owner) ->
- node_flat_odbc:get_affiliation(Nidx, Owner).
+ node_flat_sql:get_affiliation(Nidx, Owner).
set_affiliation(Nidx, Owner, Affiliation) ->
- node_flat_odbc:set_affiliation(Nidx, Owner, Affiliation).
+ node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
get_entity_subscriptions(Host, Owner) ->
- node_flat_odbc:get_entity_subscriptions(Host, Owner).
+ node_flat_sql:get_entity_subscriptions(Host, Owner).
get_node_subscriptions(Nidx) ->
- node_flat_odbc:get_node_subscriptions(Nidx).
+ node_flat_sql:get_node_subscriptions(Nidx).
get_subscriptions(Nidx, Owner) ->
- node_flat_odbc:get_subscriptions(Nidx, Owner).
+ node_flat_sql:get_subscriptions(Nidx, Owner).
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
- node_flat_odbc:set_subscriptions(Nidx, Owner, Subscription, SubId).
+ node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
get_pending_nodes(Host, Owner) ->
- node_flat_odbc:get_pending_nodes(Host, Owner).
+ node_flat_sql:get_pending_nodes(Host, Owner).
get_states(Nidx) ->
- node_flat_odbc:get_states(Nidx).
+ node_flat_sql:get_states(Nidx).
get_state(Nidx, JID) ->
- node_flat_odbc:get_state(Nidx, JID).
+ node_flat_sql:get_state(Nidx, JID).
set_state(State) ->
- node_flat_odbc:set_state(State).
+ node_flat_sql:set_state(State).
get_items(Nidx, From, RSM) ->
- node_flat_odbc:get_items(Nidx, From, RSM).
+ node_flat_sql:get_items(Nidx, From, RSM).
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
- node_flat_odbc:get_items(Nidx, JID, AccessModel,
+ node_flat_sql:get_items(Nidx, JID, AccessModel,
PresenceSubscription, RosterGroup, SubId, RSM).
get_item(Nidx, ItemId) ->
- node_flat_odbc:get_item(Nidx, ItemId).
+ node_flat_sql:get_item(Nidx, ItemId).
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
- node_flat_odbc:get_item(Nidx, ItemId, JID, AccessModel,
+ node_flat_sql:get_item(Nidx, ItemId, JID, AccessModel,
PresenceSubscription, RosterGroup, SubId).
set_item(Item) ->
- node_flat_odbc:set_item(Item).
+ node_flat_sql:set_item(Item).
get_item_name(Host, Node, Id) ->
- node_flat_odbc:get_item_name(Host, Node, Id).
+ node_flat_sql:get_item_name(Host, Node, Id).
node_to_path(Node) ->
- node_flat_odbc:node_to_path(Node).
+ node_flat_sql:node_to_path(Node).
path_to_node(Path) ->
- node_flat_odbc:path_to_node(Path).
+ node_flat_sql:path_to_node(Path).
get_entity_subscriptions_for_send_last(Host, Owner) ->
- node_flat_odbc:get_entity_subscriptions_for_send_last(Host, Owner).
+ node_flat_sql:get_entity_subscriptions_for_send_last(Host, Owner).
%%%===================================================================
%%% Internal functions
%%%----------------------------------------------------------------------
-%%% File : node_pep_odbc.erl
+%%% File : node_pep_sql.erl
%%% Author : Christophe Romain <christophe.romain@process-one.net>
%%% Purpose : Standard PubSub PEP plugin with ODBC backend
%%% Created : 1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
%%% @doc The module <strong>{@module}</strong> is the pep PubSub plugin.
%%% <p>PubSub plugin nodes are using the {@link gen_pubsub_node} behaviour.</p>
--module(node_pep_odbc).
+-module(node_pep_sql).
-behaviour(gen_pubsub_node).
-author('christophe.romain@process-one.net').
get_entity_subscriptions_for_send_last/2, get_last_items/3]).
init(Host, ServerHost, Opts) ->
- node_flat_odbc:init(Host, ServerHost, Opts),
+ node_flat_sql:init(Host, ServerHost, Opts),
complain_if_modcaps_disabled(ServerHost),
ok.
terminate(Host, ServerHost) ->
- node_flat_odbc:terminate(Host, ServerHost),
+ node_flat_sql:terminate(Host, ServerHost),
ok.
options() ->
- [{odbc, true}, {rsm, true} | node_pep:options()].
+ [{sql, true}, {rsm, true} | node_pep:options()].
features() ->
[<<"rsm">> | node_pep:features()].
node_pep:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
create_node(Nidx, Owner) ->
- node_flat_odbc:create_node(Nidx, Owner),
+ node_flat_sql:create_node(Nidx, Owner),
{result, {default, broadcast}}.
delete_node(Nodes) ->
- {result, {_, _, Result}} = node_flat_odbc:delete_node(Nodes),
+ {result, {_, _, Result}} = node_flat_sql:delete_node(Nodes),
{result, {[], Result}}.
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup, Options) ->
- node_flat_odbc:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
+ node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
PresenceSubscription, RosterGroup, Options).
unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
- case node_flat_odbc:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
+ case node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
{error, Error} -> {error, Error};
{result, _} -> {result, []}
end.
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
- node_flat_odbc:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
+ node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
remove_extra_items(Nidx, MaxItems, ItemIds) ->
- node_flat_odbc:remove_extra_items(Nidx, MaxItems, ItemIds).
+ node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
- node_flat_odbc:delete_item(Nidx, Publisher, PublishModel, ItemId).
+ node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
purge_node(Nidx, Owner) ->
- node_flat_odbc:purge_node(Nidx, Owner).
+ node_flat_sql:purge_node(Nidx, Owner).
get_entity_affiliations(_Host, Owner) ->
OwnerKey = jid:tolower(jid:remove_resource(Owner)),
- node_flat_odbc:get_entity_affiliations(OwnerKey, Owner).
+ node_flat_sql:get_entity_affiliations(OwnerKey, Owner).
get_node_affiliations(Nidx) ->
- node_flat_odbc:get_node_affiliations(Nidx).
+ node_flat_sql:get_node_affiliations(Nidx).
get_affiliation(Nidx, Owner) ->
- node_flat_odbc:get_affiliation(Nidx, Owner).
+ node_flat_sql:get_affiliation(Nidx, Owner).
set_affiliation(Nidx, Owner, Affiliation) ->
- node_flat_odbc:set_affiliation(Nidx, Owner, Affiliation).
+ node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
get_entity_subscriptions(_Host, Owner) ->
SubKey = jid:tolower(Owner),
GenKey = jid:remove_resource(SubKey),
- Host = node_flat_odbc:encode_host(element(2, SubKey)),
- SJ = node_flat_odbc:encode_jid(SubKey),
- GJ = node_flat_odbc:encode_jid(GenKey),
+ Host = node_flat_sql:encode_host(element(2, SubKey)),
+ SJ = node_flat_sql:encode_jid(SubKey),
+ GJ = node_flat_sql:encode_jid(GenKey),
Query = case SubKey of
GenKey ->
[<<"select host, node, type, i.nodeid, jid, "
"where i.nodeid = n.nodeid and jid "
"in ('">>, SJ, <<"', '">>, GJ, <<"') and host like '%@">>, Host, <<"';">>]
end,
- Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+ Reply = case catch ejabberd_sql:sql_query_t(Query) of
{selected,
[<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>],
RItems} ->
lists:map(fun ([H, N, T, I, J, S]) ->
- O = node_flat_odbc:decode_jid(H),
- Node = nodetree_tree_odbc:raw_to_node(O, [N, <<"">>, T, I]),
+ O = node_flat_sql:decode_jid(H),
+ Node = nodetree_tree_sql:raw_to_node(O, [N, <<"">>, T, I]),
{Node,
- node_flat_odbc:decode_subscriptions(S),
- node_flat_odbc:decode_jid(J)}
+ node_flat_sql:decode_subscriptions(S),
+ node_flat_sql:decode_jid(J)}
end,
RItems);
_ ->
get_entity_subscriptions_for_send_last(_Host, Owner) ->
SubKey = jid:tolower(Owner),
GenKey = jid:remove_resource(SubKey),
- Host = node_flat_odbc:encode_host(element(2, SubKey)),
- SJ = node_flat_odbc:encode_jid(SubKey),
- GJ = node_flat_odbc:encode_jid(GenKey),
+ Host = node_flat_sql:encode_host(element(2, SubKey)),
+ SJ = node_flat_sql:encode_jid(SubKey),
+ GJ = node_flat_sql:encode_jid(GenKey),
Query = case SubKey of
GenKey ->
[<<"select host, node, type, i.nodeid, jid, "
"val='on_sub_and_presence' and jid in ",
"('">>, SJ, <<"', '">>, GJ, <<"') and host like '%@">>, Host, <<"';">>]
end,
- Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+ Reply = case catch ejabberd_sql:sql_query_t(Query) of
{selected,
[<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>],
RItems} ->
lists:map(fun ([H, N, T, I, J, S]) ->
- O = node_flat_odbc:decode_jid(H),
- Node = nodetree_tree_odbc:raw_to_node(O, [N, <<"">>, T, I]),
+ O = node_flat_sql:decode_jid(H),
+ Node = nodetree_tree_sql:raw_to_node(O, [N, <<"">>, T, I]),
{Node,
- node_flat_odbc:decode_subscriptions(S),
- node_flat_odbc:decode_jid(J)}
+ node_flat_sql:decode_subscriptions(S),
+ node_flat_sql:decode_jid(J)}
end,
RItems);
_ ->
{result, Reply}.
get_node_subscriptions(Nidx) ->
- node_flat_odbc:get_node_subscriptions(Nidx).
+ node_flat_sql:get_node_subscriptions(Nidx).
get_subscriptions(Nidx, Owner) ->
- node_flat_odbc:get_subscriptions(Nidx, Owner).
+ node_flat_sql:get_subscriptions(Nidx, Owner).
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
- node_flat_odbc:set_subscriptions(Nidx, Owner, Subscription, SubId).
+ node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
get_pending_nodes(Host, Owner) ->
- node_flat_odbc:get_pending_nodes(Host, Owner).
+ node_flat_sql:get_pending_nodes(Host, Owner).
get_states(Nidx) ->
- node_flat_odbc:get_states(Nidx).
+ node_flat_sql:get_states(Nidx).
get_state(Nidx, JID) ->
- node_flat_odbc:get_state(Nidx, JID).
+ node_flat_sql:get_state(Nidx, JID).
set_state(State) ->
- node_flat_odbc:set_state(State).
+ node_flat_sql:set_state(State).
get_items(Nidx, From, RSM) ->
- node_flat_odbc:get_items(Nidx, From, RSM).
+ node_flat_sql:get_items(Nidx, From, RSM).
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
- node_flat_odbc:get_items(Nidx, JID, AccessModel,
+ node_flat_sql:get_items(Nidx, JID, AccessModel,
PresenceSubscription, RosterGroup, SubId, RSM).
get_last_items(Nidx, JID, Count) ->
- node_flat_odbc:get_last_items(Nidx, JID, Count).
+ node_flat_sql:get_last_items(Nidx, JID, Count).
get_item(Nidx, ItemId) ->
- node_flat_odbc:get_item(Nidx, ItemId).
+ node_flat_sql:get_item(Nidx, ItemId).
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
- node_flat_odbc:get_item(Nidx, ItemId, JID, AccessModel,
+ node_flat_sql:get_item(Nidx, ItemId, JID, AccessModel,
PresenceSubscription, RosterGroup, SubId).
set_item(Item) ->
- node_flat_odbc:set_item(Item).
+ node_flat_sql:set_item(Item).
get_item_name(Host, Node, Id) ->
- node_flat_odbc:get_item_name(Host, Node, Id).
+ node_flat_sql:get_item_name(Host, Node, Id).
node_to_path(Node) ->
- node_flat_odbc:node_to_path(Node).
+ node_flat_sql:node_to_path(Node).
path_to_node(Path) ->
- node_flat_odbc:path_to_node(Path).
+ node_flat_sql:path_to_node(Path).
%%%
%%% Internal
%%%----------------------------------------------------------------------
-%%% File : nodetree_tree_odbc.erl
+%%% File : nodetree_tree_sql.erl
%%% Author : Christophe Romain <christophe.romain@process-one.net>
%%% Purpose : Standard node tree plugin with ODBC backend
%%% Created : 1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
%%% useable and useful as is. Please, send us comments, feedback and
%%% improvements.</p>
--module(nodetree_tree_odbc).
+-module(nodetree_tree_sql).
-behaviour(gen_pubsub_nodetree).
-author('christophe.romain@process-one.net').
ok.
options() ->
- [{odbc, true} | nodetree_tree:options()].
+ [{sql, true} | nodetree_tree:options()].
set_node(Record) when is_record(Record, pubsub_node) ->
{Host, Node} = Record#pubsub_node.nodeid,
[First | _] -> First
end,
Type = Record#pubsub_node.type,
- H = node_flat_odbc:encode_host(Host),
- N = ejabberd_odbc:escape(Node),
- P = ejabberd_odbc:escape(Parent),
+ H = node_flat_sql:encode_host(Host),
+ N = ejabberd_sql:escape(Node),
+ P = ejabberd_sql:escape(Parent),
Nidx = case nodeidx(Host, Node) of
{result, OldNidx} ->
catch
- ejabberd_odbc:sql_query_t([<<"delete from pubsub_node_option where "
+ ejabberd_sql:sql_query_t([<<"delete from pubsub_node_option where "
"nodeid='">>, OldNidx, <<"';">>]),
catch
- ejabberd_odbc:sql_query_t([<<"update pubsub_node set host='">>,
+ ejabberd_sql:sql_query_t([<<"update pubsub_node set host='">>,
H, <<"' node='">>, N,
<<"' parent='">>, P,
<<"' type='">>, Type,
OldNidx;
_ ->
catch
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_node(host, node, "
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_node(host, node, "
"parent, type) values('">>,
H, <<"', '">>, N, <<"', '">>, P,
<<"', '">>, Type, <<"');">>]),
_ ->
lists:foreach(fun ({Key, Value}) ->
SKey = iolist_to_binary(atom_to_list(Key)),
- SValue = ejabberd_odbc:escape(
+ SValue = ejabberd_sql:escape(
list_to_binary(
lists:flatten(io_lib:fwrite("~p", [Value])))),
catch
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_node_option(nodeid, "
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_node_option(nodeid, "
"name, val) values('">>,
Nidx, <<"', '">>,
SKey, <<"', '">>, SValue, <<"');">>])
get_node(Host, Node).
get_node(Host, Node) ->
- H = node_flat_odbc:encode_host(Host),
- N = ejabberd_odbc:escape(Node),
+ H = node_flat_sql:encode_host(Host),
+ N = ejabberd_sql:escape(Node),
case catch
- ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+ ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
"pubsub_node where host='">>,
H, <<"' and node='">>, N, <<"';">>])
of
get_node(Nidx) ->
case catch
- ejabberd_odbc:sql_query_t([<<"select host, node, parent, type from "
+ ejabberd_sql:sql_query_t([<<"select host, node, parent, type from "
"pubsub_node where nodeid='">>,
Nidx, <<"';">>])
of
get_nodes(Host).
get_nodes(Host) ->
- H = node_flat_odbc:encode_host(Host),
+ H = node_flat_sql:encode_host(Host),
case catch
- ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+ ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
"pubsub_node where host='">>, H, <<"';">>])
of
{selected,
get_subnodes(Host, Node).
get_subnodes(Host, Node) ->
- H = node_flat_odbc:encode_host(Host),
- N = ejabberd_odbc:escape(Node),
+ H = node_flat_sql:encode_host(Host),
+ N = ejabberd_sql:escape(Node),
case catch
- ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+ ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
"pubsub_node where host='">>,
H, <<"' and parent='">>, N, <<"';">>])
of
get_subnodes_tree(Host, Node).
get_subnodes_tree(Host, Node) ->
- H = node_flat_odbc:encode_host(Host),
- N = ejabberd_odbc:escape(Node),
+ H = node_flat_sql:encode_host(Host),
+ N = ejabberd_sql:escape(Node),
case catch
- ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+ ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
"pubsub_node where host='">>,
H, <<"' and node like '">>, N, <<"%';">>])
of
end.
delete_node(Host, Node) ->
- H = node_flat_odbc:encode_host(Host),
- N = ejabberd_odbc:escape(Node),
+ H = node_flat_sql:encode_host(Host),
+ N = ejabberd_sql:escape(Node),
Removed = get_subnodes_tree(Host, Node),
- catch ejabberd_odbc:sql_query_t([<<"delete from pubsub_node where host='">>,
+ catch ejabberd_sql:sql_query_t([<<"delete from pubsub_node where host='">>,
H, <<"' and node like '">>, N, <<"%';">>]),
Removed.
%% helpers
raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
Options = case catch
- ejabberd_odbc:sql_query_t([<<"select name,val from pubsub_node_option "
+ ejabberd_sql:sql_query_t([<<"select name,val from pubsub_node_option "
"where nodeid='">>, Nidx, <<"';">>])
of
{selected, [<<"name">>, <<"val">>], ROptions} ->
{RKey, RValue}
end,
ROptions),
- Module = jlib:binary_to_atom(<<"node_", Type/binary, "_odbc">>),
+ Module = jlib:binary_to_atom(<<"node_", Type/binary, "_sql">>),
StdOpts = Module:options(),
lists:foldl(fun ({Key, Value}, Acc) ->
lists:keyreplace(Key, 1, Acc, {Key, Value})
id = Nidx, type = Type, options = Options}.
nodeidx(Host, Node) ->
- H = node_flat_odbc:encode_host(Host),
- N = ejabberd_odbc:escape(Node),
+ H = node_flat_sql:encode_host(Host),
+ N = ejabberd_sql:escape(Node),
case catch
- ejabberd_odbc:sql_query_t([<<"select nodeid from pubsub_node where "
+ ejabberd_sql:sql_query_t([<<"select nodeid from pubsub_node where "
"host='">>,
H, <<"' and node='">>, N, <<"';">>])
of
end.
nodeowners(Nidx) ->
- {result, Res} = node_flat_odbc:get_node_affiliations(Nidx),
+ {result, Res} = node_flat_sql:get_node_affiliations(Nidx),
[LJID || {LJID, Aff} <- Res, Aff =:= owner].
%%%----------------------------------------------------------------------
-%%% File : pubsub_db_odbc.erl
+%%% File : pubsub_db_sql.erl
%%% Author : Pablo Polvorin <pablo.polvorin@process-one.net>
%%% Purpose : Provide helpers for PubSub ODBC backend
%%% Created : 7 Aug 2009 by Pablo Polvorin <pablo.polvorin@process-one.net>
%%%
%%%----------------------------------------------------------------------
--module(pubsub_db_odbc).
+-module(pubsub_db_sql).
-author("pablo.polvorin@process-one.net").
%% -spec read_subscription(SubID :: string()) -> {ok, #pubsub_subscription{}} | notfound.
read_subscription(SubID) ->
case
- ejabberd_odbc:sql_query_t([<<"select opt_name, opt_value from pubsub_subscr"
+ ejabberd_sql:sql_query_t([<<"select opt_name, opt_value from pubsub_subscr"
"iption_opt where subid = '">>,
- ejabberd_odbc:escape(SubID), <<"'">>])
+ ejabberd_sql:escape(SubID), <<"'">>])
of
{selected, [<<"opt_name">>, <<"opt_value">>], []} ->
notfound;
{selected, [<<"opt_name">>, <<"opt_value">>], Options} ->
{ok,
#pubsub_subscription{subid = SubID,
- options = lists:map(fun subscription_opt_from_odbc/1, Options)}}
+ options = lists:map(fun subscription_opt_from_sql/1, Options)}}
end.
%% -spec delete_subscription(SubID :: string()) -> ok.
%% -spec update_subscription(#pubsub_subscription{}) -> ok .
%% -spec add_subscription(#pubsub_subscription{}) -> ok.
%% -------------- Internal utilities -----------------------
- ejabberd_odbc:sql_query_t([<<"delete from pubsub_subscription_opt "
+ ejabberd_sql:sql_query_t([<<"delete from pubsub_subscription_opt "
"where subid = '">>,
- ejabberd_odbc:escape(SubID), <<"'">>]),
+ ejabberd_sql:escape(SubID), <<"'">>]),
ok.
update_subscription(#pubsub_subscription{subid = SubId} = Sub) ->
delete_subscription(SubId), add_subscription(Sub).
add_subscription(#pubsub_subscription{subid = SubId, options = Opts}) ->
- EscapedSubId = ejabberd_odbc:escape(SubId),
+ EscapedSubId = ejabberd_sql:escape(SubId),
lists:foreach(fun (Opt) ->
- {OdbcOptName, OdbcOptValue} = subscription_opt_to_odbc(Opt),
- ejabberd_odbc:sql_query_t([<<"insert into pubsub_subscription_opt(subid, "
+ {OdbcOptName, OdbcOptValue} = subscription_opt_to_sql(Opt),
+ ejabberd_sql:sql_query_t([<<"insert into pubsub_subscription_opt(subid, "
"opt_name, opt_value)values ('">>,
EscapedSubId, <<"','">>,
OdbcOptName, <<"','">>,
Opts),
ok.
-subscription_opt_from_odbc({<<"DELIVER">>, Value}) ->
- {deliver, odbc_to_boolean(Value)};
-subscription_opt_from_odbc({<<"DIGEST">>, Value}) ->
- {digest, odbc_to_boolean(Value)};
-subscription_opt_from_odbc({<<"DIGEST_FREQUENCY">>, Value}) ->
- {digest_frequency, odbc_to_integer(Value)};
-subscription_opt_from_odbc({<<"EXPIRE">>, Value}) ->
- {expire, odbc_to_timestamp(Value)};
-subscription_opt_from_odbc({<<"INCLUDE_BODY">>, Value}) ->
- {include_body, odbc_to_boolean(Value)};
+subscription_opt_from_sql({<<"DELIVER">>, Value}) ->
+ {deliver, sql_to_boolean(Value)};
+subscription_opt_from_sql({<<"DIGEST">>, Value}) ->
+ {digest, sql_to_boolean(Value)};
+subscription_opt_from_sql({<<"DIGEST_FREQUENCY">>, Value}) ->
+ {digest_frequency, sql_to_integer(Value)};
+subscription_opt_from_sql({<<"EXPIRE">>, Value}) ->
+ {expire, sql_to_timestamp(Value)};
+subscription_opt_from_sql({<<"INCLUDE_BODY">>, Value}) ->
+ {include_body, sql_to_boolean(Value)};
%%TODO: might be > than 1 show_values value??.
%% need to use compact all in only 1 opt.
-subscription_opt_from_odbc({<<"SHOW_VALUES">>, Value}) ->
+subscription_opt_from_sql({<<"SHOW_VALUES">>, Value}) ->
{show_values, Value};
-subscription_opt_from_odbc({<<"SUBSCRIPTION_TYPE">>, Value}) ->
+subscription_opt_from_sql({<<"SUBSCRIPTION_TYPE">>, Value}) ->
{subscription_type,
case Value of
<<"items">> -> items;
<<"nodes">> -> nodes
end};
-subscription_opt_from_odbc({<<"SUBSCRIPTION_DEPTH">>, Value}) ->
+subscription_opt_from_sql({<<"SUBSCRIPTION_DEPTH">>, Value}) ->
{subscription_depth,
case Value of
<<"all">> -> all;
- N -> odbc_to_integer(N)
+ N -> sql_to_integer(N)
end}.
-subscription_opt_to_odbc({deliver, Bool}) ->
- {<<"DELIVER">>, boolean_to_odbc(Bool)};
-subscription_opt_to_odbc({digest, Bool}) ->
- {<<"DIGEST">>, boolean_to_odbc(Bool)};
-subscription_opt_to_odbc({digest_frequency, Int}) ->
- {<<"DIGEST_FREQUENCY">>, integer_to_odbc(Int)};
-subscription_opt_to_odbc({expire, Timestamp}) ->
- {<<"EXPIRE">>, timestamp_to_odbc(Timestamp)};
-subscription_opt_to_odbc({include_body, Bool}) ->
- {<<"INCLUDE_BODY">>, boolean_to_odbc(Bool)};
-subscription_opt_to_odbc({show_values, Values}) ->
+subscription_opt_to_sql({deliver, Bool}) ->
+ {<<"DELIVER">>, boolean_to_sql(Bool)};
+subscription_opt_to_sql({digest, Bool}) ->
+ {<<"DIGEST">>, boolean_to_sql(Bool)};
+subscription_opt_to_sql({digest_frequency, Int}) ->
+ {<<"DIGEST_FREQUENCY">>, integer_to_sql(Int)};
+subscription_opt_to_sql({expire, Timestamp}) ->
+ {<<"EXPIRE">>, timestamp_to_sql(Timestamp)};
+subscription_opt_to_sql({include_body, Bool}) ->
+ {<<"INCLUDE_BODY">>, boolean_to_sql(Bool)};
+subscription_opt_to_sql({show_values, Values}) ->
{<<"SHOW_VALUES">>, Values};
-subscription_opt_to_odbc({subscription_type, Type}) ->
+subscription_opt_to_sql({subscription_type, Type}) ->
{<<"SUBSCRIPTION_TYPE">>,
case Type of
items -> <<"items">>;
nodes -> <<"nodes">>
end};
-subscription_opt_to_odbc({subscription_depth, Depth}) ->
+subscription_opt_to_sql({subscription_depth, Depth}) ->
{<<"SUBSCRIPTION_DEPTH">>,
case Depth of
all -> <<"all">>;
- N -> integer_to_odbc(N)
+ N -> integer_to_sql(N)
end}.
-integer_to_odbc(N) -> iolist_to_binary(integer_to_list(N)).
+integer_to_sql(N) -> iolist_to_binary(integer_to_list(N)).
-boolean_to_odbc(true) -> <<"1">>;
-boolean_to_odbc(false) -> <<"0">>.
+boolean_to_sql(true) -> <<"1">>;
+boolean_to_sql(false) -> <<"0">>.
-timestamp_to_odbc(T) -> jlib:now_to_utc_string(T).
+timestamp_to_sql(T) -> jlib:now_to_utc_string(T).
-odbc_to_integer(N) -> jlib:binary_to_integer(N).
+sql_to_integer(N) -> jlib:binary_to_integer(N).
-odbc_to_boolean(B) -> B == <<"1">>.
+sql_to_boolean(B) -> B == <<"1">>.
-odbc_to_timestamp(T) -> jlib:datetime_string_to_timestamp(T).
+sql_to_timestamp(T) -> jlib:datetime_string_to_timestamp(T).
%%%----------------------------------------------------------------------
-%%% File : pubsub_subscription_odbc.erl
+%%% File : pubsub_subscription_sql.erl
%%% Author : Pablo Polvorin <pablo.polvorin@process-one.net>
%%% Purpose : Handle pubsub subscriptions options with ODBC backend
%%% based on pubsub_subscription.erl by Brian Cully <bjc@kublai.com>
%%%
%%%----------------------------------------------------------------------
--module(pubsub_subscription_odbc).
+-module(pubsub_subscription_sql).
-author("pablo.polvorin@process-one.net").
%% API
-define(SUBSCRIPTION_DEPTH_VALUE_ONE_LABEL, <<"Receive notification from direct child nodes only">>).
-define(SUBSCRIPTION_DEPTH_VALUE_ALL_LABEL, <<"Receive notification from all descendent nodes">>).
--define(DB_MOD, pubsub_db_odbc).
+-define(DB_MOD, pubsub_db_sql).
%%====================================================================
%% API
%%====================================================================
%%%----------------------------------------------------------------------
-%%% File : odbc_queries.erl
+%%% File : sql_queries.erl
%%% Author : Mickael Remond <mremond@process-one.net>
%%% Purpose : ODBC queries dependind on back-end
%%% Created : by Mickael Remond <mremond@process-one.net>
%%%
%%%----------------------------------------------------------------------
--module(odbc_queries).
+-module(sql_queries).
-compile([{parse_transform, ejabberd_sql_pt}]).
<<A/binary, "='", B/binary, "'">>
end,
Fields, Vals),
- case ejabberd_odbc:sql_query_t([<<"update ">>, Table,
+ case ejabberd_sql:sql_query_t([<<"update ">>, Table,
<<" set ">>, join(UPairs, <<", ">>),
<<" where ">>, Where, <<";">>])
of
{updated, 1} -> ok;
_ ->
- Res = ejabberd_odbc:sql_query_t([<<"insert into ">>, Table,
+ Res = ejabberd_sql:sql_query_t([<<"insert into ">>, Table,
<<"(">>, join(Fields, <<", ">>),
<<") values ('">>, join(Vals, <<"', '">>),
<<"');">>]),
<<A/binary, "='", B/binary, "'">>
end,
Fields, Vals),
- case ejabberd_odbc:sql_query(LServer,
+ case ejabberd_sql:sql_query(LServer,
[<<"update ">>, Table, <<" set ">>,
join(UPairs, <<", ">>), <<" where ">>, Where,
<<";">>])
of
{updated, 1} -> ok;
_ ->
- Res = ejabberd_odbc:sql_query(LServer,
+ Res = ejabberd_sql:sql_query(LServer,
[<<"insert into ">>, Table, <<"(">>,
join(Fields, <<", ">>), <<") values ('">>,
join(Vals, <<"', '">>), <<"');">>]),
%% F can be either a fun or a list of queries
%% TODO: We should probably move the list of queries transaction
-%% wrapper from the ejabberd_odbc module to this one (odbc_queries)
+%% wrapper from the ejabberd_sql module to this one (sql_queries)
sql_transaction(LServer, F) ->
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
get_last(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(seconds)d, @(state)s from last"
" where username=%(LUser)s")).
"state=%(Status)s"]).
del_last(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from last where username=%(LUser)s")).
get_password(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(password)s from users where username=%(LUser)s")).
get_password_scram(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(password)s, @(serverkey)s, @(salt)s, @(iterationcount)d"
" from users"
" where username=%(LUser)s")).
set_password_t(LServer, LUser, Password) ->
- ejabberd_odbc:sql_transaction(
+ ejabberd_sql:sql_transaction(
LServer,
fun () ->
?SQL_UPSERT_T(
set_password_scram_t(LServer, LUser,
StoredKey, ServerKey, Salt, IterationCount) ->
- ejabberd_odbc:sql_transaction(
+ ejabberd_sql:sql_transaction(
LServer,
fun () ->
?SQL_UPSERT_T(
end).
add_user(LServer, LUser, Password) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("insert into users(username, password) "
"values (%(LUser)s, %(Password)s)")).
add_user_scram(LServer, LUser,
StoredKey, ServerKey, Salt, IterationCount) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("insert into users(username, password, serverkey, salt, "
"iterationcount) "
" %(Salt)s, %(IterationCount)d)")).
del_user(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from users where username=%(LUser)s")).
del_user_return_password(_LServer, LUser, Password) ->
P =
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(password)s from users where username=%(LUser)s")),
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from users"
" where username=%(LUser)s and password=%(Password)s")),
P.
list_users(LServer) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(username)s from users")).
{offset, Start - 1}]);
list_users(LServer, [{limit, Limit}, {offset, Offset}])
when is_integer(Limit) and is_integer(Offset) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(username)s from users "
"order by username "
[{prefix, Prefix}, {limit, Limit}, {offset, Offset}])
when is_binary(Prefix) and is_integer(Limit) and
is_integer(Offset) ->
- SPrefix = ejabberd_odbc:escape_like_arg(Prefix),
+ SPrefix = ejabberd_sql:escape_like_arg(Prefix),
SPrefix2 = <<SPrefix/binary, $%>>,
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(username)s from users "
"where username like %(SPrefix2)s "
"limit %(Limit)d offset %(Offset)d")).
users_number(LServer) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
fun(pgsql, _) ->
case
fun(V) when is_boolean(V) -> V end,
false) of
true ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(reltuples :: bigint)d from pg_class"
" where oid = 'users'::regclass::oid"));
_ ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(count(*))d from users"))
end;
(_Type, _) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(count(*))d from users"))
end).
users_number(LServer, [{prefix, Prefix}])
when is_binary(Prefix) ->
- SPrefix = ejabberd_odbc:escape_like_arg(Prefix),
+ SPrefix = ejabberd_sql:escape_like_arg(Prefix),
SPrefix2 = <<SPrefix/binary, $%>>,
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(count(*))d from users "
"where username like %(SPrefix2)s"));
users_number(LServer, []) ->
users_number(LServer).
-
add_spool_sql(Username, XML) ->
[<<"insert into spool(username, xml) values ('">>,
Username, <<"', '">>, XML, <<"');">>].
add_spool(LServer, Queries) ->
- ejabberd_odbc:sql_transaction(LServer, Queries).
+ ejabberd_sql:sql_transaction(LServer, Queries).
get_and_del_spool_msg_t(LServer, LUser) ->
F = fun () ->
Result =
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(username)s, @(xml)s from spool where "
"username=%(LUser)s order by seq;")),
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from spool where username=%(LUser)s;")),
Result
end,
- ejabberd_odbc:sql_transaction(LServer, F).
+ ejabberd_sql:sql_transaction(LServer, F).
del_spool_msg(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from spool where username=%(LUser)s")).
get_roster(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(username)s, @(jid)s, @(nick)s, @(subscription)s, "
"@(ask)s, @(askmessage)s, @(server)s, @(subscribe)s, "
"@(type)s from rosterusers where username=%(LUser)s")).
get_roster_jid_groups(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(jid)s, @(grp)s from rostergroups where "
"username=%(LUser)s")).
get_roster_groups(_LServer, LUser, SJID) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(grp)s from rostergroups"
" where username=%(LUser)s and jid=%(SJID)s")).
del_user_roster_t(LServer, LUser) ->
- ejabberd_odbc:sql_transaction(
+ ejabberd_sql:sql_transaction(
LServer,
fun () ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from rosterusers where username=%(LUser)s")),
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from rostergroups where username=%(LUser)s"))
end).
get_roster_by_jid(_LServer, LUser, SJID) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(username)s, @(jid)s, @(nick)s, @(subscription)s,"
" @(ask)s, @(askmessage)s, @(server)s, @(subscribe)s,"
" @(type)s from rosterusers"
" where username=%(LUser)s and jid=%(SJID)s")).
get_rostergroup_by_jid(LServer, LUser, SJID) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(grp)s from rostergroups"
" where username=%(LUser)s and jid=%(SJID)s")).
del_roster(_LServer, LUser, SJID) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from rosterusers"
" where username=%(LUser)s and jid=%(SJID)s")),
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from rostergroups"
" where username=%(LUser)s and jid=%(SJID)s")).
update_roster(_LServer, LUser, SJID, ItemVals,
ItemGroups) ->
roster_subscribe(ItemVals),
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from rostergroups"
" where username=%(LUser)s and jid=%(SJID)s")),
lists:foreach(
fun(ItemGroup) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("insert into rostergroups(username, jid, grp) "
"values (%(LUser)s, %(SJID)s, %(ItemGroup)s)"))
end,
"type='item'"]).
get_subscription(LServer, LUser, SJID) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(subscription)s from rosterusers "
"where username=%(LUser)s and jid=%(SJID)s")).
<<"');">>]].
get_private_data(LServer, LUser, XMLNS) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(data)s from private_storage"
" where username=%(LUser)s and namespace=%(XMLNS)s")).
get_private_data(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(namespace)s, @(data)s from private_storage"
" where username=%(LUser)s")).
del_user_private_storage(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from private_storage"
" where username=%(LUser)s")).
LFamily, LGiven, LLocality, LMiddle, LNickname,
LOrgName, LOrgUnit, Locality, Middle, Nickname,
OrgName, OrgUnit, SVCARD, User) ->
- ejabberd_odbc:sql_transaction(
+ ejabberd_sql:sql_transaction(
LServer,
fun() ->
?SQL_UPSERT(LServer, "vcard",
end).
get_vcard(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(vcard)s from vcard where username=%(LUser)s")).
get_default_privacy_list(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(name)s from privacy_default_list "
"where username=%(LUser)s")).
get_default_privacy_list_t(LUser) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(name)s from privacy_default_list "
"where username=%(LUser)s")).
get_privacy_list_names(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(name)s from privacy_list"
" where username=%(LUser)s")).
get_privacy_list_names_t(LUser) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(name)s from privacy_list"
" where username=%(LUser)s")).
get_privacy_list_id(LServer, LUser, Name) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(id)d from privacy_list"
" where username=%(LUser)s and name=%(Name)s")).
get_privacy_list_id_t(LUser, Name) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(id)d from privacy_list"
" where username=%(LUser)s and name=%(Name)s")).
get_privacy_list_data(LServer, LUser, Name) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
%% Not used?
get_privacy_list_data_t(LUser, Name) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
"@(match_presence_out)b from privacy_list_data "
"order by ord")).
get_privacy_list_data_by_id(LServer, ID) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
"where id=%(ID)d order by ord")).
get_privacy_list_data_by_id_t(ID) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
"@(match_presence_out)b from privacy_list_data "
"name=%(Name)s"]).
unset_default_privacy_list(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from privacy_default_list"
" where username=%(LUser)s")).
remove_privacy_list(LUser, Name) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from privacy_list where"
" username=%(LUser)s and name=%(Name)s")).
add_privacy_list(LUser, Name) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("insert into privacy_list(username, name) "
"values (%(LUser)s, %(Name)s)")).
set_privacy_list(ID, RItems) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("delete from privacy_list_data where id=%(ID)d")),
lists:foreach(
fun({SType, SValue, SAction, Order, MatchAll, MatchIQ,
MatchMessage, MatchPresenceIn, MatchPresenceOut}) ->
- ejabberd_odbc:sql_query_t(
+ ejabberd_sql:sql_query_t(
?SQL("insert into privacy_list_data(id, t, "
"value, action, ord, match_all, match_iq, "
"match_message, match_presence_in, match_presence_out) "
RItems).
del_privacy_lists(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from privacy_list where username=%(LUser)s")),
%US = <<LUser/binary, "@", LServer/binary>>,
- %ejabberd_odbc:sql_query(
+ %ejabberd_sql:sql_query(
% LServer,
% ?SQL("delete from privacy_list_data where value=%(US)s")),
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("delete from privacy_default_list where username=%(LUser)s")).
%% Count number of records in a table given a where clause
count_records_where(LServer, Table, WhereClause) ->
- ejabberd_odbc:sql_query(LServer,
+ ejabberd_sql:sql_query(LServer,
[<<"select count(*) from ">>, Table, <<" ">>,
WhereClause, <<";">>]).
get_roster_version(LServer, LUser) ->
- ejabberd_odbc:sql_query(
+ ejabberd_sql:sql_query(
LServer,
?SQL("select @(version)s from roster_version"
" where username = %(LUser)s")).
[<<"username">>, <<"version">>], [LUser, Version],
[<<"username = '">>, LUser, <<"'">>]).
-opt_type(odbc_type) ->
+opt_type(sql_type) ->
fun (pgsql) -> pgsql;
(mysql) -> mysql;
(sqlite) -> sqlite;
end;
opt_type(pgsql_users_number_estimate) ->
fun (V) when is_boolean(V) -> V end;
-opt_type(_) -> [odbc_type, pgsql_users_number_estimate].
+opt_type(_) -> [sql_type, pgsql_users_number_estimate].
mod_muc:shutdown_rooms(?REDIS_VHOST),
set_opt(server, ?REDIS_VHOST, Config);
do_init_per_group(mysql, Config) ->
- case catch ejabberd_odbc:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
+ case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
{selected, _, _} ->
mod_muc:shutdown_rooms(?MYSQL_VHOST),
create_sql_tables(mysql, ?config(base_dir, Config)),
{skip, {mysql_not_available, Err}}
end;
do_init_per_group(pgsql, Config) ->
- case catch ejabberd_odbc:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
+ case catch ejabberd_sql:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
{selected, _, _} ->
mod_muc:shutdown_rooms(?PGSQL_VHOST),
create_sql_tables(pgsql, ?config(base_dir, Config)),
{skip, {pgsql_not_available, Err}}
end;
do_init_per_group(sqlite, Config) ->
- case catch ejabberd_odbc:sql_query(?SQLITE_VHOST, [<<"select 1;">>]) of
+ case catch ejabberd_sql:sql_query(?SQLITE_VHOST, [<<"select 1;">>]) of
{selected, _, _} ->
mod_muc:shutdown_rooms(?SQLITE_VHOST),
set_opt(server, ?SQLITE_VHOST, Config);
SQLFile = filename:join([BaseDir, "sql", File]),
CreationQueries = read_sql_queries(SQLFile),
DropTableQueries = drop_table_queries(CreationQueries),
- case ejabberd_odbc:sql_transaction(
+ case ejabberd_sql:sql_transaction(
VHost, DropTableQueries ++ CreationQueries) of
{atomic, ok} ->
ok;
host_config:
"pgsql.localhost":
- odbc_username: "@@pgsql_user@@"
- odbc_type: pgsql
- odbc_server: "@@pgsql_server@@"
- odbc_port: @@pgsql_port@@
- odbc_pool_size: 1
- odbc_password: "@@pgsql_pass@@"
- odbc_database: "@@pgsql_db@@"
- auth_method: odbc
- sm_db_type: odbc
+ sql_username: "@@pgsql_user@@"
+ sql_type: pgsql
+ sql_server: "@@pgsql_server@@"
+ sql_port: @@pgsql_port@@
+ sql_pool_size: 1
+ sql_password: "@@pgsql_pass@@"
+ sql_database: "@@pgsql_db@@"
+ auth_method: sql
+ sm_db_type: sql
modules:
mod_announce:
- db_type: odbc
+ db_type: sql
access: local
mod_blocking: []
mod_caps:
- db_type: odbc
+ db_type: sql
mod_last:
- db_type: odbc
+ db_type: sql
mod_muc:
- db_type: odbc
+ db_type: sql
mod_offline:
- db_type: odbc
+ db_type: sql
mod_privacy:
- db_type: odbc
+ db_type: sql
mod_private:
- db_type: odbc
+ db_type: sql
mod_pubsub:
- db_type: odbc
+ db_type: sql
access_createnode: pubsub_createnode
ignore_pep_from_offline: true
last_item_cache: false
mod_roster:
versioning: true
store_current_id: true
- db_type: odbc
+ db_type: sql
mod_mam:
- db_type: odbc
+ db_type: sql
mod_vcard:
- db_type: odbc
+ db_type: sql
mod_vcard_xupdate:
- db_type: odbc
+ db_type: sql
mod_adhoc: []
mod_configure: []
mod_disco: []
mod_time: []
mod_version: []
"sqlite.localhost":
- odbc_type: sqlite
- auth_method: odbc
- sm_db_type: odbc
+ sql_type: sqlite
+ auth_method: sql
+ sm_db_type: sql
modules:
mod_announce:
- db_type: odbc
+ db_type: sql
access: local
mod_blocking: []
mod_caps:
- db_type: odbc
+ db_type: sql
mod_last:
- db_type: odbc
+ db_type: sql
mod_muc:
- db_type: odbc
+ db_type: sql
mod_offline:
- db_type: odbc
+ db_type: sql
mod_privacy:
- db_type: odbc
+ db_type: sql
mod_private:
- db_type: odbc
+ db_type: sql
mod_pubsub:
- db_type: odbc
+ db_type: sql
access_createnode: pubsub_createnode
ignore_pep_from_offline: true
last_item_cache: false
mod_roster:
versioning: true
store_current_id: true
- db_type: odbc
+ db_type: sql
mod_mam:
- db_type: odbc
+ db_type: sql
mod_vcard:
- db_type: odbc
+ db_type: sql
mod_vcard_xupdate:
- db_type: odbc
+ db_type: sql
mod_adhoc: []
mod_configure: []
mod_disco: []
mod_time: []
mod_version: []
"mysql.localhost":
- odbc_username: "@@mysql_user@@"
- odbc_type: mysql
- odbc_server: "@@mysql_server@@"
- odbc_port: @@mysql_port@@
- odbc_pool_size: 1
- odbc_password: "@@mysql_pass@@"
- odbc_database: "@@mysql_db@@"
- auth_method: odbc
- sm_db_type: odbc
+ sql_username: "@@mysql_user@@"
+ sql_type: mysql
+ sql_server: "@@mysql_server@@"
+ sql_port: @@mysql_port@@
+ sql_pool_size: 1
+ sql_password: "@@mysql_pass@@"
+ sql_database: "@@mysql_db@@"
+ auth_method: sql
+ sm_db_type: sql
modules:
mod_announce:
- db_type: odbc
+ db_type: sql
access: local
mod_blocking: []
mod_caps:
- db_type: odbc
+ db_type: sql
mod_last:
- db_type: odbc
+ db_type: sql
mod_muc:
- db_type: odbc
+ db_type: sql
mod_offline:
- db_type: odbc
+ db_type: sql
mod_privacy:
- db_type: odbc
+ db_type: sql
mod_private:
- db_type: odbc
+ db_type: sql
mod_pubsub:
- db_type: odbc
+ db_type: sql
access_createnode: pubsub_createnode
ignore_pep_from_offline: true
last_item_cache: false
mod_roster:
versioning: true
store_current_id: true
- db_type: odbc
+ db_type: sql
mod_mam:
- db_type: odbc
+ db_type: sql
mod_vcard:
- db_type: odbc
+ db_type: sql
mod_vcard_xupdate:
- db_type: odbc
+ db_type: sql
mod_adhoc: []
mod_configure: []
mod_disco: []