-export([jid/0, user/0, domain/0, resource/0]).
-export([db_type/1, ldap_filter/0]).
-export([host/0, hosts/0]).
+-export([vcard_temp/0]).
-ifdef(SIP).
-export([sip_uri/0]).
-endif.
hosts() ->
list(host(), [unique]).
+-spec vcard_temp() -> yconf:validator().
+vcard_temp() ->
+ vcard_validator(
+ vcard_temp, undefined,
+ [{version, undefined, binary()},
+ {fn, undefined, binary()},
+ {n, undefined, vcard_name()},
+ {nickname, undefined, binary()},
+ {photo, undefined, vcard_photo()},
+ {bday, undefined, binary()},
+ {adr, [], list(vcard_adr())},
+ {label, [], list(vcard_label())},
+ {tel, [], list(vcard_tel())},
+ {email, [], list(vcard_email())},
+ {jabberid, undefined, binary()},
+ {mailer, undefined, binary()},
+ {tz, undefined, binary()},
+ {geo, undefined, vcard_geo()},
+ {title, undefined, binary()},
+ {role, undefined, binary()},
+ {logo, undefined, vcard_logo()},
+ {org, undefined, vcard_org()},
+ {categories, [], list(binary())},
+ {note, undefined, binary()},
+ {prodid, undefined, binary()},
+ {rev, undefined, binary()},
+ {sort_string, undefined, binary()},
+ {sound, undefined, vcard_sound()},
+ {uid, undefined, binary()},
+ {url, undefined, binary()},
+ {class, undefined, enum([confidential, private, public])},
+ {key, undefined, vcard_key()},
+ {desc, undefined, binary()}]).
+
+-spec vcard_name() -> yconf:validator().
+vcard_name() ->
+ vcard_validator(
+ vcard_name, undefined,
+ [{family, undefined, binary()},
+ {given, undefined, binary()},
+ {middle, undefined, binary()},
+ {prefix, undefined, binary()},
+ {suffix, undefined, binary()}]).
+
+-spec vcard_photo() -> yconf:validator().
+vcard_photo() ->
+ vcard_validator(
+ vcard_photo, undefined,
+ [{type, undefined, binary()},
+ {binval, undefined, binary()},
+ {extval, undefined, binary()}]).
+
+-spec vcard_adr() -> yconf:validator().
+vcard_adr() ->
+ vcard_validator(
+ vcard_adr, [],
+ [{home, false, bool()},
+ {work, false, bool()},
+ {postal, false, bool()},
+ {parcel, false, bool()},
+ {dom, false, bool()},
+ {intl, false, bool()},
+ {pref, false, bool()},
+ {pobox, undefined, binary()},
+ {extadd, undefined, binary()},
+ {street, undefined, binary()},
+ {locality, undefined, binary()},
+ {region, undefined, binary()},
+ {pcode, undefined, binary()},
+ {ctry, undefined, binary()}]).
+
+-spec vcard_label() -> yconf:validator().
+vcard_label() ->
+ vcard_validator(
+ vcard_label, [],
+ [{home, false, bool()},
+ {work, false, bool()},
+ {postal, false, bool()},
+ {parcel, false, bool()},
+ {dom, false, bool()},
+ {intl, false, bool()},
+ {pref, false, bool()},
+ {line, [], list(binary())}]).
+
+-spec vcard_tel() -> yconf:validator().
+vcard_tel() ->
+ vcard_validator(
+ vcard_tel, [],
+ [{home, false, bool()},
+ {work, false, bool()},
+ {voice, false, bool()},
+ {fax, false, bool()},
+ {pager, false, bool()},
+ {msg, false, bool()},
+ {cell, false, bool()},
+ {video, false, bool()},
+ {bbs, false, bool()},
+ {modem, false, bool()},
+ {isdn, false, bool()},
+ {pcs, false, bool()},
+ {pref, false, bool()},
+ {number, undefined, binary()}]).
+
+-spec vcard_email() -> yconf:validator().
+vcard_email() ->
+ vcard_validator(
+ vcard_email, [],
+ [{home, false, bool()},
+ {work, false, bool()},
+ {internet, false, bool()},
+ {pref, false, bool()},
+ {x400, false, bool()},
+ {userid, undefined, binary()}]).
+
+-spec vcard_geo() -> yconf:validator().
+vcard_geo() ->
+ vcard_validator(
+ vcard_geo, undefined,
+ [{lat, undefined, binary()},
+ {lon, undefined, binary()}]).
+
+-spec vcard_logo() -> yconf:validator().
+vcard_logo() ->
+ vcard_validator(
+ vcard_logo, undefined,
+ [{type, undefined, binary()},
+ {binval, undefined, binary()},
+ {extval, undefined, binary()}]).
+
+-spec vcard_org() -> yconf:validator().
+vcard_org() ->
+ vcard_validator(
+ vcard_org, undefined,
+ [{name, undefined, binary()},
+ {units, [], list(binary())}]).
+
+-spec vcard_sound() -> yconf:validator().
+vcard_sound() ->
+ vcard_validator(
+ vcard_sound, undefined,
+ [{phonetic, undefined, binary()},
+ {binval, undefined, binary()},
+ {extval, undefined, binary()}]).
+
+-spec vcard_key() -> yconv:validator().
+vcard_key() ->
+ vcard_validator(
+ vcard_key, undefined,
+ [{type, undefined, binary()},
+ {cred, undefined, binary()}]).
+
%%%===================================================================
%%% Internal functions
%%%===================================================================
-spec format(iolist(), list()) -> string().
format(Fmt, Args) ->
lists:flatten(io_lib:format(Fmt, Args)).
+
+-spec vcard_validator(atom(), term(), [{atom(), term(), validator()}]) -> validator().
+vcard_validator(Name, Default, Schema) ->
+ Defaults = [{Key, Val} || {Key, Val, _} <- Schema],
+ and_then(
+ options(
+ maps:from_list([{Key, Fun} || {Key, _, Fun} <- Schema]),
+ [{return, map}, {unique, true}]),
+ fun(Options) ->
+ merge(Defaults, Options, Name, Default)
+ end).
+
+-spec merge([{atom(), term()}], #{atom() => term()}, atom(), T) -> tuple() | T.
+merge(_, Options, _, Default) when Options == #{} ->
+ Default;
+merge(Defaults, Options, Name, _) ->
+ list_to_tuple([Name|[maps:get(Key, Options, Val) || {Key, Val} <- Defaults]]).
mod_opt_type(host) ->
econf:host();
mod_opt_type(hosts) ->
- econf:hosts().
+ econf:hosts();
+mod_opt_type(vcard) ->
+ econf:vcard_temp().
-spec mod_options(binary()) -> [{thumbnail, boolean()} |
{atom(), any()}].
[{host, <<"upload.", Host/binary>>},
{hosts, []},
{name, ?T("HTTP File Upload")},
+ {vcard, undefined},
{access, local},
{max_size, 104857600},
{secret_length, 40},
xmpp:make_iq_result(IQ, iq_disco_info(ServerHost, Lang, Name, AddInfo));
process_iq(#iq{type = get, sub_els = [#disco_items{}]} = IQ, _State) ->
xmpp:make_iq_result(IQ, #disco_items{});
+process_iq(#iq{type = get, sub_els = [#vcard_temp{}], lang = Lang} = IQ,
+ #state{server_host = ServerHost}) ->
+ VCard = case mod_http_upload_opt:vcard(ServerHost) of
+ undefined ->
+ #vcard_temp{fn = <<"ejabberd/mod_http_upload">>,
+ url = ejabberd_config:get_uri(),
+ desc = misc:get_descr(
+ Lang, ?T("ejabberd HTTP Upload service"))};
+ V ->
+ V
+ end,
+ xmpp:make_iq_result(IQ, VCard);
process_iq(#iq{type = get, sub_els = [#upload_request{filename = File,
size = Size,
'content-type' = CType,
features = [?NS_HTTP_UPLOAD,
?NS_HTTP_UPLOAD_0,
?NS_HTTP_UPLOAD_OLD,
+ ?NS_VCARD,
?NS_DISCO_INFO,
?NS_DISCO_ITEMS],
xdata = Form}.
-export([secret_length/1]).
-export([service_url/1]).
-export([thumbnail/1]).
+-export([vcard/1]).
-spec access(gen_mod:opts() | global | binary()) -> 'local' | acl:acl().
access(Opts) when is_map(Opts) ->
thumbnail(Host) ->
gen_mod:get_module_opt(Host, mod_http_upload, thumbnail).
+-spec vcard(gen_mod:opts() | global | binary()) -> 'undefined' | tuple().
+vcard(Opts) when is_map(Opts) ->
+ gen_mod:get_opt(vcard, Opts);
+vcard(Host) ->
+ gen_mod:get_module_opt(Host, mod_http_upload, vcard).
+
end.
-spec process_vcard(iq()) -> iq().
-process_vcard(#iq{type = get, lang = Lang, sub_els = [#vcard_temp{}]} = IQ) ->
- xmpp:make_iq_result(
- IQ, #vcard_temp{fn = <<"ejabberd/mod_muc">>,
- url = ejabberd_config:get_uri(),
- desc = misc:get_descr(Lang, ?T("ejabberd MUC module"))});
+process_vcard(#iq{type = get, to = To, lang = Lang, sub_els = [#vcard_temp{}]} = IQ) ->
+ ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
+ VCard = case mod_muc_opt:vcard(ServerHost) of
+ undefined ->
+ #vcard_temp{fn = <<"ejabberd/mod_muc">>,
+ url = ejabberd_config:get_uri(),
+ desc = misc:get_descr(Lang, ?T("ejabberd MUC module"))};
+ V ->
+ V
+ end,
+ xmpp:make_iq_result(IQ, VCard);
process_vcard(#iq{type = set, lang = Lang} = IQ) ->
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
mod_opt_type(queue_type) ->
econf:queue_type();
mod_opt_type(hibernation_timeout) ->
- econf:timeout(second, infinity).
+ econf:timeout(second, infinity);
+mod_opt_type(vcard) ->
+ econf:vcard_temp().
mod_options(Host) ->
[{access, all},
{user_presence_shaper, none},
{preload_rooms, true},
{hibernation_timeout, infinity},
+ {vcard, undefined},
{default_room_options,
[{allow_change_subj,true},
{allow_private_messages,true},
-export([room_shaper/1]).
-export([user_message_shaper/1]).
-export([user_presence_shaper/1]).
+-export([vcard/1]).
-spec access(gen_mod:opts() | global | binary()) -> 'all' | acl:acl().
access(Opts) when is_map(Opts) ->
user_presence_shaper(Host) ->
gen_mod:get_module_opt(Host, mod_muc, user_presence_shaper).
+-spec vcard(gen_mod:opts() | global | binary()) -> 'undefined' | tuple().
+vcard(Opts) when is_map(Opts) ->
+ gen_mod:get_opt(vcard, Opts);
+vcard(Host) ->
+ gen_mod:get_module_opt(Host, mod_muc, vcard).
+
{result, iq_disco_info(From, Lang, State)};
process_iq(#iq{type = get, sub_els = [#disco_items{}]}, _) ->
{result, #disco_items{}};
-process_iq(#iq{type = get, lang = Lang, sub_els = [#vcard_temp{}]}, _) ->
- {result, iq_vcard(Lang)};
+process_iq(#iq{type = get, lang = Lang, sub_els = [#vcard_temp{}]}, State) ->
+ {result, iq_vcard(Lang, State)};
process_iq(#iq{type = T}, _) when T == set; T == get ->
{error, xmpp:err_service_unavailable()};
process_iq(_, _) ->
features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS, ?NS_VCARD, ?NS_ADDRESS],
xdata = iq_disco_info_extras(From, State)}.
-iq_vcard(Lang) ->
- #vcard_temp{fn = <<"ejabberd/mod_multicast">>,
- url = ejabberd_config:get_uri(),
- desc = misc:get_descr(Lang, ?T("ejabberd Multicast service"))}.
+-spec iq_vcard(binary(), state()) -> #vcard_temp{}.
+iq_vcard(Lang, State) ->
+ case mod_multicast_opt:vcard(State#state.lserver) of
+ undefined ->
+ #vcard_temp{fn = <<"ejabberd/mod_multicast">>,
+ url = ejabberd_config:get_uri(),
+ desc = misc:get_descr(Lang, ?T("ejabberd Multicast service"))};
+ VCard ->
+ VCard
+ end.
%%%-------------------------
%%% Route
mod_opt_type(host) ->
econf:host();
mod_opt_type(hosts) ->
- econf:hosts().
+ econf:hosts();
+mod_opt_type(vcard) ->
+ econf:vcard_temp().
mod_options(Host) ->
[{access, all},
{host, <<"multicast.", Host/binary>>},
{hosts, []},
{limits, [{local, []}, {remote, []}]},
+ {vcard, undefined},
{name, ?T("Multicast")}].
-export([hosts/1]).
-export([limits/1]).
-export([name/1]).
+-export([vcard/1]).
-spec access(gen_mod:opts() | global | binary()) -> 'all' | acl:acl().
access(Opts) when is_map(Opts) ->
name(Host) ->
gen_mod:get_module_opt(Host, mod_multicast, name).
+-spec vcard(gen_mod:opts() | global | binary()) -> 'undefined' | tuple().
+vcard(Opts) when is_map(Opts) ->
+ gen_mod:get_opt(vcard, Opts);
+vcard(Host) ->
+ gen_mod:get_module_opt(Host, mod_multicast, vcard).
+
mod_opt_type(shaper) ->
econf:shaper();
mod_opt_type(sndbuf) ->
- econf:pos_int().
+ econf:pos_int();
+mod_opt_type(vcard) ->
+ econf:vcard_temp().
mod_options(Host) ->
[{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
{ip, undefined},
{port, 7777},
{name, ?T("SOCKS5 Bytestreams")},
+ {vcard, undefined},
{max_connections, infinity},
{auth_type, anonymous},
{recbuf, 65536},
-export([server_host/1]).
-export([shaper/1]).
-export([sndbuf/1]).
+-export([vcard/1]).
-spec access(gen_mod:opts() | global | binary()) -> 'all' | acl:acl().
access(Opts) when is_map(Opts) ->
sndbuf(Host) ->
gen_mod:get_module_opt(Host, mod_proxy65, sndbuf).
+-spec vcard(gen_mod:opts() | global | binary()) -> 'undefined' | tuple().
+vcard(Opts) when is_map(Opts) ->
+ gen_mod:get_opt(vcard, Opts);
+vcard(Host) ->
+ gen_mod:get_module_opt(Host, mod_proxy65, vcard).
+
process_vcard(#iq{type = set, lang = Lang} = IQ) ->
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
-process_vcard(#iq{type = get, lang = Lang} = IQ) ->
- xmpp:make_iq_result(
- IQ, #vcard_temp{fn = <<"ejabberd/mod_proxy65">>,
- url = ejabberd_config:get_uri(),
- desc = misc:get_descr(Lang, ?T("ejabberd SOCKS5 Bytestreams module"))}).
+process_vcard(#iq{type = get, to = To, lang = Lang} = IQ) ->
+ ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
+ VCard = case mod_proxy65_opt:vcard(ServerHost) of
+ undefined ->
+ #vcard_temp{fn = <<"ejabberd/mod_proxy65">>,
+ url = ejabberd_config:get_uri(),
+ desc = misc:get_descr(
+ Lang, ?T("ejabberd SOCKS5 Bytestreams module"))};
+ V ->
+ V
+ end,
+ xmpp:make_iq_result(IQ, VCard).
-spec process_bytestreams(iq()) -> iq().
process_bytestreams(#iq{type = get, from = JID, to = To, lang = Lang} = IQ) ->
end.
-spec process_vcard(iq()) -> iq().
-process_vcard(#iq{type = get, lang = Lang} = IQ) ->
- xmpp:make_iq_result(IQ, iq_get_vcard(Lang));
+process_vcard(#iq{type = get, to = To, lang = Lang} = IQ) ->
+ ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
+ xmpp:make_iq_result(IQ, iq_get_vcard(ServerHost, Lang));
process_vcard(#iq{type = set, lang = Lang} = IQ) ->
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang)).
xmpp:make_error(IQ, Error)
end.
--spec iq_get_vcard(binary()) -> vcard_temp().
-iq_get_vcard(Lang) ->
- Desc = misc:get_descr(Lang, ?T("ejabberd Publish-Subscribe module")),
- #vcard_temp{fn = <<"ejabberd/mod_pubsub">>,
- url = ejabberd_config:get_uri(),
- desc = Desc}.
+-spec iq_get_vcard(binary(), binary()) -> vcard_temp().
+iq_get_vcard(ServerHost, Lang) ->
+ case mod_pubsub_opt:vcard(ServerHost) of
+ undefined ->
+ Desc = misc:get_descr(Lang, ?T("ejabberd Publish-Subscribe module")),
+ #vcard_temp{fn = <<"ejabberd/mod_pubsub">>,
+ url = ejabberd_config:get_uri(),
+ desc = Desc};
+ VCard ->
+ VCard
+ end.
-spec iq_pubsub(binary() | ljid(), atom(), iq()) ->
{result, pubsub()} | {error, stanza_error()}.
mod_opt_type(hosts) ->
econf:hosts();
mod_opt_type(db_type) ->
- econf:db_type(?MODULE).
+ econf:db_type(?MODULE);
+mod_opt_type(vcard) ->
+ econf:vcard_temp().
mod_options(Host) ->
[{access_createnode, all},
{host, <<"pubsub.", Host/binary>>},
{hosts, []},
{name, ?T("Publish-Subscribe")},
+ {vcard, undefined},
{ignore_pep_from_offline, true},
{last_item_cache, false},
{max_items_node, ?MAXITEMS},
-export([nodetree/1]).
-export([pep_mapping/1]).
-export([plugins/1]).
+-export([vcard/1]).
-spec access_createnode(gen_mod:opts() | global | binary()) -> 'all' | acl:acl().
access_createnode(Opts) when is_map(Opts) ->
plugins(Host) ->
gen_mod:get_module_opt(Host, mod_pubsub, plugins).
+-spec vcard(gen_mod:opts() | global | binary()) -> 'undefined' | tuple().
+vcard(Opts) when is_map(Opts) ->
+ gen_mod:get_opt(vcard, Opts);
+vcard(Host) ->
+ gen_mod:get_module_opt(Host, mod_pubsub, vcard).
+
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
-process_local_iq(#iq{type = get, lang = Lang} = IQ) ->
- xmpp:make_iq_result(
- IQ, #vcard_temp{fn = <<"ejabberd">>,
- url = ejabberd_config:get_uri(),
- desc = misc:get_descr(Lang, ?T("Erlang Jabber Server")),
- bday = <<"2002-11-16">>}).
+process_local_iq(#iq{type = get, to = To, lang = Lang} = IQ) ->
+ ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
+ VCard = case mod_vcard_opt:vcard(ServerHost) of
+ undefined ->
+ #vcard_temp{fn = <<"ejabberd">>,
+ url = ejabberd_config:get_uri(),
+ desc = misc:get_descr(Lang, ?T("Erlang Jabber Server")),
+ bday = <<"2002-11-16">>};
+ V ->
+ V
+ end,
+ xmpp:make_iq_result(IQ, VCard).
-spec process_sm_iq(iq()) -> iq().
process_sm_iq(#iq{type = set, lang = Lang, from = From} = IQ) ->
mod_opt_type(cache_missed) ->
econf:bool();
mod_opt_type(cache_life_time) ->
- econf:timeout(second, infinity).
+ econf:timeout(second, infinity);
+mod_opt_type(vcard) ->
+ econf:vcard_temp().
mod_options(Host) ->
[{allow_return_all, false},
{matches, 30},
{search, false},
{name, ?T("vCard User Search")},
+ {vcard, undefined},
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
{use_cache, ejabberd_option:use_cache(Host)},
{cache_size, ejabberd_option:cache_size(Host)},
-export([name/1]).
-export([search/1]).
-export([use_cache/1]).
+-export([vcard/1]).
-spec allow_return_all(gen_mod:opts() | global | binary()) -> boolean().
allow_return_all(Opts) when is_map(Opts) ->
use_cache(Host) ->
gen_mod:get_module_opt(Host, mod_vcard, use_cache).
+-spec vcard(gen_mod:opts() | global | binary()) -> 'undefined' | tuple().
+vcard(Opts) when is_map(Opts) ->
+ gen_mod:get_opt(vcard, Opts);
+vcard(Host) ->
+ gen_mod:get_module_opt(Host, mod_vcard, vcard).
+
erl_types:t_binary();
spec(hosts, 0, _, _) ->
erl_types:t_list(erl_types:t_binary());
+spec(vcard_temp, 0, _, _) ->
+ erl_types:t_sup([erl_types:t_atom(undefined),
+ erl_types:t_tuple()]);
spec(options, A, [Form|OForm], Mod) when A == 1; A == 2 ->
case erl_syntax:type(Form) of
map_expr ->