From 1a320baad896b4f0d7ae6d5170f75d70a9b1020b Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Thu, 11 Sep 2014 18:18:20 +0200 Subject: Add tests for Client State Indication support --- tools/xmpp_codec.erl | 192 +++++++++++++++++++++++++++++++++++++++ tools/xmpp_codec.hrl | 246 +++++++++++++++++++++++++++----------------------- tools/xmpp_codec.spec | 41 +++++++++ 3 files changed, 368 insertions(+), 111 deletions(-) (limited to 'tools') diff --git a/tools/xmpp_codec.erl b/tools/xmpp_codec.erl index 2b9372973..d106fa8f4 100644 --- a/tools/xmpp_codec.erl +++ b/tools/xmpp_codec.erl @@ -47,6 +47,14 @@ decode({xmlel, _name, _attrs, _} = _el, Opts) -> decode_feature_sm(<<"urn:xmpp:sm:2">>, IgnoreEls, _el); {<<"sm">>, <<"urn:xmpp:sm:3">>} -> decode_feature_sm(<<"urn:xmpp:sm:3">>, IgnoreEls, _el); + {<<"inactive">>, <<"urn:xmpp:csi:0">>} -> + decode_csi_inactive(<<"urn:xmpp:csi:0">>, IgnoreEls, + _el); + {<<"active">>, <<"urn:xmpp:csi:0">>} -> + decode_csi_active(<<"urn:xmpp:csi:0">>, IgnoreEls, _el); + {<<"csi">>, <<"urn:xmpp:csi:0">>} -> + decode_feature_csi(<<"urn:xmpp:csi:0">>, IgnoreEls, + _el); {<<"sent">>, <<"urn:xmpp:carbons:2">>} -> decode_carbons_sent(<<"urn:xmpp:carbons:2">>, IgnoreEls, _el); @@ -163,6 +171,26 @@ decode({xmlel, _name, _attrs, _} = _el, Opts) -> _el); {<<"delay">>, <<"urn:xmpp:delay">>} -> decode_delay(<<"urn:xmpp:delay">>, IgnoreEls, _el); + {<<"paused">>, + <<"http://jabber.org/protocol/chatstates">>} -> + decode_chatstate_paused(<<"http://jabber.org/protocol/chatstates">>, + IgnoreEls, _el); + {<<"inactive">>, + <<"http://jabber.org/protocol/chatstates">>} -> + decode_chatstate_inactive(<<"http://jabber.org/protocol/chatstates">>, + IgnoreEls, _el); + {<<"gone">>, + <<"http://jabber.org/protocol/chatstates">>} -> + decode_chatstate_gone(<<"http://jabber.org/protocol/chatstates">>, + IgnoreEls, _el); + {<<"composing">>, + <<"http://jabber.org/protocol/chatstates">>} -> + decode_chatstate_composing(<<"http://jabber.org/protocol/chatstates">>, + IgnoreEls, _el); + {<<"active">>, + <<"http://jabber.org/protocol/chatstates">>} -> + decode_chatstate_active(<<"http://jabber.org/protocol/chatstates">>, + IgnoreEls, _el); {<<"headers">>, <<"http://jabber.org/protocol/shim">>} -> decode_shim_headers(<<"http://jabber.org/protocol/shim">>, @@ -998,6 +1026,9 @@ is_known_tag({xmlel, _name, _attrs, _} = _el) -> {<<"enable">>, <<"urn:xmpp:sm:3">>} -> true; {<<"sm">>, <<"urn:xmpp:sm:2">>} -> true; {<<"sm">>, <<"urn:xmpp:sm:3">>} -> true; + {<<"inactive">>, <<"urn:xmpp:csi:0">>} -> true; + {<<"active">>, <<"urn:xmpp:csi:0">>} -> true; + {<<"csi">>, <<"urn:xmpp:csi:0">>} -> true; {<<"sent">>, <<"urn:xmpp:carbons:2">>} -> true; {<<"received">>, <<"urn:xmpp:carbons:2">>} -> true; {<<"private">>, <<"urn:xmpp:carbons:2">>} -> true; @@ -1074,6 +1105,21 @@ is_known_tag({xmlel, _name, _attrs, _} = _el) -> true; {<<"x">>, <<"jabber:x:delay">>} -> true; {<<"delay">>, <<"urn:xmpp:delay">>} -> true; + {<<"paused">>, + <<"http://jabber.org/protocol/chatstates">>} -> + true; + {<<"inactive">>, + <<"http://jabber.org/protocol/chatstates">>} -> + true; + {<<"gone">>, + <<"http://jabber.org/protocol/chatstates">>} -> + true; + {<<"composing">>, + <<"http://jabber.org/protocol/chatstates">>} -> + true; + {<<"active">>, + <<"http://jabber.org/protocol/chatstates">>} -> + true; {<<"headers">>, <<"http://jabber.org/protocol/shim">>} -> true; @@ -1856,6 +1902,26 @@ encode({pubsub, _, _, _, _, _, _, _, _} = Pubsub) -> encode({shim, _} = Headers) -> encode_shim_headers(Headers, [{<<"xmlns">>, <<"http://jabber.org/protocol/shim">>}]); +encode({chatstate_active} = Active) -> + encode_chatstate_active(Active, + [{<<"xmlns">>, + <<"http://jabber.org/protocol/chatstates">>}]); +encode({chatstate_composing} = Composing) -> + encode_chatstate_composing(Composing, + [{<<"xmlns">>, + <<"http://jabber.org/protocol/chatstates">>}]); +encode({chatstate_gone} = Gone) -> + encode_chatstate_gone(Gone, + [{<<"xmlns">>, + <<"http://jabber.org/protocol/chatstates">>}]); +encode({chatstate_inactive} = Inactive) -> + encode_chatstate_inactive(Inactive, + [{<<"xmlns">>, + <<"http://jabber.org/protocol/chatstates">>}]); +encode({chatstate_paused} = Paused) -> + encode_chatstate_paused(Paused, + [{<<"xmlns">>, + <<"http://jabber.org/protocol/chatstates">>}]); encode({delay, _, _} = Delay) -> encode_delay(Delay, [{<<"xmlns">>, <<"urn:xmpp:delay">>}]); @@ -1926,6 +1992,14 @@ encode({carbons_received, _} = Received) -> encode({carbons_sent, _} = Sent) -> encode_carbons_sent(Sent, [{<<"xmlns">>, <<"urn:xmpp:carbons:2">>}]); +encode({feature_csi, _} = Csi) -> + encode_feature_csi(Csi, []); +encode({csi_active} = Active) -> + encode_csi_active(Active, + [{<<"xmlns">>, <<"urn:xmpp:csi:0">>}]); +encode({csi_inactive} = Inactive) -> + encode_csi_inactive(Inactive, + [{<<"xmlns">>, <<"urn:xmpp:csi:0">>}]); encode({feature_sm, _} = Sm) -> encode_feature_sm(Sm, []); encode({sm_enable, _, _, _} = Enable) -> @@ -2084,6 +2158,16 @@ get_ns({pubsub, _, _, _, _, _, _, _, _}) -> <<"http://jabber.org/protocol/pubsub">>; get_ns({shim, _}) -> <<"http://jabber.org/protocol/shim">>; +get_ns({chatstate_active}) -> + <<"http://jabber.org/protocol/chatstates">>; +get_ns({chatstate_composing}) -> + <<"http://jabber.org/protocol/chatstates">>; +get_ns({chatstate_gone}) -> + <<"http://jabber.org/protocol/chatstates">>; +get_ns({chatstate_inactive}) -> + <<"http://jabber.org/protocol/chatstates">>; +get_ns({chatstate_paused}) -> + <<"http://jabber.org/protocol/chatstates">>; get_ns({delay, _, _}) -> <<"urn:xmpp:delay">>; get_ns({legacy_delay, _, _}) -> <<"jabber:x:delay">>; get_ns({streamhost, _, _, _}) -> @@ -2115,6 +2199,9 @@ get_ns({carbons_private}) -> <<"urn:xmpp:carbons:2">>; get_ns({carbons_received, _}) -> <<"urn:xmpp:carbons:2">>; get_ns({carbons_sent, _}) -> <<"urn:xmpp:carbons:2">>; +get_ns({feature_csi, _}) -> <<"urn:xmpp:csi:0">>; +get_ns({csi_active}) -> <<"urn:xmpp:csi:0">>; +get_ns({csi_inactive}) -> <<"urn:xmpp:csi:0">>; get_ns(_) -> <<>>. dec_int(Val) -> dec_int(Val, infinity, infinity). @@ -2272,6 +2359,11 @@ pp(pubsub, 8) -> [subscriptions, affiliations, publish, subscribe, unsubscribe, options, items, retract]; pp(shim, 1) -> [headers]; +pp(chatstate_active, 0) -> []; +pp(chatstate_composing, 0) -> []; +pp(chatstate_gone, 0) -> []; +pp(chatstate_inactive, 0) -> []; +pp(chatstate_paused, 0) -> []; pp(delay, 2) -> [stamp, from]; pp(legacy_delay, 2) -> [stamp, from]; pp(streamhost, 3) -> [jid, host, port]; @@ -2298,6 +2390,9 @@ pp(carbons_enable, 0) -> []; pp(carbons_private, 0) -> []; pp(carbons_received, 1) -> [forwarded]; pp(carbons_sent, 1) -> [forwarded]; +pp(feature_csi, 1) -> [xmlns]; +pp(csi_active, 0) -> []; +pp(csi_inactive, 0) -> []; pp(feature_sm, 1) -> [xmlns]; pp(sm_enable, 3) -> [max, resume, xmlns]; pp(sm_enabled, 5) -> [id, location, max, resume, xmlns]; @@ -3268,6 +3363,54 @@ encode_feature_sm_attr_xmlns(undefined, _acc) -> _acc; encode_feature_sm_attr_xmlns(_val, _acc) -> [{<<"xmlns">>, _val} | _acc]. +decode_csi_inactive(__TopXMLNS, __IgnoreEls, + {xmlel, <<"inactive">>, _attrs, _els}) -> + {csi_inactive}. + +encode_csi_inactive({csi_inactive}, _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"inactive">>, _attrs, _els}. + +decode_csi_active(__TopXMLNS, __IgnoreEls, + {xmlel, <<"active">>, _attrs, _els}) -> + {csi_active}. + +encode_csi_active({csi_active}, _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"active">>, _attrs, _els}. + +decode_feature_csi(__TopXMLNS, __IgnoreEls, + {xmlel, <<"csi">>, _attrs, _els}) -> + Xmlns = decode_feature_csi_attrs(__TopXMLNS, _attrs, + undefined), + {feature_csi, Xmlns}. + +decode_feature_csi_attrs(__TopXMLNS, + [{<<"xmlns">>, _val} | _attrs], _Xmlns) -> + decode_feature_csi_attrs(__TopXMLNS, _attrs, _val); +decode_feature_csi_attrs(__TopXMLNS, [_ | _attrs], + Xmlns) -> + decode_feature_csi_attrs(__TopXMLNS, _attrs, Xmlns); +decode_feature_csi_attrs(__TopXMLNS, [], Xmlns) -> + decode_feature_csi_attr_xmlns(__TopXMLNS, Xmlns). + +encode_feature_csi({feature_csi, Xmlns}, + _xmlns_attrs) -> + _els = [], + _attrs = encode_feature_csi_attr_xmlns(Xmlns, + _xmlns_attrs), + {xmlel, <<"csi">>, _attrs, _els}. + +decode_feature_csi_attr_xmlns(__TopXMLNS, undefined) -> + undefined; +decode_feature_csi_attr_xmlns(__TopXMLNS, _val) -> _val. + +encode_feature_csi_attr_xmlns(undefined, _acc) -> _acc; +encode_feature_csi_attr_xmlns(_val, _acc) -> + [{<<"xmlns">>, _val} | _acc]. + decode_carbons_sent(__TopXMLNS, __IgnoreEls, {xmlel, <<"sent">>, _attrs, _els}) -> Forwarded = decode_carbons_sent_els(__TopXMLNS, @@ -5355,6 +5498,55 @@ encode_delay_attr_from(undefined, _acc) -> _acc; encode_delay_attr_from(_val, _acc) -> [{<<"from">>, enc_jid(_val)} | _acc]. +decode_chatstate_paused(__TopXMLNS, __IgnoreEls, + {xmlel, <<"paused">>, _attrs, _els}) -> + {chatstate_paused}. + +encode_chatstate_paused({chatstate_paused}, + _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"paused">>, _attrs, _els}. + +decode_chatstate_inactive(__TopXMLNS, __IgnoreEls, + {xmlel, <<"inactive">>, _attrs, _els}) -> + {chatstate_inactive}. + +encode_chatstate_inactive({chatstate_inactive}, + _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"inactive">>, _attrs, _els}. + +decode_chatstate_gone(__TopXMLNS, __IgnoreEls, + {xmlel, <<"gone">>, _attrs, _els}) -> + {chatstate_gone}. + +encode_chatstate_gone({chatstate_gone}, _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"gone">>, _attrs, _els}. + +decode_chatstate_composing(__TopXMLNS, __IgnoreEls, + {xmlel, <<"composing">>, _attrs, _els}) -> + {chatstate_composing}. + +encode_chatstate_composing({chatstate_composing}, + _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"composing">>, _attrs, _els}. + +decode_chatstate_active(__TopXMLNS, __IgnoreEls, + {xmlel, <<"active">>, _attrs, _els}) -> + {chatstate_active}. + +encode_chatstate_active({chatstate_active}, + _xmlns_attrs) -> + _els = [], + _attrs = _xmlns_attrs, + {xmlel, <<"active">>, _attrs, _els}. + decode_shim_headers(__TopXMLNS, __IgnoreEls, {xmlel, <<"headers">>, _attrs, _els}) -> Headers = decode_shim_headers_els(__TopXMLNS, diff --git a/tools/xmpp_codec.hrl b/tools/xmpp_codec.hrl index 549c6fb1b..6e142414f 100644 --- a/tools/xmpp_codec.hrl +++ b/tools/xmpp_codec.hrl @@ -8,6 +8,8 @@ -record(text, {lang :: binary(), data :: binary()}). +-record(chatstate_paused, {}). + -record(streamhost, {jid :: any(), host :: binary(), port = 1080 :: non_neg_integer()}). @@ -24,6 +26,8 @@ jid :: any(), subid :: binary()}). +-record(csi_inactive, {}). + -record(ping, {}). -record(delay, {stamp :: any(), @@ -57,6 +61,8 @@ resume = false :: any(), xmlns :: binary()}). +-record(chatstate_gone, {}). + -record(starttls_failure, {}). -record(sasl_challenge, {text :: any()}). @@ -123,14 +129,20 @@ -record(sasl_response, {text :: any()}). +-record(chatstate_inactive, {}). + -record(pubsub_subscribe, {node :: binary(), jid :: any()}). +-record(chatstate_composing, {}). + -record(sasl_auth, {mechanism :: binary(), text :: any()}). -record(p1_push, {}). +-record(feature_csi, {xmlns :: binary()}). + -record(legacy_delay, {stamp :: binary(), from :: any()}). @@ -220,6 +232,8 @@ -record(block_list, {}). +-record(csi_active, {}). + -record(xdata_field, {label :: binary(), type :: 'boolean' | 'fixed' | 'hidden' | 'jid-multi' | 'jid-single' | 'list-multi' | 'list-single' | 'text-multi' | 'text-private' | 'text-single', var :: binary(), @@ -255,6 +269,8 @@ mode = tcp :: 'tcp' | 'udp', sid :: binary()}). +-record(chatstate_active, {}). + -record(vcard_org, {name :: binary(), units = [] :: [binary()]}). @@ -475,114 +491,122 @@ -record(time, {tzo :: any(), utc :: any()}). --type xmpp_element() :: #session{} | - #compression{} | - #pubsub_subscription{} | - #version{} | - #pubsub_affiliation{} | - #muc_admin{} | - #sm_a{} | - #carbons_sent{} | - #p1_rebind{} | - #sasl_abort{} | - #carbons_received{} | - #pubsub_retract{} | - #compressed{} | - #block_list{} | - #'see-other-host'{} | - #starttls_proceed{} | - #sm_resumed{} | - #forwarded{} | - #privacy_list{} | - #text{} | - #vcard_org{} | - #feature_sm{} | - #pubsub_item{} | - #roster_item{} | - #pubsub_event_item{} | - #muc_item{} | - #shim{} | - #caps{} | - #muc{} | - #stream_features{} | - #stats{} | - #pubsub_items{} | - #pubsub_event_items{} | - #disco_items{} | - #pubsub_options{} | - #starttls{} | - #sasl_mechanisms{} | - #sasl_success{} | - #compress{} | - #bytestreams{} | - #vcard_key{} | - #identity{} | - #legacy_delay{} | - #muc_user_destroy{} | - #muc_owner_destroy{} | - #privacy{} | - #delay{} | - #muc_history{} | - #bookmark_url{} | - #vcard_email{} | - #vcard_label{} | - #vcard_tel{} | - #disco_info{} | - #vcard_logo{} | - #vcard_geo{} | - #vcard_photo{} | - #muc_owner{} | - #pubsub{} | - #sm_r{} | - #muc_actor{} | - #error{} | - #stream_error{} | - #feature_register{} | - #roster{} | - #muc_user{} | - #vcard_adr{} | - #register{} | - #muc_invite{} | - #carbons_disable{} | - #bookmark_conference{} | - #time{} | - #sasl_response{} | - #pubsub_subscribe{} | - #presence{} | - #message{} | - #sm_enable{} | - #starttls_failure{} | - #sasl_challenge{} | - #gone{} | - #private{} | - #compress_failure{} | - #sasl_failure{} | - #bookmark_storage{} | - #vcard_name{} | - #sm_resume{} | - #carbons_enable{} | - #carbons_private{} | - #pubsub_unsubscribe{} | - #muc_decline{} | - #sasl_auth{} | - #p1_push{} | - #pubsub_publish{} | - #unblock{} | - #p1_ack{} | - #block{} | - #xdata{} | - #iq{} | - #last{} | - #redirect{} | - #sm_enabled{} | - #pubsub_event{} | - #vcard_sound{} | - #streamhost{} | - #stat{} | - #xdata_field{} | - #bind{} | - #sm_failed{} | - #vcard{} | - #ping{} | - #disco_item{} | - #privacy_item{}. +-type xmpp_codec_type() :: #session{} | + #compression{} | + #pubsub_subscription{} | + #version{} | + #pubsub_affiliation{} | + #muc_admin{} | + #sm_a{} | + #carbons_sent{} | + #p1_rebind{} | + #sasl_abort{} | + #carbons_received{} | + #pubsub_retract{} | + #compressed{} | + #block_list{} | + #'see-other-host'{} | + #starttls_proceed{} | + #sm_resumed{} | + #forwarded{} | + #privacy_list{} | + #text{} | + #vcard_org{} | + #feature_sm{} | + #pubsub_item{} | + #roster_item{} | + #pubsub_event_item{} | + #muc_item{} | + #shim{} | + #pubsub_event_items{} | + #disco_items{} | + #pubsub_options{} | + #sasl_success{} | + #compress{} | + #bytestreams{} | + #vcard_key{} | + #identity{} | + #feature_csi{} | + #legacy_delay{} | + #muc_user_destroy{} | + #muc_owner_destroy{} | + #privacy{} | + #delay{} | + #muc_history{} | + #bookmark_url{} | + #vcard_email{} | + #vcard_label{} | + #vcard_tel{} | + #vcard_logo{} | + #disco_info{} | + #vcard_geo{} | + #vcard_photo{} | + #muc_owner{} | + #pubsub{} | + #sm_r{} | + #muc_actor{} | + #error{} | + #stream_error{} | + #feature_register{} | + #roster{} | + #muc_user{} | + #vcard_adr{} | + #register{} | + #csi_active{} | + #muc_invite{} | + #carbons_disable{} | + #chatstate_active{} | + #bookmark_conference{} | + #time{} | + #sasl_response{} | + #chatstate_inactive{} | + #pubsub_subscribe{} | + #presence{} | + #message{} | + #sm_enable{} | + #chatstate_gone{} | + #starttls_failure{} | + #sasl_challenge{} | + #gone{} | + #private{} | + #compress_failure{} | + #sasl_failure{} | + #bookmark_storage{} | + #vcard_name{} | + #sm_resume{} | + #carbons_enable{} | + #carbons_private{} | + #pubsub_unsubscribe{} | + #csi_inactive{} | + #muc_decline{} | + #sasl_auth{} | + #p1_push{} | + #pubsub_publish{} | + #unblock{} | + #p1_ack{} | + #block{} | + #xdata{} | + #iq{} | + #last{} | + #redirect{} | + #sm_enabled{} | + #pubsub_event{} | + #vcard_sound{} | + #chatstate_paused{} | + #streamhost{} | + #stat{} | + #xdata_field{} | + #bind{} | + #sm_failed{} | + #vcard{} | + #chatstate_composing{} | + #ping{} | + #disco_item{} | + #privacy_item{} | + #caps{} | + #muc{} | + #stream_features{} | + #stats{} | + #pubsub_items{} | + #starttls{} | + #sasl_mechanisms{}. diff --git a/tools/xmpp_codec.spec b/tools/xmpp_codec.spec index 4d218839b..c5d9013ed 100644 --- a/tools/xmpp_codec.spec +++ b/tools/xmpp_codec.spec @@ -1757,6 +1757,31 @@ result = {shim, '$headers'}, refs = [#ref{name = shim_header, label = '$headers'}]}). +-xml(chatstate_active, + #elem{name = <<"active">>, + xmlns = <<"http://jabber.org/protocol/chatstates">>, + result = {chatstate_active}}). + +-xml(chatstate_composing, + #elem{name = <<"composing">>, + xmlns = <<"http://jabber.org/protocol/chatstates">>, + result = {chatstate_composing}}). + +-xml(chatstate_gone, + #elem{name = <<"gone">>, + xmlns = <<"http://jabber.org/protocol/chatstates">>, + result = {chatstate_gone}}). + +-xml(chatstate_inactive, + #elem{name = <<"inactive">>, + xmlns = <<"http://jabber.org/protocol/chatstates">>, + result = {chatstate_inactive}}). + +-xml(chatstate_paused, + #elem{name = <<"paused">>, + xmlns = <<"http://jabber.org/protocol/chatstates">>, + result = {chatstate_paused}}). + -xml(delay, #elem{name = <<"delay">>, xmlns = <<"urn:xmpp:delay">>, @@ -2070,6 +2095,22 @@ refs = [#ref{name = forwarded, min = 1, max = 1, label = '$forwarded'}]}). +-xml(feature_csi, + #elem{name = <<"csi">>, + xmlns = <<"urn:xmpp:csi:0">>, + result = {feature_csi, '$xmlns'}, + attrs = [#attr{name = <<"xmlns">>}]}). + +-xml(csi_active, + #elem{name = <<"active">>, + xmlns = <<"urn:xmpp:csi:0">>, + result = {csi_active}}). + +-xml(csi_inactive, + #elem{name = <<"inactive">>, + xmlns = <<"urn:xmpp:csi:0">>, + result = {csi_inactive}}). + -xml(feature_sm, #elem{name = <<"sm">>, xmlns = [<<"urn:xmpp:sm:2">>, <<"urn:xmpp:sm:3">>], -- cgit v1.2.3