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

ODBC support for mod_irc

This commit is contained in:
Evgeniy Khramtsov 2012-04-03 20:23:41 +10:00
parent ca5f028016
commit 5fab00011e
7 changed files with 1119 additions and 11 deletions

View File

@ -75,6 +75,7 @@
\newcommand{\modhttpbind}{\module{mod\_http\_bind}}
\newcommand{\modhttpfileserver}{\module{mod\_http\_fileserver}}
\newcommand{\modirc}{\module{mod\_irc}}
\newcommand{\modircodbc}{\module{mod\_irc\_odbc}}
\newcommand{\modlast}{\module{mod\_last}}
\newcommand{\modlastodbc}{\module{mod\_last\_odbc}}
\newcommand{\modmuc}{\module{mod\_muc}}
@ -2591,6 +2592,7 @@ The following table lists all modules included in \ejabberd{}.
\hline \ahrefloc{modhttpbind}{\modhttpbind{}} & XMPP over Bosh service (HTTP Binding) & \\
\hline \ahrefloc{modhttpfileserver}{\modhttpfileserver{}} & Small HTTP file server & \\
\hline \ahrefloc{modirc}{\modirc{}} & IRC transport & \\
\hline \ahrefloc{modirc}{\modircodbc{}} & IRC transport & supported DB (*) \\
\hline \ahrefloc{modlast}{\modlast{}} & Last Activity (\xepref{0012}) & \\
\hline \ahrefloc{modlast}{\modlastodbc{}} & Last Activity (\xepref{0012}) & supported DB (*) \\
\hline \ahrefloc{modmuc}{\modmuc{}} & Multi-User Chat (\xepref{0045}) & \\
@ -2661,6 +2663,7 @@ database for the following data:
\item Pub-Sub nodes, items and subscriptions: Use \term{mod\_pubsub\_odbc} instead of \term{mod\_pubsub}.
\item Multi-user chats: Use \term{mod\_muc\_odbc} instead of \term{mod\_muc}.
\item Manage announcements: Use \term{mod\_announce\_odbc} instead of \term{mod\_announce}.
\item IRC transport: Use \term{mod\_irc\_odbc} instead of \term{mod\_irc}.
\end{itemize}
You can find more

View File

