mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Convert mod_muc to Exmpp.
PR: EJABP-1 Submitted by: Pablo Polvorin <pablo.polvorin@process-one.net> SVN Revision: 1692
This commit is contained in:
parent
e06f533f6b
commit
bd300e870c
11
ChangeLog
11
ChangeLog
@ -1,7 +1,18 @@
|
|||||||
|
2008-11-04 Pablo Polvorin <pablo.polvorin@process-one.net>
|
||||||
|
|
||||||
|
* src/mod_muc/mod_muc_log.erl: Convert to exmpp, fix recursive
|
||||||
|
directory creation.
|
||||||
|
|
||||||
|
* src/mod_muc/mod_muc_room.erl: Default values as binary() instead of
|
||||||
|
list().
|
||||||
|
|
||||||
2008-11-03 Pablo Polvorin <pablo.polvorin@process-one.net>
|
2008-11-03 Pablo Polvorin <pablo.polvorin@process-one.net>
|
||||||
|
|
||||||
* src/ejabberd_app.erl: Start the exmpp application.
|
* src/ejabberd_app.erl: Start the exmpp application.
|
||||||
|
|
||||||
|
* src/mod_muc/mod_muc.erl, src/mod_muc/mod_muc_room.erl: Convert to
|
||||||
|
exmpp.
|
||||||
|
|
||||||
2008-10-31 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-10-31 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/mod_last_odbc.erl (store_last_info/4): Fix a bug where the
|
* src/mod_last_odbc.erl (store_last_info/4): Fix a bug where the
|
||||||
|
@ -45,8 +45,9 @@
|
|||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
|
|
||||||
|
|
||||||
-record(muc_room, {name_host, opts}).
|
-record(muc_room, {name_host, opts}).
|
||||||
@ -123,20 +124,19 @@ forget_room(Host, Name) ->
|
|||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
process_iq_disco_items(Host, From, To, #iq{lang = Lang} = IQ) ->
|
process_iq_disco_items(Host, From, To, #iq{} = IQ) ->
|
||||||
Res = IQ#iq{type = result,
|
Lang = exmpp_stanza:get_lang(IQ),
|
||||||
sub_el = [{xmlelement, "query",
|
Res = exmpp_iq:result(IQ, #xmlel{ns = ?NS_DISCO_ITEMS,
|
||||||
[{"xmlns", ?NS_DISCO_ITEMS}],
|
name = 'query',
|
||||||
iq_disco_items(Host, From, Lang)}]},
|
children = iq_disco_items(Host, From, Lang)}),
|
||||||
ejabberd_router:route(To,
|
ejabberd_router:route(To,
|
||||||
From,
|
From,
|
||||||
jlib:iq_to_xml(Res)).
|
exmpp_iq:iq_to_xmlel(Res)).
|
||||||
|
|
||||||
can_use_nick(_Host, _JID, "") ->
|
can_use_nick(_Host, _JID, "") ->
|
||||||
false;
|
false;
|
||||||
can_use_nick(Host, JID, Nick) ->
|
can_use_nick(Host, JID, Nick) ->
|
||||||
{LUser, LServer, _} = jlib:jid_tolower(JID),
|
LUS = {JID#jid.lnode, JID#jid.ldomain},
|
||||||
LUS = {LUser, LServer},
|
|
||||||
case catch mnesia:dirty_select(
|
case catch mnesia:dirty_select(
|
||||||
muc_registered,
|
muc_registered,
|
||||||
[{#muc_registered{us_host = '$1',
|
[{#muc_registered{us_host = '$1',
|
||||||
@ -300,11 +300,11 @@ do_route(Host, ServerHost, Access, HistorySize, RoomShaper,
|
|||||||
do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
||||||
From, To, Packet, DefRoomOpts);
|
From, To, Packet, DefRoomOpts);
|
||||||
_ ->
|
_ ->
|
||||||
{xmlelement, _Name, Attrs, _Els} = Packet,
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
Lang = xml:get_attr_s("xml:lang", Attrs),
|
ErrText = "Access denied by service policy",
|
||||||
ErrText = "Access denied by service policy",
|
Err = exmpp_iq:error(Packet,exmpp_stanza:error(Packet#xmlel.ns,
|
||||||
Err = jlib:make_error_reply(Packet,
|
'forbidden',
|
||||||
?ERRT_FORBIDDEN(Lang, ErrText)),
|
{Lang,ErrText})),
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -312,124 +312,109 @@ do_route(Host, ServerHost, Access, HistorySize, RoomShaper,
|
|||||||
do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
||||||
From, To, Packet, DefRoomOpts) ->
|
From, To, Packet, DefRoomOpts) ->
|
||||||
{_AccessRoute, AccessCreate, AccessAdmin, _AccessPersistent} = Access,
|
{_AccessRoute, AccessCreate, AccessAdmin, _AccessPersistent} = Access,
|
||||||
{Room, _, Nick} = jlib:jid_tolower(To),
|
Room = To#jid.lnode,
|
||||||
{xmlelement, Name, Attrs, _Els} = Packet,
|
Nick = To#jid.lresource,
|
||||||
|
#xmlel{name = Name} = Packet,
|
||||||
case Room of
|
case Room of
|
||||||
"" ->
|
'undefined' ->
|
||||||
case Nick of
|
case Nick of
|
||||||
"" ->
|
'undefined' ->
|
||||||
case Name of
|
case Name of
|
||||||
"iq" ->
|
'iq' ->
|
||||||
case jlib:iq_query_info(Packet) of
|
case exmpp_iq:xmlel_to_iq(Packet) of
|
||||||
#iq{type = get, xmlns = ?NS_DISCO_INFO = XMLNS,
|
#iq{type = get, ns = ?NS_DISCO_INFO = XMLNS,
|
||||||
sub_el = _SubEl, lang = Lang} = IQ ->
|
payload = _SubEl, lang = Lang} = IQ ->
|
||||||
Res = IQ#iq{type = result,
|
|
||||||
sub_el = [{xmlelement, "query",
|
ResPayload = #xmlel{ns = XMLNS, name = 'query',
|
||||||
[{"xmlns", XMLNS}],
|
children = iq_disco_info(Lang)},
|
||||||
iq_disco_info(Lang)}]},
|
Res = exmpp_iq:result(IQ, ResPayload),
|
||||||
ejabberd_router:route(To,
|
ejabberd_router:route(To,
|
||||||
From,
|
From,
|
||||||
jlib:iq_to_xml(Res));
|
exmpp_iq:iq_to_xmlel(Res));
|
||||||
#iq{type = get,
|
#iq{type = get,
|
||||||
xmlns = ?NS_DISCO_ITEMS} = IQ ->
|
ns = ?NS_DISCO_ITEMS} = IQ ->
|
||||||
spawn(?MODULE,
|
spawn(?MODULE,
|
||||||
process_iq_disco_items,
|
process_iq_disco_items,
|
||||||
[Host, From, To, IQ]);
|
[Host, From, To, IQ]);
|
||||||
#iq{type = get,
|
#iq{type = get,
|
||||||
xmlns = ?NS_REGISTER = XMLNS,
|
ns = ?NS_INBAND_REGISTER = XMLNS,
|
||||||
lang = Lang,
|
lang = Lang} = IQ ->
|
||||||
sub_el = _SubEl} = IQ ->
|
ResPayload = #xmlel{ns = XMLNS, name = 'query',
|
||||||
Res = IQ#iq{type = result,
|
children = iq_get_register_info(Host,
|
||||||
sub_el =
|
From,
|
||||||
[{xmlelement, "query",
|
Lang)},
|
||||||
[{"xmlns", XMLNS}],
|
Res = exmpp_iq:result(IQ,ResPayload),
|
||||||
iq_get_register_info(
|
|
||||||
Host, From, Lang)}]},
|
|
||||||
ejabberd_router:route(To,
|
ejabberd_router:route(To,
|
||||||
From,
|
From,
|
||||||
jlib:iq_to_xml(Res));
|
exmpp_iq:iq_to_xmlel(Res));
|
||||||
#iq{type = set,
|
#iq{type = set,
|
||||||
xmlns = ?NS_REGISTER = XMLNS,
|
ns = ?NS_INBAND_REGISTER ,
|
||||||
lang = Lang,
|
lang = Lang,
|
||||||
sub_el = SubEl} = IQ ->
|
payload = SubEl} = IQ ->
|
||||||
case process_iq_register_set(Host, From, SubEl, Lang) of
|
case process_iq_register_set(Host, From, SubEl, Lang) of
|
||||||
{result, IQRes} ->
|
ok ->
|
||||||
Res = IQ#iq{type = result,
|
Res = exmpp_iq:result(IQ),
|
||||||
sub_el =
|
|
||||||
[{xmlelement, "query",
|
|
||||||
[{"xmlns", XMLNS}],
|
|
||||||
IQRes}]},
|
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
To, From, jlib:iq_to_xml(Res));
|
To, From, exmpp_iq:iq_to_xmlel(Res));
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(IQ,Error),
|
||||||
Packet, Error),
|
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
To, From, Err)
|
To, From, exmpp_iq:iq_to_xmlel(Err))
|
||||||
end;
|
end;
|
||||||
#iq{type = get,
|
#iq{type = get,
|
||||||
xmlns = ?NS_VCARD = XMLNS,
|
ns = ?NS_VCARD,
|
||||||
lang = Lang,
|
lang = Lang} = IQ ->
|
||||||
sub_el = _SubEl} = IQ ->
|
Res = exmpp_iq:result(IQ,iq_get_vcard(Lang)),
|
||||||
Res = IQ#iq{type = result,
|
|
||||||
sub_el =
|
|
||||||
[{xmlelement, "vCard",
|
|
||||||
[{"xmlns", XMLNS}],
|
|
||||||
iq_get_vcard(Lang)}]},
|
|
||||||
ejabberd_router:route(To,
|
ejabberd_router:route(To,
|
||||||
From,
|
From,
|
||||||
jlib:iq_to_xml(Res));
|
exmpp_iq:iq_to_xmlel(Res));
|
||||||
#iq{} ->
|
#iq{} = IQ ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(IQ,'feature-not-implemented'),
|
||||||
Packet,
|
|
||||||
?ERR_FEATURE_NOT_IMPLEMENTED),
|
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
"message" ->
|
'message' ->
|
||||||
case xml:get_attr_s("type", Attrs) of
|
case exmpp_xml:get_attribute(Packet,type, "chat") of
|
||||||
"error" ->
|
"error" ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
case acl:match_rule(ServerHost, AccessAdmin, From) of
|
case acl:match_rule(ServerHost, AccessAdmin, From) of
|
||||||
allow ->
|
allow ->
|
||||||
Msg = xml:get_path_s(
|
Msg = exmpp_xml:get_path(Packet,
|
||||||
Packet,
|
[{element,'body'},cdata]),
|
||||||
[{elem, "body"}, cdata]),
|
|
||||||
broadcast_service_message(Host, Msg);
|
broadcast_service_message(Host, Msg);
|
||||||
_ ->
|
_ ->
|
||||||
Lang = xml:get_attr_s("xml:lang", Attrs),
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
ErrText = "Only service administrators "
|
ErrText = "Only service administrators "
|
||||||
"are allowed to send service messages",
|
"are allowed to send service messages",
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(Packet,exmpp_stanza:error(Packet#xmlel.ns,
|
||||||
Packet,
|
'forbidden',
|
||||||
?ERRT_FORBIDDEN(Lang, ErrText)),
|
{Lang,ErrText})),
|
||||||
ejabberd_router:route(
|
ejabberd_router:route(
|
||||||
To, From, Err)
|
To, From, Err)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
"presence" ->
|
'presence' ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
case xml:get_attr_s("type", Attrs) of
|
case exmpp_stanza:get_type(Packet) of
|
||||||
"error" ->
|
"error" ->
|
||||||
ok;
|
ok;
|
||||||
"result" ->
|
"result" ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(Packet,'item-not-found'),
|
||||||
Packet, ?ERR_ITEM_NOT_FOUND),
|
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
case mnesia:dirty_read(muc_online_room, {Room, Host}) of
|
case mnesia:dirty_read(muc_online_room, {Room, Host}) of
|
||||||
[] ->
|
[] ->
|
||||||
Type = xml:get_attr_s("type", Attrs),
|
Type = exmpp_stanza:get_type(Packet),
|
||||||
case {Name, Type} of
|
case {Name, Type} of
|
||||||
{"presence", ""} ->
|
{'presence', 'undefined'} ->
|
||||||
case acl:match_rule(ServerHost, AccessCreate, From) of
|
case acl:match_rule(ServerHost, AccessCreate, From) of
|
||||||
allow ->
|
allow ->
|
||||||
?DEBUG("MUC: open new room '~s'~n", [Room]),
|
?DEBUG("MUC: open new room '~s'~n", [Room]),
|
||||||
@ -442,17 +427,20 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
|||||||
mod_muc_room:route(Pid, From, Nick, Packet),
|
mod_muc_room:route(Pid, From, Nick, Packet),
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
Lang = xml:get_attr_s("xml:lang", Attrs),
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
ErrText = "Room creation is denied by service policy",
|
ErrText = "Room creation is denied by service policy",
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_stanza:reply_with_error(Packet,exmpp_stanza:error(Packet#xmlel.ns,
|
||||||
Packet, ?ERRT_FORBIDDEN(Lang, ErrText)),
|
'forbidden',
|
||||||
|
{Lang,ErrText})),
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
Lang = xml:get_attr_s("xml:lang", Attrs),
|
Lang = exmpp_stanza:get_lang(Packet),
|
||||||
ErrText = "Conference room does not exist",
|
ErrText = "Conference room does not exist",
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_stanza:reply_with_error(Packet,
|
||||||
Packet, ?ERRT_ITEM_NOT_FOUND(Lang, ErrText)),
|
exmpp_stanza:error(Packet#xmlel.ns,
|
||||||
|
'item-not-found',
|
||||||
|
{Lang,ErrText})),
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end;
|
end;
|
||||||
[R] ->
|
[R] ->
|
||||||
@ -504,13 +492,23 @@ register_room(Host, Room, Pid) ->
|
|||||||
|
|
||||||
|
|
||||||
iq_disco_info(Lang) ->
|
iq_disco_info(Lang) ->
|
||||||
[{xmlelement, "identity",
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'identity',
|
||||||
[{"category", "conference"},
|
attrs = [#xmlattr{name = 'category',
|
||||||
{"type", "text"},
|
value = "conference"},
|
||||||
{"name", translate:translate(Lang, "Chatrooms")}], []},
|
#xmlattr{name = 'type',
|
||||||
{xmlelement, "feature", [{"var", ?NS_MUC}], []},
|
value = "text"},
|
||||||
{xmlelement, "feature", [{"var", ?NS_REGISTER}], []},
|
#xmlattr{name = 'name',
|
||||||
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}].
|
value = translate:translate(Lang, "Chatrooms")}]},
|
||||||
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs =
|
||||||
|
[#xmlattr{name = 'var',
|
||||||
|
value = ?NS_MUC_s}]},
|
||||||
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs =
|
||||||
|
[#xmlattr{name = 'var',
|
||||||
|
value = ?NS_INBAND_REGISTER_s}]},
|
||||||
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs =
|
||||||
|
[#xmlattr{name = 'var',
|
||||||
|
value = ?NS_VCARD_s}]}].
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
iq_disco_items(Host, From, Lang) ->
|
iq_disco_items(Host, From, Lang) ->
|
||||||
@ -520,9 +518,13 @@ iq_disco_items(Host, From, Lang) ->
|
|||||||
{item, Desc} ->
|
{item, Desc} ->
|
||||||
flush(),
|
flush(),
|
||||||
{true,
|
{true,
|
||||||
{xmlelement, "item",
|
#xmlel{name = 'item',
|
||||||
[{"jid", jlib:jid_to_string({Name, Host, ""})},
|
attrs = [#xmlattr{name = 'jid',
|
||||||
{"name", Desc}], []}};
|
value = exmpp_jid:jid_to_list(Name,
|
||||||
|
Host,
|
||||||
|
"")},
|
||||||
|
#xmlattr{name = 'name',
|
||||||
|
value = Desc}]}};
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -537,13 +539,17 @@ flush() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-define(XFIELD(Type, Label, Var, Val),
|
-define(XFIELD(Type, Label, Var, Val),
|
||||||
{xmlelement, "field", [{"type", Type},
|
#xmlel{name = "field",
|
||||||
{"label", translate:translate(Lang, Label)},
|
attrs = [#xmlattr{name = 'type', value = Type},
|
||||||
{"var", Var}],
|
#xmlattr{name = 'label',
|
||||||
[{xmlelement, "value", [], [{xmlcdata, Val}]}]}).
|
value = translate:translate(Lang, Label)},
|
||||||
|
#xmlattr{name = 'var', value = Var}],
|
||||||
|
children = [#xmlel{name = 'value',
|
||||||
|
children = [#xmlcdata{cdata = Val}]}]}).
|
||||||
|
|
||||||
iq_get_register_info(Host, From, Lang) ->
|
iq_get_register_info(Host, From, Lang) ->
|
||||||
{LUser, LServer, _} = jlib:jid_tolower(From),
|
LUser = From#jid.lnode,
|
||||||
|
LServer = From#jid.ldomain,
|
||||||
LUS = {LUser, LServer},
|
LUS = {LUser, LServer},
|
||||||
{Nick, Registered} =
|
{Nick, Registered} =
|
||||||
case catch mnesia:dirty_read(muc_registered, {LUS, Host}) of
|
case catch mnesia:dirty_read(muc_registered, {LUS, Host}) of
|
||||||
@ -552,27 +558,28 @@ iq_get_register_info(Host, From, Lang) ->
|
|||||||
[] ->
|
[] ->
|
||||||
{"", []};
|
{"", []};
|
||||||
[#muc_registered{nick = N}] ->
|
[#muc_registered{nick = N}] ->
|
||||||
{N, [{xmlelement, "registered", [], []}]}
|
{N, [#xmlel{name = 'registered'}]}
|
||||||
end,
|
end,
|
||||||
Registered ++
|
Registered ++
|
||||||
[{xmlelement, "instructions", [],
|
[#xmlel{name = 'instructions' ,
|
||||||
[{xmlcdata,
|
children = [#xmlcdata{cdata =
|
||||||
translate:translate(
|
translate:translate(Lang,
|
||||||
Lang, "You need an x:data capable client to register nickname")}]},
|
"You need an x:data capable client to register nickname")}]},
|
||||||
{xmlelement, "x",
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'x',
|
||||||
[{"xmlns", ?NS_XDATA}],
|
children = [
|
||||||
[{xmlelement, "title", [],
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title',
|
||||||
[{xmlcdata,
|
children = [#xmlcdata{cdata =
|
||||||
translate:translate(
|
translate:translate(Lang, "Nickname Registration at ") ++ Host}]},
|
||||||
Lang, "Nickname Registration at ") ++ Host}]},
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'instructions',
|
||||||
{xmlelement, "instructions", [],
|
children = [#xmlcdata{cdata =
|
||||||
[{xmlcdata,
|
translate:translate(Lang, "Enter nickname you want to register")}]},
|
||||||
translate:translate(
|
|
||||||
Lang, "Enter nickname you want to register")}]},
|
|
||||||
?XFIELD("text-single", "Nickname", "nick", Nick)]}].
|
?XFIELD("text-single", "Nickname", "nick", Nick)]}].
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
iq_set_register_info(Host, From, Nick, Lang) ->
|
iq_set_register_info(Host, From, Nick, Lang) ->
|
||||||
{LUser, LServer, _} = jlib:jid_tolower(From),
|
LUser = From#jid.lnode,
|
||||||
|
LServer = From#jid.ldomain,
|
||||||
LUS = {LUser, LServer},
|
LUS = {LUser, LServer},
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
case Nick of
|
case Nick of
|
||||||
@ -606,56 +613,64 @@ iq_set_register_info(Host, From, Nick, Lang) ->
|
|||||||
end,
|
end,
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
{atomic, ok} ->
|
{atomic, ok} ->
|
||||||
{result, []};
|
ok;
|
||||||
{atomic, false} ->
|
{atomic, false} ->
|
||||||
ErrText = "Specified nickname is already registered",
|
ErrText = "Specified nickname is already registered",
|
||||||
{error, ?ERRT_CONFLICT(Lang, ErrText)};
|
%%TODO: Always in the jabber:client namespace?
|
||||||
|
{error,exmpp_stanza:error(?NS_JABBER_CLIENT,
|
||||||
|
'conflict',
|
||||||
|
{Lang, ErrText})};
|
||||||
_ ->
|
_ ->
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, 'internal-server-error'}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_iq_register_set(Host, From, SubEl, Lang) ->
|
process_iq_register_set(Host, From, SubEl, Lang) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = SubEl,
|
% {xmlelement, _Name, _Attrs, Els} = SubEl,
|
||||||
case xml:get_subtag(SubEl, "remove") of
|
case exmpp_xml:get_element(SubEl,'remove') of
|
||||||
false ->
|
undefined ->
|
||||||
case xml:remove_cdata(Els) of
|
case exmpp_xml:get_child_elements(SubEl) of
|
||||||
[{xmlelement, "x", _Attrs1, _Els1} = XEl] ->
|
[#xmlel{ns= NS, name = 'x'} = XEl] ->
|
||||||
case {xml:get_tag_attr_s("xmlns", XEl),
|
case {NS, exmpp_stanza:get_type(XEl)} of
|
||||||
xml:get_tag_attr_s("type", XEl)} of
|
{?NS_DATA_FORMS, "cancel"} ->
|
||||||
{?NS_XDATA, "cancel"} ->
|
ok;
|
||||||
{result, []};
|
{?NS_DATA_FORMS, "submit"} ->
|
||||||
{?NS_XDATA, "submit"} ->
|
|
||||||
XData = jlib:parse_xdata_submit(XEl),
|
XData = jlib:parse_xdata_submit(XEl),
|
||||||
case XData of
|
case XData of
|
||||||
invalid ->
|
invalid ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, 'bad-request'};
|
||||||
_ ->
|
_ ->
|
||||||
case lists:keysearch("nick", 1, XData) of
|
case lists:keysearch("nick", 1, XData) of
|
||||||
false ->
|
false ->
|
||||||
ErrText = "You must fill in field \"Nickname\" in the form",
|
ErrText = "You must fill in field \"Nickname\" in the form",
|
||||||
{error, ?ERRT_NOT_ACCEPTABLE(Lang, ErrText)};
|
Err = exmpp_stanza:error(SubEl#xmlel.ns,
|
||||||
|
'not-acceptable',
|
||||||
|
{Lang, translate:translate(Lang,ErrText)}),
|
||||||
|
{error, Err};
|
||||||
{value, {_, [Nick]}} ->
|
{value, {_, [Nick]}} ->
|
||||||
iq_set_register_info(Host, From, Nick, Lang)
|
iq_set_register_info(Host, From, Nick, Lang)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
{error, ?ERR_BAD_REQUEST}
|
{error, 'bad-request'}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
{error, ?ERR_BAD_REQUEST}
|
{error, 'bad-request'}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
iq_set_register_info(Host, From, "", Lang)
|
iq_set_register_info(Host, From, "", Lang)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
iq_get_vcard(Lang) ->
|
iq_get_vcard(Lang) ->
|
||||||
[{xmlelement, "FN", [],
|
#xmlel{ns = ?NS_VCARD, name = 'vCard',
|
||||||
[{xmlcdata, "ejabberd/mod_muc"}]},
|
children =
|
||||||
{xmlelement, "URL", [],
|
[#xmlel{ns = ?NS_VCARD, name = 'FN',
|
||||||
[{xmlcdata, ?EJABBERD_URI}]},
|
children = [#xmlcdata{cdata = <<"ejabberd/mod_muc">>}]},
|
||||||
{xmlelement, "DESC", [],
|
#xmlel{ns = ?NS_VCARD, name = 'URL',
|
||||||
[{xmlcdata, translate:translate(Lang, "ejabberd MUC module") ++
|
children = [#xmlcdata{cdata = ?EJABBERD_URI}]},
|
||||||
"\nCopyright (c) 2003-2008 Alexey Shchepin"}]}].
|
#xmlel{ns = ?NS_VCARD, name = 'DESC',
|
||||||
|
children = [#xmlcdata{cdata =
|
||||||
|
translate:translate(Lang, "ejabberd MUC module") ++
|
||||||
|
"\nCopyright (c) 2003-2008 Alexey Shchepin"}]}]}.
|
||||||
|
|
||||||
|
|
||||||
broadcast_service_message(Host, Msg) ->
|
broadcast_service_message(Host, Msg) ->
|
||||||
|
@ -41,8 +41,9 @@
|
|||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
|
|
||||||
-define(T(Text), translate:translate(Lang, Text)).
|
-define(T(Text), translate:translate(Lang, Text)).
|
||||||
-define(PROCNAME, ejabberd_mod_muc_log).
|
-define(PROCNAME, ejabberd_mod_muc_log).
|
||||||
@ -204,14 +205,15 @@ code_change(_OldVsn, State, _Extra) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
add_to_log2(text, {Nick, Packet}, Room, Opts, State) ->
|
add_to_log2(text, {Nick, Packet}, Room, Opts, State) ->
|
||||||
case {xml:get_subtag(Packet, "subject"), xml:get_subtag(Packet, "body")} of
|
case {exmpp_xml:get_element(Packet, 'subject'),
|
||||||
{false, false} ->
|
exmpp_xml:get_element(Packet, 'body')} of
|
||||||
|
{'undefined', 'undefined'} ->
|
||||||
ok;
|
ok;
|
||||||
{false, SubEl} ->
|
{'undefined', SubEl} ->
|
||||||
Message = {body, xml:get_tag_cdata(SubEl)},
|
Message = {body, exmpp_xml:get_cdata_as_list(SubEl)},
|
||||||
add_message_to_log(Nick, Message, Room, Opts, State);
|
add_message_to_log(Nick, Message, Room, Opts, State);
|
||||||
{SubEl, _} ->
|
{SubEl, _} ->
|
||||||
Message = {subject, xml:get_tag_cdata(SubEl)},
|
Message = {subject, exmpp_xml:get_cdata_as_list(SubEl)},
|
||||||
add_message_to_log(Nick, Message, Room, Opts, State)
|
add_message_to_log(Nick, Message, Room, Opts, State)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -225,13 +227,13 @@ add_to_log2(join, Nick, Room, Opts, State) ->
|
|||||||
add_message_to_log(Nick, join, Room, Opts, State);
|
add_message_to_log(Nick, join, Room, Opts, State);
|
||||||
|
|
||||||
add_to_log2(leave, {Nick, Reason}, Room, Opts, State) ->
|
add_to_log2(leave, {Nick, Reason}, Room, Opts, State) ->
|
||||||
case Reason of
|
case binary_to_list(Reason) of
|
||||||
"" -> add_message_to_log(Nick, leave, Room, Opts, State);
|
"" -> add_message_to_log(Nick, leave, Room, Opts, State);
|
||||||
_ -> add_message_to_log(Nick, {leave, Reason}, Room, Opts, State)
|
R -> add_message_to_log(Nick, {leave, R}, Room, Opts, State)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
add_to_log2(kickban, {Nick, Reason, Code}, Room, Opts, State) ->
|
add_to_log2(kickban, {Nick, Reason, Code}, Room, Opts, State) ->
|
||||||
add_message_to_log(Nick, {kickban, Code, Reason}, Room, Opts, State).
|
add_message_to_log(Nick, {kickban, Code, binary_to_list(Reason)}, Room, Opts, State).
|
||||||
|
|
||||||
|
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
@ -269,8 +271,8 @@ build_filename_string(TimeStamp, OutDir, RoomJID, DirType, DirName, FileFormat)
|
|||||||
{Fd, Fn, Fnrel}.
|
{Fd, Fn, Fnrel}.
|
||||||
|
|
||||||
get_room_name(RoomJID) ->
|
get_room_name(RoomJID) ->
|
||||||
JID = jlib:string_to_jid(RoomJID),
|
JID = exmpp_jid:list_to_jid(RoomJID),
|
||||||
JID#jid.user.
|
JID#jid.node.
|
||||||
|
|
||||||
%% calculate day before
|
%% calculate day before
|
||||||
get_timestamp_daydiff(TimeStamp, Daydiff) ->
|
get_timestamp_daydiff(TimeStamp, Daydiff) ->
|
||||||
@ -458,16 +460,27 @@ get_dateweek(Date, Lang) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
make_dir_rec(Dir) ->
|
make_dir_rec(Dir) ->
|
||||||
|
Path = filename:split(Dir),
|
||||||
|
inc_foreach(Path,fun make_dir_if_not_exists/1).
|
||||||
|
|
||||||
|
|
||||||
|
make_dir_if_not_exists(DirPath) ->
|
||||||
|
Dir = filename:join(DirPath),
|
||||||
case file:read_file_info(Dir) of
|
case file:read_file_info(Dir) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
ok;
|
ok;
|
||||||
{error, enoent} ->
|
{error, enoent} ->
|
||||||
DirS = filename:split(Dir),
|
|
||||||
DirR = lists:sublist(DirS, length(DirS)-1),
|
|
||||||
make_dir_rec(filename:join(DirR)),
|
|
||||||
file:make_dir(Dir)
|
file:make_dir(Dir)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
inc_foreach(Lists, F) ->
|
||||||
|
lists:foldl(fun(Item, Accum) ->
|
||||||
|
New = Accum ++ [Item],
|
||||||
|
F(New),
|
||||||
|
New
|
||||||
|
end,[],Lists).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% {ok, F1}=file:open("valid-xhtml10.png", [read]).
|
%% {ok, F1}=file:open("valid-xhtml10.png", [read]).
|
||||||
%% {ok, F1b}=file:read(F1, 1000000).
|
%% {ok, F1b}=file:read(F1, 1000000).
|
||||||
@ -723,6 +736,8 @@ put_room_config(F, RoomConfig, Lang, _FileFormat) ->
|
|||||||
%% htmlize
|
%% htmlize
|
||||||
%% The default behaviour is to ignore the nofollow spam prevention on links
|
%% The default behaviour is to ignore the nofollow spam prevention on links
|
||||||
%% (NoFollow=false)
|
%% (NoFollow=false)
|
||||||
|
|
||||||
|
|
||||||
htmlize(S1) ->
|
htmlize(S1) ->
|
||||||
htmlize(S1, html).
|
htmlize(S1, html).
|
||||||
|
|
||||||
@ -779,7 +794,7 @@ get_room_info(RoomJID, Opts) ->
|
|||||||
{value, {_, SA}} -> SA;
|
{value, {_, SA}} -> SA;
|
||||||
false -> ""
|
false -> ""
|
||||||
end,
|
end,
|
||||||
#room{jid = jlib:jid_to_string(RoomJID),
|
#room{jid = exmpp_jid:jid_to_list(RoomJID),
|
||||||
title = Title,
|
title = Title,
|
||||||
subject = Subject,
|
subject = Subject,
|
||||||
subject_author = SubjectAuthor,
|
subject_author = SubjectAuthor,
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user