在 MongooseIM 上实现 mod_blocking
Posted
技术标签:
【中文标题】在 MongooseIM 上实现 mod_blocking【英文标题】:Implementing mod_blocking on MongooseIM 【发布时间】:2014-06-05 12:01:06 【问题描述】:我正在尝试实现仅适用于 odbc 模块中的 mod_privacy 的 mod_blocking。
我不断收到回复:
<error code='500' type='wait'><internal-server-error0 xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>
这是我的代码:
process_blocklist_block(LUser, LServer, JIDs) ->
Filter = fun (List) ->
AlreadyBlocked = list_to_blocklist_jids(List, []),
lists:foldr(fun (JID, List1) ->
case lists:member(JID, AlreadyBlocked)
of
true -> List1;
false ->
[#listitemtype = jid,
value = JID,
action = deny,
order = 0,
match_all = true
| List1]
end
end,
List, JIDs)
end,
case process_blocklist_block(LUser, LServer, Filter,odbc)
of
atomic, ok, Default, List ->
UserList = make_userlist(Default, List),
broadcast_list_update(LUser, LServer, Default,
UserList),
broadcast_blocklist_event(LUser, LServer,
block, JIDs),
result, [], UserList;
_ -> error, ?ERR_INTERNAL_SERVER_ERROR
end.
process_blocklist_block(LUser, LServer, Filter, odbc) ->
F = fun () ->
Default = case mod_privacy_odbc:sql_get_default_privacy_list_t(LUser)
of
selected, [<<"name">>], [] ->
Name = <<"Blocked contacts">>,
mod_privacy_odbc:sql_add_privacy_list(LUser, Name),
mod_privacy_odbc:sql_set_default_privacy_list(LUser, Name),
Name;
selected, [<<"name">>], [[Name]] -> Name
end,
selected, [<<"id">>], [[ID]] = mod_privacy_odbc:sql_get_privacy_list_id_t(LUser, Default),
case mod_privacy_odbc:sql_get_privacy_list_data_by_id_t(ID)
of
selected,
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
<<"match_presence_in">>, <<"match_presence_out">>],
RItems = [_ | _] ->
List = lists:map(fun mod_privacy_odbc:raw_to_item/1, RItems);
_ -> List = []
end,
NewList = Filter(List),
NewRItems = lists:map(fun mod_privacy_odbc:item_to_raw/1, NewList),
mod_privacy_odbc:sql_set_privacy_list(ID, NewRItems),
ok, Default, NewList
end,
ejabberd_odbc:sql_transaction(LServer, F).
我已经检查了所有的查询。他们工作正常。我在努力理解这段代码的逻辑。调试此代码的最佳方法是什么,以便我可以理解我的逻辑何时失败?谁能指出我正确的方向?
UserList = make_userlist(Default, List),
broadcast_list_update(LUser, LServer, Default,
UserList),
broadcast_blocklist_event(LUser, LServer,
block, JIDs),
result, [], UserList;
_ -> error, ?ERR_INTERNAL_SERVER_ERROR
【问题讨论】:
我发现了这个问题:selected, [>], [[ID]] = mod_privacy_odbc:sql_get_privacy_list_id_t(LUser, Default) 应该是selected, [>], [ID] = mod_privacy_odbc:sql_get_privacy_list_id_t(LUser, Default) 【参考方案1】:如你所愿
_ -> error, ?ERR_INTERNAL_SERVER_ERROR
是服务器返回“内部服务器错误”的地方,你可以把这个地方改成
_Otherwise ->
?WARNING_MSG("Got some unexpected result in mod_priv ~100000p",[_Otherwise]),
error, ?ERR_INTERNAL_SERVER_ERROR)
然后查看log/ejabberd.log
当然你需要在 ejabberd.cfg 中以至少 3 的 loglevel 启动 mongooseim
【讨论】:
以上是关于在 MongooseIM 上实现 mod_blocking的主要内容,如果未能解决你的问题,请参考以下文章
MongooseIM 可以在 PostgreSQL 后端处理多少用户?
如何在 mongooseim 服务器中从 sql 注册用户名密码字段
MUC 消息的 MongooseIM 推送通知(不是 MUC 灯)
为啥 MongooseIM 会在 60 秒后关闭 websocket 连接?