25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Convert XMPP codec specification to the new format

This commit is contained in:
Evgeniy Khramtsov 2013-06-14 02:34:45 +10:00 committed by Alexey Shchepin
parent f123263230
commit 8a5ec41279
4 changed files with 10556 additions and 10059 deletions

View File

@ -11,6 +11,7 @@
-compile(export_all). -compile(export_all).
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include("xml.hrl").
-include("ns.hrl"). -include("ns.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("xmpp_codec.hrl"). -include("xmpp_codec.hrl").
@ -82,7 +83,7 @@ end_per_testcase(_TestCase, _Config) ->
groups() -> groups() ->
[]. [].
%%all() -> [start_ejabberd, pubsub]. %%all() -> [start_ejabberd, vcard].
all() -> all() ->
[start_ejabberd, [start_ejabberd,
@ -134,7 +135,7 @@ connect(Config) ->
<<"1.0">> = xml:get_attr_s(<<"version">>, Attrs), <<"1.0">> = xml:get_attr_s(<<"version">>, Attrs),
#stream_features{sub_els = Fs} = recv(), #stream_features{sub_els = Fs} = recv(),
Mechs = lists:flatmap( Mechs = lists:flatmap(
fun(#sasl_mechanisms{mechanism = Ms}) -> fun(#sasl_mechanisms{list = Ms}) ->
Ms; Ms;
(_) -> (_) ->
[] []
@ -279,9 +280,9 @@ privacy(Config) ->
I2 = send(Config, I2 = send(Config,
#iq{type = set, #iq{type = set,
sub_els = [#privacy{ sub_els = [#privacy{
list = [#privacy_list{ lists = [#privacy_list{
name = <<"public">>, name = <<"public">>,
privacy_item = items =
[#privacy_item{ [#privacy_item{
type = jid, type = jid,
order = 3, order = 3,
@ -291,7 +292,7 @@ privacy(Config) ->
#iq{type = result, id = I2, sub_els = []} = recv(), #iq{type = result, id = I2, sub_els = []} = recv(),
_Push1 = #iq{type = set, id = PushI1, _Push1 = #iq{type = set, id = PushI1,
sub_els = [#privacy{ sub_els = [#privacy{
list = [#privacy_list{ lists = [#privacy_list{
name = <<"public">>}]}]} = recv(), name = <<"public">>}]}]} = recv(),
%% BUG: ejabberd replies on this result %% BUG: ejabberd replies on this result
%% TODO: this should be fixed in ejabberd %% TODO: this should be fixed in ejabberd
@ -306,7 +307,7 @@ privacy(Config) ->
#iq{type = result, id = I5, #iq{type = result, id = I5,
sub_els = [#privacy{default = <<"public">>, sub_els = [#privacy{default = <<"public">>,
active = <<"public">>, active = <<"public">>,
list = [#privacy_list{name = <<"public">>}]}]} = recv(), lists = [#privacy_list{name = <<"public">>}]}]} = recv(),
I6 = send(Config, I6 = send(Config,
#iq{type = set, sub_els = [#privacy{default = none}]}), #iq{type = set, sub_els = [#privacy{default = none}]}),
#iq{type = result, id = I6, sub_els = []} = recv(), #iq{type = result, id = I6, sub_els = []} = recv(),
@ -314,7 +315,7 @@ privacy(Config) ->
#iq{type = result, id = I7, sub_els = []} = recv(), #iq{type = result, id = I7, sub_els = []} = recv(),
I8 = send(Config, #iq{type = set, I8 = send(Config, #iq{type = set,
sub_els = [#privacy{ sub_els = [#privacy{
list = lists =
[#privacy_list{ [#privacy_list{
name = <<"public">>}]}]}), name = <<"public">>}]}]}),
#iq{type = result, id = I8, sub_els = []} = recv(), #iq{type = result, id = I8, sub_els = []} = recv(),
@ -323,7 +324,7 @@ privacy(Config) ->
%% TODO: this should be fixed in ejabberd %% TODO: this should be fixed in ejabberd
_Push2 = #iq{type = set, id = PushI2, _Push2 = #iq{type = set, id = PushI2,
sub_els = [#privacy{ sub_els = [#privacy{
list = [#privacy_list{ lists = [#privacy_list{
name = <<"public">>}]}]} = recv(), name = <<"public">>}]}]} = recv(),
disconnect(Config). disconnect(Config).
@ -333,19 +334,19 @@ blocking(Config) ->
I1 = send(Config, #iq{type = get, sub_els = [#block_list{}]}), I1 = send(Config, #iq{type = get, sub_els = [#block_list{}]}),
#iq{type = result, id = I1, sub_els = [#block_list{}]} = recv(), #iq{type = result, id = I1, sub_els = [#block_list{}]} = recv(),
I2 = send(Config, #iq{type = set, I2 = send(Config, #iq{type = set,
sub_els = [#block{block_item = [JID]}]}), sub_els = [#block{items = [JID]}]}),
#iq{type = result, id = I2, sub_els = []} = recv(), #iq{type = result, id = I2, sub_els = []} = recv(),
#iq{type = set, id = _, #iq{type = set, id = _,
sub_els = [#privacy{list = [#privacy_list{}]}]} = recv(), sub_els = [#privacy{lists = [#privacy_list{}]}]} = recv(),
#iq{type = set, id = _, #iq{type = set, id = _,
sub_els = [#block{block_item = [JID]}]} = recv(), sub_els = [#block{items = [JID]}]} = recv(),
I3 = send(Config, #iq{type = set, I3 = send(Config, #iq{type = set,
sub_els = [#unblock{block_item = [JID]}]}), sub_els = [#unblock{items = [JID]}]}),
#iq{type = result, id = I3, sub_els = []} = recv(), #iq{type = result, id = I3, sub_els = []} = recv(),
#iq{type = set, id = _, #iq{type = set, id = _,
sub_els = [#privacy{list = [#privacy_list{}]}]} = recv(), sub_els = [#privacy{lists = [#privacy_list{}]}]} = recv(),
#iq{type = set, id = _, #iq{type = set, id = _,
sub_els = [#unblock{block_item = [JID]}]} = recv(), sub_els = [#unblock{items = [JID]}]} = recv(),
disconnect(Config). disconnect(Config).
vcard(Config) -> vcard(Config) ->
@ -402,20 +403,6 @@ stats(Config) ->
disconnect(Config). disconnect(Config).
pubsub(Config) -> pubsub(Config) ->
true = is_feature_advertised(Config, ?NS_PUBSUB),
%% Get subscriptions
%% true = is_feature_advertised(Config, ?PUBSUB("retrieve-subscriptions")),
%% I1 = send(Config, #iq{type = get, to = pubsub_jid(Config),
%% sub_els = [#pubsub{subscriptions = {none, []}}]}),
%% #iq{type = result, id = I1,
%% sub_els = [#pubsub{subscriptions = {none, []}}]} = recv(),
%% %% Get affiliations
%% true = is_feature_advertised(Config, ?PUBSUB("retrieve-affiliations")),
%% I2 = send(Config, #iq{type = get, to = pubsub_jid(Config),
%% sub_els = [#pubsub{affiliations = []}]}),
%% #iq{type = result, id = I2,
%% sub_els = [#pubsub{affiliations = []}]} = recv(),
true = is_feature_advertised(Config, ?NS_PUBSUB), true = is_feature_advertised(Config, ?NS_PUBSUB),
%% Publish <presence/> element within node "presence" %% Publish <presence/> element within node "presence"
ItemID = randoms:get_string(), ItemID = randoms:get_string(),
@ -433,6 +420,23 @@ pubsub(Config) ->
sub_els = [#pubsub{subscribe = {Node, my_jid(Config)}}]}), sub_els = [#pubsub{subscribe = {Node, my_jid(Config)}}]}),
#message{sub_els = [#pubsub_event{}, #delay{}]} = recv(), #message{sub_els = [#pubsub_event{}, #delay{}]} = recv(),
#iq{type = result, id = I2} = recv(), #iq{type = result, id = I2} = recv(),
%% Get subscriptions
true = is_feature_advertised(Config, ?PUBSUB("retrieve-subscriptions")),
I3 = send(Config, #iq{type = get, to = pubsub_jid(Config),
sub_els = [#pubsub{subscriptions = {none, []}}]}),
#iq{type = result, id = I3,
sub_els =
[#pubsub{subscriptions =
{none, [#pubsub_subscription{node = Node}]}}]} = recv(),
%% Get affiliations
true = is_feature_advertised(Config, ?PUBSUB("retrieve-affiliations")),
I4 = send(Config, #iq{type = get, to = pubsub_jid(Config),
sub_els = [#pubsub{affiliations = []}]}),
#iq{type = result, id = I4,
sub_els = [#pubsub{
affiliations =
[#pubsub_affiliation{node = Node, type = owner}]}]}
= recv(),
disconnect(Config). disconnect(Config).
auth_md5(Config) -> auth_md5(Config) ->
@ -460,7 +464,7 @@ auth_SASL(Mech, Config) ->
?config(user, Config), ?config(user, Config),
?config(server, Config), ?config(server, Config),
?config(password, Config)), ?config(password, Config)),
send(Config, #sasl_auth{mechanism = Mech, cdata = Response}), send(Config, #sasl_auth{mechanism = Mech, text = Response}),
wait_auth_SASL_result([{sasl, SASL}|Config]). wait_auth_SASL_result([{sasl, SASL}|Config]).
wait_auth_SASL_result(Config) -> wait_auth_SASL_result(Config) ->
@ -475,9 +479,9 @@ wait_auth_SASL_result(Config) ->
<<"1.0">> = xml:get_attr_s(<<"version">>, Attrs), <<"1.0">> = xml:get_attr_s(<<"version">>, Attrs),
#stream_features{} = recv(), #stream_features{} = recv(),
Config; Config;
#sasl_challenge{cdata = ClientIn} -> #sasl_challenge{text = ClientIn} ->
{Response, SASL} = (?config(sasl, Config))(ClientIn), {Response, SASL} = (?config(sasl, Config))(ClientIn),
send(Config, #sasl_response{cdata = Response}), send(Config, #sasl_response{text = Response}),
Config1 = proplists:delete(sasl, Config), Config1 = proplists:delete(sasl, Config),
wait_auth_SASL_result([{sasl, SASL}|Config1]); wait_auth_SASL_result([{sasl, SASL}|Config1]);
#sasl_failure{} -> #sasl_failure{} ->
@ -498,11 +502,24 @@ recv() ->
receive receive
{'$gen_event', {xmlstreamelement, El}} -> {'$gen_event', {xmlstreamelement, El}} ->
ct:log("recv: ~p", [El]), ct:log("recv: ~p", [El]),
xmpp_codec:decode(El); xmpp_codec:decode(fix_ns(El));
{'$gen_event', Event} -> {'$gen_event', Event} ->
Event Event
end. end.
fix_ns(#xmlel{name = Tag, attrs = Attrs} = El)
when Tag == <<"stream:features">>; Tag == <<"stream:error">> ->
NewAttrs = [{<<"xmlns">>, <<"http://etherx.jabber.org/streams">>}
|lists:keydelete(<<"xmlns">>, 1, Attrs)],
El#xmlel{attrs = NewAttrs};
fix_ns(#xmlel{name = Tag, attrs = Attrs} = El)
when Tag == <<"message">>; Tag == <<"iq">>; Tag == <<"presence">> ->
NewAttrs = [{<<"xmlns">>, <<"jabber:client">>}
|lists:keydelete(<<"xmlns">>, 1, Attrs)],
El#xmlel{attrs = NewAttrs};
fix_ns(El) ->
El.
send_text(Config, Text) -> send_text(Config, Text) ->
ejabberd_socket:send(?config(socket, Config), Text). ejabberd_socket:send(?config(socket, Config), Text).

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +1,48 @@
-record(last, {seconds, text}). -record(last, {seconds, text}).
-record(version, {name, version, os}). -record(version,
{version_name, version_ver, version_os}).
-record(roster, {item = [], ver}).
-record(roster_item, -record(roster_item,
{jid, name, groups = [], subscription = none, ask}). {jid, name, groups = [], subscription = none, ask}).
-record(roster, {item = [], ver}).
-record(privacy_item, -record(privacy_item,
{order, action, type, value, stanza}). {order, action, type, value, stanza}).
-record(privacy, {list = [], default, active}). -record(privacy_list, {name, items = []}).
-record(privacy_list, {name, privacy_item = []}). -record(privacy, {lists = [], default, active}).
-record(block, {block_item = []}). -record(block, {items = []}).
-record(unblock, {block_item = []}). -record(unblock, {items = []}).
-record(block_list, {}). -record(block_list, {}).
-record(identity, {category, type, name}).
-record(disco_info, -record(disco_info,
{node, identity = [], feature = [], xdata = []}). {node, identity = [], feature = [], xdata = []}).
-record(disco_items, {node, items = []}).
-record(disco_item, {jid, name, node}). -record(disco_item, {jid, name, node}).
-record(disco_items, {node, items = []}).
-record(private, {sub_els = []}). -record(private, {sub_els = []}).
-record(bookmark_conference, -record(bookmark_conference,
{name, jid, autojoin = false, nick, password}). {name, jid, autojoin = false, nick, password}).
-record(bookmark_storage, {conference = [], url = []}).
-record(bookmark_url, {name, url}). -record(bookmark_url, {name, url}).
-record(stats, {stat = []}). -record(bookmark_storage, {conference = [], url = []}).
-record(stat, {name, units, value, error = []}). -record(stat, {name, units, value, error = []}).
-record(stats, {stat = []}).
-record(iq, -record(iq,
{id, type, lang, from, to, error, sub_els = []}). {id, type, lang, from, to, error, sub_els = []}).
@ -51,27 +54,27 @@
{id, type, lang, from, to, show, status = [], priority, {id, type, lang, from, to, show, status = [], priority,
error, sub_els = []}). error, sub_els = []}).
-record(error, {error_type, by, reason, text}). -record(gone, {uri}).
-record(redirect, {cdata}). -record(redirect, {uri}).
-record(gone, {cdata}). -record(error, {type, by, reason, text}).
-record(bind, {jid, resource}). -record(bind, {jid, resource}).
-record(sasl_auth, {mechanism, cdata}). -record(sasl_auth, {mechanism, text}).
-record(sasl_abort, {}). -record(sasl_abort, {}).
-record(sasl_challenge, {cdata}). -record(sasl_challenge, {text}).
-record(sasl_response, {cdata}). -record(sasl_response, {text}).
-record(sasl_success, {cdata}). -record(sasl_success, {text}).
-record(sasl_failure, {reason, text}). -record(sasl_failure, {reason, text = []}).
-record(sasl_mechanisms, {mechanism = []}). -record(sasl_mechanisms, {list = []}).
-record(starttls, {required = false}). -record(starttls, {required = false}).
@ -89,7 +92,7 @@
-record(caps, {hash, node, ver}). -record(caps, {hash, node, ver}).
-record(register, {}). -record(register_feature, {}).
-record(session, {}). -record(session, {}).
@ -97,9 +100,9 @@
-record(time, {tzo, utc}). -record(time, {tzo, utc}).
-record(stream_error, {reason, text}). -record('see-other-host', {host}).
-record('see-other-host', {cdata}). -record(stream_error, {reason, text}).
-record(vcard_name, -record(vcard_name,
{family, given, middle, prefix, suffix}). {family, given, middle, prefix, suffix}).
@ -136,14 +139,16 @@
-record(vcard_key, {type, cred}). -record(vcard_key, {type, cred}).
-record(vcard_agent, {vcard, extval}).
-record(vcard, -record(vcard,
{version, fn, n, nickname, photo, bday, adr = [], {version, fn, n, nickname, photo, bday, adr = [],
label = [], tel = [], email = [], jabberid, mailer, tz, label = [], tel = [], email = [], jabberid, mailer, tz,
geo, title, role, logo, org, categories = [], note, geo, title, role, logo, org, categories = [], note,
prodid, rev, 'sort-string', sound, uid, url, class, key, prodid, agent, rev, sort_string, sound, uid, url, class,
desc}). key, desc}).
-record(xfield, -record(xdata_field,
{label, type, var, required = false, desc, values = [], {label, type, var, required = false, desc, values = [],
options = []}). options = []}).
@ -158,7 +163,12 @@
-record(pubsub_item, {id, sub_els = []}). -record(pubsub_item, {id, sub_els = []}).
-record(pubsub_items, -record(pubsub_items,
{node, max_items, subid, item = []}). {node, max_items, subid, items = []}).
-record(pubsub_event_item, {id, node, publisher}).
-record(pubsub_event_items,
{node, retract = [], items = []}).
-record(pubsub_event, {items = []}). -record(pubsub_event, {items = []}).

File diff suppressed because it is too large Load Diff