ejabberd_local用于注册发到服务器本身的IQ以及路由到本地的ejabberd_sm(message)
对外主要提供route,register_iq_handler,unregister_iq_response_handler方法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 from ~p~n to ~p~n packet " "~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注册的信息