mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
* src/odbc/mysql.sql: Database description for MySQL Database
4.1 (Max version, with Innodb) * src/ejabberd_auth_odbc.erl: MySQL ODBC support. * src/mod_offline_odbc.erl: likewise * src/mod_vcard_odbc.erl: likewsie * src/mod_roster_odbc.erl: likewise * src/odbc/ejabberd_odbc.erl: likewise * src/mod_last_odbc.erl: likewise SVN Revision: 474
This commit is contained in:
parent
c275a24597
commit
559b5cae14
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2005-12-21 Mickael Remond <mickael.remond@process-one.net>
|
||||||
|
|
||||||
|
* src/odbc/mysql.sql: Database description for MySQL Database 4.1 (Max
|
||||||
|
version, with Innodb)
|
||||||
|
* src/ejabberd_auth_odbc.erl: MySQL ODBC support.
|
||||||
|
* src/mod_offline_odbc.erl: likewise
|
||||||
|
* src/mod_vcard_odbc.erl: likewsie
|
||||||
|
* src/mod_roster_odbc.erl: likewise
|
||||||
|
* src/odbc/ejabberd_odbc.erl: likewise
|
||||||
|
* src/mod_last_odbc.erl: likewise
|
||||||
|
|
||||||
2005-12-16 Mickael Remond <mickael.remond@process-one.net>
|
2005-12-16 Mickael Remond <mickael.remond@process-one.net>
|
||||||
|
|
||||||
* doc/Makefile: Added helper to generate the docs (Thanks to Sander
|
* doc/Makefile: Added helper to generate the docs (Thanks to Sander
|
||||||
|
@ -91,12 +91,12 @@ set_password(User, Server, Password) ->
|
|||||||
LUser ->
|
LUser ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
Pass = ejabberd_odbc:escape(Password),
|
Pass = ejabberd_odbc:escape(Password),
|
||||||
catch ejabberd_odbc:sql_query(
|
LServer = jlib:nameprep(Server),
|
||||||
jlib:nameprep(Server),
|
catch ejabberd_odbc:sql_transaction(
|
||||||
["begin;"
|
LServer,
|
||||||
"delete from users where username='", Username ,"';"
|
[["delete from users where username='", Username ,"';"],
|
||||||
"insert into users(username, password) "
|
["insert into users(username, password) "
|
||||||
"values ('", Username, "', '", Pass, "'); commit"])
|
"values ('", Username, "', '", Pass, "');"]])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -203,21 +203,25 @@ remove_user(User, Server, Password) ->
|
|||||||
LUser ->
|
LUser ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
Pass = ejabberd_odbc:escape(Password),
|
Pass = ejabberd_odbc:escape(Password),
|
||||||
case catch
|
LServer = jlib:nameprep(Server),
|
||||||
ejabberd_odbc:sql_query(
|
F = fun() ->
|
||||||
jlib:nameprep(Server),
|
Result = ejabberd_odbc:sql_query_t(
|
||||||
["begin;"
|
["select password from users where username='",
|
||||||
"select password from users where username='", Username, "';"
|
Username, "';"]),
|
||||||
"delete from users "
|
ejabberd_odbc:sql_query_t(["delete from users "
|
||||||
"where username='", Username, "' and password='", Pass, "';"
|
"where username='", Username,
|
||||||
"commit"]) of
|
"' and password='", Pass, "';"]),
|
||||||
{selected, ["password"], [{Password}]} ->
|
case Result of
|
||||||
ejabberd_hooks:run(remove_user, jlib:nameprep(Server),
|
{selected, ["password"], [{Password}]} ->
|
||||||
[User, Server]),
|
ejabberd_hooks:run(remove_user, jlib:nameprep(Server),
|
||||||
ok;
|
[User, Server]),
|
||||||
{selected, ["password"], []} ->
|
ok;
|
||||||
not_exists;
|
{selected, ["password"], []} ->
|
||||||
_ ->
|
not_exists;
|
||||||
not_allowed
|
_ ->
|
||||||
end
|
not_allowed
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
{atomic, Result } = ejabberd_odbc:transaction(LServer, F),
|
||||||
|
Result
|
||||||
end.
|
end.
|
||||||
|
@ -56,7 +56,6 @@ process_local_iq(_From, _To, #iq{type = Type, sub_el = SubEl} = IQ) ->
|
|||||||
[]}]}
|
[]}]}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
|
process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||||
case Type of
|
case Type of
|
||||||
set ->
|
set ->
|
||||||
@ -99,7 +98,7 @@ get_last(IQ, SubEl, LUser, LServer) ->
|
|||||||
case catch ejabberd_odbc:sql_query(
|
case catch ejabberd_odbc:sql_query(
|
||||||
LServer,
|
LServer,
|
||||||
["select seconds, state from last "
|
["select seconds, state from last "
|
||||||
"where username='", Username, "'"]) of
|
"where username='", Username, "';"]) of
|
||||||
{'EXIT', _Reason} ->
|
{'EXIT', _Reason} ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
|
||||||
{selected, ["seconds","state"], []} ->
|
{selected, ["seconds","state"], []} ->
|
||||||
@ -121,8 +120,6 @@ get_last(IQ, SubEl, LUser, LServer) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
on_presence_update(User, Server, _Resource, Status) ->
|
on_presence_update(User, Server, _Resource, Status) ->
|
||||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
{MegaSecs, Secs, _MicroSecs} = now(),
|
||||||
TimeStamp = MegaSecs * 1000000 + Secs,
|
TimeStamp = MegaSecs * 1000000 + Secs,
|
||||||
@ -134,20 +131,16 @@ store_last_info(User, Server, TimeStamp, Status) ->
|
|||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
Seconds = ejabberd_odbc:escape(integer_to_list(TimeStamp)),
|
Seconds = ejabberd_odbc:escape(integer_to_list(TimeStamp)),
|
||||||
State = ejabberd_odbc:escape(Status),
|
State = ejabberd_odbc:escape(Status),
|
||||||
ejabberd_odbc:sql_query(
|
%% MREMOND: I think this should be turn into a non transactional behaviour
|
||||||
|
ejabberd_odbc:sql_transaction(
|
||||||
LServer,
|
LServer,
|
||||||
["begin;"
|
[["delete from last where username='", Username, "';"],
|
||||||
"delete from last where username='", Username, "';"
|
["insert into last(username, seconds, state) "
|
||||||
"insert into last(username, seconds, state) "
|
"values ('", Username, "', '", Seconds, "', '", State, "');"]]).
|
||||||
"values ('", Username, "', '", Seconds, "', '", State, "');",
|
|
||||||
"commit"]).
|
|
||||||
|
|
||||||
|
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
ejabberd_odbc:sql_query(
|
ejabberd_odbc:sql_query(LServer,
|
||||||
LServer,
|
["delete from last where username='", Username, "';"]).
|
||||||
["delete from last where username='", Username, "'"]).
|
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
%%% Created : 5 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
%%% Created : 5 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
||||||
%%% Id : $Id$
|
%%% Id : $Id$
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
-module(mod_offline_odbc).
|
-module(mod_offline_odbc).
|
||||||
-author('alexey@sevcom.net').
|
-author('alexey@sevcom.net').
|
||||||
|
|
||||||
@ -73,9 +72,9 @@ loop(Host) ->
|
|||||||
XML,
|
XML,
|
||||||
"');"]
|
"');"]
|
||||||
end, Msgs),
|
end, Msgs),
|
||||||
case catch ejabberd_odbc:sql_query(
|
case catch ejabberd_odbc:sql_transaction(
|
||||||
Host,
|
Host,
|
||||||
["begin; ", Query, " commit"]) of
|
Query) of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~n", [Reason]);
|
?ERROR_MSG("~p~n", [Reason]);
|
||||||
_ ->
|
_ ->
|
||||||
@ -212,17 +211,16 @@ pop_offline_messages(Ls, User, Server) ->
|
|||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
EUser = ejabberd_odbc:escape(LUser),
|
EUser = ejabberd_odbc:escape(LUser),
|
||||||
case ejabberd_odbc:sql_query(
|
F = fun() ->
|
||||||
LServer,
|
Result = ejabberd_odbc:sql_query_t(
|
||||||
["begin;"
|
["select username, xml from spool where username='", EUser, "'"
|
||||||
"select username, xml from spool where username='", EUser, "'"
|
" order by seq;"]),
|
||||||
" order by seq;"
|
ejabberd_odbc:sql_query_t(
|
||||||
"delete from spool where username='", EUser, "';"
|
["delete from spool where username='", EUser, "';"]),
|
||||||
"commit"]) of
|
Result
|
||||||
[{updated, undefined},
|
end,
|
||||||
{selected, ["username","xml"], Rs},
|
case ejabberd_odbc:sql_transaction(LServer,F) of
|
||||||
{updated, _},
|
{atomic, {selected, ["username","xml"], Rs}} ->
|
||||||
{updated, undefined}] ->
|
|
||||||
Ls ++ lists:flatmap(
|
Ls ++ lists:flatmap(
|
||||||
fun({_, XML}) ->
|
fun({_, XML}) ->
|
||||||
case xml_stream:parse_element(XML) of
|
case xml_stream:parse_element(XML) of
|
||||||
@ -253,5 +251,5 @@ remove_user(User, Server) ->
|
|||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
ejabberd_odbc:sql_query(
|
ejabberd_odbc:sql_query(
|
||||||
LServer,
|
LServer,
|
||||||
["delete from spool where username='", Username, "'"]).
|
["delete from spool where username='", Username, "';"]).
|
||||||
|
|
||||||
|
@ -255,29 +255,35 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
ejabberd_odbc:sql_query_t(
|
ejabberd_odbc:sql_query_t(
|
||||||
["delete from rosterusers "
|
["delete from rosterusers "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';"
|
" and jid='", SJID, "';"]),
|
||||||
"delete from rostergroups "
|
ejabberd_odbc:sql_query_t(
|
||||||
|
["delete from rostergroups "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "'"]);
|
" and jid='", SJID, "';"]);
|
||||||
_ ->
|
_ ->
|
||||||
ItemVals = record_to_string(Item2),
|
ItemVals = record_to_string(Item2),
|
||||||
ItemGroups = groups_to_string(Item2),
|
ItemGroups = groups_to_string(Item2),
|
||||||
ejabberd_odbc:sql_query_t(
|
ejabberd_odbc:sql_query_t(
|
||||||
["delete from rosterusers "
|
["delete from rosterusers "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';"
|
" and jid='", SJID, "';"]),
|
||||||
"insert into rosterusers("
|
ejabberd_odbc:sql_query_t(
|
||||||
|
["insert into rosterusers("
|
||||||
" username, jid, nick, "
|
" username, jid, nick, "
|
||||||
" subscription, ask, "
|
" subscription, ask, "
|
||||||
" server, subscribe, type) "
|
" server, subscribe, type) "
|
||||||
" values ", ItemVals, ";"
|
" values ", ItemVals, ";"]),
|
||||||
"delete from rostergroups "
|
ejabberd_odbc:sql_query_t(
|
||||||
|
["delete from rostergroups "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';",
|
" and jid='", SJID, "';"]),
|
||||||
[["insert into rostergroups("
|
lists:foreach(fun(ItemGroup) ->
|
||||||
" username, jid, grp) "
|
ejabberd_odbc:sql_query_t(
|
||||||
" values ", ItemGroup, ";"] ||
|
["insert into rostergroups("
|
||||||
ItemGroup <- ItemGroups]])
|
" username, jid, grp) "
|
||||||
|
" values ", ItemGroup, ";"])
|
||||||
|
end,
|
||||||
|
ItemGroups)
|
||||||
end,
|
end,
|
||||||
{Item, Item2}
|
{Item, Item2}
|
||||||
end,
|
end,
|
||||||
@ -466,7 +472,7 @@ process_subscription(Direction, User, Server, JID1, Type) ->
|
|||||||
["select username, jid, nick, subscription, ask, "
|
["select username, jid, nick, subscription, ask, "
|
||||||
"server, subscribe, type from rosterusers "
|
"server, subscribe, type from rosterusers "
|
||||||
"where username='", Username, "' "
|
"where username='", Username, "' "
|
||||||
"and jid='", SJID, "'"]) of
|
"and jid='", SJID, "';"]) of
|
||||||
{selected,
|
{selected,
|
||||||
["username", "jid", "nick", "subscription", "ask",
|
["username", "jid", "nick", "subscription", "ask",
|
||||||
"server", "subscribe", "type"],
|
"server", "subscribe", "type"],
|
||||||
@ -476,7 +482,7 @@ process_subscription(Direction, User, Server, JID1, Type) ->
|
|||||||
case ejabberd_odbc:sql_query_t(
|
case ejabberd_odbc:sql_query_t(
|
||||||
["select grp from rostergroups "
|
["select grp from rostergroups "
|
||||||
"where username='", Username, "' "
|
"where username='", Username, "' "
|
||||||
"and jid='", SJID, "'"]) of
|
"and jid='", SJID, "';"]) of
|
||||||
{selected, ["grp"], JGrps} when is_list(JGrps) ->
|
{selected, ["grp"], JGrps} when is_list(JGrps) ->
|
||||||
[JGrp || {JGrp} <- JGrps];
|
[JGrp || {JGrp} <- JGrps];
|
||||||
_ ->
|
_ ->
|
||||||
@ -518,12 +524,13 @@ process_subscription(Direction, User, Server, JID1, Type) ->
|
|||||||
ejabberd_odbc:sql_query_t(
|
ejabberd_odbc:sql_query_t(
|
||||||
["delete from rosterusers "
|
["delete from rosterusers "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';"
|
" and jid='", SJID, "';"]),
|
||||||
"insert into rosterusers("
|
ejabberd_odbc:sql_query_t(
|
||||||
|
["insert into rosterusers("
|
||||||
" username, jid, nick, "
|
" username, jid, nick, "
|
||||||
" subscription, ask, "
|
" subscription, ask, "
|
||||||
" server, subscribe, type) "
|
" server, subscribe, type) "
|
||||||
" values ", ItemVals]),
|
" values ", ItemVals, ";"]),
|
||||||
{{push, NewItem}, AutoReply}
|
{{push, NewItem}, AutoReply}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -659,9 +666,10 @@ remove_user(User, Server) ->
|
|||||||
fun() ->
|
fun() ->
|
||||||
ejabberd_odbc:sql_query_t(
|
ejabberd_odbc:sql_query_t(
|
||||||
["delete from rosterusers "
|
["delete from rosterusers "
|
||||||
" where username='", Username, "';"
|
" where username='", Username, "';"]),
|
||||||
"delete from rostergroups "
|
ejabberd_odbc:sql_query_t(
|
||||||
" where username='", Username, "'"])
|
["delete from rostergroups "
|
||||||
|
" where username='", Username, "';"])
|
||||||
end),
|
end),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
@ -671,13 +679,11 @@ set_items(User, Server, SubEl) ->
|
|||||||
{xmlelement, _Name, _Attrs, Els} = SubEl,
|
{xmlelement, _Name, _Attrs, Els} = SubEl,
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
catch ejabberd_odbc:sql_query(
|
catch ejabberd_odbc:transaction(
|
||||||
LServer,
|
LServer,
|
||||||
["begin;",
|
|
||||||
lists:map(fun(El) ->
|
lists:map(fun(El) ->
|
||||||
process_item_set_t(LUser, LServer, El)
|
process_item_set_t(LUser, LServer, El)
|
||||||
end, Els),
|
end, Els)).
|
||||||
"commit"]).
|
|
||||||
|
|
||||||
process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) ->
|
process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) ->
|
||||||
JID1 = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
|
JID1 = jlib:string_to_jid(xml:get_attr_s("jid", Attrs)),
|
||||||
@ -695,26 +701,26 @@ process_item_set_t(LUser, LServer, {xmlelement, _Name, Attrs, Els}) ->
|
|||||||
Item2 = process_item_els(Item1, Els),
|
Item2 = process_item_els(Item1, Els),
|
||||||
case Item2#roster.subscription of
|
case Item2#roster.subscription of
|
||||||
remove ->
|
remove ->
|
||||||
["delete from rosterusers "
|
[["delete from rosterusers "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';"
|
" and jid='", SJID, "';"],
|
||||||
"delete from rostergroups "
|
["delete from rostergroups "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';"];
|
" and jid='", SJID, "';"]];
|
||||||
_ ->
|
_ ->
|
||||||
ItemVals = record_to_string(Item1),
|
ItemVals = record_to_string(Item1),
|
||||||
ItemGroups = groups_to_string(Item2),
|
ItemGroups = groups_to_string(Item2),
|
||||||
["delete from rosterusers "
|
[["delete from rosterusers "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';"
|
" and jid='", SJID, "';"],
|
||||||
"insert into rosterusers("
|
["insert into rosterusers("
|
||||||
" username, jid, nick, "
|
" username, jid, nick, "
|
||||||
" subscription, ask, "
|
" subscription, ask, "
|
||||||
" server, subscribe, type) "
|
" server, subscribe, type) "
|
||||||
" values ", ItemVals, ";"
|
" values ", ItemVals, ";"],
|
||||||
"delete from rostergroups "
|
["delete from rostergroups "
|
||||||
" where username='", Username, "' "
|
" where username='", Username, "' "
|
||||||
" and jid='", SJID, "';",
|
" and jid='", SJID, "';"],
|
||||||
[["insert into rostergroups("
|
[["insert into rostergroups("
|
||||||
" username, jid, grp) "
|
" username, jid, grp) "
|
||||||
" values ", ItemGroup, ";"] ||
|
" values ", ItemGroup, ";"] ||
|
||||||
|
@ -136,7 +136,7 @@ process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
|
|||||||
case catch ejabberd_odbc:sql_query(
|
case catch ejabberd_odbc:sql_query(
|
||||||
LServer,
|
LServer,
|
||||||
["select vcard from vcard "
|
["select vcard from vcard "
|
||||||
"where username='", Username, "'"]) of
|
"where username='", Username, "';"]) of
|
||||||
{selected, ["vcard"], [{SVCARD}]} ->
|
{selected, ["vcard"], [{SVCARD}]} ->
|
||||||
case xml_stream:parse_element(SVCARD) of
|
case xml_stream:parse_element(SVCARD) of
|
||||||
{error, _Reason} ->
|
{error, _Reason} ->
|
||||||
@ -231,32 +231,30 @@ set_vcard(User, LServer, VCARD) ->
|
|||||||
SOrgUnit = ejabberd_odbc:escape(OrgUnit),
|
SOrgUnit = ejabberd_odbc:escape(OrgUnit),
|
||||||
SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
|
SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
|
||||||
|
|
||||||
ejabberd_odbc:sql_query(
|
ejabberd_odbc:sql_transaction(
|
||||||
LServer,
|
LServer,
|
||||||
["begin;"
|
[["delete from vcard where username='", LUsername, "';"],
|
||||||
"delete from vcard where username='", LUsername, "';"
|
["insert into vcard(username, vcard) "
|
||||||
"insert into vcard(username, vcard) "
|
"values ('", LUsername, "', '", SVCARD, "');"],
|
||||||
"values ('", LUsername, "', '", SVCARD, "');"
|
["delete from vcard_search where lusername='", LUsername, "';"],
|
||||||
"delete from vcard_search where lusername='", LUsername, "';"
|
["insert into vcard_search("
|
||||||
"insert into vcard_search("
|
" username, lusername, fn, lfn, family, lfamily,"
|
||||||
" username, lusername, fn, lfn, family, lfamily,"
|
" given, lgiven, middle, lmiddle, nickname, lnickname,"
|
||||||
" given, lgiven, middle, lmiddle, nickname, lnickname,"
|
" bday, lbday, ctry, lctry, locality, llocality,"
|
||||||
" bday, lbday, ctry, lctry, locality, llocality,"
|
" email, lemail, orgname, lorgname, orgunit, lorgunit)"
|
||||||
" email, lemail, orgname, lorgname, orgunit, lorgunit)"
|
"values (",
|
||||||
"values (",
|
" '", Username, "', '", LUsername, "',"
|
||||||
" '", Username, "', '", LUsername, "',"
|
" '", SFN, "', '", SLFN, "',"
|
||||||
" '", SFN, "', '", SLFN, "',"
|
" '", SFamily, "', '", SLFamily, "',"
|
||||||
" '", SFamily, "', '", SLFamily, "',"
|
" '", SGiven, "', '", SLGiven, "',"
|
||||||
" '", SGiven, "', '", SLGiven, "',"
|
" '", SMiddle, "', '", SLMiddle, "',"
|
||||||
" '", SMiddle, "', '", SLMiddle, "',"
|
" '", SNickname, "', '", SLNickname, "',"
|
||||||
" '", SNickname, "', '", SLNickname, "',"
|
" '", SBDay, "', '", SLBDay, "',"
|
||||||
" '", SBDay, "', '", SLBDay, "',"
|
" '", SCTRY, "', '", SLCTRY, "',"
|
||||||
" '", SCTRY, "', '", SLCTRY, "',"
|
" '", SLocality, "', '", SLLocality, "',"
|
||||||
" '", SLocality, "', '", SLLocality, "',"
|
" '", SEMail, "', '", SLEMail, "',"
|
||||||
" '", SEMail, "', '", SLEMail, "',"
|
" '", SOrgName, "', '", SLOrgName, "',"
|
||||||
" '", SOrgName, "', '", SLOrgName, "',"
|
" '", SOrgUnit, "', '", SLOrgUnit, "');"]])
|
||||||
" '", SOrgUnit, "', '", SLOrgUnit, "');"
|
|
||||||
"commit"])
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-define(TLFIELD(Type, Label, Var),
|
-define(TLFIELD(Type, Label, Var),
|
||||||
@ -291,9 +289,6 @@ set_vcard(User, LServer, VCARD) ->
|
|||||||
?TLFIELD("text-single", "Organization Unit", "orgunit")
|
?TLFIELD("text-single", "Organization Unit", "orgunit")
|
||||||
]}]).
|
]}]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
do_route(ServerHost, From, To, Packet) ->
|
do_route(ServerHost, From, To, Packet) ->
|
||||||
#jid{user = User, resource = Resource} = To,
|
#jid{user = User, resource = Resource} = To,
|
||||||
if
|
if
|
||||||
@ -514,7 +509,7 @@ search(LServer, Data) ->
|
|||||||
["select username, fn, family, given, middle, "
|
["select username, fn, family, given, middle, "
|
||||||
" nickname, bday, ctry, locality, "
|
" nickname, bday, ctry, locality, "
|
||||||
" email, orgname, orgunit from vcard_search ",
|
" email, orgname, orgunit from vcard_search ",
|
||||||
MatchSpec, Limit]) of
|
MatchSpec, Limit, ";"]) of
|
||||||
{selected, ["username", "fn", "family", "given", "middle",
|
{selected, ["username", "fn", "family", "given", "middle",
|
||||||
"nickname", "bday", "ctry", "locality",
|
"nickname", "bday", "ctry", "locality",
|
||||||
"email", "orgname", "orgunit"],
|
"email", "orgname", "orgunit"],
|
||||||
@ -660,11 +655,9 @@ remove_user(User, Server) ->
|
|||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
ejabberd_odbc:sql_query(
|
ejabberd_odbc:sql_transaction(
|
||||||
LServer,
|
LServer,
|
||||||
["begin;"
|
[["delete from vcard where username='", Username, "';"],
|
||||||
"delete from vcard where username='", Username, "';"
|
["delete from vcard_search where lusername='", Username, "';"]]).
|
||||||
"delete from vcard_search where lusername='", Username, "';"
|
|
||||||
"commit"]).
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,10 +45,22 @@ sql_query(Host, Query) ->
|
|||||||
gen_server:call(ejabberd_odbc_sup:get_random_pid(Host),
|
gen_server:call(ejabberd_odbc_sup:get_random_pid(Host),
|
||||||
{sql_query, Query}, 60000).
|
{sql_query, Query}, 60000).
|
||||||
|
|
||||||
|
%% SQL transaction based on a list of queries
|
||||||
|
%% This function automatically
|
||||||
|
sql_transaction(Host, Queries) when is_list(Queries) ->
|
||||||
|
F = fun() ->
|
||||||
|
lists:foreach(fun(Query) ->
|
||||||
|
R = sql_query(Host, Query)
|
||||||
|
end,
|
||||||
|
Queries)
|
||||||
|
end,
|
||||||
|
sql_transaction(Host, F);
|
||||||
|
%% SQL transaction, based on a erlang anonymous function (F = fun)
|
||||||
sql_transaction(Host, F) ->
|
sql_transaction(Host, F) ->
|
||||||
gen_server:call(ejabberd_odbc_sup:get_random_pid(Host),
|
gen_server:call(ejabberd_odbc_sup:get_random_pid(Host),
|
||||||
{sql_transaction, F}, 60000).
|
{sql_transaction, F}, 60000).
|
||||||
|
|
||||||
|
%% This function is intended to be used from inside an sql_transaction:
|
||||||
sql_query_t(Query) ->
|
sql_query_t(Query) ->
|
||||||
State = get(?STATE_KEY),
|
State = get(?STATE_KEY),
|
||||||
QRes = sql_query_internal(State, Query),
|
QRes = sql_query_internal(State, Query),
|
||||||
@ -106,7 +118,7 @@ init([Host]) ->
|
|||||||
_ when is_list(SQLServer) ->
|
_ when is_list(SQLServer) ->
|
||||||
{ok, Ref} = odbc:connect(SQLServer,
|
{ok, Ref} = odbc:connect(SQLServer,
|
||||||
[{scrollable_cursors, off}]),
|
[{scrollable_cursors, off}]),
|
||||||
{ok, #state{db_ref = Ref,
|
{ok, #state{db_ref = Ref,
|
||||||
db_type = odbc}}
|
db_type = odbc}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -177,15 +189,15 @@ execute_transaction(_State, _F, 0) ->
|
|||||||
{aborted, restarts_exceeded};
|
{aborted, restarts_exceeded};
|
||||||
execute_transaction(State, F, NRestarts) ->
|
execute_transaction(State, F, NRestarts) ->
|
||||||
put(?STATE_KEY, State),
|
put(?STATE_KEY, State),
|
||||||
sql_query_internal(State, "begin"),
|
sql_query_internal(State, "begin;"),
|
||||||
case catch F() of
|
case catch F() of
|
||||||
aborted ->
|
aborted ->
|
||||||
execute_transaction(State, F, NRestarts - 1);
|
execute_transaction(State, F, NRestarts - 1);
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
sql_query_internal(State, "rollback"),
|
sql_query_internal(State, "rollback;"),
|
||||||
{aborted, Reason};
|
{aborted, Reason};
|
||||||
Res ->
|
Res ->
|
||||||
sql_query_internal(State, "commit"),
|
sql_query_internal(State, "commit;"),
|
||||||
{atomic, Res}
|
{atomic, Res}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user