ejabberd-contrib/jorge/mod_logdb/erlang-mysql_userflag.diff

181 lines
7.5 KiB
Diff
Raw Permalink Normal View History

Index: mysql_conn.erl
===================================================================
--- mysql_conn.erl (revision 861)
+++ mysql_conn.erl (working copy)
@@ -64,6 +64,7 @@
%% External exports
%%--------------------------------------------------------------------
-export([start/6,
+ start/7,
start_link/6,
fetch/3,
fetch/4,
@@ -99,12 +100,14 @@
%%--------------------------------------------------------------------
%% Function: start(Host, Port, User, Password, Database, LogFun)
+%% Function: start(Host, Port, User, Password, Database, UserFlags, LogFun)
%% Function: start_link(Host, Port, User, Password, Database, LogFun)
%% Host = string()
%% Port = integer()
%% User = string()
%% Password = string()
%% Database = string()
+%% UserFlags = list()
%% LogFun = undefined | function() of arity 3
%% Descrip.: Starts a mysql_conn process that connects to a MySQL
%% server, logs in and chooses a database.
@@ -112,11 +115,13 @@
%% Pid = pid()
%% Reason = string()
%%--------------------------------------------------------------------
-start(Host, Port, User, Password, Database, LogFun) when is_list(Host), is_integer(Port), is_list(User),
- is_list(Password), is_list(Database) ->
+start(Host, Port, User, Password, Database, LogFun) ->
+ start(Host, Port, User, Password, Database, [], LogFun).
+start(Host, Port, User, Password, Database, UserFlags, LogFun) when is_list(Host), is_integer(Port), is_list(User),
+ is_list(Password), is_list(Database), is_list(UserFlags) ->
ConnPid = self(),
Pid = spawn(fun () ->
- init(Host, Port, User, Password, Database, LogFun, ConnPid)
+ init(Host, Port, User, Password, Database, UserFlags, LogFun, ConnPid)
end),
post_start(Pid, LogFun).
@@ -124,7 +129,7 @@
is_list(Password), is_list(Database) ->
ConnPid = self(),
Pid = spawn_link(fun () ->
- init(Host, Port, User, Password, Database, LogFun, ConnPid)
+ init(Host, Port, User, Password, Database, [], LogFun, ConnPid)
end),
post_start(Pid, LogFun).
@@ -243,6 +248,7 @@
%% User = string()
%% Password = string()
%% Database = string()
+%% UserFlags = list()
%% LogFun = undefined | function() of arity 3
%% Parent = pid() of process starting this mysql_conn
%% Descrip.: Connect to a MySQL server, log in and chooses a database.
@@ -250,10 +256,10 @@
%% we were successfull.
%% Returns : void() | does not return
%%--------------------------------------------------------------------
-init(Host, Port, User, Password, Database, LogFun, Parent) ->
+init(Host, Port, User, Password, Database, UserFlags, LogFun, Parent) ->
case mysql_recv:start_link(Host, Port, LogFun, self()) of
{ok, RecvPid, Sock} ->
- case mysql_init(Sock, RecvPid, User, Password, LogFun) of
+ case mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun) of
{ok, Version} ->
case do_query(Sock, RecvPid, LogFun, "use " ++ Database, Version, [{result_type, binary}]) of
{error, MySQLRes} ->
@@ -318,7 +324,7 @@
end.
%%--------------------------------------------------------------------
-%% Function: mysql_init(Sock, RecvPid, User, Password, LogFun)
+%% Function: mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun)
%% Sock = term(), gen_tcp socket
%% RecvPid = pid(), mysql_recv process
%% User = string()
@@ -328,16 +334,16 @@
%% Returns : ok | {error, Reason}
%% Reason = string()
%%--------------------------------------------------------------------
-mysql_init(Sock, RecvPid, User, Password, LogFun) ->
+mysql_init(Sock, RecvPid, User, Password, UserFlags, LogFun) ->
case do_recv(LogFun, RecvPid, undefined) of
{ok, Packet, InitSeqNum} ->
{Version, Salt1, Salt2, Caps} = greeting(Packet, LogFun),
AuthRes =
case Caps band ?SECURE_CONNECTION of
?SECURE_CONNECTION ->
- mysql_auth:do_new_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, Salt1, Salt2, LogFun);
+ mysql_auth:do_new_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, UserFlags, Salt1, Salt2, LogFun);
_ ->
- mysql_auth:do_old_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, Salt1, LogFun)
+ mysql_auth:do_old_auth(Sock, RecvPid, InitSeqNum + 1, User, Password, UserFlags, Salt1, LogFun)
end,
case AuthRes of
{ok, <<0:8, _Rest/binary>>, _RecvNum} ->
Index: mysql_auth.erl
===================================================================
--- mysql_auth.erl (revision 861)
+++ mysql_auth.erl (working copy)
@@ -17,8 +17,8 @@
%% External exports (should only be used by the 'mysql_conn' module)
%%--------------------------------------------------------------------
-export([
- do_old_auth/7,
- do_new_auth/8
+ do_old_auth/8,
+ do_new_auth/9
]).
%%--------------------------------------------------------------------
@@ -51,9 +51,9 @@
%% Descrip.: Perform old-style MySQL authentication.
%% Returns : result of mysql_conn:do_recv/3
%%--------------------------------------------------------------------
-do_old_auth(Sock, RecvPid, SeqNum, User, Password, Salt1, LogFun) ->
+do_old_auth(Sock, RecvPid, SeqNum, User, Password, UserFlags, Salt1, LogFun) ->
Auth = password_old(Password, Salt1),
- Packet2 = make_auth(User, Auth),
+ Packet2 = make_auth(User, Auth, UserFlags),
do_send(Sock, Packet2, SeqNum, LogFun),
mysql_conn:do_recv(LogFun, RecvPid, SeqNum).
@@ -71,9 +71,9 @@
%% Descrip.: Perform MySQL authentication.
%% Returns : result of mysql_conn:do_recv/3
%%--------------------------------------------------------------------
-do_new_auth(Sock, RecvPid, SeqNum, User, Password, Salt1, Salt2, LogFun) ->
+do_new_auth(Sock, RecvPid, SeqNum, User, Password, UserFlags, Salt1, Salt2, LogFun) ->
Auth = password_new(Password, Salt1 ++ Salt2),
- Packet2 = make_new_auth(User, Auth, none),
+ Packet2 = make_new_auth(User, Auth, none, UserFlags),
do_send(Sock, Packet2, SeqNum, LogFun),
case mysql_conn:do_recv(LogFun, RecvPid, SeqNum) of
{ok, Packet3, SeqNum2} ->
@@ -105,9 +105,11 @@
end, L)).
%% part of do_old_auth/4, which is part of mysql_init/4
-make_auth(User, Password) ->
- Caps = ?LONG_PASSWORD bor ?LONG_FLAG
- bor ?TRANSACTIONS bor ?FOUND_ROWS,
+make_auth(User, Password, UserFlags) ->
+ Flags = lists:append(UserFlags, [?LONG_PASSWORD, ?LONG_FLAG, ?TRANSACTIONS, ?FOUND_ROWS]),
+ Caps = lists:foldl(fun(Flag, TCaps) when is_integer(Flag) ->
+ TCaps bor Flag
+ end, 0, Flags),
Maxsize = 0,
UserB = list_to_binary(User),
PasswordB = Password,
@@ -115,16 +117,18 @@
PasswordB/binary>>.
%% part of do_new_auth/4, which is part of mysql_init/4
-make_new_auth(User, Password, Database) ->
+make_new_auth(User, Password, Database, UserFlags) ->
DBCaps = case Database of
none ->
0;
_ ->
?CONNECT_WITH_DB
end,
- Caps = ?LONG_PASSWORD bor ?LONG_FLAG bor ?TRANSACTIONS bor
- ?PROTOCOL_41 bor ?SECURE_CONNECTION bor DBCaps
- bor ?FOUND_ROWS,
+
+ Flags = lists:append(UserFlags, [?LONG_PASSWORD, ?LONG_FLAG, ?TRANSACTIONS, ?PROTOCOL_41, ?SECURE_CONNECTION, DBCaps, ?FOUND_ROWS]),
+ Caps = lists:foldl(fun(Flag, TCaps) when is_integer(Flag) ->
+ TCaps bor Flag
+ end, DBCaps, Flags),
Maxsize = ?MAX_PACKET_SIZE,
UserB = list_to_binary(User),
PasswordL = size(Password),