ejabberd_local

ejabberd_local用于注册发到服务器本身的IQ以及路由到本地的ejabberd_sm(message)

对外主要提供route,register_iq_handler,unregister_iq_response_handler方法

route(From, To, Packet) ->
    case catch do_route(From, To, Packet) of
      {‘EXIT‘, Reason} ->
      ?ERROR_MSG("~p~nwhen processing: ~p",
             [Reason, {From, To, Packet}]);
      _ -> ok
    end.

do_route(From, To, Packet) ->
    ?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket "
       "~P~n",
       [From, To, Packet, 8]),
    if To#jid.luser /= <<"">> ->
       ejabberd_sm:route(From, To, Packet);
       To#jid.lresource == <<"">> ->
       #xmlel{name = Name} = Packet,
       case Name of
         <<"iq">> -> process_iq(From, To, Packet);
         <<"message">> -> ok;
         <<"presence">> -> ok;
         _ -> ok
       end;
       true ->
       #xmlel{attrs = Attrs} = Packet,
       case xml:get_attr_s(<<"type">>, Attrs) of
         <<"error">> -> ok;
         <<"result">> -> ok;
         _ ->
         ejabberd_hooks:run(local_send_to_resource_hook,
                    To#jid.lserver, [From, To, Packet])
       end
    end.

route当是完整的message的信息的时候,通过ejabberd_sm:route路由信息

当是IQ信息的时候route:process_iq(From, To, Packet)处理,根据register_iq_handler注册的信息

时间: 2024-10-22 17:13:53

ejabberd_local的相关文章

ejabberd_router、ejabberd_router_multicast

ejabberd_router作为gen_server启动,作为系统的路由 对外提供注册路由.删除路由 初始化时创建route(mnesia)表,监控注册的路由进程 主要方法为do_route(OrigFrom, OrigTo, OrigPacket)方法 do_route(OrigFrom, OrigTo, OrigPacket) -> ?DEBUG("route~n\tfrom ~p~n\tto ~p~n\tpacket " "~p~n", [OrigFr

ejabberd_iq_sup

ejabberd_iq_sup作为supervisor启动,子程序启动的模块为gen_iq_handler gen_iq_handler: 根据配置参数iqdisc,可选项为no_queue, one_queue, {quques, N}和parallel add_iq_handler(Component, Host, NS, Module, Function, Type) -> case Type of no_queue -> Component:register_iq_handler(Ho