@ -39,6 +39,7 @@
export_privacy/2,
export_motd/2,
export_motd_users/2,
export_irc_custom/2,
export_muc_room/2,
export_muc_registered/2]).
@ -66,6 +67,7 @@
orgunit, lorgunit
}).
-record(private_storage, {usns, xml}).
-record(irc_custom, {us_host, data}).
-record(muc_room, {name_host, opts}).
-record(muc_registered, {us_host, nick}).
-record(motd, {server, packet}).
@ -329,6 +331,26 @@ export_muc_registered(Server, Output) ->
end
end).
export_irc_custom(Server, Output) ->
export_common(
Server, irc_custom, Output,
fun(Host, #irc_custom{us_host = {{U, S}, IRCHost}, data = Data}) ->
case lists:suffix(Host, IRCHost) of
true ->
SJID = ejabberd_odbc:escape(
jlib:jid_to_string(
jlib:make_jid(U, S, ""))),
SIRCHost = ejabberd_odbc:escape(IRCHost),
SData = mod_irc_odbc:encode_data(Data),
["delete from irc_custom where jid='", SJID,
"' and host='", SIRCHost, "';"
"insert into irc_custom(jid, host, data) values ("
"'", SJID, "', '", SIRCHost, "', '", SData, "');"];
false ->
[]
end
end).
export_privacy(Server, Output) ->
case ejabberd_odbc:sql_query(
jlib:nameprep(Server),

View File

@ -348,7 +348,8 @@ do_route1(Host, ServerHost, From, To, Packet) ->
end,
{ok, Pid} = mod_irc_connection:start(
From, Host, ServerHost, Server,
ConnectionUsername, Encoding, Port, Password),
ConnectionUsername, Encoding, Port,
Password, ?MODULE),
ets:insert(
irc_connection,
#irc_connection{jid_server_host = {From, Server, Host},

View File

@ -30,7 +30,7 @@
-behaviour(gen_fsm).
%% External exports
-export([start_link/7, start/8, route_chan/4, route_nick/3]).
-export([start_link/8, start/9, route_chan/4, route_nick/3]).
%% gen_fsm callbacks
-export([init/1,
@ -51,7 +51,7 @@
-record(state, {socket, encoding, port, password,
queue, user, host, server, nick,
channels = dict:new(),
nickchannel,
nickchannel, mod,
inbuf = "", outbuf = ""}).
%-define(DBGFSM, true).
@ -65,13 +65,13 @@
%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
start(From, Host, ServerHost, Server, Username, Encoding, Port, Password) ->
start(From, Host, ServerHost, Server, Username, Encoding, Port, Password, Mod) ->
Supervisor = gen_mod:get_module_proc(ServerHost, ejabberd_mod_irc_sup),
supervisor:start_child(
Supervisor, [From, Host, Server, Username, Encoding, Port, Password]).
Supervisor, [From, Host, Server, Username, Encoding, Port, Password, Mod]).
start_link(From, Host, Server, Username, Encoding, Port, Password) ->
gen_fsm:start_link(?MODULE, [From, Host, Server, Username, Encoding, Port, Password],
start_link(From, Host, Server, Username, Encoding, Port, Password, Mod) ->
gen_fsm:start_link(?MODULE, [From, Host, Server, Username, Encoding, Port, Password, Mod],
?FSMOPTS).
%%%----------------------------------------------------------------------
@ -85,9 +85,10 @@ start_link(From, Host, Server, Username, Encoding, Port, Password) ->
%% ignore |
%% {stop, StopReason}
%%----------------------------------------------------------------------
init([From, Host, Server, Username, Encoding, Port, Password]) ->
init([From, Host, Server, Username, Encoding, Port, Password, Mod]) ->
gen_fsm:send_event(self(), init),
{ok, open_socket, #state{queue = queue:new(),
mod = Mod,
encoding = Encoding,
port = Port,
password = Password,
@ -651,9 +652,9 @@ terminate(_Reason, _StateName, FullStateData) ->
[{xmlcdata, "Server Connect Failed"}]},
FullStateData}
end,
mod_irc:closed_connection(StateData#state.host,
StateData#state.user,
StateData#state.server),
(FullStateData#state.mod):closed_connection(StateData#state.host,
StateData#state.user,
StateData#state.server),
bounce_messages("Server Connect Failed"),
lists:foreach(
fun(Chan) ->

1063
src/mod_irc/mod_irc_odbc.erl Normal file

File diff suppressed because it is too large Load Diff

View File

@ -244,6 +244,15 @@ CREATE TABLE muc_registered (
CREATE INDEX i_muc_registered_nick USING BTREE ON muc_registered(nick(75));
CREATE UNIQUE INDEX i_muc_registered_jid_host USING BTREE ON muc_registered(jid(75), host(75));
CREATE TABLE irc_custom (
jid text NOT NULL,
host text NOT NULL,
data text NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8;
CREATE UNIQUE INDEX i_irc_custom_jid_host USING BTREE ON irc_custom(jid(75), host(75));
CREATE TABLE motd (
username varchar(250) PRIMARY KEY,
xml text,

View File

@ -245,6 +245,15 @@ CREATE TABLE muc_registered (
CREATE INDEX i_muc_registered_nick ON muc_registered USING btree (nick);
CREATE UNIQUE INDEX i_muc_registered_jid_host ON muc_registered USING btree (jid, host);
CREATE TABLE irc_custom (
jid text NOT NULL,
host text NOT NULL,
data text NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX i_irc_custom_jid_host ON irc_custom USING btree (jid, host);
CREATE TABLE motd (
username text PRIMARY KEY,
xml text,