0

我正在尝试实现仅适用于 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 ->
                       [#listitem{type = 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}
4

1 回答 1

2

如果你期望

  _ -> {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 中以 loglevel 至少 3 启动 mongooseim

于 2014-06-05T14:43:39.347 回答