在ejabberd.yml文件中配置一些参数

时间:2015-11-03 05:10:52

标签: erlang ejabberd mnesia

我想在ejabberd.yml中配置参数说MYNAME =“Heelo”。如何在erl文件中获取该参数?

2 个答案:

答案 0 :(得分:1)

对于每个Ejabberd模块,必须实现两个函数start/2stop/1start/2函数需要两个参数HostOptions。当您启动Ejabberd时,Ejabberd会逐个调用您在start/2中指定的模块的每个ejabberd.yml函数,并将提供的YAML选项转换为Erlang项,并将它们作为参数传递给start/2函数。

这样您可以按如下方式获取YAML选项:

ejabberd.yml

modules:
  mod_custom:
    key_1: value_atom
    key_2: "value_binary"
    key_3: 123456
    key_4:
      - item_1
      - item_2
      - item_3

mod_custom.erl

-module(mod_custom).
-behaviour(gen_mod).

start(Host, Options) ->
  Val1 = proplists:get_value(key_1, Options), %% Val1 = value_atom
  Val2 = proplists:get_value(key_2, Options), %% Val2 = <<"value_binary">>
  Val3 = proplists:get_value(key_3, Options), %% Val3 = 123456
  Val4 = proplists:get_value(key_4, Options), %% Val4 = [item_1,item_2,item_3]
  %% ...

答案 1 :(得分:0)

您可以编写与Ejabberd中的事件挂钩的自定义模块。

以下是ejabberd的事件列表:

c2s_stream_features(Acc)
c2s_unauthenticated_iq(Acc, Server, IQ) -> Packet
roster_get(Acc, {User, Server}) -> [RosterItem]
roster_get_jid_info(Acc, User, Server, JID) -> {Subscription, Groups}
roster_get_subscription_lists(Acc, User, Server) -> {[FromSubscription],[ToSubscription]}
roster_in_subscription(Acc, User, Server, JID, SubscriptionType, Reason) -> bool()
roster_out_subscription(Acc, User, Server, JID, SubscriptionType, Reason) -> bool()
roster_process_item(RosterItem, Server) -> RosterItem
disco_local_features(Acc, From, To, Node, Lang) -> Adhoc
disco_local_identity(Acc, From, To, Node, Lang) -> Adhoc
disco_local_items(Acc, From, To, Node, Lang) -> Adhoc
disco_sm_features(Acc, From, To, Node, Lang) -> Adhoc
disco_sm_identity(Acc, From, To, Node, Lang) -> Adhoc
disco_sm_items(Acc, From, To, Node, Lang) -> Adhoc
adhoc_local_items(Acc, From, To, Lang) -> Adhoc
adhoc_sm_items(Acc, From, To, Lang) -> Adhoc
ejabberd_ctl_process(Args) -> CtlStatus
filter_packet({From, To, Packet}) -> {From, To, Packet}
local_send_to_resource_hook(From, To, Packet) -> ok
offline_message_hook(From, To, Packet) -> ok
pubsub_publish_item(Host, Node, From, To, ItemId, Payload) -> ok
remove_user(User, Server) -> ok
resend_offline_messages_hook(Acc, User, Server) -> [Route]
resend_subscription_requests_hook(Acc, User, Server) -> [Packet]
sm_register_connection_hook(SID, JID, Info) -> ok
sm_remove_connection_hook(SID, JID, Info) -> ok
unset_presence_hook(User, Server, Resource, Status) -> void()
user_available_hook(JID) -> ok
user_receive_packet(JID, From, To, Packet) -> ok
user_send_packet(From, To, Packet) -> ok
privacy_check_packet(Acc, User, Server, PrivacyList, {From, To, Packet}, Dir) -> Auth
privacy_get_user_list(Acc, User, Server) -> PrivacyList
privacy_iq_get(Acc, From, To, IQ, ActiveList) -> {result, Packet} | {error, Error}
privacy_iq_set(Acc, From, To, IQ) -> {result, Packet} | {error, Error}
privacy_updated_list(Acc, OldPrivacyList, NewPrivacyList) -> PrivacyList

您可以在此处找到事件和摘要,例如https://www.ejabberd.im/Events+and+Hooks和官方文档https//docs.ejabberd.im/developer/hooks/

基本上编写自定义模块,注册/添加到ejabberd.yml文件将类似于

modules:
  mod_custom: []

以下是我发现最适合为ejabberd创建模块的教程:http://happy.cat/blog/XMPP-Bots-ejabberd-mod-motion-2010-02-01-10-00.html

另一个自定义开发的ejabberd节ack的例子:h ttps://github.com/Mingism/ejabberd-stanza-ack